~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/ec2/live_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
        "crypto/rand"
8
8
        "fmt"
9
9
        "io"
10
 
        "strings"
11
10
 
12
11
        jc "github.com/juju/testing/checkers"
13
12
        "github.com/juju/utils/arch"
24
23
        jujutesting "github.com/juju/juju/juju/testing"
25
24
        "github.com/juju/juju/provider/ec2"
26
25
        coretesting "github.com/juju/juju/testing"
27
 
        "github.com/juju/juju/version"
 
26
        jujuversion "github.com/juju/juju/version"
28
27
)
29
28
 
30
29
// uniqueName is generated afresh for every test run, so that
49
48
        //  access-key: $AWS_ACCESS_KEY_ID
50
49
        //  secret-key: $AWS_SECRET_ACCESS_KEY
51
50
        attrs := coretesting.FakeConfig().Merge(map[string]interface{}{
52
 
                "name":           "sample-" + uniqueName,
53
 
                "type":           "ec2",
54
 
                "control-bucket": "juju-test-" + uniqueName,
55
 
                "admin-secret":   "for real",
56
 
                "firewall-mode":  config.FwInstance,
57
 
                "agent-version":  coretesting.FakeVersionNumber.String(),
 
51
                "name":          "sample-" + uniqueName,
 
52
                "type":          "ec2",
 
53
                "admin-secret":  "for real",
 
54
                "firewall-mode": config.FwInstance,
 
55
                "agent-version": coretesting.FakeVersionNumber.String(),
58
56
        })
59
57
        gc.Suite(&LiveTests{
60
58
                LiveTests: jujutest.LiveTests{
79
77
        t.UploadArches = []string{arch.AMD64, arch.I386}
80
78
        t.BaseSuite.SetUpSuite(c)
81
79
        t.LiveTests.SetUpSuite(c)
 
80
        t.BaseSuite.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber)
 
81
        t.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
 
82
        t.BaseSuite.PatchValue(&series.HostSeries, func() string { return coretesting.FakeDefaultSeries })
82
83
}
83
84
 
84
85
func (t *LiveTests) TearDownSuite(c *gc.C) {
87
88
}
88
89
 
89
90
func (t *LiveTests) SetUpTest(c *gc.C) {
90
 
        t.BaseSuite.PatchValue(&version.Current, coretesting.FakeVersionNumber)
91
 
        t.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
92
 
        t.BaseSuite.PatchValue(&series.HostSeries, func() string { return coretesting.FakeDefaultSeries })
93
91
        t.BaseSuite.SetUpTest(c)
94
92
        t.LiveTests.SetUpTest(c)
95
93
}
139
137
        c.Assert(*hc.CpuPower, gc.Equals, uint64(650))
140
138
}
141
139
 
 
140
func (t *LiveTests) TestControllerInstances(c *gc.C) {
 
141
        t.BootstrapOnce(c)
 
142
        allInsts, err := t.Env.AllInstances()
 
143
        c.Assert(err, jc.ErrorIsNil)
 
144
        c.Assert(allInsts, gc.HasLen, 1) // bootstrap instance
 
145
        bootstrapInstId := allInsts[0].Id()
 
146
 
 
147
        inst0, _ := testing.AssertStartInstance(c, t.Env, "98")
 
148
        defer t.Env.StopInstances(inst0.Id())
 
149
 
 
150
        inst1, _ := testing.AssertStartInstance(c, t.Env, "99")
 
151
        defer t.Env.StopInstances(inst1.Id())
 
152
 
 
153
        insts, err := t.Env.ControllerInstances()
 
154
        c.Assert(err, jc.ErrorIsNil)
 
155
        c.Assert(insts, gc.DeepEquals, []instance.Id{bootstrapInstId})
 
156
}
 
157
 
142
158
func (t *LiveTests) TestInstanceGroups(c *gc.C) {
143
159
        t.BootstrapOnce(c)
144
160
        allInsts, err := t.Env.AllInstances()
350
366
        }
351
367
}
352
368
 
353
 
func (t *LiveTests) TestPutBucketOnlyOnce(c *gc.C) {
354
 
        t.PrepareOnce(c)
355
 
        s3inst := ec2.EnvironS3(t.Env)
356
 
        b, err := s3inst.Bucket("test-once-" + uniqueName)
357
 
        c.Assert(err, jc.ErrorIsNil)
358
 
        s := ec2.BucketStorage(b)
359
 
 
360
 
        // Check that we don't do a PutBucket every time by
361
 
        // getting it to create the bucket, destroying the bucket behind
362
 
        // the scenes, and trying to put another object,
363
 
        // which should fail because it doesn't try to do
364
 
        // the PutBucket again.
365
 
 
366
 
        err = s.Put("test-object", strings.NewReader("test"), 4)
367
 
        c.Assert(err, jc.ErrorIsNil)
368
 
 
369
 
        err = s.Remove("test-object")
370
 
        c.Assert(err, jc.ErrorIsNil)
371
 
 
372
 
        err = ec2.DeleteBucket(s)
373
 
        c.Assert(err, jc.ErrorIsNil)
374
 
 
375
 
        err = s.Put("test-object", strings.NewReader("test"), 4)
376
 
        c.Assert(err, gc.ErrorMatches, ".*The specified bucket does not exist")
377
 
}
378
 
 
379
369
// createGroup creates a new EC2 group and returns it. If it already exists,
380
370
// it revokes all its permissions and returns the existing group.
381
371
func createGroup(c *gc.C, ec2conn *amzec2.EC2, name, descr string) amzec2.SecurityGroup {