Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 400f3eb

Browse files
authored
Refactor InstallerURL config passing. (#259)
In order to accommodate unique installers on a per test basis always treat the InstallerURL from the provisioner as the default and override it when `installer_url` is specified in the test parameter JSON. This was previously available for the install test, but is now available for all tests in the sanity suite. This is needed to spit the images between upgrade and all other testing for incremental rollout of new robotest images: gravitational/gravity#1908 gravitational/gravity#1915
1 parent 854b185 commit 400f3eb

File tree

7 files changed

+24
-32
lines changed

7 files changed

+24
-32
lines changed

suite/sanity/install.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ func install(p interface{}) (gravity.TestFunc, error) {
9696
g.Maybe("destroy", cluster.Destroy())
9797
}()
9898

99-
installerURL := cfg.InstallerURL
100-
if param.InstallerURL != "" {
101-
installerURL = param.InstallerURL
102-
}
103-
104-
g.OK("installer downloaded", g.SetInstaller(cluster.Nodes, installerURL, "install"))
99+
g.OK("installer downloaded", g.SetInstaller(cluster.Nodes, param.InstallerURL, "install"))
105100
if param.Script != nil {
106101
g.OK("post bootstrap script",
107102
g.ExecScript(cluster.Nodes, param.Script.Url, param.Script.Args, param.Script.Timeout.Duration))
@@ -121,11 +116,6 @@ func provision(p interface{}) (gravity.TestFunc, error) {
121116
g.Maybe("destroy", cluster.Destroy())
122117
}()
123118

124-
installerURL := cfg.InstallerURL
125-
if param.InstallerURL != "" {
126-
installerURL = param.InstallerURL
127-
}
128-
129-
g.OK("download installer", g.SetInstaller(cluster.Nodes, installerURL, "install"))
119+
g.OK("download installer", g.SetInstaller(cluster.Nodes, param.InstallerURL, "install"))
130120
}, nil
131121
}

suite/sanity/loss_recover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func lossAndRecovery(p interface{}) (gravity.TestFunc, error) {
9696
g.Maybe("destroy", cluster.Destroy())
9797
}()
9898

99-
g.OK("download installer", g.SetInstaller(cluster.Nodes, cfg.InstallerURL, "install"))
99+
g.OK("download installer", g.SetInstaller(cluster.Nodes, param.InstallerURL, "install"))
100100

101101
nodes := cluster.Nodes[0:param.NodeCount]
102102
g.OK("install", g.OfflineInstall(nodes, param.InstallParam))

suite/sanity/resize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func resize(p interface{}) (gravity.TestFunc, error) {
5454
g.Maybe("destroy", cluster.Destroy())
5555
}()
5656

57-
g.OK("download installer", g.SetInstaller(cluster.Nodes, cfg.InstallerURL, "install"))
57+
g.OK("download installer", g.SetInstaller(cluster.Nodes, param.InstallerURL, "install"))
5858
g.OK(fmt.Sprintf("install on %d node", param.NodeCount),
5959
g.OfflineInstall(cluster.Nodes[:param.NodeCount], param.InstallParam))
6060
g.OK("wait for active status", g.WaitForActiveStatus(cluster.Nodes[:param.NodeCount]))

suite/sanity/sanity.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import (
2222
"github.com/gravitational/robotest/lib/defaults"
2323
)
2424

25-
var defaultInstallParam = installParam{
26-
InstallParam: gravity.InstallParam{
27-
StateDir: defaults.GravityDir,
28-
},
29-
}
30-
3125
// Suite returns base configuration for a suite which may be further customized
32-
func Suite() *config.Config {
26+
func Suite(provisionerConfig gravity.ProvisionerConfig) *config.Config {
3327
cfg := config.New()
3428

29+
defaultInstallParam := installParam{
30+
InstallParam: gravity.InstallParam{
31+
InstallerURL: provisionerConfig.InstallerURL,
32+
StateDir: defaults.GravityDir,
33+
},
34+
}
35+
3536
cfg.Add("noop", noop, noopParam{})
3637
cfg.Add("noopV", noopVariety, noopParam{})
3738
cfg.Add("provision", provision, defaultInstallParam)
@@ -40,7 +41,7 @@ func Suite() *config.Config {
4041
cfg.Add("recover", lossAndRecovery, lossAndRecoveryParam{installParam: defaultInstallParam})
4142
cfg.Add("recoverV", lossAndRecoveryVariety, defaultInstallParam)
4243
cfg.Add("shrink", shrink, defaultInstallParam)
43-
cfg.Add("upgrade", upgrade, upgradeParam{installParam: defaultInstallParam})
44+
cfg.Add("upgrade", upgrade, upgradeParam{installParam: defaultInstallParam, GravityURL: provisionerConfig.GravityURL})
4445
// upgrade3lts is vestigial alias for upgrade needed for backwards compat
4546
// to prevent issues like:
4647
// https://github.com/gravitational/gravity/issues/1508

suite/sanity/shrink.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func shrink(p interface{}) (gravity.TestFunc, error) {
4242
copy(others, cluster.Nodes[1:])
4343
g.Logger().WithFields(logrus.Fields{"target": target, "others": others}).Info("Select join/shrink target.")
4444

45-
g.OK("Download installer.", g.SetInstaller(all, cfg.InstallerURL, "install"))
45+
g.OK("Download installer.", g.SetInstaller(all, param.InstallerURL, "install"))
4646

4747
g.OK("Install.", g.OfflineInstall(others, param.InstallParam))
4848
g.OK("Wait for active status.", g.WaitForActiveStatus(others))

suite/sanity/upgrade.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type upgradeParam struct {
2727
installParam
2828
// BaseInstallerURL is initial app installer URL
2929
BaseInstallerURL string `json:"from" validate:"required"`
30+
GravityURL string `json:"gravity_url"`
3031
}
3132

3233
func (p upgradeParam) Save() (row map[string]bigquery.Value, insertID string, err error) {
@@ -52,7 +53,7 @@ func upgrade(p interface{}) (gravity.TestFunc, error) {
5253
g.OK("base installer", g.SetInstaller(cluster.Nodes, param.BaseInstallerURL, "base"))
5354
g.OK("install", g.OfflineInstall(cluster.Nodes, param.InstallParam))
5455
g.OK("wait for active status", g.WaitForActiveStatus(cluster.Nodes))
55-
g.OK("upgrade", g.Upgrade(cluster.Nodes, cfg.InstallerURL, cfg.GravityURL, "upgrade"))
56+
g.OK("upgrade", g.Upgrade(cluster.Nodes, param.InstallerURL, param.GravityURL, "upgrade"))
5657
g.OK("wait for active status", g.WaitForActiveStatus(cluster.Nodes))
5758
}, nil
5859
}

suite/suite_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
)
3939

4040
var testSuite = flag.String("suite", "sanity", "test suite to run")
41-
var provision = flag.String("provision", "", "cloud credentials in JSON string")
41+
var provision = flag.String("provision", "", "cloud credentials in YAML string")
4242
var tag = flag.String("tag", "", "tag to uniquely mark resources in cloud")
4343

4444
var repeat = flag.Int("repeat", 1, "the number of times to schedule each test")
@@ -60,10 +60,6 @@ var versionFlag = flag.Bool("version", false, "Display version information")
6060
// max amount of time test will run
6161
var testMaxTime = time.Hour * 12
6262

63-
var suites = map[string]*config.Config{
64-
"sanity": sanity.Suite(),
65-
}
66-
6763
func setupSignals(suite gravity.TestSuite) {
6864
c := make(chan os.Signal, 3)
6965
signal.Notify(c, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
@@ -99,8 +95,12 @@ func TestMain(t *testing.T) {
9995
log.Debugf("Version:\t%s", robotest.Version)
10096
log.Debugf("Git Commit:\t%s", robotest.GitCommit)
10197

102-
config := gravity.LoadConfig(t, []byte(*provision))
103-
config = config.WithTag(*tag)
98+
provisionerConfig := gravity.LoadConfig(t, []byte(*provision))
99+
provisionerConfig = provisionerConfig.WithTag(*tag)
100+
101+
suites := map[string]*config.Config{
102+
"sanity": sanity.Suite(provisionerConfig),
103+
}
104104

105105
suiteCfg, there := suites[*testSuite]
106106
if !there {
@@ -141,7 +141,7 @@ func TestMain(t *testing.T) {
141141
for r := 1; r <= *repeat; r++ {
142142
for ts, entry := range testSet {
143143
suite.Schedule(entry.TestFunc,
144-
config.WithTag(fmt.Sprintf("%s-%d", ts, r)),
144+
provisionerConfig.WithTag(fmt.Sprintf("%s-%d", ts, r)),
145145
entry.Param)
146146
}
147147
}

0 commit comments

Comments
 (0)