~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/local_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:
29
29
        "github.com/juju/juju/constraints"
30
30
        "github.com/juju/juju/environs"
31
31
        "github.com/juju/juju/environs/bootstrap"
32
 
        "github.com/juju/juju/environs/config"
33
 
        "github.com/juju/juju/environs/configstore"
34
32
        "github.com/juju/juju/environs/imagemetadata"
35
33
        imagetesting "github.com/juju/juju/environs/imagemetadata/testing"
36
34
        "github.com/juju/juju/environs/jujutest"
47
45
        "github.com/juju/juju/provider/common"
48
46
        "github.com/juju/juju/provider/ec2"
49
47
        coretesting "github.com/juju/juju/testing"
50
 
        "github.com/juju/juju/version"
 
48
        jujuversion "github.com/juju/juju/version"
51
49
)
52
50
 
53
51
type ProviderSuite struct {
57
55
var _ = gc.Suite(&ProviderSuite{})
58
56
 
59
57
var localConfigAttrs = coretesting.FakeConfig().Merge(coretesting.Attrs{
60
 
        "name":           "sample",
61
 
        "type":           "ec2",
62
 
        "control-bucket": "test-bucket",
63
 
        "agent-version":  coretesting.FakeVersionNumber.String(),
 
58
        "name":          "sample",
 
59
        "type":          "ec2",
 
60
        "agent-version": coretesting.FakeVersionNumber.String(),
64
61
})
65
62
 
66
63
func registerLocalTests() {
100
97
        t.TestConfig = localConfigAttrs
101
98
        t.restoreEC2Patching = patchEC2ForTesting(c)
102
99
        imagetesting.PatchOfficialDataSources(&t.BaseSuite.CleanupSuite, "test:")
 
100
        t.BaseSuite.PatchValue(&imagemetadata.SimplestreamsImagesPublicKey, sstesting.SignedMetadataPublicKey)
103
101
        t.srv.createRootDisks = true
104
102
        t.srv.startServer(c)
105
103
}
192
190
 
193
191
func (t *localServerSuite) SetUpSuite(c *gc.C) {
194
192
        t.BaseSuite.SetUpSuite(c)
195
 
        t.Tests.SetUpSuite(c)
196
193
        t.Credential = cloud.NewCredential(
197
194
                cloud.AccessKeyAuthType,
198
195
                map[string]string{
207
204
        t.UploadArches = []string{arch.AMD64, arch.I386}
208
205
        t.TestConfig = localConfigAttrs
209
206
        t.restoreEC2Patching = patchEC2ForTesting(c)
 
207
        imagetesting.PatchOfficialDataSources(&t.BaseSuite.CleanupSuite, "test:")
 
208
        t.BaseSuite.PatchValue(&imagemetadata.SimplestreamsImagesPublicKey, sstesting.SignedMetadataPublicKey)
 
209
        t.BaseSuite.PatchValue(&juju.JujuPublicKey, sstesting.SignedMetadataPublicKey)
 
210
        t.BaseSuite.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber)
 
211
        t.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
 
212
        t.BaseSuite.PatchValue(&series.HostSeries, func() string { return coretesting.FakeDefaultSeries })
210
213
        t.srv.createRootDisks = true
 
214
        t.srv.startServer(c)
 
215
        // TODO(jam) I don't understand why we shouldn't do this.
 
216
        // t.Tests embeds the sstesting.TestDataSuite, but if we call this
 
217
        // SetUpSuite, then all of the tests fail because they go to access
 
218
        // "test:/streams/..." and it isn't found
 
219
        // t.Tests.SetUpSuite(c)
211
220
}
212
221
 
213
222
func (t *localServerSuite) TearDownSuite(c *gc.C) {
 
223
        t.restoreEC2Patching()
214
224
        t.Tests.TearDownSuite(c)
215
225
        t.BaseSuite.TearDownSuite(c)
216
 
        t.restoreEC2Patching()
217
226
}
218
227
 
219
228
func (t *localServerSuite) SetUpTest(c *gc.C) {
220
 
        t.BaseSuite.PatchValue(&version.Current, coretesting.FakeVersionNumber)
221
 
        t.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 })
222
 
        t.BaseSuite.PatchValue(&series.HostSeries, func() string { return coretesting.FakeDefaultSeries })
223
229
        t.BaseSuite.SetUpTest(c)
224
230
        t.SetFeatureFlags(feature.AddressAllocation)
225
231
        t.srv.startServer(c)
339
345
        t.srv.ec2srv.SetInitialInstanceState(ec2test.Terminated)
340
346
        inst, _ := testing.AssertStartInstance(c, env, "1")
341
347
        c.Assert(err, jc.ErrorIsNil)
342
 
        c.Assert(inst.Status(), gc.Equals, "terminated")
 
348
        c.Assert(inst.Status().Message, gc.Equals, "terminated")
343
349
}
344
350
 
345
351
func (t *localServerSuite) TestStartInstanceHardwareCharacteristics(c *gc.C) {
763
769
        env := t.Prepare(c)
764
770
        validator, err := env.ConstraintsValidator()
765
771
        c.Assert(err, jc.ErrorIsNil)
766
 
        cons := constraints.MustParse("arch=amd64 tags=foo")
 
772
        cons := constraints.MustParse("arch=amd64 tags=foo virt-type=kvm")
767
773
        unsupported, err := validator.Validate(cons)
768
774
        c.Assert(err, jc.ErrorIsNil)
769
 
        c.Assert(unsupported, gc.DeepEquals, []string{"tags"})
 
775
        c.Assert(unsupported, jc.SameContents, []string{"tags", "virt-type"})
770
776
}
771
777
 
772
778
func (t *localServerSuite) TestConstraintsValidatorVocab(c *gc.C) {
1260
1266
        }
1261
1267
        t.srv.startServer(c)
1262
1268
 
1263
 
        cfg, err := config.New(config.NoDefaults, localConfigAttrs)
1264
 
        c.Assert(err, jc.ErrorIsNil)
1265
1269
        env, err := environs.Prepare(
1266
 
                envtesting.BootstrapContext(c), configstore.NewMem(),
 
1270
                envtesting.BootstrapContext(c),
1267
1271
                jujuclienttesting.NewMemStore(),
1268
 
                cfg.Name(), environs.PrepareForBootstrapParams{
1269
 
                        Config: cfg,
1270
 
                        Credentials: cloud.NewCredential(
 
1272
                environs.PrepareParams{
 
1273
                        BaseConfig: localConfigAttrs,
 
1274
                        Credential: cloud.NewCredential(
1271
1275
                                cloud.AccessKeyAuthType,
1272
1276
                                map[string]string{
1273
1277
                                        "access-key": "x",
1274
1278
                                        "secret-key": "x",
1275
1279
                                },
1276
1280
                        ),
1277
 
                        CloudRegion: "test",
 
1281
                        ControllerName: localConfigAttrs["name"].(string),
 
1282
                        CloudName:      "ec2",
 
1283
                        CloudRegion:    "test",
1278
1284
                },
1279
1285
        )
1280
1286
        c.Assert(err, jc.ErrorIsNil)