// JujuConnSuite very helpfully uploads some default // tools to the environment's storage. We don't want // 'em there; but we do want a consistent default-series // in the environment state. func (s *UpgradeJujuSuite) Reset(c *C) { s.JujuConnSuite.Reset(c) envtesting.RemoveTools(c, s.Conn.Environ.Storage()) envtesting.RemoveTools(c, s.Conn.Environ.PublicStorage().(environs.Storage)) cfg, err := s.State.EnvironConfig() c.Assert(err, IsNil) cfg, err = cfg.Apply(map[string]interface{}{ "default-series": "always", "agent-version": "1.2.3", }) c.Assert(err, IsNil) err = s.State.SetEnvironConfig(cfg) c.Assert(err, IsNil) }
func (suite *EnvironSuite) TestBootstrapFailsIfNoTools(c *C) { suite.setupFakeTools(c) env := suite.makeEnviron() // Can't RemoveAllTools, no public storage. envtesting.RemoveTools(c, env.Storage()) err := env.Bootstrap(constraints.Value{}) c.Check(err, ErrorMatches, "no tools available") c.Check(err, FitsTypeOf, (*errors.NotFoundError)(nil)) }
func (suite *EnvironSuite) TestStartInstanceStartsInstance(c *C) { suite.setupFakeTools(c) env := suite.makeEnviron() // Create node 0: it will be used as the bootstrap node. suite.testMAASObject.TestServer.NewNode(`{"system_id": "node0", "hostname": "host0"}`) err := environs.Bootstrap(env, constraints.Value{}) c.Assert(err, IsNil) // The bootstrap node has been acquired and started. operations := suite.testMAASObject.TestServer.NodeOperations() actions, found := operations["node0"] c.Check(found, Equals, true) c.Check(actions, DeepEquals, []string{"acquire", "start"}) // Test the instance id is correctly recorded for the bootstrap node. // Check that the state holds the id of the bootstrap machine. stateData, err := environs.LoadState(env.Storage()) c.Assert(err, IsNil) c.Assert(stateData.StateInstances, HasLen, 1) insts, err := env.AllInstances() c.Assert(err, IsNil) c.Assert(insts, HasLen, 1) c.Check(insts[0].Id(), Equals, stateData.StateInstances[0]) // Create node 1: it will be used as instance number 1. suite.testMAASObject.TestServer.NewNode(`{"system_id": "node1", "hostname": "host1"}`) stateInfo, apiInfo, err := env.StateInfo() c.Assert(err, IsNil) stateInfo.Tag = "machine-1" apiInfo.Tag = "machine-1" series := version.Current.Series nonce := "12345" // TODO(wallyworld) - test instance metadata instance, _, err := env.StartInstance("1", nonce, series, constraints.Value{}, stateInfo, apiInfo) c.Assert(err, IsNil) c.Check(instance, NotNil) // The instance number 1 has been acquired and started. actions, found = operations["node1"] c.Assert(found, Equals, true) c.Check(actions, DeepEquals, []string{"acquire", "start"}) // The value of the "user data" parameter used when starting the node // contains the run cmd used to write the machine information onto // the node's filesystem. requestValues := suite.testMAASObject.TestServer.NodeOperationRequestValues() nodeRequestValues, found := requestValues["node1"] c.Assert(found, Equals, true) c.Assert(len(nodeRequestValues), Equals, 2) userData := nodeRequestValues[1].Get("user_data") decodedUserData, err := decodeUserData(userData) c.Assert(err, IsNil) info := machineInfo{"host1"} cloudinitRunCmd, err := info.cloudinitRunCmd() c.Assert(err, IsNil) data, err := goyaml.Marshal(cloudinitRunCmd) c.Assert(err, IsNil) c.Check(string(decodedUserData), Matches, "(.|\n)*"+string(data)+"(\n|.)*") // Trash the tools and try to start another instance. envtesting.RemoveTools(c, env.Storage()) instance, _, err = env.StartInstance("2", "fake-nonce", series, constraints.Value{}, stateInfo, apiInfo) c.Check(instance, IsNil) c.Check(err, ErrorMatches, "no tools available") c.Check(err, FitsTypeOf, (*errors.NotFoundError)(nil)) }