diff --git a/cluster-provision/gocli/cmd/run_test.go b/cluster-provision/gocli/cmd/run_test.go index bc55c6c97e..ef97ac5155 100644 --- a/cluster-provision/gocli/cmd/run_test.go +++ b/cluster-provision/gocli/cmd/run_test.go @@ -1,12 +1,19 @@ package cmd import ( - "fmt" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" "kubevirt.io/kubevirtci/cluster-provision/gocli/cmd/nodesconfig" + "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/pkg/k8s" kubevirtcimocks "kubevirt.io/kubevirtci/cluster-provision/gocli/utils/mock" ) @@ -14,38 +21,43 @@ var _ = Describe("Node Provisioning", func() { var ( mockCtrl *gomock.Controller sshClient *kubevirtcimocks.MockSSHClient + reactors []k8s.ReactorConfig + k8sClient k8s.K8sDynamicClient ) BeforeEach(func() { mockCtrl = gomock.NewController(GinkgoT()) sshClient = kubevirtcimocks.NewMockSSHClient(mockCtrl) + reactors = []k8s.ReactorConfig{ + k8s.NewReactorConfig("create", "istiooperators", istio.IstioReactor), + k8s.NewReactorConfig("create", "cephblockpools", rookceph.CephReactor), + k8s.NewReactorConfig("create", "persistentvolumeclaims", nfscsi.NfsCsiReactor), + } + + k8sClient = k8s.NewTestClient(reactors...) }) AfterEach(func() { mockCtrl.Finish() sshClient = nil + k8sClient = nil }) Describe("ProvisionNode", func() { It("should execute the correct commands", func() { - n := nodesconfig.NewNodeLinuxConfig(1, "k8s-1.30", "", "512M", "", false, true, true, true, true, true) - cmds := []string{ - "sudo mkdir -p /var/lib/etcd", - "sudo test -d /var/lib/etcd", - fmt.Sprintf("sudo mount -t tmpfs -o size=%s tmpfs /var/lib/etcd", n.EtcdSize), - "sudo df -h /var/lib/etcd", - "/scripts/realtime.sh", - "touch /home/vagrant/single_stack", - "touch /home/vagrant/enable_audit", - "-s -- --vendor 8086:2668 < /scripts/bind_device_to_vfio.sh", - "-s -- --vendor 8086:2415 < /scripts/bind_device_to_vfio.sh", - "/scripts/psa.sh", - "/scripts/node01.sh", + linuxConfigFuncs := []nodesconfig.LinuxConfigFunc{ + nodesconfig.WithEtcdInMemory(true), + nodesconfig.WithEtcdSize("512M"), + nodesconfig.WithPSA(true), } - for _, cmd := range cmds { - sshClient.EXPECT().Command(cmd).Return(nil) - } + n := nodesconfig.NewNodeLinuxConfig(1, "k8s-1.30", linuxConfigFuncs) + + etcdinmemory.AddExpectCalls(sshClient, "512M") + bindvfio.AddExpectCalls(sshClient, "8086:2668") + bindvfio.AddExpectCalls(sshClient, "8086:2415") + psa.AddExpectCalls(sshClient) + node01.AddExpectCalls(sshClient) err := provisionNode(sshClient, n) Expect(err).NotTo(HaveOccurred()) @@ -54,19 +66,21 @@ var _ = Describe("Node Provisioning", func() { Describe("ProvisionNodeK8sOpts", func() { It("should execute the correct K8s option commands", func() { - 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 { - sshClient.EXPECT().Command(cmd).Return(nil) - } + istio.AddExpectCalls(sshClient) + aaq.AddExpectCalls(sshClient) - err := provisionK8sOptions(sshClient, n) + err := provisionK8sOptions(sshClient, k8sClient, n, "k8s-1.30") Expect(err).NotTo(HaveOccurred()) }) })