From 85ee3f763b7065c7ec4d63becc09d5f9d6dfc146 Mon Sep 17 00:00:00 2001 From: aerosouund Date: Thu, 11 Jul 2024 21:36:58 +0300 Subject: [PATCH] test: Modify tests for provisionK8sOptions and provisionNode to use opts and new constructors Signed-off-by: aerosouund --- cluster-provision/gocli/cmd/run_test.go | 68 +++++++++++++++---------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/cluster-provision/gocli/cmd/run_test.go b/cluster-provision/gocli/cmd/run_test.go index 5ec1002aa1..951fd37518 100644 --- a/cluster-provision/gocli/cmd/run_test.go +++ b/cluster-provision/gocli/cmd/run_test.go @@ -1,20 +1,35 @@ package cmd import ( - "fmt" - "github.com/stretchr/testify/suite" "go.uber.org/mock/gomock" nodesconfig "kubevirt.io/kubevirtci/cluster-provision/gocli/cmd/config" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/aaq" + bindvfio "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/bind-vfio" + etcdinmemory "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/etcd" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/istio" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/nfscsi" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/node01" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/psa" + "kubevirt.io/kubevirtci/cluster-provision/gocli/opts/rookceph" + k8s "kubevirt.io/kubevirtci/cluster-provision/gocli/utils/k8s" kubevirtcimocks "kubevirt.io/kubevirtci/cluster-provision/gocli/utils/mock" ) type TestSuite struct { suite.Suite sshClient *kubevirtcimocks.MockSSHClient + k8sClient *k8s.K8sDynamicClientImpl } func (ts *TestSuite) SetupTest() { + reactors := []k8s.ReactorConfig{ + k8s.NewReactorConfig("create", "istiooperators", istio.IstioReactor), + k8s.NewReactorConfig("create", "cephblockpools", rookceph.CephReactor), + k8s.NewReactorConfig("create", "persistentvolumeclaims", nfscsi.NfsCsiReactor), + } + + ts.k8sClient = k8s.NewTestClient(reactors...) ts.sshClient = kubevirtcimocks.NewMockSSHClient(gomock.NewController(ts.T())) } @@ -23,42 +38,39 @@ func (ts *TestSuite) TearDownTest() { } func (ts *TestSuite) TestProvisionNode() { - n := nodesconfig.NewNodeLinuxConfig(1, "k8s-1.30", "", "512M", "", false, true, true, true, true, true) - cmds := []string{ - "mkdir -p /var/lib/etcd", - "test -d /var/lib/etcd", - fmt.Sprintf("mount -t tmpfs -o size=%s tmpfs /var/lib/etcd", n.EtcdSize), - "df -h /var/lib/etcd", - "/scripts/realtime.sh", - "-s -- --vendor 8086:2668 < /scripts/bind_device_to_vfio.sh", - "-s -- --vendor 8086:2415 < /scripts/bind_device_to_vfio.sh", - "touch /home/vagrant/single_stack", - "touch /home/vagrant/enable_audit", - "/scripts/psa.sh", - "/scripts/node01.sh", + linuxConfigFuncs := []nodesconfig.LinuxConfigFunc{ + nodesconfig.WithEtcdInMemory(true), + nodesconfig.WithEtcdSize("512M"), + nodesconfig.WithPSA(true), } - for _, cmd := range cmds { - ts.sshClient.EXPECT().SSH(cmd).Return(nil) - } + n := nodesconfig.NewNodeLinuxConfig(1, "k8s-1.30", linuxConfigFuncs) + + etcdinmemory.AddExpectCalls(ts.sshClient, "512M") + bindvfio.AddExpectCalls(ts.sshClient, "8086:2668") + bindvfio.AddExpectCalls(ts.sshClient, "8086:2415") + psa.AddExpectCalls(ts.sshClient) + node01.AddExpectCalls(ts.sshClient) err := provisionNode(ts.sshClient, n) ts.NoError(err) } func (ts *TestSuite) TestProvisionNodeK8sOpts() { - n := nodesconfig.NewNodeK8sConfig(true, true, true, true, true, true) - cmds := []string{ - "/scripts/rook-ceph.sh", - "/scripts/nfs-csi.sh", - "/scripts/istio.sh", - "-s -- --alertmanager true --grafana true < /scripts/prometheus.sh", + k8sConfs := []nodesconfig.K8sConfigFunc{ + nodesconfig.WithCeph(true), + nodesconfig.WithPrometheus(true), + nodesconfig.WithAlertmanager(true), + nodesconfig.WithGrafana(true), + nodesconfig.WithIstio(true), + nodesconfig.WithNfsCsi(true), + nodesconfig.WithAAQ(true), } + n := nodesconfig.NewNodeK8sConfig(k8sConfs) - for _, cmd := range cmds { - ts.sshClient.EXPECT().SSH(cmd).Return(nil) - } + istio.AddExpectCalls(ts.sshClient) + aaq.AddExpectCalls(ts.sshClient) - err := provisionK8sOptions(ts.sshClient, n) + err := provisionK8sOptions(ts.sshClient, ts.k8sClient, n, "k8s-1.30") ts.NoError(err) }