Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibu mgmt: add proxy test to upgrade suite #1

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions tests/lca/imagebasedupgrade/internal/seedimage/seedimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"`
Expand Down
59 changes: 57 additions & 2 deletions tests/lca/imagebasedupgrade/mgmt/upgrade/tests/e2e-upgrade-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading