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

Unified Diff: environs/jujutest/livetests.go

Issue 6347044: environs/ec2: bootstrap (Closed)
Patch Set: environs/ec2: bootstrap Created 5 years, 6 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
« no previous file with comments | « environs/ec2/suite_test.go ('k') | environs/jujutest/test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: environs/jujutest/livetests.go
=== modified file 'environs/jujutest/livetests.go'
--- environs/jujutest/livetests.go 2012-06-21 20:40:39 +0000
+++ environs/jujutest/livetests.go 2012-06-28 06:38:11 +0000
@@ -75,6 +75,13 @@
if t.CanOpenState {
st, err := state.Open(info)
c.Assert(err, IsNil)
+ env, err := st.EnvironConfig()
+ c.Assert(err, IsNil)
+ err = t.seedSecrets(env)
+ c.Assert(err, IsNil)
+ if t.HasProvisioner {
+ t.testProvisioning(c, st)
+ }
st.Close()
}
@@ -85,6 +92,98 @@
t.BootstrapOnce(c)
}
+// seed secrets pushes into the state
+func (t *LiveTests) seedSecrets(env *state.ConfigNode) error {
+ // TODO(dfc) need some way to publish correct ec2 secrets
+ return nil
+}
+
+func (t *LiveTests) testProvisioning(c *C, st *state.State) {
+ // place a new machine into the state
+ m, err := st.AddMachine()
+ c.Assert(err, IsNil)
+
+ t.checkStartInstance(c, m)
+
+ // now remove it
+ c.Assert(st.RemoveMachine(m.Id()), IsNil)
+
+ // watch the PA remove it
+ t.checkStopInstance(c, m)
+ checkMachineId(c, m, nil)
+}
+
+var agentReaction = environs.AttemptStrategy{
+ Total: 30 * time.Second,
+ Delay: 1 * time.Second,
+}
+
+func (t *LiveTests) checkStartInstance(c *C, m *state.Machine) (instId string) {
+ // Wait for machine to get instance id.
+ for a := agentReaction.Start(); a.Next(); {
+ var err error
+ instId, err = m.InstanceId()
+ if _, ok := err.(*state.NoInstanceIdError); ok {
+ continue
+ }
+ c.Assert(err, IsNil)
+ if instId != "" {
+ break
+ }
+ }
+ if instId == "" {
+ c.Fatalf("provisioner failed to start machine after %v", agentReaction.Total)
+ }
+ _, err := t.Env.Instances([]string{instId})
+ c.Assert(err, IsNil)
+ return
+}
+
+func (t *LiveTests) checkStopInstance(c *C, m *state.Machine) (instId string) {
+ // Wait for machine to get instance id.
+ for a := agentReaction.Start(); a.Next(); {
+ var err error
+ instId, err = m.InstanceId()
+ c.Assert(err, IsNil)
+ if instId != "" {
+ break
+ }
+ }
+ if instId == "" {
+ c.Fatalf("provisioner failed to stop machine after %v", agentReaction.Total)
+ }
+ _, err := t.Env.Instances([]string{instId})
+ c.Assert(err, IsNil)
+ return
+}
+
+// checkMachineIdSet checks that the machine has an instance id
+// that matches that of the given instance. If the instance is nil,
+// It checks that the instance id is unset.
+func checkMachineId(c *C, m *state.Machine, inst environs.Instance) {
+ // TODO(dfc) add machine.WatchConfig() to avoid having to poll.
+ instId := ""
+ if inst != nil {
+ instId = inst.Id()
+ }
+ for a := agentReaction.Start(); a.Next(); {
+ _, err := m.InstanceId()
+ _, notset := err.(*state.NoInstanceIdError)
+ if notset {
+ if inst == nil {
+ return
+ } else {
+ continue
+ }
+ }
+ c.Assert(err, IsNil)
+ break
+ }
+ id, err := m.InstanceId()
+ c.Assert(err, IsNil)
+ c.Assert(id, Equals, instId)
+}
+
// TODO check that binary data works ok?
var contents = []byte("hello\n")
var contents2 = []byte("goodbye\n\n")
« no previous file with comments | « environs/ec2/suite_test.go ('k') | environs/jujutest/test.go » ('j') | no next file with comments »

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