func (s *uniterSuite) setUpTest(c *gc.C, addController bool) { s.JujuConnSuite.SetUpTest(c) if addController { s.controllerMachine = testing.AddControllerMachine(c, s.State) } // Bind "db" relation of wordpress to space "internal", // and the "admin-api" extra-binding to space "public". bindings := map[string]string{ "db": "internal", "admin-api": "public", } _, err := s.State.AddSpace("internal", "", nil, false) c.Assert(err, jc.ErrorIsNil) _, err = s.State.AddSpace("public", "", nil, true) c.Assert(err, jc.ErrorIsNil) // Create a machine, a service and add a unit so we can log in as // its agent. s.wordpressMachine, s.wordpressService, s.wordpressCharm, s.wordpressUnit = s.addMachineBoundServiceCharmAndUnit(c, "wordpress", bindings) password, err := utils.RandomPassword() c.Assert(err, jc.ErrorIsNil) err = s.wordpressUnit.SetPassword(password) c.Assert(err, jc.ErrorIsNil) s.st = s.OpenAPIAs(c, s.wordpressUnit.Tag(), password) // Create the uniter API facade. s.uniter, err = s.st.Uniter() c.Assert(err, jc.ErrorIsNil) c.Assert(s.uniter, gc.NotNil) }
func addControllerMachine(c *gc.C, st *state.State) { // The AddControllerMachine call will update the API host ports // to made-up addresses. We need valid addresses so that the uniter // can download charms from the API server. apiHostPorts, err := st.APIHostPorts() c.Assert(err, gc.IsNil) testing.AddControllerMachine(c, st) err = st.SetAPIHostPorts(apiHostPorts) c.Assert(err, gc.IsNil) }
func (s *provisionerSuite) setUpTest(c *gc.C, withController bool) { s.JujuConnSuite.ConfigAttrs = map[string]interface{}{ "image-stream": "daily", } s.JujuConnSuite.SetUpTest(c) // We're testing with address allocation on by default. There are // separate tests to check the behavior when the flag is not // enabled. s.SetFeatureFlags(feature.AddressAllocation) // Reset previous machines (if any) and create 3 machines // for the tests, plus an optional controller machine. s.machines = nil // Note that the specific machine ids allocated are assumed // to be numerically consecutive from zero. if withController { s.machines = append(s.machines, testing.AddControllerMachine(c, s.State)) } for i := 0; i < 5; i++ { machine, err := s.State.AddMachine("quantal", state.JobHostUnits) c.Check(err, jc.ErrorIsNil) s.machines = append(s.machines, machine) } // Create a FakeAuthorizer so we can check permissions, // set up assuming we logged in as the environment manager. s.authorizer = apiservertesting.FakeAuthorizer{ EnvironManager: true, } // Create the resource registry separately to track invocations to // Register, and to register the root for tools URLs. s.resources = common.NewResources() // Create a provisioner API for the machine. provisionerAPI, err := provisioner.NewProvisionerAPI( s.State, s.resources, s.authorizer, ) c.Assert(err, jc.ErrorIsNil) s.provisioner = provisionerAPI }
// primeAgent creates a unit, and sets up the unit agent's directory. // It returns the assigned machine, new unit and the agent's configuration. func (s *UnitSuite) primeAgent(c *gc.C) (*state.Machine, *state.Unit, agent.Config, *tools.Tools) { jujutesting.AddControllerMachine(c, s.State) svc := s.AddTestingService(c, "wordpress", s.AddTestingCharm(c, "wordpress")) unit, err := svc.AddUnit() c.Assert(err, jc.ErrorIsNil) err = unit.SetPassword(initialUnitPassword) c.Assert(err, jc.ErrorIsNil) // Assign the unit to a machine. err = unit.AssignToNewMachine() c.Assert(err, jc.ErrorIsNil) id, err := unit.AssignedMachineId() c.Assert(err, jc.ErrorIsNil) machine, err := s.State.Machine(id) c.Assert(err, jc.ErrorIsNil) inst, md := jujutesting.AssertStartInstance(c, s.Environ, id) err = machine.SetProvisioned(inst.Id(), agent.BootstrapNonce, md) c.Assert(err, jc.ErrorIsNil) conf, tools := s.PrimeAgent(c, unit.Tag(), initialUnitPassword) return machine, unit, conf, tools }
func (s *uniterSuite) setUpTest(c *gc.C, addController bool) { s.JujuConnSuite.SetUpTest(c) if addController { s.controllerMachine = testing.AddControllerMachine(c, s.State) } // Create a machine, a service and add a unit so we can log in as // its agent. s.wordpressMachine, s.wordpressService, s.wordpressCharm, s.wordpressUnit = s.addMachineServiceCharmAndUnit(c, "wordpress") password, err := utils.RandomPassword() c.Assert(err, jc.ErrorIsNil) err = s.wordpressUnit.SetPassword(password) c.Assert(err, jc.ErrorIsNil) s.st = s.OpenAPIAs(c, s.wordpressUnit.Tag(), password) // Create the uniter API facade. s.uniter, err = s.st.Uniter() c.Assert(err, jc.ErrorIsNil) c.Assert(s.uniter, gc.NotNil) }