Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(461)

Unified Diff: environs/cloudinit/cloudinit_test.go

Issue 83530043: environs/cloudinit: use StateServingInfo
Patch Set: environs/cloudinit: use StateServingInfo Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: environs/cloudinit/cloudinit_test.go
=== modified file 'environs/cloudinit/cloudinit_test.go'
--- environs/cloudinit/cloudinit_test.go 2014-04-01 08:19:52 +0000
+++ environs/cloudinit/cloudinit_test.go 2014-04-02 09:32:24 +0000
@@ -71,6 +71,13 @@
return s
}
+var stateServingInfo = &params.StateServingInfo{
+ Cert: string(serverCert),
+ PrivateKey: string(serverKey),
+ StatePort: 37017,
+ APIPort: 17070,
+}
+
// Each test gives a cloudinit config - we check the
// output to see if it looks correct.
var cloudinitTests = []cloudinitTest{
@@ -81,13 +88,10 @@
AuthorizedKeys: "sshkey1",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
// precise currently needs mongo from PPA
- Tools: newSimpleTools("1.2.3-precise-amd64"),
- StateServer: true,
- StateServerCert: serverCert,
- StateServerKey: serverKey,
- StatePort: 37017,
- APIPort: 17070,
- MachineNonce: "FAKE_NONCE",
+ Tools: newSimpleTools("1.2.3-precise-amd64"),
+ Bootstrap: true,
+ StateServingInfo: stateServingInfo,
+ MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
Password: "arble",
CACert: []byte("CA CERT\n" + testing.CACert),
@@ -162,13 +166,10 @@
AuthorizedKeys: "sshkey1",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
// raring provides mongo in the archive
- Tools: newSimpleTools("1.2.3-raring-amd64"),
- StateServer: true,
- StateServerCert: serverCert,
- StateServerKey: serverKey,
- StatePort: 37017,
- APIPort: 17070,
- MachineNonce: "FAKE_NONCE",
+ Tools: newSimpleTools("1.2.3-raring-amd64"),
+ Bootstrap: true,
+ StateServingInfo: stateServingInfo,
+ MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
Password: "arble",
CACert: []byte("CA CERT\n" + testing.CACert),
@@ -207,13 +208,10 @@
AuthorizedKeys: "sshkey1",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
// raring provides mongo in the archive
- Tools: newSimpleTools("1.2.3-trusty-amd64"),
- StateServer: true,
- StateServerCert: serverCert,
- StateServerKey: serverKey,
- StatePort: 37017,
- APIPort: 17070,
- MachineNonce: "FAKE_NONCE",
+ Tools: newSimpleTools("1.2.3-trusty-amd64"),
+ Bootstrap: true,
+ StateServingInfo: stateServingInfo,
+ MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
Password: "arble",
CACert: []byte("CA CERT\n" + testing.CACert),
@@ -248,7 +246,7 @@
LogDir: agent.DefaultLogDir,
Jobs: normalMachineJobs,
CloudInitOutputLog: environs.CloudInitOutputLog,
- StateServer: false,
+ Bootstrap: false,
Tools: newSimpleTools("1.2.3-linux-amd64"),
MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
@@ -303,7 +301,7 @@
LogDir: agent.DefaultLogDir,
Jobs: normalMachineJobs,
CloudInitOutputLog: environs.CloudInitOutputLog,
- StateServer: false,
+ Bootstrap: false,
Tools: newSimpleTools("1.2.3-linux-amd64"),
MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
@@ -339,7 +337,7 @@
LogDir: agent.DefaultLogDir,
Jobs: normalMachineJobs,
CloudInitOutputLog: environs.CloudInitOutputLog,
- StateServer: false,
+ Bootstrap: false,
Tools: newSimpleTools("1.2.3-linux-amd64"),
MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
@@ -368,13 +366,10 @@
AuthorizedKeys: "sshkey1",
AgentEnvironment: map[string]string{agent.ProviderType: "dummy"},
// precise currently needs mongo from PPA
- Tools: newSimpleTools("1.2.3-precise-amd64"),
- StateServer: true,
- StateServerCert: serverCert,
- StateServerKey: serverKey,
- StatePort: 37017,
- APIPort: 17070,
- MachineNonce: "FAKE_NONCE",
+ Tools: newSimpleTools("1.2.3-precise-amd64"),
+ Bootstrap: true,
+ StateServingInfo: stateServingInfo,
+ MachineNonce: "FAKE_NONCE",
StateInfo: &state.Info{
Password: "arble",
CACert: []byte("CA CERT\n" + testing.CACert),
@@ -445,7 +440,7 @@
var actual map[string]interface{}
err = goyaml.Unmarshal(buf, &actual)
c.Assert(err, gc.IsNil)
- c.Assert(cfg.AllAttrs(), gc.DeepEquals, actual)
+ c.Assert(cfg.AllAttrs(), jc.DeepEquals, actual)
}
c.Assert(found, gc.Equals, true)
}
@@ -491,7 +486,7 @@
tag := names.MachineTag(test.cfg.MachineId)
acfg := getAgentConfig(c, tag, scripts)
c.Assert(acfg, jc.Contains, "AGENT_SERVICE_NAME: jujud-"+tag)
- if test.cfg.StateServer {
+ if test.cfg.Bootstrap {
series := test.cfg.Tools.Version.Series
mongoPackage := expectedMongoPackage[series]
checkPackage(c, x, mongoPackage, true)
@@ -681,7 +676,7 @@
cfg.APIInfo = nil
}},
{"missing state hosts", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
+ cfg.Bootstrap = false
cfg.StateInfo = &state.Info{
Tag: "machine-99",
CACert: []byte(testing.CACert),
@@ -693,7 +688,7 @@
}
}},
{"missing API hosts", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
+ cfg.Bootstrap = false
cfg.StateInfo = &state.Info{
Addrs: []string{"foo:35"},
Tag: "machine-99",
@@ -708,17 +703,31 @@
cfg.StateInfo = &state.Info{Addrs: []string{"host:98765"}}
}},
{"missing CA certificate", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
+ cfg.Bootstrap = false
cfg.StateInfo = &state.Info{
Tag: "machine-99",
Addrs: []string{"host:98765"},
}
}},
{"missing state server certificate", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServerCert = []byte{}
+ info := *cfg.StateServingInfo
+ info.Cert = ""
+ cfg.StateServingInfo = &info
}},
{"missing state server private key", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServerKey = []byte{}
+ info := *cfg.StateServingInfo
+ info.PrivateKey = ""
+ cfg.StateServingInfo = &info
+ }},
+ {"missing state port", func(cfg *cloudinit.MachineConfig) {
+ info := *cfg.StateServingInfo
+ info.StatePort = 0
+ cfg.StateServingInfo = &info
+ }},
+ {"missing API port", func(cfg *cloudinit.MachineConfig) {
+ info := *cfg.StateServingInfo
+ info.APIPort = 0
+ cfg.StateServingInfo = &info
}},
{"missing var directory", func(cfg *cloudinit.MachineConfig) {
cfg.DataDir = ""
@@ -736,44 +745,38 @@
cfg.Tools = &tools.Tools{}
}},
{"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
- info := *cfg.StateInfo
- info.Tag = "machine-0"
- cfg.StateInfo = &info
- }},
- {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
- info := *cfg.StateInfo
- info.Tag = ""
- cfg.StateInfo = &info
- }},
- {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
- info := *cfg.APIInfo
- info.Tag = "machine-0"
- cfg.APIInfo = &info
- }},
- {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
- cfg.StateServer = false
- info := *cfg.APIInfo
- info.Tag = ""
- cfg.APIInfo = &info
- }},
- {"entity tag must be blank when starting a state server", func(cfg *cloudinit.MachineConfig) {
- info := *cfg.StateInfo
- info.Tag = "machine-0"
- cfg.StateInfo = &info
- }},
- {"entity tag must be blank when starting a state server", func(cfg *cloudinit.MachineConfig) {
- info := *cfg.APIInfo
- info.Tag = "machine-0"
- cfg.APIInfo = &info
- }},
- {"missing state port", func(cfg *cloudinit.MachineConfig) {
- cfg.StatePort = 0
- }},
- {"missing API port", func(cfg *cloudinit.MachineConfig) {
- cfg.APIPort = 0
+ cfg.Bootstrap = false
+ info := *cfg.StateInfo
+ info.Tag = "machine-0"
+ cfg.StateInfo = &info
+ }},
+ {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
+ cfg.Bootstrap = false
+ info := *cfg.StateInfo
+ info.Tag = ""
+ cfg.StateInfo = &info
+ }},
+ {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
+ cfg.Bootstrap = false
+ info := *cfg.APIInfo
+ info.Tag = "machine-0"
+ cfg.APIInfo = &info
+ }},
+ {"entity tag must match started machine", func(cfg *cloudinit.MachineConfig) {
+ cfg.Bootstrap = false
+ info := *cfg.APIInfo
+ info.Tag = ""
+ cfg.APIInfo = &info
+ }},
+ {"entity tag must be blank when starting a state server", func(cfg *cloudinit.MachineConfig) {
+ info := *cfg.StateInfo
+ info.Tag = "machine-0"
+ cfg.StateInfo = &info
+ }},
+ {"entity tag must be blank when starting a state server", func(cfg *cloudinit.MachineConfig) {
+ info := *cfg.APIInfo
+ info.Tag = "machine-0"
+ cfg.APIInfo = &info
}},
{"missing machine nonce", func(cfg *cloudinit.MachineConfig) {
cfg.MachineNonce = ""
@@ -787,17 +790,23 @@
{"missing instance-id", func(cfg *cloudinit.MachineConfig) {
cfg.InstanceId = ""
}},
+ {"state serving info unexpectedly present", func(cfg *cloudinit.MachineConfig) {
+ cfg.Bootstrap = false
+ apiInfo := *cfg.APIInfo
+ apiInfo.Tag = "machine-99"
+ cfg.APIInfo = &apiInfo
+ stateInfo := *cfg.StateInfo
+ stateInfo.Tag = "machine-99"
+ cfg.StateInfo = &stateInfo
+ }},
}
// TestCloudInitVerify checks that required fields are appropriately
// checked for by NewCloudInit.
func (*cloudinitSuite) TestCloudInitVerify(c *gc.C) {
cfg := &cloudinit.MachineConfig{
- StateServer: true,
- StateServerCert: serverCert,
- StateServerKey: serverKey,
- StatePort: 1234,
- APIPort: 1235,
+ Bootstrap: true,
+ StateServingInfo: stateServingInfo,
MachineId: "99",
Tools: newSimpleTools("9.9.9-linux-arble"),
AuthorizedKeys: "sshkey1",
@@ -824,15 +833,20 @@
}
// check that the base configuration does not give an error
ci := coreCloudinit.New()
- err := cloudinit.Configure(cfg, ci)
- c.Assert(err, gc.IsNil)
for i, test := range verifyTests {
+ // check that the base configuration does not give an error
+ // and that a previous test hasn't mutated it accidentially.
+ err := cloudinit.Configure(cfg, ci)
+ c.Assert(err, gc.IsNil)
+
c.Logf("test %d. %s", i, test.err)
+
cfg1 := *cfg
test.mutate(&cfg1)
err = cloudinit.Configure(&cfg1, ci)
c.Assert(err, gc.ErrorMatches, "invalid machine configuration: "+test.err)
+
}
}
@@ -859,7 +873,7 @@
c.Assert(err, gc.IsNil)
cmds := cloudcfg.BootCmds()
- c.Assert(cmds, gc.DeepEquals, []interface{}{})
+ c.Assert(cmds, jc.DeepEquals, []interface{}{})
}
func (s *cloudinitSuite) TestAptProxyWritten(c *gc.C) {
@@ -875,7 +889,7 @@
cmds := cloudcfg.BootCmds()
expected := "[ -f /etc/apt/apt.conf.d/42-juju-proxy-settings ] || (printf '%s\\n' 'Acquire::http::Proxy \"http://user@10.0.0.1\";' > /etc/apt/apt.conf.d/42-juju-proxy-settings)"
- c.Assert(cmds, gc.DeepEquals, []interface{}{expected})
+ c.Assert(cmds, jc.DeepEquals, []interface{}{expected})
}
func (s *cloudinitSuite) TestProxyWritten(c *gc.C) {

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b