Ai
5 Star 6 Fork 4

zstackio/zstack-vyos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zsn_test.go 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
shixin.ruan 提交于 2024-07-08 14:31 +08:00 . [root]: use openeuler image for vpc
package plugin
import (
"bytes"
"io/ioutil"
"reflect"
"text/template"
"zstack-vyos/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("zsn_test", func() {
It("[REPLACE_VYOS]: pre test env", func() {
utils.InitLog(utils.GetVyosUtLogDir()+"zsn_test.log", false)
utils.CleanTestEnvForUT()
SetKeepalivedStatusForUt(KeepAlivedStatus_Master)
utils.SetEnableVyosCmdForUT(false)
cleanUpCrondConfig()
})
It("[REPLACE_VYOS]: test enable zsn-agent", func() {
cmd := &setDistributedRoutingReq{Enabled: true}
_ = setDistributedRouting(cmd)
//Expect(err).To(BeNil(), "setDistributedRouting error: %+v", err)
checkZsnCronJob(true)
})
It("[REPLACE_VYOS]: test disable zsn-agent", func() {
cmd := &setDistributedRoutingReq{Enabled: false}
_ = setDistributedRouting(cmd)
//Expect(err).To(BeNil(), "setDistributedRouting error: %+v", err)
checkZsnCronJob(false)
utils.SetEnableVyosCmdForUT(true)
utils.CleanTestEnvForUT()
})
})
func checkZsnCronJob(enable bool) {
if enable {
testMap := utils.CronjobMap{}
zsnJob := utils.NewCronjob().SetId(6).SetCommand(utils.Cronjob_file_zsn).SetMinute("*/1")
cronJobMap := utils.CronjobMap{6: zsnJob}
err := utils.JsonLoadConfig("/home/vyos/zvr/.zstack_config/cronjob", &testMap)
Expect(err).To(BeNil(), "JsonLoadConfig cronjob error : %+v", err)
ret := reflect.DeepEqual(cronJobMap, testMap)
Expect(ret).To(BeTrue(), "attr map should equal")
buf := bytes.Buffer{}
tmpl, err := template.New("crond.conf").Parse(utils.CrondTemplate)
Expect(err).To(BeNil(), "template parse error: %+v", err)
err = tmpl.Execute(&buf, cronJobMap)
Expect(err).To(BeNil(), "template execute error: %+v", err)
err = ioutil.WriteFile("/tmp/zsn_test", buf.Bytes(), 0664)
Expect(err).To(BeNil(), "template write error: %+v", err)
checkDiffConfig(utils.CROND_CONFIG_FILE, "/tmp/zsn_test")
} else {
testMap := utils.CronjobMap{}
err := utils.JsonLoadConfig("/home/vyos/zvr/.zstack_config/cronjob", &testMap)
Expect(err).To(BeNil(), "JsonLoadConfig cronjob error : %+v", err)
Expect(len(testMap)).To(Equal(0), "zsn cronjob should be nil")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zstackio/zstack-vyos.git
git@gitee.com:zstackio/zstack-vyos.git
zstackio
zstack-vyos
zstack-vyos
master

搜索帮助