Skip to content

Commit e1ae86a

Browse files
Merge pull request #29954 from petr-muller/ota-1580-test-oc-adm-upgrade-status
OTA-1580: Add basic test for `oc adm upgrade status` CLI
2 parents af0e85d + 85cad81 commit e1ae86a

File tree

6 files changed

+84
-9
lines changed

6 files changed

+84
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md
2+
3+
approvers:
4+
- cluster-version-operator-test-case-approvers
5+
reviewers:
6+
- cluster-version-operator-test-case-reviewers
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package adm_upgrade
2+
3+
import (
4+
g "github.com/onsi/ginkgo/v2"
5+
o "github.com/onsi/gomega"
6+
exutil "github.com/openshift/origin/test/extended/util"
7+
"k8s.io/kubernetes/test/e2e/framework"
8+
)
9+
10+
var _ = g.Describe("[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status", func() {
11+
defer g.GinkgoRecover()
12+
13+
f := framework.NewDefaultFramework("oc-adm-upgrade-status")
14+
f.SkipNamespaceCreation = true
15+
16+
oc := exutil.NewCLIWithoutNamespace("oc-adm-upgrade-status").AsAdmin()
17+
18+
g.It("reports correctly when the cluster is not updating", func() {
19+
cmd := oc.Run("adm", "upgrade", "status").EnvVar("OC_ENABLE_CMD_UPGRADE_STATUS", "true")
20+
out, err := cmd.Output()
21+
o.Expect(err).NotTo(o.HaveOccurred())
22+
o.Expect(out).To(o.Equal("The cluster is not updating."))
23+
})
24+
})

test/extended/include.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
_ "github.com/openshift/origin/test/extended/builds"
1818
_ "github.com/openshift/origin/test/extended/ci"
1919
_ "github.com/openshift/origin/test/extended/cli"
20+
_ "github.com/openshift/origin/test/extended/cli/adm_upgrade"
2021
_ "github.com/openshift/origin/test/extended/cloud_controller_manager"
2122
_ "github.com/openshift/origin/test/extended/cluster"
2223
_ "github.com/openshift/origin/test/extended/clusterversion"

test/extended/util/annotate/generated/zz_generated.annotations.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/extended/util/client.go

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,22 @@ type CLI struct {
9292
// manifest files can be stored under directory tree
9393
staticConfigManifestDir string
9494

95-
token string
96-
username string
97-
globalArgs []string
98-
commandArgs []string
99-
finalArgs []string
100-
namespacesToDelete []string
101-
stdin *bytes.Buffer
102-
stdout io.Writer
103-
stderr io.Writer
95+
token string
96+
username string
97+
globalArgs []string
98+
commandArgs []string
99+
finalArgs []string
100+
namespacesToDelete []string
101+
stdin *bytes.Buffer
102+
stdout io.Writer
103+
stderr io.Writer
104+
105+
// env allows setting environment variables for the command (when nil, the environment
106+
// is inherited from the current process)
107+
env []string
108+
// addEnvVars allows adding environment variables on top of what is defined in env.
109+
addEnvVars map[string]string
110+
104111
verbose bool
105112
withoutNamespace bool
106113
withManagedNamespace bool
@@ -883,6 +890,26 @@ func (c *CLI) setOutput(out io.Writer) *CLI {
883890
return c
884891
}
885892

893+
// Env sets the command's environment variables with the same semantics as exec.Cmd's Env property.
894+
// https://pkg.go.dev/os/exec#Cmd
895+
//
896+
// EnvVar()-provided variables will be appended to whatever Env was set before.
897+
func (c *CLI) Env(env ...string) *CLI {
898+
c.env = env
899+
return c
900+
}
901+
902+
// EnvVar sets an environment variable for the command, appended to whatever Env is set on the CLI
903+
// when eventually executed, or to environment inherited from the current process if Env() was not
904+
// called.
905+
func (c *CLI) EnvVar(name, value string) *CLI {
906+
if c.addEnvVars == nil {
907+
c.addEnvVars = make(map[string]string)
908+
}
909+
c.addEnvVars[name] = value
910+
return c
911+
}
912+
886913
// Run executes given OpenShift CLI command verb (iow. "oc <verb>").
887914
// This function also override the default 'stdout' to redirect all output
888915
// 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) {
9821009
// Redact any bearer token information from the log.
9831010
framework.Logf("Running '%s %s'", c.execPath, RedactBearerToken(strings.Join(c.finalArgs, " ")))
9841011

1012+
cmd.Env = c.env
1013+
if len(c.addEnvVars) > 0 {
1014+
// This is a nil check to allow setting empty environment with Env()
1015+
if cmd.Env == nil {
1016+
cmd.Env = os.Environ()
1017+
}
1018+
for name, value := range c.addEnvVars {
1019+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", name, value))
1020+
}
1021+
}
1022+
9851023
cmd.Stdout = stdOutBuff
9861024
cmd.Stderr = stdErrBuff
9871025
err := cmd.Start()

zz_generated.manifests/test-reporting.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,10 @@ spec:
15751575
container''s primary UID belongs to some groups in the image when scheduled
15761576
node supports SupplementalGroupsPolicy it should NOT add SupplementalGroups
15771577
to them [LinuxOnly]'
1578+
- featureGate: UpgradeStatus
1579+
tests:
1580+
- testName: '[sig-cli][OCPFeatureGate:UpgradeStatus] oc adm upgrade status reports
1581+
correctly when the cluster is not updating'
15781582
- featureGate: UserNamespacesSupport
15791583
tests:
15801584
- testName: '[Suite:openshift/usernamespace] [sig-node] [FeatureGate:ProcMountType]

0 commit comments

Comments
 (0)