[agent-operator] - cmii deploy part
This commit is contained in:
213
agent-operator/image/CmiiImageOperator_test.go
Normal file
213
agent-operator/image/CmiiImageOperator_test.go
Normal file
@@ -0,0 +1,213 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"wdd.io/agent-common/assert"
|
||||
"wdd.io/agent-common/image"
|
||||
"wdd.io/agent-common/utils"
|
||||
"wdd.io/agent-operator/config"
|
||||
"wdd.io/agent-operator/real_project/zjjt"
|
||||
)
|
||||
|
||||
func TestGetRunningContainer(t *testing.T) {
|
||||
|
||||
allContainer := GetRunningContainer()
|
||||
|
||||
for _, container := range allContainer {
|
||||
utils.BeautifulPrint(container)
|
||||
}
|
||||
|
||||
}
|
||||
func TestGetAllContainer(t *testing.T) {
|
||||
|
||||
allContainer := GetAllContainer()
|
||||
|
||||
for _, container := range allContainer {
|
||||
utils.BeautifulPrint(container)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageGetAll(t *testing.T) {
|
||||
imageGetAll := GetAll()
|
||||
|
||||
for _, summary := range imageGetAll {
|
||||
utils.BeautifulPrint(summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageGetByName(t *testing.T) {
|
||||
image := "harbor.cdcyy.com.cn/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
imageGetByName := GetByName(image)
|
||||
|
||||
utils.BeautifulPrint(imageGetByName)
|
||||
}
|
||||
|
||||
func TestImageDelete(t *testing.T) {
|
||||
image := "harbor.cdcyy.com.cn/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
imageDelete := Delete(image)
|
||||
|
||||
for _, item := range imageDelete {
|
||||
utils.BeautifulPrint(item)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImagePullFromCmiiHarbor(t *testing.T) {
|
||||
image := "harbor.cdcyy.com.cn/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
|
||||
pullFromCmiiHarbor := PullFromCmiiHarbor(image)
|
||||
defer pullFromCmiiHarbor.Close()
|
||||
|
||||
scanner := bufio.NewScanner(pullFromCmiiHarbor)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if strings.Contains(line, "\"status\":\"Pulling from") {
|
||||
fmt.Println(line)
|
||||
}
|
||||
if strings.Contains(line, "Status: Image is up to date for") {
|
||||
fmt.Println(line)
|
||||
}
|
||||
}
|
||||
|
||||
//var fs uintptr
|
||||
//
|
||||
//tools.DisplayJSONMessagesStream(pullFromCmiiHarbor, os.Stdout, fs, true, func(message tools.JSONMessage) {
|
||||
//
|
||||
//})
|
||||
}
|
||||
|
||||
func TestImagePushToOctopusKindHarbor(t *testing.T) {
|
||||
|
||||
// re-tag
|
||||
image := "harbor.cdcyy.com.cn/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
newTag := "10.250.0.100:8033/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
target := TagFromSourceToTarget(image, newTag)
|
||||
assert.Equal(t, target, true, "image re-tag error !")
|
||||
|
||||
// push
|
||||
pushResult := UploadToOctopusKindHarbor(newTag)
|
||||
defer pushResult.Close()
|
||||
|
||||
scanner := bufio.NewScanner(pushResult)
|
||||
for scanner.Scan() {
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("image push success!")
|
||||
}
|
||||
|
||||
func TestImageLoadFromFile(t *testing.T) {
|
||||
|
||||
loadFromFile := LoadFromGzipFilePath("/root/cmlc=cmii=srs=v5.0.195.tar.gz")
|
||||
|
||||
assert.Equal(t, loadFromFile, true, "image load error !")
|
||||
}
|
||||
|
||||
func TestImageSaveToTarGZ(t *testing.T) {
|
||||
image := "harbor.cdcyy.com.cn/cmii/cmii-uav-gateway:4.1.6-beta"
|
||||
|
||||
imageSaveToTarGZ, _ := SaveToGzipFile(image, "/home/wdd/IdeaProjects/ProjectOctopus/cmii_operator/log")
|
||||
|
||||
assert.Equal(t, imageSaveToTarGZ, true, "image save to tar gz file error !")
|
||||
}
|
||||
|
||||
func TestImageFullNameToGzipFileName(t *testing.T) {
|
||||
|
||||
test := []string{
|
||||
"bitnami/redis:6.2.6-debian-10-r0",
|
||||
"simonrupf/chronyd:0.4.3",
|
||||
"harbor.cdcyy.com.cn/cmii/cmii-rtsp-operator:v4.1.0",
|
||||
"harbor.cdcyy.com.cn/cmii/ossrs/srs:v4.0.136",
|
||||
"ossrs/srs:v4.0.136",
|
||||
"mongo:5.0",
|
||||
"bitnami/minio:2023.5.4",
|
||||
"busybox:latest",
|
||||
"busybox",
|
||||
}
|
||||
|
||||
test = append(test, config.MiddlewareAmd64...)
|
||||
|
||||
for _, s := range test {
|
||||
gzipFileName := image.ImageFullNameToGzipFileName(s)
|
||||
fmt.Println(gzipFileName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImagePruneAllCmiiImages(t *testing.T) {
|
||||
|
||||
errorRemoveImageNameList := PruneAllCmiiImages()
|
||||
|
||||
utils.BeautifulPrintListWithTitle(errorRemoveImageNameList, "CMII Image Prune Error")
|
||||
}
|
||||
|
||||
func TestImageTagFromSourceToTarget(t *testing.T) {
|
||||
|
||||
sourceImageName := "ossrs/srs:v5.0.195"
|
||||
targetImageName := "harbor.wdd.io:8033/cmii/srs:v5.0.195"
|
||||
|
||||
if TagFromSourceToTarget(sourceImageName, targetImageName) {
|
||||
pushResult := UploadToOctopusKindHarbor(targetImageName)
|
||||
defer pushResult.Close()
|
||||
|
||||
scanner := bufio.NewScanner(pushResult)
|
||||
for scanner.Scan() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSaveSpecificImageToGzipFile(t *testing.T) {
|
||||
|
||||
imageGzipFilePathPrefix := "/root/ai_image/"
|
||||
|
||||
imageFullNameList := []string{
|
||||
"harbor.cdcyy.com.cn/cmii/cmlc-ai/cmlc-ai-operator:v5.2.0-t4-no-dino",
|
||||
}
|
||||
|
||||
for _, imageFullName := range imageFullNameList {
|
||||
result := PullFromCmiiHarbor(imageFullName)
|
||||
if result == nil {
|
||||
log.ErrorF("image pull error ! => %s", imageFullName)
|
||||
return
|
||||
}
|
||||
scc := bufio.NewScanner(result)
|
||||
for scc.Scan() {
|
||||
line := scc.Text()
|
||||
if strings.Contains(line, "\"status\":\"Pulling from") {
|
||||
fmt.Println(line)
|
||||
}
|
||||
if strings.Contains(line, "Status: Image is up to date for") {
|
||||
fmt.Println(line)
|
||||
}
|
||||
}
|
||||
|
||||
// image pull success
|
||||
log.InfoF("image should have pulled successful ! => %s", imageFullName)
|
||||
ok, _ := SaveToGzipFile(imageFullName, imageGzipFilePathPrefix)
|
||||
if !ok {
|
||||
log.ErrorF("image save to gzip file error ! => %s", imageFullName)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestConvertCmiiImageMapFromGzipFolder(t *testing.T) {
|
||||
|
||||
versionMap := CmiiImageMapFromGzipFolder(OfflineImageGzipFolderPrefix)
|
||||
|
||||
utils.BeautifulPrint(versionMap)
|
||||
}
|
||||
|
||||
func TestFrontendBackendImageMapFromCmiiImageMap(t *testing.T) {
|
||||
frontendImageVersionMap, backendImageVersionMap, _ := FrontendBackendSrsImageMapFromCmiiImageMap(zjjt.CmiiImageMap)
|
||||
|
||||
utils.BeautifulPrint(frontendImageVersionMap)
|
||||
utils.BeautifulPrint(backendImageVersionMap)
|
||||
}
|
||||
Reference in New Issue
Block a user