Skip to content

Commit

Permalink
adjustment for the remote cmd and homedir (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
elenagerman authored Jul 20, 2024
1 parent 20c17ca commit e9bbaa3
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 101 deletions.
24 changes: 15 additions & 9 deletions tests/system-tests/internal/mirroring/mirror-images.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func MirrorImageToTheLocalRegistry(
user,
pass,
combinedPullSecretFile,
localRegistryRepository,
homeDir string) (string, string, error) {
localRegistryRepository string) (string, string, error) {
if originServerURL == "" {
glog.V(100).Infof("The originServerURL is empty")

Expand Down Expand Up @@ -69,7 +68,7 @@ func MirrorImageToTheLocalRegistry(

if _, err = os.Stat(combinedPullSecretFile); errors.Is(err, os.ErrNotExist) {
localRegistryPullSecretFilePath, err =
CopyRegistryAuthLocally(host, user, pass, combinedPullSecretFile, homeDir)
CopyRegistryAuthLocally(host, user, pass, combinedPullSecretFile)

if err != nil {
return "", "", err
Expand All @@ -92,18 +91,25 @@ func MirrorImageToTheLocalRegistry(
}

// CopyRegistryAuthLocally copy mirror registry authentication files locally.
func CopyRegistryAuthLocally(host, user, pass, combinedPullSecretFile, homeDir string) (string, error) {
out, err := remote.ExecCmdOnHost(host, user, pass, "pwd")
func CopyRegistryAuthLocally(host, user, pass, combinedPullSecretFile string) (string, error) {
remoteHostHomeDir, err := remote.ExecCmdOnHost(host, user, pass, "pwd")
if err != nil {
return "", err
}

remoteUserHomeDir := strings.Trim(out, "\n")
remoteHostHomeDir = strings.Trim(remoteHostHomeDir, "\n")

remoteRegistryPullSecretFilePath := filepath.Join(remoteUserHomeDir, combinedPullSecretFile)
localHostHomeDirBytes, err := shell.ExecuteCmd("pwd")
if err != nil {
return "", err
}

localHostHomeDir := string(localHostHomeDirBytes)

remoteRegistryPullSecretFilePath := filepath.Join(remoteHostHomeDir, combinedPullSecretFile)
localRegistryPullSecretFilePath := filepath.Join("/tmp", combinedPullSecretFile)
remoteDockerDirectoryPath := filepath.Join(remoteUserHomeDir, ".docker")
localDockerDirectoryPath := filepath.Join(homeDir, ".docker")
remoteDockerDirectoryPath := filepath.Join(remoteHostHomeDir, ".docker")
localDockerDirectoryPath := filepath.Join(localHostHomeDir, ".docker")

err = remote.ScpFileFrom(
remoteRegistryPullSecretFilePath,
Expand Down
34 changes: 15 additions & 19 deletions tests/system-tests/internal/ocpcli/ocpcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func ApplyConfig(

cfgFilePath := filepath.Join(destinationDir, finalFileName)

applyCmd := fmt.Sprintf("oc apply -f %s", cfgFilePath)
kubeConfigURL := os.Getenv("KUBECONFIG")

applyCmd := fmt.Sprintf("oc apply -f %s --kubeconfig=%s", cfgFilePath, kubeConfigURL)
_, err = shell.ExecuteCmd(applyCmd)

if err != nil {
Expand All @@ -117,7 +119,9 @@ func CreateConfig(

cfgFilePath := filepath.Join(destinationDir, finalFileName)

applyCmd := fmt.Sprintf("oc create -f %s", cfgFilePath)
kubeConfigURL := os.Getenv("KUBECONFIG")

applyCmd := fmt.Sprintf("oc create -f %s --kubeconfig=%s", cfgFilePath, kubeConfigURL)
_, err = shell.ExecuteCmd(applyCmd)

if err != nil {
Expand All @@ -135,24 +139,13 @@ func PatchAPIObject(objName, objNamespace, objKind, patchType, patchStr string)
patchCmd := fmt.Sprintf("oc patch %s/%s --type %s -p '%v'",
objKind, objName, patchType, patchStr)

if objNamespace != "" {
patchCmd = fmt.Sprintf("oc patch %s/%s -n %s --type %s -p '%v'",
objKind, objName, objNamespace, patchType, patchStr)
}
kubeConfigURL := os.Getenv("KUBECONFIG")

_, err := shell.ExecuteCmd(patchCmd)
if err != nil {
return fmt.Errorf("failed to execute %s command due to: %w", patchCmd, err)
if objNamespace != "" {
patchCmd = fmt.Sprintf("oc patch %s/%s -n %s --type %s -p '%v' --kubeconfig=%s",
objKind, objName, objNamespace, patchType, patchStr, kubeConfigURL)
}

return nil
}

// AddClusterRoleToServiceAccount adds specific cluster role to the serviceaccount.
func AddClusterRoleToServiceAccount(serviceAccountName, namespace, clusterRole string) error {
patchCmd := fmt.Sprintf("oc adm policy add-cluster-role-to-user %s -z %s -n '%s'",
clusterRole, serviceAccountName, namespace)

_, err := shell.ExecuteCmd(patchCmd)
if err != nil {
return fmt.Errorf("failed to execute %s command due to: %w", patchCmd, err)
Expand All @@ -165,8 +158,11 @@ func AddClusterRoleToServiceAccount(serviceAccountName, namespace, clusterRole s
func ExecuteViaDebugPodOnNode(
nodeName string,
cmd string) (string, error) {
execCmd := fmt.Sprintf("oc debug nodes/%s -- bash -c \"chroot /host %s\" --insecure-skip-tls-verify",
nodeName, cmd)
kubeConfigURL := os.Getenv("KUBECONFIG")

execCmd := fmt.Sprintf("oc debug nodes/%s -- bash -c \"chroot /host %s\" "+
"--insecure-skip-tls-verify --kubeconfig=%s",
nodeName, cmd, kubeConfigURL)
glog.V(100).Infof("Execute command %s", execCmd)

output, err := shell.ExecuteCmd(execCmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ additionalAffinities:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
- key: node-role.kubernetes.io/worker
operator: Exists

securityContext:
Expand Down
19 changes: 8 additions & 11 deletions tests/system-tests/vcore/internal/vcorecommon/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
. "github.com/onsi/gomega"
"github.com/openshift-kni/eco-gotests/tests/system-tests/internal/files"
"github.com/openshift-kni/eco-gotests/tests/system-tests/internal/shell"
. "github.com/openshift-kni/eco-gotests/tests/system-tests/vcore/internal/vcoreinittools"
"github.com/openshift-kni/eco-gotests/tests/system-tests/vcore/internal/vcoreparams"
)

Expand All @@ -23,14 +22,14 @@ func VerifyHelmSuite() {
"Helm validation",
Label(vcoreparams.LabelVCoreOperators), func() {
BeforeAll(func() {
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderName))
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderPath))

vcoreConfigsFolder := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)
glog.V(vcoreparams.VCoreLogLevel).Infof("vcoreConfigsFolder: %s",
vcoreparams.ConfigurationFolderPath)

glog.V(vcoreparams.VCoreLogLevel).Infof("vcoreConfigsFolder: %s", vcoreConfigsFolder)

if err := os.Mkdir(vcoreConfigsFolder, 0755); os.IsExist(err) {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists", vcoreConfigsFolder)
if err := os.Mkdir(vcoreparams.ConfigurationFolderPath, 0755); os.IsExist(err) {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists",
vcoreparams.ConfigurationFolderPath)
}
})

Expand All @@ -43,14 +42,12 @@ func VerifyHelmSuite() {
func VerifyHelmDeploymentProcedure(ctx SpecContext) {
glog.V(vcoreparams.VCoreLogLevel).Infof("Verify Helm could be installed and works correctly")

vcoreConfigsFolder := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)

helmScriptURL := "https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3"
helmScriptName := "get_helm.sh"
helmScriptLocalPath := filepath.Join(vcoreConfigsFolder, helmScriptName)
helmScriptLocalPath := filepath.Join(vcoreparams.ConfigurationFolderPath, helmScriptName)

glog.V(vcoreparams.VCoreLogLevel).Infof("Download %s script", helmScriptName)
err := files.DownloadFile(helmScriptURL, helmScriptName, vcoreConfigsFolder)
err := files.DownloadFile(helmScriptURL, helmScriptName, vcoreparams.ConfigurationFolderPath)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to download %s file locally from the %s due to %v",
helmScriptName, helmScriptURL, err))

Expand Down
3 changes: 1 addition & 2 deletions tests/system-tests/vcore/internal/vcorecommon/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func getImageURL(repository, name, tag string) (string, error) {
VCoreConfig.User,
VCoreConfig.Pass,
VCoreConfig.CombinedPullSecretFile,
VCoreConfig.RegistryRepository,
VCoreConfig.HomeDir)
VCoreConfig.RegistryRepository)

if err != nil {
return "", fmt.Errorf("failed to mirror image %s:%s locally due to %w",
Expand Down
17 changes: 7 additions & 10 deletions tests/system-tests/vcore/internal/vcorecommon/keda-validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ func VerifyKedaSuite() {
"Keda validation",
Label(vcoreparams.LabelVCoreOperators), func() {
BeforeAll(func() {
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderName))
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderPath))

vcoreConfigsFolder := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)
err := os.Mkdir(vcoreparams.ConfigurationFolderPath, 0755)

glog.V(vcoreparams.VCoreLogLevel).Infof("vcoreConfigsFolder: %s", vcoreConfigsFolder)

if err := os.Mkdir(vcoreConfigsFolder, 0755); os.IsExist(err) {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists", vcoreConfigsFolder)
if err != nil {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists",
vcoreparams.ConfigurationFolderPath)
}
})

Expand Down Expand Up @@ -324,8 +323,6 @@ func VerifyScaleObjectDeployment(ctx SpecContext) {
varsToReplace["ServiceAccountName"] = serviceAccountName
varsToReplace["RoleName"] = metricsReaderName

destinationDirectoryPath := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)

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

Expand All @@ -334,7 +331,7 @@ func VerifyScaleObjectDeployment(ctx SpecContext) {
err = ocpcli.CreateConfig(
templateDir,
kedaRoleBindingTemplateName,
destinationDirectoryPath,
vcoreparams.ConfigurationFolderPath,
kedaRoleBindingTemplateName,
varsToReplace)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create load job due to %v", err))
Expand Down Expand Up @@ -389,7 +386,7 @@ func VerifyScaleObjectDeployment(ctx SpecContext) {
err = ocpcli.CreateConfig(
templateDir,
appLoadJobTemplateName,
destinationDirectoryPath,
vcoreparams.ConfigurationFolderPath,
appLoadJobTemplateName,
varsToReplace)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create load job due to %v", err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vcorecommon
import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/openshift-kni/eco-goinfra/pkg/reportxml"
Expand All @@ -28,14 +27,16 @@ func VerifyMetaLBSuite() {
"MetalLB validation",
Label(vcoreparams.LabelVCoreOperators), func() {
BeforeAll(func() {
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderName))
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderPath))

vcoreConfigsFolder := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)
err := os.Mkdir(vcoreparams.ConfigurationFolderPath, 0755)

if err := os.Mkdir(vcoreConfigsFolder, 0755); os.IsExist(err) {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists", vcoreConfigsFolder)
if err != nil {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists",
vcoreparams.ConfigurationFolderPath)
}
})

It(fmt.Sprintf("Verifies %s namespace exists", vcoreparams.MetalLBOperatorNamespace),
Label("metallb"), VerifyMetalLBNamespaceExists)

Expand Down
9 changes: 6 additions & 3 deletions tests/system-tests/vcore/internal/vcorecommon/odf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vcorecommon

import (
"fmt"
"os"

"github.com/openshift-kni/eco-goinfra/pkg/configmap"
"github.com/openshift-kni/eco-goinfra/pkg/storage"
Expand Down Expand Up @@ -124,14 +125,16 @@ func VerifyODFOperatorDeployment(ctx SpecContext) {
func VerifyODFTaints(ctx SpecContext) {
glog.V(vcoreparams.VCoreLogLevel).Infof("Apply taints to the ODF nodes")

kubeConfigURL := os.Getenv("KUBECONFIG")

odfNodesList, err := nodes.List(APIClient, VCoreConfig.OdfLabelListOption)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get cluster nodes list due to %v", err))

for _, odfNode := range odfNodesList {
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",
odfNode.Definition.Name)
"oc adm taint node %s node.ocs.openshift.io/storage=true:NoSchedule --overwrite=true --kubeconfig=%s",
odfNode.Definition.Name, kubeConfigURL)
_, err = shell.ExecuteCmd(applyTaintsCmd)
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to execute %s script due to %v",
applyTaintsCmd, err))
Expand Down Expand Up @@ -197,7 +200,7 @@ func VerifyLocalVolumeDiscovery(ctx SpecContext) {
Expect(await.WaitUntilLVDIsDiscovering(APIClient,
localVolumeDiscoveryObj.Definition.Name,
localVolumeDiscoveryObj.Definition.Namespace,
5*time.Minute)).To(Equal(true),
5*time.Minute)).ToNot(HaveOccurred(),
fmt.Sprintf("localvolumediscovery %s in namespace %s failed to discover",
vcoreparams.ODFLocalVolumeDiscoveryName, vcoreparams.LSONamespace))
} // func VerifyLocalVolumeDiscovery (ctx SpecContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ func VerifyPostDeploymentConfig() {
"Post-deployment config validation",
Label(vcoreparams.LabelVCoreDeployment), func() {
BeforeAll(func() {
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderName))
By(fmt.Sprintf("Asserting %s folder exists", vcoreparams.ConfigurationFolderPath))

vcoreConfigsFolder := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)
err := os.Mkdir(vcoreparams.ConfigurationFolderPath, 0755)

glog.V(vcoreparams.VCoreLogLevel).Infof("vcoreConfigsFolder: %s", vcoreConfigsFolder)

if err := os.Mkdir(vcoreConfigsFolder, 0755); os.IsExist(err) {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists", vcoreConfigsFolder)
if err != nil {
glog.V(vcoreparams.VCoreLogLevel).Infof("%s folder already exists",
vcoreparams.ConfigurationFolderPath)
}
})

Expand All @@ -60,7 +59,7 @@ func VerifyPostDeploymentConfig() {
Label("day2"), reportxml.ID("60086"), VerifySCTPModuleActivation)

It("Verifies system reserved memory for masters succeeded",
Label("debug"), reportxml.ID("60045"), SetSystemReservedMemoryForMasterNodes)
Label("day2"), reportxml.ID("60045"), SetSystemReservedMemoryForMasterNodes)
})
}

Expand Down Expand Up @@ -178,8 +177,6 @@ func VerifySCTPModuleActivation(ctx SpecContext) {
varsToReplace["SctpModuleName"] = "load-sctp-module"
varsToReplace["McNodeRole"] = vcoreparams.CpMCSelector

destinationDirectoryPath := filepath.Join(VCoreConfig.HomeDir, vcoreparams.ConfigurationFolderName)

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

Expand All @@ -188,7 +185,7 @@ func VerifySCTPModuleActivation(ctx SpecContext) {
err = ocpcli.ApplyConfig(
templateDir,
sctpModuleTemplateName,
destinationDirectoryPath,
vcoreparams.ConfigurationFolderPath,
sctpModuleTemplateName,
varsToReplace)
Expect(err).To(BeNil(), fmt.Sprint(err))
Expand Down
Loading

0 comments on commit e9bbaa3

Please sign in to comment.