Skip to content

Commit

Permalink
Merge pull request #19388 from hongkailiu/projExist
Browse files Browse the repository at this point in the history
Handle project existence in cluster-loader
  • Loading branch information
openshift-merge-robot authored May 4, 2018
2 parents 75aaf51 + 99844ae commit 40951ce
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
27 changes: 24 additions & 3 deletions test/extended/cluster/cl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
exutil "github.com/openshift/origin/test/extended/util"
)

const checkDeleteProjectInterval = 10 * time.Second
const checkDeleteProjectTimeout = 3 * time.Minute
const deploymentRunTimeout = 5 * time.Minute
const testResultFile = "/tmp/TestResult"

Expand Down Expand Up @@ -75,11 +77,30 @@ var _ = g.Describe("[Feature:Performance][Serial][Slow] Load cluster", func() {
e2e.Logf("Our tuning set is: %v", tuning)
}
for j := 0; j < p.Number; j++ {
// Create namespaces as defined in Cluster Loader config
nsName := fmt.Sprintf("%s%d", p.Basename, j)
err := oc.Run("new-project").Args(nsName).Execute()

projectExists, err := ProjectExists(oc, nsName)
o.Expect(err).NotTo(o.HaveOccurred())
e2e.Logf("%d/%d : Created new namespace: %v", j+1, p.Number, nsName)

switch p.IfExists {
case IF_EXISTS_REUSE:
e2e.Logf("reuse project %v", nsName)
if !projectExists {
e2e.Failf("reusing project which does not exist: %v", nsName)
}
case IF_EXISTS_DELETE:
if projectExists {
err = DeleteProject(oc, nsName, checkDeleteProjectInterval, checkDeleteProjectTimeout)
o.Expect(err).NotTo(o.HaveOccurred())
}
// Create namespaces as defined in Cluster Loader config
err = oc.Run("new-project").Args(nsName).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
e2e.Logf("%d/%d : Created new namespace: %v", j+1, p.Number, nsName)
default:
e2e.Failf("Unsupported ifexists value '%v' for project %v", p.IfExists, project)
}

// label namespace nsName
if p.Labels != nil {
_, err = SetNamespaceLabels(c, nsName, p.Labels)
Expand Down
6 changes: 6 additions & 0 deletions test/extended/cluster/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/spf13/viper"
)

const (
IF_EXISTS_DELETE = "delete"
IF_EXISTS_REUSE = "reuse"
)

// ContextType is the root config struct
type ContextType struct {
ClusterLoader struct {
Expand All @@ -22,6 +27,7 @@ type ContextType struct {
type ClusterLoaderType struct {
Number int `mapstructure:"num" yaml:"num"`
Basename string
IfExists string `json:"ifexists"`
Labels map[string]string `yaml:",omitempty"`
Tuning string `yaml:",omitempty"`
Configmaps map[string]interface{} `yaml:",omitempty"`
Expand Down
34 changes: 34 additions & 0 deletions test/extended/cluster/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,37 @@ func SetNamespaceLabels(c kclientset.Interface, name string, labels map[string]s
ns.Labels = labels
return c.CoreV1().Namespaces().Update(ns)
}

func ProjectExists(oc *exutil.CLI, name string) (bool, error) {
p, err := oc.AdminProjectClient().Project().Projects().Get(name, metav1.GetOptions{})
if err != nil {
if strings.Contains(err.Error(), "not found") {
return false, nil
}
return false, err
}
if (*p).Name == name {
return true, nil
}
return false, nil
}

func DeleteProject(oc *exutil.CLI, name string, interval, timeout time.Duration) error {
e2e.Logf("Deleting project %v ...", name)
err := oc.AdminProjectClient().Project().Projects().Delete(name, &metav1.DeleteOptions{})
if err != nil {
return err
}
err = wait.Poll(interval, timeout, func() (bool, error) {
exists, err := ProjectExists(oc, name)
if err != nil {
return true, err
}
if exists {
e2e.Logf("The project %v is still there", name)
return false, nil
}
return true, nil
})
return err
}

0 comments on commit 40951ce

Please sign in to comment.