// CreateContainerTest tries to create a container and returns any errors encountered along the // way func CreateContainerTest(c *gc.C, manager container.Manager, machineId string) (instance.Instance, error) { instanceConfig, err := MockMachineConfig(machineId) if err != nil { return nil, errors.Trace(err) } envConfig, err := config.New(config.NoDefaults, dummy.SampleConfig()) if err != nil { return nil, errors.Trace(err) } instanceConfig.Config = envConfig network := container.BridgeNetworkConfig("nic42", 0, nil) storage := &container.StorageConfig{} callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil } inst, hardware, err := manager.CreateContainer(instanceConfig, "quantal", network, storage, callback) if err != nil { return nil, errors.Trace(err) } if hardware == nil { return nil, errors.New("nil hardware characteristics") } if hardware.String() == "" { return nil, errors.New("empty hardware characteristics") } return inst, nil }
func createContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance { machineNonce := "fake-nonce" stateInfo := jujutesting.FakeStateInfo(machineId) apiInfo := jujutesting.FakeAPIInfo(machineId) instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, imagemetadata.ReleasedStream, "quantal", "", true, stateInfo, apiInfo) c.Assert(err, jc.ErrorIsNil) network := container.BridgeNetworkConfig("virbr0", 0, nil) err = instanceConfig.SetTools(tools.List{ &tools.Tools{ Version: version.MustParseBinary("2.3.4-foo-bar"), URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz", }, }) c.Assert(err, jc.ErrorIsNil) environConfig := dummyConfig(c) err = instancecfg.FinishInstanceConfig(instanceConfig, environConfig) c.Assert(err, jc.ErrorIsNil) callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil } inst, hardware, err := manager.CreateContainer(instanceConfig, "precise", network, nil, callback) c.Assert(err, jc.ErrorIsNil) c.Assert(hardware, gc.NotNil) expected := fmt.Sprintf("arch=%s cpu-cores=1 mem=512M root-disk=8192M", arch.HostArch()) c.Assert(hardware.String(), gc.Equals, expected) return inst }
func shutdownMachines(manager container.Manager) func(*gc.C) { return func(c *gc.C) { instances, err := manager.ListContainers() c.Assert(err, jc.ErrorIsNil) for _, instance := range instances { err := manager.DestroyContainer(instance.Id()) c.Check(err, jc.ErrorIsNil) } } }
func CreateContainerWithMachineConfig( c *gc.C, manager container.Manager, machineConfig *cloudinit.MachineConfig, ) instance.Instance { network := container.BridgeNetworkConfig("nic42") inst, hardware, err := manager.CreateContainer(machineConfig, "quantal", network) c.Assert(err, gc.IsNil) c.Assert(hardware, gc.NotNil) c.Assert(hardware.String(), gc.Not(gc.Equals), "") return inst }
func CreateContainerWithMachineAndNetworkAndStorageConfig( c *gc.C, manager container.Manager, instanceConfig *instancecfg.InstanceConfig, networkConfig *container.NetworkConfig, storageConfig *container.StorageConfig, ) instance.Instance { callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil } inst, hardware, err := manager.CreateContainer(instanceConfig, constraints.Value{}, "quantal", networkConfig, storageConfig, callback) c.Assert(err, jc.ErrorIsNil) c.Assert(hardware, gc.NotNil) c.Assert(hardware.String(), gc.Not(gc.Equals), "") return inst }
func CreateContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance { stateInfo := jujutesting.FakeStateInfo(machineId) apiInfo := jujutesting.FakeAPIInfo(machineId) machineConfig := environs.NewMachineConfig(machineId, "fake-nonce", nil, stateInfo, apiInfo) machineConfig.Tools = &tools.Tools{ Version: version.MustParseBinary("2.3.4-foo-bar"), URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz", } series := "series" network := container.BridgeNetworkConfig("nic42") inst, hardware, err := manager.CreateContainer(machineConfig, series, network) c.Assert(err, gc.IsNil) c.Assert(hardware, gc.NotNil) c.Assert(hardware.String(), gc.Not(gc.Equals), "") return inst }
func CreateContainerWithMachineAndNetworkAndStorageConfig( c *gc.C, manager container.Manager, instanceConfig *instancecfg.InstanceConfig, networkConfig *container.NetworkConfig, storageConfig *container.StorageConfig, ) instance.Instance { if networkConfig != nil && len(networkConfig.Interfaces) > 0 { name := "test-" + names.NewMachineTag(instanceConfig.MachineId).String() EnsureRootFSEtcNetwork(c, name) } inst, hardware, err := manager.CreateContainer(instanceConfig, "quantal", networkConfig, storageConfig) c.Assert(err, jc.ErrorIsNil) c.Assert(hardware, gc.NotNil) c.Assert(hardware.String(), gc.Not(gc.Equals), "") return inst }
func CreateContainerWithMachineAndNetworkAndStorageConfig( c *gc.C, manager container.Manager, instanceConfig *instancecfg.InstanceConfig, networkConfig *container.NetworkConfig, storageConfig *container.StorageConfig, ) instance.Instance { if networkConfig != nil && len(networkConfig.Interfaces) > 0 { name := "test-" + names.NewMachineTag(instanceConfig.MachineId).String() EnsureLXCRootFSEtcNetwork(c, name) } callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil } inst, hardware, err := manager.CreateContainer(instanceConfig, "quantal", networkConfig, storageConfig, callback) c.Assert(err, jc.ErrorIsNil) c.Assert(hardware, gc.NotNil) c.Assert(hardware.String(), gc.Not(gc.Equals), "") return inst }
func createContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance { machineNonce := "fake-nonce" stateInfo := jujutesting.FakeStateInfo(machineId) apiInfo := jujutesting.FakeAPIInfo(machineId) machineConfig := environs.NewMachineConfig(machineId, machineNonce, nil, stateInfo, apiInfo) network := container.BridgeNetworkConfig("virbr0") machineConfig.Tools = &tools.Tools{ Version: version.MustParseBinary("2.3.4-foo-bar"), URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz", } environConfig := dummyConfig(c) err := environs.FinishMachineConfig(machineConfig, environConfig, constraints.Value{}) c.Assert(err, gc.IsNil) inst, hardware, err := manager.CreateContainer(machineConfig, "precise", network) c.Assert(err, gc.IsNil) c.Assert(hardware, gc.NotNil) expected := fmt.Sprintf("arch=%s cpu-cores=1 mem=512M root-disk=8192M", version.Current.Arch) c.Assert(hardware.String(), gc.Equals, expected) return inst }
func assertNumberOfContainers(c *gc.C, manager container.Manager, count int) { containers, err := manager.ListContainers() c.Assert(err, jc.ErrorIsNil) c.Assert(containers, gc.HasLen, count) }