diff --git a/tests/system-tests/internal/remote/scp.go b/tests/system-tests/internal/remote/scp.go index f318eb01a..224332835 100644 --- a/tests/system-tests/internal/remote/scp.go +++ b/tests/system-tests/internal/remote/scp.go @@ -8,7 +8,7 @@ import ( ssh "github.com/povsister/scp" ) -// ScpFileFrom transfers specific file using scp method. +// ScpFileFrom transfers specific file using scp method from remote host. func ScpFileFrom(source, destination, remoteHostname, remoteHostUsername, remoteHostPass string) error { if source == "" { glog.V(100).Info("The source is empty") @@ -76,7 +76,65 @@ func ScpFileFrom(source, destination, remoteHostname, remoteHostUsername, remote return nil } -// ScpDirectoryFrom transfers specific directory using scp method. +// ScpFileTo transfers specific file using scp method to remote host. +func ScpFileTo(source, destination, remoteHostname, remoteHostUsername, remoteHostPass string) error { + if source == "" { + glog.V(100).Info("The source is empty") + + return fmt.Errorf("the source could not be empty") + } + + if destination == "" { + glog.V(100).Info("The destination is empty") + + return fmt.Errorf("the destination could not be empty") + } + + if remoteHostname == "" { + glog.V(100).Info("The remoteHostname is empty") + + return fmt.Errorf("the remoteHostname could not be empty") + } + + if remoteHostUsername == "" { + glog.V(100).Info("The remoteHostUsername is empty") + + return fmt.Errorf("the remoteHostUsername could not be empty") + } + + if remoteHostPass == "" { + glog.V(100).Info("The remoteHostPass is empty") + + return fmt.Errorf("the remoteHostPass could not be empty") + } + + glog.V(100).Infof("Verify file %s exists", destination) + + if _, err := os.Stat(source); !os.IsExist(err) { + glog.V(100).Infof("File file %s not found", source) + } + + glog.V(100).Infof("Copy file %s to the %s@%s", source, remoteHostname, destination) + glog.V(100).Info("Build a SSH config from username/password") + + sshConf := ssh.NewSSHConfigFromPassword(remoteHostUsername, remoteHostPass) + + glog.V(100).Infof("Dial SSH to %s", remoteHostname) + + scpClient, err := ssh.NewClient(remoteHostname, sshConf, &ssh.ClientOption{}) + + if err != nil { + return err + } + + glog.V(100).Infof("Transfer file %s to %s", source, destination) + + err = scpClient.CopyFileToRemote(source, destination, &ssh.FileTransferOption{}) + + return err +} + +// ScpDirectoryFrom transfers specific directory using scp method from destination. func ScpDirectoryFrom(source, destination, remoteHostname, remoteHostUsername, remoteHostPass string) error { if source == "" { glog.V(100).Info("The source is empty") @@ -139,3 +197,60 @@ func ScpDirectoryFrom(source, destination, remoteHostname, remoteHostUsername, r return nil } + +// ScpDirectoryTo transfers specific directory using scp method to destination. +func ScpDirectoryTo(source, destination, remoteHostname, remoteHostUsername, remoteHostPass string) error { + if source == "" { + glog.V(100).Info("The source is empty") + + return fmt.Errorf("the source could not be empty") + } + + if destination == "" { + glog.V(100).Info("The destination is empty") + + return fmt.Errorf("the destination could not be empty") + } + + if remoteHostname == "" { + glog.V(100).Info("The remoteHostname is empty") + + return fmt.Errorf("the remoteHostname could not be empty") + } + + if remoteHostUsername == "" { + glog.V(100).Info("The remoteHostUsername is empty") + + return fmt.Errorf("the remoteHostUsername could not be empty") + } + + glog.V(100).Infof("Copy directory %s from %s", source, destination) + + glog.V(100).Info("Build a SSH config from username/password") + + sshConf := ssh.NewSSHConfigFromPassword(remoteHostUsername, remoteHostPass) + + glog.V(100).Infof("Dial SSH to %s", remoteHostname) + + scpClient, err := ssh.NewClient(remoteHostname, sshConf, &ssh.ClientOption{}) + + if err != nil { + return err + } + + glog.V(100).Infof("recursively copy from directory %s to the %s", source, destination) + + err = scpClient.CopyDirToRemote(source, destination, &ssh.DirTransferOption{}) + + if err != nil { + return err + } + + glog.V(100).Infof("Insure directory %s was transferred", destination) + + if _, err := os.Stat(destination); os.IsNotExist(err) { + return err + } + + return nil +} diff --git a/tests/system-tests/internal/template/template.go b/tests/system-tests/internal/template/template.go index f3f7278a7..d9b96eaff 100644 --- a/tests/system-tests/internal/template/template.go +++ b/tests/system-tests/internal/template/template.go @@ -3,7 +3,6 @@ package template import ( "fmt" "os" - "path/filepath" "text/template" "github.com/golang/glog" @@ -11,54 +10,32 @@ import ( // SaveTemplate read template file, replace variables and save it to the provided destination folder. func SaveTemplate( - templateDir, - fileName, - destinationDir, - finalFileName string, + source, + destination string, variablesToReplace map[string]interface{}) error { - if fileName == "" { - glog.V(100).Infof("The filename is empty") + if source == "" { + glog.V(100).Infof("The source is empty") - return fmt.Errorf("the filename should be provided") + return fmt.Errorf("the source should be provided") } - if finalFileName == "" { - finalFileName = fileName - } - - glog.V(100).Infof("Read %s template, replace variables and save it locally to the %s/%s", - fileName, destinationDir, finalFileName) + glog.V(100).Infof("Read %s template, replace variables and save it locally to the %s", + source, destination) - if templateDir == "" { - glog.V(100).Infof("The template folder is empty") + if destination == "" { + glog.V(100).Infof("The destination file is empty") - return fmt.Errorf("the template folder should be provided") + return fmt.Errorf("the destination file should be provided") } - pathToTemplate := filepath.Join(templateDir, fileName) - destination := filepath.Join(destinationDir, finalFileName) - tmpl, err := template.ParseFiles(pathToTemplate) + tmpl, err := template.ParseFiles(source) if err != nil { - glog.V(100).Infof("Error to read config file %s", pathToTemplate) - - return err - } + glog.V(100).Infof("Error to read config file %s", source) - glog.V(100).Infof("create %s folder if not exists", destinationDir) - - err = os.Mkdir(destinationDir, 0755) - - if err != nil && !os.IsExist(err) { return err } - err = os.Remove(destination) - - if err != nil && !os.IsExist(err) { - glog.V(100).Infof("%s file not found", destination) - } - // create a new file file, err := os.Create(destination) if err != nil { @@ -81,7 +58,7 @@ func SaveTemplate( err = os.Chmod(destination, 0755) if err != nil { - glog.V(100).Infof("Error to chmod file %", destination) + glog.V(100).Infof("Error to chmod file %s", destination) return err } diff --git a/tests/system-tests/vcore/internal/ocpcli/ocpcli.go b/tests/system-tests/vcore/internal/ocpcli/ocpcli.go index a5cd633ce..b8c3e099f 100644 --- a/tests/system-tests/vcore/internal/ocpcli/ocpcli.go +++ b/tests/system-tests/vcore/internal/ocpcli/ocpcli.go @@ -80,22 +80,24 @@ func DownloadAndExtractOcBinaryArchive(apiClient *clients.Settings) error { // ApplyConfig applies config using shell method. func ApplyConfig( - templateDir, - fileName, - destinationDir, - finalFileName string, + pathToTemplate, + pathToConfigFile string, variablesToReplace map[string]interface{}) error { - err := template.SaveTemplate( - templateDir, fileName, destinationDir, finalFileName, variablesToReplace) + err := template.SaveTemplate(pathToTemplate, pathToConfigFile, variablesToReplace) if err != nil { return err } - cfgFilePath := filepath.Join(destinationDir, finalFileName) + err = remote.ScpFileTo(pathToConfigFile, pathToConfigFile, VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass) + + if err != nil { + return fmt.Errorf("failed to transfer file %s to the %s/%s due to: %w", + pathToConfigFile, VCoreConfig.Host, pathToConfigFile, err) + } applyCmd := fmt.Sprintf("oc apply -f %s --kubeconfig=%s", - cfgFilePath, VCoreConfig.KubeconfigPath) + pathToConfigFile, VCoreConfig.KubeconfigPath) _, err = remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, applyCmd) if err != nil { @@ -107,21 +109,23 @@ func ApplyConfig( // CreateConfig creates config using shell method. func CreateConfig( - templateDir, - fileName, - destinationDir, - finalFileName string, + pathToTemplate, + pathToConfigFile string, variablesToReplace map[string]interface{}) error { - err := template.SaveTemplate( - templateDir, fileName, destinationDir, finalFileName, variablesToReplace) + err := template.SaveTemplate(pathToTemplate, pathToConfigFile, variablesToReplace) if err != nil { return err } - cfgFilePath := filepath.Join(destinationDir, finalFileName) + err = remote.ScpFileTo(pathToConfigFile, pathToConfigFile, VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass) + + if err != nil { + return fmt.Errorf("failed to transfer file %s to the %s/%s due to: %w", + pathToConfigFile, VCoreConfig.Host, pathToConfigFile, err) + } - createCmd := fmt.Sprintf("oc create -f %s --kubeconfig=%s", cfgFilePath, VCoreConfig.KubeconfigPath) + createCmd := fmt.Sprintf("oc create -f %s --kubeconfig=%s", pathToConfigFile, VCoreConfig.KubeconfigPath) _, err = remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, createCmd) if err != nil { diff --git a/tests/system-tests/vcore/internal/vcorecommon/keda-validation.go b/tests/system-tests/vcore/internal/vcorecommon/keda-validation.go index 6d99d419a..2854079d2 100644 --- a/tests/system-tests/vcore/internal/vcorecommon/keda-validation.go +++ b/tests/system-tests/vcore/internal/vcorecommon/keda-validation.go @@ -319,10 +319,8 @@ func VerifyScaleObjectDeployment(ctx SpecContext) { templateDir := filepath.Join(workingDir, vcoreparams.TemplateFilesFolder) err = ocpcli.CreateConfig( - templateDir, - kedaRoleBindingTemplateName, - vcoreparams.ConfigurationFolderPath, - kedaRoleBindingTemplateName, + filepath.Join(templateDir, kedaRoleBindingTemplateName), + filepath.Join(vcoreparams.ConfigurationFolderPath, kedaRoleBindingTemplateName), varsToReplace) Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create load job due to %v", err)) @@ -374,10 +372,8 @@ func VerifyScaleObjectDeployment(ctx SpecContext) { varsToReplace["AbImageURL"] = abImageURL err = ocpcli.CreateConfig( - templateDir, - appLoadJobTemplateName, - vcoreparams.ConfigurationFolderPath, - appLoadJobTemplateName, + filepath.Join(templateDir, appLoadJobTemplateName), + filepath.Join(vcoreparams.ConfigurationFolderPath, appLoadJobTemplateName), varsToReplace) Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create load job due to %v", err)) diff --git a/tests/system-tests/vcore/internal/vcorecommon/post-deployment-config.go b/tests/system-tests/vcore/internal/vcorecommon/post-deployment-config.go index dacf08e61..218b4e08f 100644 --- a/tests/system-tests/vcore/internal/vcorecommon/post-deployment-config.go +++ b/tests/system-tests/vcore/internal/vcorecommon/post-deployment-config.go @@ -173,10 +173,8 @@ func VerifySCTPModuleActivation(ctx SpecContext) { templateDir := filepath.Join(workingDir, vcoreparams.TemplateFilesFolder) err = ocpcli.ApplyConfig( - templateDir, - sctpModuleTemplateName, - vcoreparams.ConfigurationFolderPath, - sctpModuleTemplateName, + filepath.Join(templateDir, sctpModuleTemplateName), + filepath.Join(vcoreparams.ConfigurationFolderPath, sctpModuleTemplateName), varsToReplace) Expect(err).To(BeNil(), fmt.Sprint(err)) diff --git a/tests/system-tests/vcore/internal/vcorecommon/redis.go b/tests/system-tests/vcore/internal/vcorecommon/redis.go index ef748a0dc..f515d359a 100644 --- a/tests/system-tests/vcore/internal/vcorecommon/redis.go +++ b/tests/system-tests/vcore/internal/vcorecommon/redis.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/openshift-kni/eco-gotests/tests/system-tests/internal/shell" + "github.com/openshift-kni/eco-gotests/tests/system-tests/internal/remote" "github.com/openshift-kni/eco-goinfra/pkg/lso" @@ -40,7 +42,7 @@ func VerifyRedisSuite() { "Redis validation", Label(vcoreparams.LabelVCoreOperators), func() { It("Verify redis localvolumeset instance exists", - Label("redis"), VerifyRedisLocalVolumeSet) + Label("redis2"), VerifyRedisLocalVolumeSet) It("Verify Redis deployment procedure", Label("redis"), reportxml.ID("59503"), VerifyRedisDeploymentProcedure) @@ -136,8 +138,14 @@ func VerifyRedisDeploymentProcedure(ctx SpecContext) { glog.V(vcoreparams.VCoreLogLevel).Infof("Install redis") - localHostHomeDir, err := remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, "pwd") - Expect(err).ToNot(HaveOccurred(), "failed to detect local home directory due to %v", err) + glog.V(100).Infof("Insure local directory %s exists", vcoreparams.ConfigurationFolderPath) + + err = os.Mkdir(vcoreparams.ConfigurationFolderPath, 0755) + + if err != nil { + glog.V(100).Infof("Failed to create directory %s, it is already exists", + vcoreparams.ConfigurationFolderPath) + } installRedisCmd := []string{ "helm repo add dandydev https://dandydeveloper.github.io/charts", @@ -145,12 +153,20 @@ func VerifyRedisDeploymentProcedure(ctx SpecContext) { fmt.Sprintf("helm fetch dandydev/redis-ha --version 4.12.9 -d %s/.", vcoreparams.ConfigurationFolderPath), fmt.Sprintf("tar xvfz %s/redis-ha-4.12.9.tgz --directory=%s/.", - vcoreparams.ConfigurationFolderPath, localHostHomeDir)} + vcoreparams.ConfigurationFolderPath, vcoreparams.ConfigurationFolderPath)} for _, cmd := range installRedisCmd { - _, err = remote.ExecCmdOnHost(VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass, cmd) + _, err = shell.ExecuteCmd(cmd) Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to execute %s command due to %v", cmd, err)) } + err = remote.ScpDirectoryTo( + filepath.Join(vcoreparams.ConfigurationFolderPath, "redis-ha"), + vcoreparams.ConfigurationFolderPath, + VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass) + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to transfer folder %s to the %s/%s due to: %v", + filepath.Join(vcoreparams.ConfigurationFolderPath, "redis-ha"), + VCoreConfig.Host, vcoreparams.ConfigurationFolderPath, err)) + glog.V(vcoreparams.VCoreLogLevel).Info("Create redis namespace") redisNamespaceBuilder := namespace.NewBuilder(APIClient, redisNamespace) @@ -212,14 +228,21 @@ func VerifyRedisDeploymentProcedure(ctx SpecContext) { Expect(err).ToNot(HaveOccurred(), err) templateDir := filepath.Join(workingDir, vcoreparams.TemplateFilesFolder) + cfgFilePath := filepath.Join(vcoreparams.ConfigurationFolderPath, redisCustomValuesTemplate) - err = template.SaveTemplate(templateDir, redisCustomValuesTemplate, vcoreparams.ConfigurationFolderPath, - redisCustomValuesTemplate, varsToReplace) + err = template.SaveTemplate( + filepath.Join(templateDir, redisCustomValuesTemplate), + cfgFilePath, + varsToReplace) Expect(err).ToNot(HaveOccurred(), "failed to create config file %s at folder %s due to %w", redisCustomValuesTemplate, vcoreparams.ConfigurationFolderPath, err) + err = remote.ScpFileTo(cfgFilePath, cfgFilePath, VCoreConfig.Host, VCoreConfig.User, VCoreConfig.Pass) + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to transfer file %s to the %s/%s due to: %v", + cfgFilePath, VCoreConfig.Host, cfgFilePath, err)) + customConfigCmd := fmt.Sprintf("helm upgrade --install %s -n %s %s/%s -f %s --kubeconfig=%s", - redisAppName, redisNamespace, localHostHomeDir, redisAppName, + redisAppName, redisNamespace, vcoreparams.ConfigurationFolderPath, redisAppName, redisConfigFilePath, VCoreConfig.KubeconfigPath) glog.V(vcoreparams.VCoreLogLevel).Infof("Execute command %s", customConfigCmd) diff --git a/tests/system-tests/vcore/internal/vcorecommon/smo-validation.go b/tests/system-tests/vcore/internal/vcorecommon/smo-validation.go index 0b1f8ed5d..14727a306 100644 --- a/tests/system-tests/vcore/internal/vcorecommon/smo-validation.go +++ b/tests/system-tests/vcore/internal/vcorecommon/smo-validation.go @@ -53,7 +53,7 @@ func VerifyServiceMeshSuite() { Label("smo"), reportxml.ID("73732"), VerifyServiceMeshDeployment) It("Verifies Service Mesh configuration procedure succeeded", - Label("smo"), reportxml.ID("59502"), VerifyServiceMeshConfig) + Label("debug"), reportxml.ID("59502"), VerifyServiceMeshConfig) }) } @@ -179,10 +179,8 @@ func VerifyServiceMeshConfig(ctx SpecContext) { varsToReplace["ControlPlaneNamespace"] = vcoreparams.IstioNamespace err = ocpcli.ApplyConfig( - templateDir, - smoCpTemplateName, - vcoreparams.ConfigurationFolderPath, - smoCpTemplateName, + filepath.Join(templateDir, smoCpTemplateName), + filepath.Join(vcoreparams.ConfigurationFolderPath, smoCpTemplateName), varsToReplace) Expect(err).To(BeNil(), fmt.Sprint(err)) Expect(controlPlaneBuilder.Exists()).To(Equal(true), diff --git a/tests/system-tests/vcore/tests/01_validate_odf.go b/tests/system-tests/vcore/tests/01_validate_odf.go deleted file mode 100644 index 239e5bb09..000000000 --- a/tests/system-tests/vcore/tests/01_validate_odf.go +++ /dev/null @@ -1,21 +0,0 @@ -package vcore_system_test - -import ( - . "github.com/onsi/ginkgo/v2" - - "github.com/openshift-kni/eco-gotests/tests/system-tests/vcore/internal/vcorecommon" - "github.com/openshift-kni/eco-gotests/tests/system-tests/vcore/internal/vcoreparams" -) - -var _ = Describe( - "vCore Internal ODF Test Suite", - Ordered, - ContinueOnFailure, - Label(vcoreparams.Label), func() { - vcorecommon.VerifyLSOSuite() - - vcorecommon.VerifyODFSuite() - - vcorecommon.VerifyLokiSuite() - - }) diff --git a/tests/system-tests/vcore/tests/02_validate_required_operators.go b/tests/system-tests/vcore/tests/01_validate_operators.go similarity index 82% rename from tests/system-tests/vcore/tests/02_validate_required_operators.go rename to tests/system-tests/vcore/tests/01_validate_operators.go index e84ad6771..040ea645c 100644 --- a/tests/system-tests/vcore/tests/02_validate_required_operators.go +++ b/tests/system-tests/vcore/tests/01_validate_operators.go @@ -8,10 +8,16 @@ import ( ) var _ = Describe( - "vCore Operators Deployment Suite", + "vCore Operators Test Suite", Ordered, ContinueOnFailure, Label(vcoreparams.Label), func() { + vcorecommon.VerifyLSOSuite() + + vcorecommon.VerifyODFSuite() + + vcorecommon.VerifyLokiSuite() + vcorecommon.VerifyNMStateSuite() vcorecommon.VerifyServiceMeshSuite()