Skip to content

Commit

Permalink
test: Modify tests for provisionK8sOptions and provisionNode to use o…
Browse files Browse the repository at this point in the history
…pts and new constructors

Signed-off-by: aerosouund <[email protected]>
  • Loading branch information
aerosouund committed Jul 11, 2024
1 parent 76143c3 commit 85ee3f7
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions cluster-provision/gocli/cmd/run_test.go
Original file line number Diff line number Diff line change
@@ -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()))
}

Expand All @@ -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)
}

0 comments on commit 85ee3f7

Please sign in to comment.