Skip to content

Commit

Permalink
Merge pull request #11320 from soltysh/issue11305
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Oct 20, 2016
2 parents 7405f17 + 9f6c430 commit 28ae87f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
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

0 comments on commit 28ae87f

Please sign in to comment.