Skip to content

Commit

Permalink
Samsung ODF: move label and taints test to the lso package (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
elenagerman authored Aug 17, 2024
1 parent 07e5e78 commit 1b88669
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ package vcorecommon

import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/openshift-kni/eco-goinfra/pkg/mco"
"github.com/openshift-kni/eco-goinfra/pkg/nodes"
"github.com/openshift-kni/eco-gotests/tests/system-tests/internal/remote"
"github.com/openshift-kni/eco-gotests/tests/system-tests/vcore/internal/ocpcli"

"github.com/openshift-kni/eco-goinfra/pkg/lso"
"github.com/openshift-kni/eco-gotests/tests/system-tests/internal/await"
lsov1 "github.com/openshift/local-storage-operator/api/v1"
Expand Down Expand Up @@ -35,6 +42,9 @@ func VerifyLSOSuite() {

It("Verify localvolumeset instance exists",
Label("lso"), reportxml.ID("74918"), VerifyLocalVolumeSet)

It("Apply taints to the ODF nodes",
Label("lso"), reportxml.ID("74916"), LabelODFNodesAndSetTaints)
})
}

Expand Down Expand Up @@ -124,3 +134,61 @@ func VerifyLocalVolumeSet(ctx SpecContext) {
metav1.ListOptions{LabelSelector: pvLabel})
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create persistentVolumes due to %v", err))
} // func VerifyLocalVolumeSet (ctx SpecContext)

// LabelODFNodesAndSetTaints asserts ODF nodes taints configuration.
func LabelODFNodesAndSetTaints(ctx SpecContext) {
glog.V(vcoreparams.VCoreLogLevel).Infof("Create new mcp %s", VCoreConfig.OdfMCPName)
odfMcp := mco.NewMCPBuilder(APIClient, VCoreConfig.OdfMCPName)

if !odfMcp.Exists() {
odfMCPTemplateName := "odf-mcp.yaml"
varsToReplace := make(map[string]interface{})
varsToReplace["MCPName"] = VCoreConfig.OdfMCPName

workingDir, err := os.Getwd()
Expect(err).ToNot(HaveOccurred(), err)

templateDir := filepath.Join(workingDir, vcoreparams.TemplateFilesFolder)

err = ocpcli.ApplyConfig(
filepath.Join(templateDir, odfMCPTemplateName),
filepath.Join(vcoreparams.ConfigurationFolderPath, odfMCPTemplateName),
varsToReplace)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))

err = odfMcp.WaitForUpdate(3 * time.Minute)
Expect(err).To(BeNil(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))
}

for _, odfNode := range odfNodesList {
currentODFNode, err := nodes.Pull(APIClient, odfNode)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to retrieve node %s object due to %v",
odfNode, err))

glog.V(vcoreparams.VCoreLogLevel).Infof("Change node %s role to the %s", odfNode, VCoreConfig.OdfMCPName)

_, err = currentODFNode.
WithNewLabel("custom-label/used", "").
WithNewLabel("cluster.ocs.openshift.io/openshift-storage", "").
WithNewLabel("node-role.kubernetes.io/infra", "").
WithNewLabel("node-role.kubernetes.io/odf", "").
RemoveLabel("node-role.kubernetes.io/worker", "").Update()
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to update labels for the node %s due to %v",
odfNode, err))

glog.V(vcoreparams.VCoreLogLevel).Infof("Insure taints applyed to the %s node", odfNode)

applyTaintsCmd := fmt.Sprintf(
"oc adm taint node %s node.ocs.openshift.io/storage=true:NoSchedule --overwrite=true --kubeconfig=%s",
odfNode, VCoreConfig.KubeconfigPath)
_, err = remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, applyTaintsCmd)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to execute %s script due to %v",
applyTaintsCmd, err))
}

glog.V(vcoreparams.VCoreLogLevel).Infof("Wait for the mcp %s to update", VCoreConfig.OdfMCPName)
time.Sleep(3 * time.Second)

err := odfMcp.WaitForUpdate(3 * time.Minute)
Expect(err).To(BeNil(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))
} // func LabelODFNodesAndSetTaints (ctx SpecContext)
67 changes: 0 additions & 67 deletions tests/system-tests/vcore/internal/vcorecommon/odf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ package vcorecommon

import (
"fmt"
"os"
"path/filepath"

"github.com/openshift-kni/eco-goinfra/pkg/mco"

"time"

"github.com/openshift-kni/eco-goinfra/pkg/configmap"
Expand All @@ -16,7 +11,6 @@ import (

"github.com/openshift-kni/eco-goinfra/pkg/console"
"github.com/openshift-kni/eco-goinfra/pkg/deployment"
"github.com/openshift-kni/eco-goinfra/pkg/nodes"
"github.com/openshift-kni/eco-goinfra/pkg/pod"
"github.com/openshift-kni/eco-goinfra/pkg/reportxml"
ocsoperatorv1 "github.com/red-hat-storage/ocs-operator/api/v1"
Expand Down Expand Up @@ -57,9 +51,6 @@ func VerifyODFSuite() {
It("Verify ODF console enabled",
Label("odf"), reportxml.ID("74917"), VerifyODFConsoleConfig)

It("Apply taints to the ODF nodes",
Label("odf"), reportxml.ID("74916"), VerifyODFTaints)

It("Verify ODF operator StorageSystem configuration procedure",
Label("odf"), reportxml.ID("59487"), VerifyODFStorageSystemConfig)

Expand Down Expand Up @@ -133,64 +124,6 @@ func VerifyODFConsoleConfig(ctx SpecContext) {
time.Sleep(5 * time.Minute)
} // func VerifyODFConsoleConfig (ctx SpecContext)

// VerifyODFTaints asserts ODF nodes taints configuration.
func VerifyODFTaints(ctx SpecContext) {
glog.V(vcoreparams.VCoreLogLevel).Infof("Create new mcp %s", VCoreConfig.OdfMCPName)
odfMcp := mco.NewMCPBuilder(APIClient, VCoreConfig.OdfMCPName)

if !odfMcp.Exists() {
odfMCPTemplateName := "odf-mcp.yaml"
varsToReplace := make(map[string]interface{})
varsToReplace["MCPName"] = VCoreConfig.OdfMCPName

workingDir, err := os.Getwd()
Expect(err).ToNot(HaveOccurred(), err)

templateDir := filepath.Join(workingDir, vcoreparams.TemplateFilesFolder)

err = ocpcli.ApplyConfig(
filepath.Join(templateDir, odfMCPTemplateName),
filepath.Join(vcoreparams.ConfigurationFolderPath, odfMCPTemplateName),
varsToReplace)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))

err = odfMcp.WaitForUpdate(3 * time.Minute)
Expect(err).To(BeNil(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))
}

for _, odfNode := range odfNodesList {
currentODFNode, err := nodes.Pull(APIClient, odfNode)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to retrieve node %s object due to %v",
odfNode, err))

glog.V(vcoreparams.VCoreLogLevel).Infof("Change node %s role to the %s", odfNode, VCoreConfig.OdfMCPName)

_, err = currentODFNode.
WithNewLabel("custom-label/used", "").
WithNewLabel("cluster.ocs.openshift.io/openshift-storage", "").
WithNewLabel("node-role.kubernetes.io/infra", "").
WithNewLabel("node-role.kubernetes.io/odf", "").
RemoveLabel("node-role.kubernetes.io/worker", "").Update()
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to update labels for the node %s due to %v",
odfNode, err))

glog.V(vcoreparams.VCoreLogLevel).Infof("Insure taints applyed to the %s node", odfNode)

applyTaintsCmd := fmt.Sprintf(
"oc adm taint node %s node.ocs.openshift.io/storage=true:NoSchedule --overwrite=true --kubeconfig=%s",
odfNode, VCoreConfig.KubeconfigPath)
_, err = remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, applyTaintsCmd)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to execute %s script due to %v",
applyTaintsCmd, err))
}

glog.V(vcoreparams.VCoreLogLevel).Infof("Wait for the mcp %s to update", VCoreConfig.OdfMCPName)
time.Sleep(3 * time.Second)

err := odfMcp.WaitForUpdate(3 * time.Minute)
Expect(err).To(BeNil(), fmt.Sprintf("Failed to create mcp %s", VCoreConfig.OdfMCPName))
} // func VerifyODFTaints (ctx SpecContext)

// VerifyODFStorageSystemConfig asserts ODF storage cluster system successfully configured.
func VerifyODFStorageSystemConfig(ctx SpecContext) {
glog.V(vcoreparams.VCoreLogLevel).Infof("Cleanup StorageSystem and StorageCluster config")
Expand Down

0 comments on commit 1b88669

Please sign in to comment.