diff --git a/test/extended/cli/adm_upgrade/OWNERS b/test/extended/cli/adm_upgrade/OWNERS new file mode 100644 index 000000000000..8a5a3abc2b33 --- /dev/null +++ b/test/extended/cli/adm_upgrade/OWNERS @@ -0,0 +1,6 @@ +# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md + +approvers: +- cluster-version-operator-test-case-approvers +reviewers: +- cluster-version-operator-test-case-reviewers diff --git a/test/extended/cli/adm_upgrade/status.go b/test/extended/cli/adm_upgrade/status.go new file mode 100644 index 000000000000..092ed3680364 --- /dev/null +++ b/test/extended/cli/adm_upgrade/status.go @@ -0,0 +1,24 @@ +package adm_upgrade + +import ( + g "github.com/onsi/ginkgo/v2" + o "github.com/onsi/gomega" + exutil "github.com/openshift/origin/test/extended/util" + "k8s.io/kubernetes/test/e2e/framework" +) + +var _ = g.Describe("[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status", func() { + defer g.GinkgoRecover() + + f := framework.NewDefaultFramework("oc-adm-upgrade-status") + f.SkipNamespaceCreation = true + + oc := exutil.NewCLIWithoutNamespace("oc-adm-upgrade-status").AsAdmin() + + g.It("reports correctly when the cluster is not updating", func() { + cmd := oc.Run("adm", "upgrade", "status").EnvVar("OC_ENABLE_CMD_UPGRADE_STATUS", "true") + out, err := cmd.Output() + o.Expect(err).NotTo(o.HaveOccurred()) + o.Expect(out).To(o.Equal("The cluster is not updating.")) + }) +}) diff --git a/test/extended/include.go b/test/extended/include.go index 0bfae962edc8..d497d422d371 100644 --- a/test/extended/include.go +++ b/test/extended/include.go @@ -17,6 +17,7 @@ import ( _ "github.com/openshift/origin/test/extended/builds" _ "github.com/openshift/origin/test/extended/ci" _ "github.com/openshift/origin/test/extended/cli" + _ "github.com/openshift/origin/test/extended/cli/adm_upgrade" _ "github.com/openshift/origin/test/extended/cloud_controller_manager" _ "github.com/openshift/origin/test/extended/cluster" _ "github.com/openshift/origin/test/extended/clusterversion" diff --git a/test/extended/util/annotate/generated/zz_generated.annotations.go b/test/extended/util/annotate/generated/zz_generated.annotations.go index a171097730da..45048da3ad8b 100644 --- a/test/extended/util/annotate/generated/zz_generated.annotations.go +++ b/test/extended/util/annotate/generated/zz_generated.annotations.go @@ -991,6 +991,8 @@ var Annotations = map[string]string{ "[sig-cli][Feature:LegacyCommandTests][Disruptive][Serial] test-cmd: test/cmd/volumes.sh [apigroup:image.openshift.io]": "", + "[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status reports correctly when the cluster is not updating": " [Suite:openshift/conformance/parallel]", + "[sig-cli][Slow] can use rsync to upload files to pods [apigroup:template.openshift.io] copy by strategy should copy files with the rsync strategy": "", "[sig-cli][Slow] can use rsync to upload files to pods [apigroup:template.openshift.io] copy by strategy should copy files with the rsync-daemon strategy": "", diff --git a/test/extended/util/client.go b/test/extended/util/client.go index f9b55c76d26f..90ed122f0aed 100644 --- a/test/extended/util/client.go +++ b/test/extended/util/client.go @@ -92,15 +92,22 @@ type CLI struct { // manifest files can be stored under directory tree staticConfigManifestDir string - token string - username string - globalArgs []string - commandArgs []string - finalArgs []string - namespacesToDelete []string - stdin *bytes.Buffer - stdout io.Writer - stderr io.Writer + token string + username string + globalArgs []string + commandArgs []string + finalArgs []string + namespacesToDelete []string + stdin *bytes.Buffer + stdout io.Writer + stderr io.Writer + + // env allows setting environment variables for the command (when nil, the environment + // is inherited from the current process) + env []string + // addEnvVars allows adding environment variables on top of what is defined in env. + addEnvVars map[string]string + verbose bool withoutNamespace bool withManagedNamespace bool @@ -883,6 +890,26 @@ func (c *CLI) setOutput(out io.Writer) *CLI { return c } +// Env sets the command's environment variables with the same semantics as exec.Cmd's Env property. +// https://pkg.go.dev/os/exec#Cmd +// +// EnvVar()-provided variables will be appended to whatever Env was set before. +func (c *CLI) Env(env ...string) *CLI { + c.env = env + return c +} + +// EnvVar sets an environment variable for the command, appended to whatever Env is set on the CLI +// when eventually executed, or to environment inherited from the current process if Env() was not +// called. +func (c *CLI) EnvVar(name, value string) *CLI { + if c.addEnvVars == nil { + c.addEnvVars = make(map[string]string) + } + c.addEnvVars[name] = value + return c +} + // Run executes given OpenShift CLI command verb (iow. "oc "). // This function also override the default 'stdout' to redirect all output // to a buffer and prepare the global flags such as namespace and config path. @@ -982,6 +1009,17 @@ func (c *CLI) start(stdOutBuff, stdErrBuff *bytes.Buffer) (*exec.Cmd, error) { // Redact any bearer token information from the log. framework.Logf("Running '%s %s'", c.execPath, RedactBearerToken(strings.Join(c.finalArgs, " "))) + cmd.Env = c.env + if len(c.addEnvVars) > 0 { + // This is a nil check to allow setting empty environment with Env() + if cmd.Env == nil { + cmd.Env = os.Environ() + } + for name, value := range c.addEnvVars { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", name, value)) + } + } + cmd.Stdout = stdOutBuff cmd.Stderr = stdErrBuff err := cmd.Start() diff --git a/zz_generated.manifests/test-reporting.yaml b/zz_generated.manifests/test-reporting.yaml index a87159afd88d..5f00758b1cf5 100644 --- a/zz_generated.manifests/test-reporting.yaml +++ b/zz_generated.manifests/test-reporting.yaml @@ -1575,6 +1575,10 @@ spec: container''s primary UID belongs to some groups in the image when scheduled node supports SupplementalGroupsPolicy it should NOT add SupplementalGroups to them [LinuxOnly]' + - featureGate: UpgradeStatus + tests: + - testName: '[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status reports + correctly when the cluster is not updating' - featureGate: UserNamespacesSupport tests: - testName: '[Suite:openshift/usernamespace] [sig-node] [FeatureGate:ProcMountType]