Skip to content
Closed
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
81 changes: 81 additions & 0 deletions cmd/openshift-tests/disaster-recovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"encoding/json"
"fmt"
"strings"
"time"

"k8s.io/kubernetes/pkg/kubectl/util/templates"

"github.com/openshift/origin/pkg/test/ginkgo"
_ "github.com/openshift/origin/test/e2e/dr"
)

// disasterRecoverySuites are all known disaster recovery test suites this binary should run
var disasterRecoverySuites = []*ginkgo.TestSuite{
{
Name: "all",
Description: templates.LongDesc(`
Run all tests.
`),
Matches: func(name string) bool {
return strings.Contains(name, "[Feature:DisasterRecovery]")
},
TestTimeout: 120 * time.Minute,
},
}

// DisasterRecoveryOptions lists all options for disaster recovery tests
type DisasterRecoveryOptions struct {
Suite string
TestOptions []string
}

func (o *DisasterRecoveryOptions) OptionsMap() (map[string]string, error) {
options := make(map[string]string)
for _, option := range o.TestOptions {
parts := strings.SplitN(option, "=", 2)
switch {
case len(parts) != 2, len(parts[0]) == 0:
return nil, fmt.Errorf("test option %q is not valid, must be KEY=VALUE", option)
}
_, exists := options[parts[0]]
if exists {
return nil, fmt.Errorf("option %q declared twice", parts[0])
}
options[parts[0]] = parts[1]
}
return options, nil
}

func (o *DisasterRecoveryOptions) ToEnv() string {
out, err := json.Marshal(o)
if err != nil {
panic(err)
}
return string(out)
}

func initDRSnapshotRestore(value string) error {
if len(value) == 0 {
Copy link
Member

@runcom runcom Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit if value == ""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit if value == ""

project standard is to use len. If you have instances of the == "" please update to match the kube/openshift standard.

return nil
}
var opt DisasterRecoveryOptions
if err := json.Unmarshal([]byte(value), &opt); err != nil {
return err
}
for _, suite := range disasterRecoverySuites {
if suite.Name == opt.Suite {
o, err := opt.OptionsMap()
if err != nil {
return err
}
if suite.Init != nil {
return suite.Init(o)
}
return nil
}
}
return fmt.Errorf("unrecognized test info")
}
40 changes: 40 additions & 0 deletions cmd/openshift-tests/openshift-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
newRunUpgradeCommand(),
newRunTestCommand(),
newRunMonitorCommand(),
newRunDisasterRecoveryRestoreSnapshotCommand(),
)

pflag.CommandLine = pflag.NewFlagSet("empty", pflag.ExitOnError)
Expand Down Expand Up @@ -192,6 +193,45 @@ func newRunUpgradeCommand() *cobra.Command {
return cmd
}

func newRunDisasterRecoveryRestoreSnapshotCommand() *cobra.Command {
opt := &testginkgo.Options{Suites: disasterRecoverySuites}
disasterRecoveryOpt := &DisasterRecoveryOptions{}

cmd := &cobra.Command{
Use: "run-dr-restore-snapshot SUITE",
Short: "Run a restore snapshot disaster recovery suite",
Long: templates.LongDesc(`
Help, I'm being held at long description factory

`) + testginkgo.SuitesString(opt.Suites, "\n\nAvailable test suites:\n\n"),

SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
return mirrorToFile(opt, func() error {
if err := initProvider(opt.Provider); err != nil {
return err
}

disasterRecoveryOpt.Suite = "all"
value := disasterRecoveryOpt.ToEnv()
if err := initDRSnapshotRestore(value); err != nil {
return err
}
opt.SuiteOptions = value

e2e.AfterReadingAllFlags(exutil.TestContext)
e2e.TestContext.DumpLogsOnFailure = true
exutil.TestContext.DumpLogsOnFailure = true
return opt.Run(args)
})
},
}

bindOptions(opt, cmd.Flags())
return cmd
}

func newRunTestCommand() *cobra.Command {
testOpt := &testginkgo.TestOptions{
Out: os.Stdout,
Expand Down
Loading