132 lines
3.7 KiB
Go
132 lines
3.7 KiB
Go
package k8s_exec
|
|
|
|
import (
|
|
"agent-go/utils"
|
|
"fmt"
|
|
"github.com/magiconair/properties/assert"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFindAppNotHealthyOrRestartCountGreaterThanN(t *testing.T) {
|
|
|
|
deploymentRestartCountGreaterThanN := FindAppNotHealthyOrRestartCountGreaterThanN("devflight", 10)
|
|
deploymentRestartCountGreaterThanN = FilterAllCmiiAppSoft(deploymentRestartCountGreaterThanN)
|
|
|
|
for _, deploymentInterface := range deploymentRestartCountGreaterThanN {
|
|
println()
|
|
utils.BeautifulPrint(deploymentInterface)
|
|
println()
|
|
}
|
|
|
|
}
|
|
|
|
func TestFindDeploymentReplicasSmallerThanN(t *testing.T) {
|
|
|
|
deploymentReplicasSmallerThanN := FindDeploymentReplicasSmallerThanN("devflight", 0)
|
|
|
|
for _, deploymentInterface := range deploymentReplicasSmallerThanN {
|
|
println()
|
|
utils.BeautifulPrint(deploymentInterface)
|
|
println()
|
|
}
|
|
|
|
}
|
|
|
|
func TestGetCmiiAllDeploymentFromEnv(t *testing.T) {
|
|
|
|
BackupAllDeploymentFromEnv("uavms")
|
|
|
|
}
|
|
|
|
func TestBackupAllCmiiDeploymentToMap(t *testing.T) {
|
|
backendMap, frontendMap := BackupAllCmiiDeploymentToMap("demo")
|
|
|
|
utils.BeautifulPrint(backendMap)
|
|
utils.BeautifulPrint(frontendMap)
|
|
|
|
}
|
|
|
|
func TestUpdateCmiiDeploymentImageTag(t *testing.T) {
|
|
|
|
//tag := UpdateCmiiDeploymentImageTag("devflight", "cmii-uav-depotautoreturn", "123sdsa45678")
|
|
//tag := UpdateCmiiDeploymentImageTag("demo", "cmii-uav-platform", "5.2.0-011101")
|
|
tag := UpdateCmiiDeploymentImageTag("demo", "cmii-uav-waypoint", "5.2.0-011102")
|
|
//tag := UpdateCmiiDeploymentImageTag("uavms", "uavms-lowaltitude-platform", "5.1.0-011103")
|
|
|
|
assert.Equal(t, tag, true, "update image tag failed !")
|
|
}
|
|
|
|
func TestRollBackCmiiDeploymentFromUpdateLog(t *testing.T) {
|
|
updateLog := RollBackCmiiDeploymentFromUpdateLog("2024-01-10-14-37-07 uavcloud-devflight cmii-uav-depotautoreturn 12345678 123sdsa45678")
|
|
|
|
assert.Equal(t, updateLog, true, "roll back from update log failed !")
|
|
}
|
|
|
|
func TestRestartCmiiBackendDeployment(t *testing.T) {
|
|
|
|
RestartCmiiBackendDeployment("devflight")
|
|
}
|
|
|
|
func TestRestartCmiiFrontendDeployment(t *testing.T) {
|
|
RestartCmiiFrontendDeployment("devflight")
|
|
}
|
|
|
|
func TestFindDeploymentNotHealthy(t *testing.T) {
|
|
notHealthy := FindDeploymentNotHealthy("devflight")
|
|
|
|
notHealthy = FilterAllCmiiAppSoft(notHealthy)
|
|
for _, deploymentInterface := range notHealthy {
|
|
utils.BeautifulPrint(deploymentInterface)
|
|
}
|
|
}
|
|
|
|
func TestFindAllNodeNotHealthy(t *testing.T) {
|
|
start := time.Now()
|
|
allNodeNotHealthy := FindAllNodeNotHealthy()
|
|
elapsed := time.Since(start).Milliseconds()
|
|
fmt.Printf("执行耗时: %d ms\n", elapsed)
|
|
|
|
for _, nodeInterface := range allNodeNotHealthy {
|
|
println()
|
|
utils.BeautifulPrint(nodeInterface)
|
|
println()
|
|
}
|
|
|
|
}
|
|
|
|
func TestFindPodNotHealthy(t *testing.T) {
|
|
podNotHealthy := FindPodNotHealthy("int")
|
|
podNotHealthy = FilterAllCmiiPodSoft(podNotHealthy)
|
|
|
|
for _, podInterface := range podNotHealthy {
|
|
t.Logf("[%s] [%s]", podInterface.Name, podInterface.PodPhase)
|
|
}
|
|
}
|
|
|
|
func TestFindPodNotHealthy_And_Delete(t *testing.T) {
|
|
podNotHealthy := FindPodNotHealthy("int")
|
|
podNotHealthy = FilterAllCmiiPodSoft(podNotHealthy)
|
|
|
|
for _, podInterface := range podNotHealthy {
|
|
t.Logf("[%s] [%s]", podInterface.Name, podInterface.PodPhase)
|
|
podDelete := CmiiOperator.PodDelete(podInterface.Namespace, podInterface.Name)
|
|
|
|
assert.Equal(t, podDelete, true, "delete of ", podInterface.Namespace, podInterface.Name, " failed !")
|
|
}
|
|
|
|
}
|
|
|
|
func TestFilterAllCmiiAppStrict(t *testing.T) {
|
|
allInterface := CmiiOperator.DeploymentAllInterface("devflight")
|
|
FilterAllCmiiAppStrict(allInterface)
|
|
}
|
|
|
|
func TestRestartDeploymentFromList(t *testing.T) {
|
|
allInterface := CmiiOperator.DeploymentAllInterface("devflight")
|
|
allInterface = FilterAllCmiiAppSoft(allInterface)
|
|
|
|
RestartDeploymentFromList(allInterface)
|
|
|
|
}
|