diff --git a/tests/lca/imagebasedupgrade/internal/seedimage/seedimage.go b/tests/lca/imagebasedupgrade/internal/seedimage/seedimage.go index 16684812c..d27031635 100644 --- a/tests/lca/imagebasedupgrade/internal/seedimage/seedimage.go +++ b/tests/lca/imagebasedupgrade/internal/seedimage/seedimage.go @@ -3,7 +3,10 @@ package seedimage import ( "encoding/json" "fmt" + "regexp" + "strings" + "github.com/golang/glog" "github.com/openshift-kni/eco-goinfra/pkg/clients" "github.com/openshift-kni/eco-goinfra/pkg/nodes" "github.com/openshift-kni/eco-gotests/tests/internal/cluster" @@ -17,6 +20,8 @@ const ( ) // GetContent returns the structured contents of a seed image as SeedImageContent. +// +//nolint:funlen func GetContent(apiClient *clients.Settings, seedImageLocation string) (*SeedImageContent, error) { if apiClient == nil { return nil, fmt.Errorf("nil apiclient passed to seed image function") @@ -86,5 +91,86 @@ func GetContent(apiClient *clients.Settings, seedImageLocation string) (*SeedIma return nil, err } + if seedInfo.HasProxy { + podmanPullCmd := fmt.Sprintf("%s podman pull %s", connectionString, seedImageLocation) + + _, err = cluster.ExecCmdWithStdout( + apiClient, podmanPullCmd, metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", seedNode), + }) + + if err != nil { + return nil, err + } + + mountedFilePathOutput, err := cluster.ExecCmdWithStdout( + apiClient, fmt.Sprintf("sudo podman image mount %s", seedImageLocation), metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", seedNode), + }) + + if err != nil { + return nil, err + } + + defer func() { + _, err := cluster.ExecCmdWithStdout( + apiClient, fmt.Sprintf("sudo podman image unmount %s", seedImageLocation), metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", seedNode), + }) + + if err != nil { + glog.V(100).Info("Error occurred while unmounting image") + } + }() + + mountedFilePath := regexp.MustCompile(`\n`).ReplaceAllString(mountedFilePathOutput[seedNode], "") + + proxyEnvOutput, err := cluster.ExecCmdWithStdout( + apiClient, fmt.Sprintf("sudo tar xzf %s/etc.tgz -O etc/mco/proxy.env", mountedFilePath), metav1.ListOptions{ + FieldSelector: fmt.Sprintf("metadata.name=%s", seedNode), + }) + + if err != nil { + return nil, err + } + + proxyEnv := proxyEnvOutput[seedNode] + + seedInfo.ParseProxyEnv(proxyEnv) + } + return seedInfo, nil } + +// ParseProxyEnv reads a proxy.env config and sets SeedImageContent.Proxy values accordingly. +func (s *SeedImageContent) ParseProxyEnv(config string) { + httpProxyRE := regexp.MustCompile(`HTTP_PROXY=(.+)`) + httpProxyResult := httpProxyRE.FindString(config) + + if len(httpProxyResult) > 0 { + httpProxyKeyVal := strings.Split(httpProxyResult, "=") + if len(httpProxyKeyVal) == 2 { + s.Proxy.HTTPProxy = httpProxyKeyVal[1] + } + } + + httpsProxyRE := regexp.MustCompile(`HTTPS_PROXY=(.+)`) + httpsProxyResult := httpsProxyRE.FindString(config) + + if len(httpsProxyResult) > 0 { + httpsKeyVal := strings.Split(httpsProxyResult, "=") + if len(httpsKeyVal) == 2 { + s.Proxy.HTTPSProxy = httpsKeyVal[1] + } + } + + noProxyRE := regexp.MustCompile(`NO_PROXY=(.*)`) + noProxyResult := noProxyRE.FindString(config) + + if len(noProxyResult) > 0 { + noProxyKeyVal := strings.Split(noProxyResult, "=") + if len(noProxyKeyVal) == 2 { + s.Proxy.NOProxy = noProxyKeyVal[1] + } + } +} diff --git a/tests/lca/imagebasedupgrade/internal/seedimage/seedimage_types.go b/tests/lca/imagebasedupgrade/internal/seedimage/seedimage_types.go index b0fedb45d..a88555572 100644 --- a/tests/lca/imagebasedupgrade/internal/seedimage/seedimage_types.go +++ b/tests/lca/imagebasedupgrade/internal/seedimage/seedimage_types.go @@ -7,6 +7,11 @@ import ( // SeedImageContent contains the seed image manifest and proxy info. type SeedImageContent struct { *seedclusterinfo.SeedClusterInfo + Proxy struct { + HTTPSProxy string + HTTPProxy string + NOProxy string + } } // ImageInspect contains the fields for unmarshalling podman container image's labels. diff --git a/tests/lca/imagebasedupgrade/mgmt/internal/mgmtconfig/config.go b/tests/lca/imagebasedupgrade/mgmt/internal/mgmtconfig/config.go index eac7c242a..81e908020 100644 --- a/tests/lca/imagebasedupgrade/mgmt/internal/mgmtconfig/config.go +++ b/tests/lca/imagebasedupgrade/mgmt/internal/mgmtconfig/config.go @@ -4,6 +4,7 @@ import ( "github.com/golang/glog" "github.com/kelseyhightower/envconfig" "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/internal/ibuconfig" + "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/internal/seedimage" "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/mgmtparams" ) @@ -13,7 +14,7 @@ import ( type MGMTConfig struct { *ibuconfig.IBUConfig SeedImage string `envconfig:"ECO_LCA_IBU_MGMT_SEED_IMAGE" default:"quay.io/ocp-edge-qe/ib-seedimage-public:ci"` - SeedImageVersion string `envconfig:"ECO_LCA_IBU_MGMT_SEED_IMAGE_VERSION" default:""` + SeedClusterInfo *seedimage.SeedImageContent IBUWorkloadImage string `envconfig:"ECO_LCA_IBU_MGMT_WORKLOAD_IMAGE" default:"registry.redhat.io/openshift4/ose-hello-openshift-rhel8@sha256:10dca31348f07e1bfb56ee93c324525cceefe27cb7076b23e42ac181e4d1863e"` IdlePostUpgrade bool `envconfig:"ECO_LCA_IBU_MGMT_IDLE_POST_UPGRADE" default:"false"` RollbackAfterUpgrade bool `envconfig:"ECO_LCA_IBU_MGMT_ROLLBACK_AFTER_UPGRADE" default:"false"` diff --git a/tests/lca/imagebasedupgrade/mgmt/upgrade/tests/e2e-upgrade-test.go b/tests/lca/imagebasedupgrade/mgmt/upgrade/tests/e2e-upgrade-test.go index a167895c2..9d9b28c17 100644 --- a/tests/lca/imagebasedupgrade/mgmt/upgrade/tests/e2e-upgrade-test.go +++ b/tests/lca/imagebasedupgrade/mgmt/upgrade/tests/e2e-upgrade-test.go @@ -21,6 +21,7 @@ import ( "github.com/openshift-kni/eco-goinfra/pkg/nodes" "github.com/openshift-kni/eco-goinfra/pkg/olm" "github.com/openshift-kni/eco-goinfra/pkg/pod" + "github.com/openshift-kni/eco-goinfra/pkg/proxy" "github.com/openshift-kni/eco-goinfra/pkg/reportxml" "github.com/openshift-kni/eco-goinfra/pkg/route" "github.com/openshift-kni/eco-goinfra/pkg/service" @@ -67,8 +68,15 @@ var _ = Describe( "Performing image based upgrade", Ordered, Label(tsparams.LabelEndToEndUpgrade), func() { + var ( + originalTargetProxy *proxy.Builder + ) BeforeAll(func() { + By("Get target cluster proxy configuration") + originalTargetProxy, err = proxy.Pull(APIClient) + Expect(err).NotTo(HaveOccurred(), "error pulling target cluster proxy") + By("Pull the imagebasedupgrade from the cluster") ibu, err = lca.PullImageBasedUpgrade(APIClient) Expect(err).NotTo(HaveOccurred(), "error pulling ibu resource from cluster") @@ -285,13 +293,60 @@ var _ = Describe( Expect(extraConfigmap.Object.Data["hello"]).To(Equal("world"), "error: extra manifest configmap has incorrect content") }) + + It("contains same proxy configuration as seed after upgrade", reportxml.ID("73103"), func() { + if originalTargetProxy.Object.Spec.HTTPProxy == "" && + originalTargetProxy.Object.Spec.HTTPSProxy == "" && + originalTargetProxy.Object.Spec.NoProxy == "" { + Skip("Target was not installed with proxy") + } + + if originalTargetProxy.Object.Spec.HTTPProxy != MGMTConfig.SeedClusterInfo.Proxy.HTTPProxy || + originalTargetProxy.Object.Spec.HTTPSProxy != MGMTConfig.SeedClusterInfo.Proxy.HTTPSProxy || + originalTargetProxy.Object.Spec.NoProxy != MGMTConfig.SeedClusterInfo.Proxy.NOProxy { + Skip("Target was not installed with the same proxy as seed") + } + + targetProxyPostUpgrade, err := proxy.Pull(APIClient) + Expect(err).NotTo(HaveOccurred(), "error pulling target proxy") + Expect(originalTargetProxy.Object.Spec.HTTPProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.HTTPProxy), + "HTTP_PROXY postupgrade config does not match pre upgrade config") + Expect(originalTargetProxy.Object.Spec.HTTPSProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.HTTPSProxy), + "HTTPS_PROXY postupgrade config does not match pre upgrade config") + Expect(originalTargetProxy.Object.Spec.NoProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.NoProxy), + "NO_PROXY postupgrade config does not match pre upgrade config") + }) + + It("contains different proxy configuration than seed after upgrade", reportxml.ID("73369"), func() { + if originalTargetProxy.Object.Spec.HTTPProxy == "" && + originalTargetProxy.Object.Spec.HTTPSProxy == "" && + originalTargetProxy.Object.Spec.NoProxy == "" { + Skip("Target was not installed with proxy") + } + + if originalTargetProxy.Object.Spec.HTTPProxy == MGMTConfig.SeedClusterInfo.Proxy.HTTPProxy && + originalTargetProxy.Object.Spec.HTTPSProxy == MGMTConfig.SeedClusterInfo.Proxy.HTTPSProxy && + originalTargetProxy.Object.Spec.NoProxy == MGMTConfig.SeedClusterInfo.Proxy.NOProxy { + Skip("Target was installed with the same proxy as seed") + } + + targetProxyPostUpgrade, err := proxy.Pull(APIClient) + Expect(err).NotTo(HaveOccurred(), "error pulling target proxy") + Expect(originalTargetProxy.Object.Spec.HTTPProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.HTTPProxy), + "HTTP_PROXY postupgrade config does not match pre upgrade config") + Expect(originalTargetProxy.Object.Spec.HTTPSProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.HTTPSProxy), + "HTTPS_PROXY postupgrade config does not match pre upgrade config") + Expect(originalTargetProxy.Object.Spec.NoProxy).To(Equal(targetProxyPostUpgrade.Object.Spec.NoProxy), + "NO_PROXY postupgrade config does not match pre upgrade config") + }) }) //nolint:funlen func upgrade() { By("Updating the seed image reference") - ibu, err = ibu.WithSeedImage(MGMTConfig.SeedImage).WithSeedImageVersion(MGMTConfig.SeedImageVersion).Update() + ibu, err = ibu.WithSeedImage(MGMTConfig.SeedImage). + WithSeedImageVersion(MGMTConfig.SeedClusterInfo.SeedClusterOCPVersion).Update() Expect(err).NotTo(HaveOccurred(), "error updating ibu with image and version") By("Updating the oadpContent") @@ -360,7 +415,7 @@ func upgrade() { clusterVersion, err := clusterversion.Pull(APIClient) Expect(err).NotTo(HaveOccurred(), "error pulling clusterversion") - Expect(MGMTConfig.SeedImageVersion).To( + Expect(MGMTConfig.SeedClusterInfo.SeedClusterOCPVersion).To( Equal(clusterVersion.Object.Status.Desired.Version), "error: clusterversion does not match seedimageversion") By("Check that no cluster operators are progressing") diff --git a/tests/lca/imagebasedupgrade/mgmt/upgrade/upgrade_suite_test.go b/tests/lca/imagebasedupgrade/mgmt/upgrade/upgrade_suite_test.go index 0f5ffdcfd..006319a04 100644 --- a/tests/lca/imagebasedupgrade/mgmt/upgrade/upgrade_suite_test.go +++ b/tests/lca/imagebasedupgrade/mgmt/upgrade/upgrade_suite_test.go @@ -28,12 +28,11 @@ func TestUpgrade(t *testing.T) { } var _ = BeforeSuite(func() { - if MGMTConfig.SeedImageVersion == "" { - seedInfo, err := seedimage.GetContent(APIClient, MGMTConfig.SeedImage) - Expect(err).NotTo(HaveOccurred(), "error getting seed image info") + var err error + seedClusterInfo, err := seedimage.GetContent(APIClient, MGMTConfig.SeedImage) + Expect(err).NotTo(HaveOccurred(), "error getting seed image info") - MGMTConfig.SeedImageVersion = seedInfo.SeedClusterOCPVersion - } + MGMTConfig.SeedClusterInfo = seedClusterInfo }) var _ = ReportAfterSuite("", func(report Report) {