Skip to content

Commit

Permalink
vcore: fix verification statement (#166)
Browse files Browse the repository at this point in the history
* vcore: fix verification statement

* vcore: move mcp creation and odf node labeling to the upper level
  • Loading branch information
elenagerman authored Aug 18, 2024
1 parent 1b88669 commit 70dda82
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfigPool
metadata:
name: "{{ .MCPName }}"
name: '{{ .MCPName }}'
spec:
machineConfigSelector:
matchExpressions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ 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 @@ -42,9 +35,6 @@ 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 @@ -134,61 +124,3 @@ 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)
24 changes: 24 additions & 0 deletions tests/system-tests/vcore/internal/vcorecommon/odf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

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

"github.com/openshift-kni/eco-goinfra/pkg/configmap"
"github.com/openshift-kni/eco-goinfra/pkg/storage"
"github.com/openshift-kni/eco-gotests/tests/system-tests/internal/remote"
Expand Down Expand Up @@ -51,6 +53,9 @@ 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 @@ -124,6 +129,25 @@ 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("Apply taints to the ODF nodes")

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

glog.V(vcoreparams.VCoreLogLevel).Infof("Insure taints applyed to the %s node", odfNode.Definition.Name)
applyTaintsCmd := fmt.Sprintf(
"oc adm taint node %s node.ocs.openshift.io/storage=true:NoSchedule --overwrite=true --kubeconfig=%s",
odfNode.Definition.Name, 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))
}
} // 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 70dda82

Please sign in to comment.