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

Allow running extended test without specifying namespace #11320

Merged
merged 1 commit into from
Oct 20, 2016
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
6 changes: 3 additions & 3 deletions test/extended/images/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ = g.Describe("[images] prune images", func() {
o.Expect(err).NotTo(o.HaveOccurred())

g.By(fmt.Sprintf("give a user %s a right to prune images with %s role", oc.Username(), "system:image-pruner"))
err = oc.AsAdmin().Run("adm").Args("policy", "add-cluster-role-to-user", "system:image-pruner", oc.Username()).Execute()
err = oc.AsAdmin().WithoutNamespace().Run("adm").Args("policy", "add-cluster-role-to-user", "system:image-pruner", oc.Username()).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
})

Expand Down Expand Up @@ -126,7 +126,7 @@ func testPruneImages(oc *exutil.CLI, schemaVersion int) {
o.Expect(imgKeep.DockerImageManifestMediaType).To(o.Equal(mediaType))

g.By("prune the first image uploaded (dry-run)")
output, err := oc.Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0").Output()
output, err := oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0").Output()

g.By("verify images, layers and configs about to be pruned")
o.Expect(output).To(o.ContainSubstring(imgPruneName))
Expand Down Expand Up @@ -154,7 +154,7 @@ func testPruneImages(oc *exutil.CLI, schemaVersion int) {
o.Expect(noConfirmSize).To(o.Equal(keepSize))

g.By("prune the first image uploaded (confirm)")
output, err = oc.Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm").Output()
output, err = oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm").Output()

g.By("verify images, layers and configs about to be pruned")
o.Expect(output).To(o.ContainSubstring(imgPruneName))
Expand Down
41 changes: 25 additions & 16 deletions test/extended/util/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ import (
// CLI provides function to call the OpenShift CLI and Kubernetes and OpenShift
// REST clients.
type CLI struct {
execPath string
verb string
configPath string
adminConfigPath string
username string
outputDir string
globalArgs []string
commandArgs []string
finalArgs []string
stdin *bytes.Buffer
stdout io.Writer
stderr io.Writer
verbose bool
cmd *cobra.Command
kubeFramework *e2e.Framework
execPath string
verb string
configPath string
adminConfigPath string
username string
outputDir string
globalArgs []string
commandArgs []string
finalArgs []string
stdin *bytes.Buffer
stdout io.Writer
stderr io.Writer
verbose bool
withoutNamespace bool
cmd *cobra.Command
kubeFramework *e2e.Framework
}

// NewCLI initialize the upstream E2E framework and set the namespace to match
Expand Down Expand Up @@ -129,6 +130,12 @@ func (c *CLI) SetNamespace(ns string) *CLI {
return c
}

// WithoutNamespace instructs the command should be invoked without adding --namespace parameter
func (c *CLI) WithoutNamespace() *CLI {
c.withoutNamespace = true
return c
}

// SetOutputDir change the default output directory for temporary files
func (c *CLI) SetOutputDir(dir string) *CLI {
c.outputDir = dir
Expand Down Expand Up @@ -239,10 +246,12 @@ func (c *CLI) Run(commands ...string) *CLI {
username: c.username,
outputDir: c.outputDir,
globalArgs: append(commands, []string{
fmt.Sprintf("--namespace=%s", c.Namespace()),
fmt.Sprintf("--config=%s", c.configPath),
}...),
}
if !c.withoutNamespace {
nc.globalArgs = append(nc.globalArgs, fmt.Sprintf("--namespace=%s", c.Namespace()))
}
nc.stdin, nc.stdout, nc.stderr = in, out, errout
return nc.setOutput(c.stdout)
}
Expand Down