16
17
"launchpad.net/juju-core/environs"
17
18
"launchpad.net/juju-core/environs/bootstrap"
18
19
"launchpad.net/juju-core/environs/config"
20
"launchpad.net/juju-core/environs/imagemetadata"
21
"launchpad.net/juju-core/environs/simplestreams"
19
22
envtesting "launchpad.net/juju-core/environs/testing"
23
envtools "launchpad.net/juju-core/environs/tools"
20
24
"launchpad.net/juju-core/errors"
21
25
"launchpad.net/juju-core/instance"
22
26
"launchpad.net/juju-core/provider"
51
// makeEnviron creates a functional maasEnviron for a test. Its configuration
52
// is a bit arbitrary and none of the test code's business.
55
// makeEnviron creates a functional maasEnviron for a test.
53
56
func (suite *environSuite) makeEnviron() *maasEnviron {
54
config, err := config.New(map[string]interface{}{
55
"name": suite.environ.Name(),
57
"admin-secret": "local-secret",
58
"authorized-keys": "foo",
59
"agent-version": version.CurrentNumber().String(),
60
"maas-oauth": "a:b:c",
61
"maas-server": suite.testMAASObject.TestServer.URL,
62
// These are not needed by MAAS, but juju-core breaks without them. Needs
64
"ca-cert": testing.CACert,
65
"ca-private-key": testing.CAKey,
57
attrs := testing.FakeConfig().Merge(testing.Attrs{
58
"name": suite.environ.Name(),
60
"maas-oauth": "a:b:c",
61
"maas-server": suite.testMAASObject.TestServer.URL,
63
cfg, err := config.New(config.NoDefaults, attrs)
70
env, err := NewEnviron(config)
67
env, err := NewEnviron(cfg)
474
471
err := bootstrap.Bootstrap(env, constraints.Value{})
475
472
c.Assert(err, gc.IsNil)
475
func assertSourceContents(c *gc.C, source simplestreams.DataSource, filename string, content []byte) {
476
rc, _, err := source.Fetch(filename)
477
c.Assert(err, gc.IsNil)
479
retrieved, err := ioutil.ReadAll(rc)
480
c.Assert(err, gc.IsNil)
481
c.Assert(retrieved, gc.DeepEquals, content)
484
func (suite *environSuite) TestGetImageMetadataSources(c *gc.C) {
485
env := suite.makeEnviron()
486
// Add a dummy file to storage so we can use that to check the
487
// obtained source later.
488
data := makeRandomBytes(10)
489
suite.testMAASObject.TestServer.NewFile("filename", data)
490
sources, err := imagemetadata.GetMetadataSources(env)
491
c.Assert(err, gc.IsNil)
492
c.Assert(len(sources), gc.Equals, 2)
493
assertSourceContents(c, sources[0], "filename", data)
494
url, err := sources[1].URL("")
495
c.Assert(err, gc.IsNil)
496
c.Assert(url, gc.Equals, imagemetadata.DefaultBaseURL+"/")
499
func (suite *environSuite) TestGetToolsMetadataSources(c *gc.C) {
500
env := suite.makeEnviron()
501
// Add a dummy file to storage so we can use that to check the
502
// obtained source later.
503
data := makeRandomBytes(10)
504
suite.testMAASObject.TestServer.NewFile("tools/filename", data)
505
sources, err := envtools.GetMetadataSources(env)
506
c.Assert(err, gc.IsNil)
507
c.Assert(len(sources), gc.Equals, 1)
508
assertSourceContents(c, sources[0], "filename", data)