func (s *RemoveUnitSuite) setupUnitForRemove(c *gc.C) *state.Service { ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") err := runDeploy(c, "-n", "2", ch, "dummy", "--series", series.LatestLts()) c.Assert(err, jc.ErrorIsNil) curl := charm.MustParseURL(fmt.Sprintf("local:%s/dummy-1", series.LatestLts())) svc, _ := s.AssertService(c, "dummy", curl, 2, 0) return svc }
func (s *DeploySuite) TestForceMachine(c *gc.C) { ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") machine, err := s.State.AddMachine(series.LatestLts(), state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) err = runDeploy(c, "--to", machine.Id(), ch, "portlandia", "--series", series.LatestLts()) c.Assert(err, jc.ErrorIsNil) s.assertForceMachine(c, machine.Id()) }
func (s *DeploySuite) TestForceMachineExistingContainer(c *gc.C) { ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") template := state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, } container, err := s.State.AddMachineInsideNewMachine(template, template, instance.LXC) c.Assert(err, jc.ErrorIsNil) err = runDeploy(c, "--to", container.Id(), ch, "portlandia", "--series", series.LatestLts()) c.Assert(err, jc.ErrorIsNil) s.assertForceMachine(c, container.Id()) machines, err := s.State.AllMachines() c.Assert(err, jc.ErrorIsNil) c.Assert(machines, gc.HasLen, 2) }
func (s *environPolSuite) TestPrecheckInstanceUnsupportedArch(c *gc.C) { cons := constraints.MustParse("instance-type=n1-standard-1 arch=i386") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, jc.ErrorIsNil) }
func (s *environPolSuite) TestPrecheckInstanceInvalidInstanceType(c *gc.C) { cons := constraints.MustParse("instance-type=n1-standard-1.invalid") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, gc.ErrorMatches, `.*invalid GCE instance type.*`) }
func (s *LXCDefaultMTUSuite) TestDefaultMTUPropagatedToNewLXCBroker(c *gc.C) { // create a machine to host the container. m, err := s.BackingState.AddOneMachine(state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, Constraints: s.defaultConstraints, }) c.Assert(err, jc.ErrorIsNil) err = m.SetSupportedContainers([]instance.ContainerType{instance.LXC, instance.KVM}) c.Assert(err, jc.ErrorIsNil) current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } err = m.SetAgentVersion(current) c.Assert(err, jc.ErrorIsNil) brokerCalled := false newlxcbroker := func(api provisioner.APICalls, agentConfig agent.Config, managerConfig container.ManagerConfig, imageURLGetter container.ImageURLGetter, enableNAT bool, defaultMTU int) (environs.InstanceBroker, error) { brokerCalled = true c.Assert(defaultMTU, gc.Equals, 9000) return nil, fmt.Errorf("lxc broker error") } s.PatchValue(&provisioner.NewLxcBroker, newlxcbroker) s.createContainer(c, m, instance.LXC) c.Assert(brokerCalled, jc.IsTrue) }
func (s *ContainerSetupSuite) TestContainerInitLockError(c *gc.C) { m, err := s.BackingState.AddOneMachine(state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, Constraints: s.defaultConstraints, }) c.Assert(err, jc.ErrorIsNil) current := version.Binary{ Number: jujuversion.Current, Arch: arch.HostArch(), Series: series.HostSeries(), } err = m.SetAgentVersion(current) c.Assert(err, jc.ErrorIsNil) err = os.RemoveAll(s.initLockDir) c.Assert(err, jc.ErrorIsNil) handler, runner := s.setupContainerWorker(c, m.Tag().(names.MachineTag)) runner.Kill() err = runner.Wait() c.Assert(err, jc.ErrorIsNil) _, err = handler.SetUp() c.Assert(err, jc.ErrorIsNil) err = handler.Handle(nil, []string{"0/lxc/0"}) c.Assert(err, gc.ErrorMatches, ".*failed to acquire initialization lock:.*") }
func (s *funcSuite) SetUpTest(c *gc.C) { s.baseImageMetadataSuite.SetUpTest(c) var err error s.env, err = environs.Prepare( envtesting.BootstrapContext(c), jujuclienttesting.NewMemStore(), environs.PrepareParams{ ControllerName: "dummycontroller", BaseConfig: mockConfig(), CloudName: "dummy", }, ) c.Assert(err, jc.ErrorIsNil) s.state = s.constructState(s.env.Config()) s.expected = cloudimagemetadata.Metadata{ cloudimagemetadata.MetadataAttributes{ Stream: "released", Source: "custom", Series: series.LatestLts(), Arch: "amd64", Region: "dummy_region", }, 0, "", } }
func (s *ProvisionerSuite) TestProvisioningDoesNotOccurForKVM(c *gc.C) { p := s.newEnvironProvisioner(c) defer stop(c, p) // create a machine to host the container. m, err := s.addMachine() c.Assert(err, jc.ErrorIsNil) inst := s.checkStartInstance(c, m) // make a container on the machine we just created template := state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, } container, err := s.State.AddMachineInsideMachine(template, m.Id(), instance.KVM) c.Assert(err, jc.ErrorIsNil) // the PA should not attempt to create it s.checkNoOperations(c) // cleanup c.Assert(container.EnsureDead(), gc.IsNil) c.Assert(container.Remove(), gc.IsNil) c.Assert(m.EnsureDead(), gc.IsNil) s.checkStopInstances(c, inst) s.waitForRemovalMark(c, m) }
func (s *environPolSuite) TestPrecheckInstanceAvailZone(c *gc.C) { cons := constraints.Value{} placement := "zone=a-zone" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, gc.ErrorMatches, `unknown placement directive: .*`) }
func (s *ImageMetadataSuite) TestImageMetadataFilesLatestLts(c *gc.C) { ec2Config, err := config.New(config.UseDefaults, map[string]interface{}{ "name": "ec2-latest-lts", "type": "ec2", "uuid": testing.ModelTag.Id(), "controller-uuid": testing.ModelTag.Id(), "region": "us-east-1", }) c.Assert(err, jc.ErrorIsNil) s.store.BootstrapConfig["ec2-controller"] = jujuclient.BootstrapConfig{ Cloud: "ec2", CloudRegion: "us-east-1", Config: ec2Config.AllAttrs(), } ctx, err := runImageMetadata(c, s.store, "-m", "ec2-controller:ec2-latest-lts", "-d", s.dir, "-i", "1234", "-r", "region", "-a", "arch", "-u", "endpoint", ) c.Assert(err, jc.ErrorIsNil) out := testing.Stdout(ctx) expected := expectedMetadata{ series: series.LatestLts(), arch: "arch", } s.assertCommandOutput(c, expected, out, defaultIndexFileName, defaultImageFileName) }
func (s *environPolSuite) TestPrecheckInstanceDiskSize(c *gc.C) { cons := constraints.MustParse("root-disk=1G") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, jc.ErrorIsNil) }
func (s *environPolSuite) TestPrecheckInstanceOkay(c *gc.C) { cons := constraints.Value{} placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, jc.ErrorIsNil) }
func (s *environPolSuite) TestPrecheckInstanceHasInstanceType(c *gc.C) { cons := constraints.MustParse("instance-type=some-instance-type") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, gc.ErrorMatches, `LXD does not support instance types.*`) }
func (s *environSuite) TestPrecheckInstanceAvailZone(c *gc.C) { s.testMAASObject.TestServer.AddZone("zone1", "the grass is greener in zone1") env := s.makeEnviron() placement := "zone=zone1" err := env.PrecheckInstance(series.LatestLts(), constraints.Value{}, placement) c.Assert(err, jc.ErrorIsNil) }
func (s *environSuite) TestPrecheckInstanceAvailZoneUnknown(c *gc.C) { s.testMAASObject.TestServer.AddZone("zone1", "the grass is greener in zone1") env := s.makeEnviron() placement := "zone=zone2" err := env.PrecheckInstance(series.LatestLts(), constraints.Value{}, placement) c.Assert(err, gc.ErrorMatches, `invalid availability zone "zone2"`) }
func (s *baseProviderSuite) SetUpTest(c *gc.C) { s.FakeJujuXDGDataHomeSuite.SetUpTest(c) s.ToolsFixture.SetUpTest(c) s.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber) s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 }) s.PatchValue(&series.HostSeries, func() string { return series.LatestLts() }) }
func (s *clientSuite) TestClientAddMachinesWithInstanceIdSomeErrors(c *gc.C) { apiParams := make([]params.AddMachineParams, 3) addrs := network.NewAddresses("1.2.3.4") hc := instance.MustParseHardware("mem=4G") for i := 0; i < 3; i++ { apiParams[i] = params.AddMachineParams{ Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits}, InstanceId: instance.Id(fmt.Sprintf("1234-%d", i)), Nonce: "foo", HardwareCharacteristics: hc, Addrs: params.FromNetworkAddresses(addrs...), } } // This will cause the last add-machine to fail. apiParams[2].Nonce = "" machines, err := s.APIState.Client().AddMachines(apiParams) c.Assert(err, jc.ErrorIsNil) c.Assert(len(machines), gc.Equals, 3) for i, machineResult := range machines { if i == 2 { c.Assert(machineResult.Error, gc.NotNil) c.Assert(machineResult.Error, gc.ErrorMatches, "cannot add a new machine: cannot add a machine with an instance id and no nonce") } else { c.Assert(machineResult.Machine, gc.DeepEquals, strconv.Itoa(i)) s.checkMachine(c, machineResult.Machine, series.LatestLts(), apiParams[i].Constraints.String()) instanceId := fmt.Sprintf("1234-%d", i) s.checkInstance(c, machineResult.Machine, instanceId, "foo", hc, addrs) } } }
func (s *rebootSuite) SetUpTest(c *gc.C) { var err error template := state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, } s.JujuConnSuite.SetUpTest(c) s.stateAPI, s.machine = s.OpenAPIAsNewMachine(c) s.rebootState, err = s.stateAPI.Reboot() c.Assert(err, jc.ErrorIsNil) c.Assert(s.rebootState, gc.NotNil) //Add container s.ct, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.KVM) c.Assert(err, jc.ErrorIsNil) password, err := utils.RandomPassword() c.Assert(err, jc.ErrorIsNil) err = s.ct.SetPassword(password) c.Assert(err, jc.ErrorIsNil) err = s.ct.SetProvisioned("foo", "fake_nonce", nil) c.Assert(err, jc.ErrorIsNil) // Open api as container ctState := s.OpenAPIAsMachine(c, s.ct.Tag(), password, "fake_nonce") s.ctRebootState, err = ctState.Reboot() c.Assert(err, jc.ErrorIsNil) c.Assert(s.ctRebootState, gc.NotNil) s.clock = &fakeClock{delay: time.Millisecond} }
func (s *CommonProvisionerSuite) addMachineWithConstraints(cons constraints.Value) (*state.Machine, error) { return s.BackingState.AddOneMachine(state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, Constraints: cons, }) }
func (s *RepoSuite) SetUpTest(c *gc.C) { s.JujuConnSuite.SetUpTest(c) s.CharmsPath = c.MkDir() // Change the environ's config to ensure we're using the one in state. updateAttrs := map[string]interface{}{"default-series": series.LatestLts()} err := s.State.UpdateModelConfig(updateAttrs, nil, nil) c.Assert(err, jc.ErrorIsNil) }
func (s *environPolSuite) TestPrecheckInstanceUnsupportedArch(c *gc.C) { s.Policy.Arches = []string{arch.AMD64} cons := constraints.MustParse("arch=i386") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, jc.ErrorIsNil) }
func (s *ebsSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) s.BaseSuite.PatchValue(&jujuversion.Current, testing.FakeVersionNumber) s.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 }) s.BaseSuite.PatchValue(&series.HostSeries, func() string { return series.LatestLts() }) s.srv.startServer(c) s.Tests.SetUpTest(c) s.PatchValue(&ec2.DestroyVolumeAttempt.Delay, time.Duration(0)) }
func (s *environPolSuite) TestPrecheckInstanceUnsupportedArch(c *gc.C) { s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 }) cons := constraints.MustParse("arch=i386") placement := "" err := s.Env.PrecheckInstance(series.LatestLts(), cons, placement) c.Check(err, jc.ErrorIsNil) }
func (s *kvmProvisionerSuite) addContainer(c *gc.C) *state.Machine { template := state.MachineTemplate{ Series: series.LatestLts(), Jobs: []state.MachineJob{state.JobHostUnits}, } container, err := s.State.AddMachineInsideMachine(template, "0", instance.KVM) c.Assert(err, jc.ErrorIsNil) return container }
// setParams sets parameters based on the environment configuration // for those which have not been explicitly specified. func (c *imageMetadataCommand) setParams(context *cmd.Context) error { c.privateStorage = "<private storage name>" var environ environs.Environ if environ, err := c.prepare(context); err == nil { logger.Infof("creating image metadata for model %q", environ.Config().Name()) // If the user has not specified region and endpoint, try and get it from the environment. if c.Region == "" || c.Endpoint == "" { var cloudSpec simplestreams.CloudSpec if inst, ok := environ.(simplestreams.HasRegion); ok { if cloudSpec, err = inst.Region(); err != nil { return err } } else { return errors.Errorf("model %q cannot provide region and endpoint", environ.Config().Name()) } // If only one of region or endpoint is provided, that is a problem. if cloudSpec.Region != cloudSpec.Endpoint && (cloudSpec.Region == "" || cloudSpec.Endpoint == "") { return errors.Errorf("cannot generate metadata without a complete cloud configuration") } if c.Region == "" { c.Region = cloudSpec.Region } if c.Endpoint == "" { c.Endpoint = cloudSpec.Endpoint } } cfg := environ.Config() if c.Series == "" { c.Series = config.PreferredSeries(cfg) } } else { logger.Warningf("model could not be opened: %v", err) } if environ == nil { logger.Infof("no model found, creating image metadata using user supplied data") } if c.Series == "" { c.Series = series.LatestLts() } if c.ImageId == "" { return errors.Errorf("image id must be specified") } if c.Region == "" { return errors.Errorf("image region must be specified") } if c.Endpoint == "" { return errors.Errorf("cloud endpoint URL must be specified") } if c.Dir == "" { logger.Infof("no destination directory specified, using current directory") var err error if c.Dir, err = os.Getwd(); err != nil { return err } } return nil }
func (s *DeploySuite) TestForceMachineSubordinate(c *gc.C) { machine, err := s.State.AddMachine(series.LatestLts(), state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "logging") err = runDeploy(c, "--to", machine.Id(), ch, "--series", "quantal") c.Assert(err, gc.ErrorMatches, "cannot use --num-units or --to with subordinate service") _, err = s.State.Service("dummy") c.Assert(err, gc.ErrorMatches, `service "dummy" not found`) }
func (s *kvmProvisionerSuite) TestDoesNotStartEnvironMachines(c *gc.C) { p := s.newKvmProvisioner(c) defer stop(c, p) // Check that an instance is not provisioned when the machine is created. _, err := s.State.AddMachine(series.LatestLts(), state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) s.expectNoEvents(c) }
func (t *LiveTests) SetUpSuite(c *gc.C) { // Upload arches that ec2 supports; add to this // as ec2 coverage expands. t.UploadArches = []string{arch.AMD64, arch.I386} t.BaseSuite.SetUpSuite(c) t.LiveTests.SetUpSuite(c) t.BaseSuite.PatchValue(&jujuversion.Current, coretesting.FakeVersionNumber) t.BaseSuite.PatchValue(&arch.HostArch, func() string { return arch.AMD64 }) t.BaseSuite.PatchValue(&series.HostSeries, func() string { return series.LatestLts() }) }
func (s *DeploySuite) TestForceMachineNewContainer(c *gc.C) { ch := testcharms.Repo.CharmArchivePath(s.CharmsPath, "dummy") machine, err := s.State.AddMachine(series.LatestLts(), state.JobHostUnits) c.Assert(err, jc.ErrorIsNil) err = runDeploy(c, "--to", "lxc:"+machine.Id(), ch, "portlandia", "--series", series.LatestLts()) c.Assert(err, jc.ErrorIsNil) s.assertForceMachine(c, machine.Id()+"/lxc/0") for a := coretesting.LongAttempt.Start(); a.Next(); { machines, err := s.State.AllMachines() c.Assert(err, jc.ErrorIsNil) if !a.HasNext() { c.Assert(machines, gc.HasLen, 2) break } if len(machines) == 2 { break } } }