Exemple #1
0
func (s *specSuite) TestFindInstanceSpec(c *gc.C) {
	for i, test := range findInstanceSpecTests {
		c.Logf("\ntest %d: %q; %q; %q; %v", i, test.series, test.arches, test.cons, test.storage)
		stor := test.storage
		if len(stor) == 0 {
			stor = []string{ssdStorage, ebsStorage}
		}
		// We need to filter the image metadata to the test's
		// arches and series; the provisioner and bootstrap
		// code will do this.
		imageMetadata := filterImageMetadata(
			c, TestImageMetadata, test.series, test.arches,
		)
		spec, err := findInstanceSpec(
			false, // non-controller
			imageMetadata,
			ec2instancetypes.RegionInstanceTypes("test"),
			&instances.InstanceConstraint{
				Region:      "test",
				Series:      test.series,
				Arches:      test.arches,
				Constraints: constraints.MustParse(test.cons),
				Storage:     stor,
			})
		c.Assert(err, jc.ErrorIsNil)
		c.Check(spec.InstanceType.Name, gc.Equals, test.itype)
		c.Check(spec.Image.Id, gc.Equals, test.image)
	}
}
Exemple #2
0
func (s *InstanceTypesSuite) TestRegionInstanceTypesAvailability(c *gc.C) {
	// Some instance types are only available in some regions.
	usWest1InstanceTypes := set.NewStrings()
	usEast1InstanceTypes := set.NewStrings()
	for _, instanceType := range ec2instancetypes.RegionInstanceTypes("us-west-1") {
		usWest1InstanceTypes.Add(instanceType.Name)
	}
	for _, instanceType := range ec2instancetypes.RegionInstanceTypes("us-east-1") {
		usEast1InstanceTypes.Add(instanceType.Name)
	}
	c.Assert(
		usEast1InstanceTypes.Difference(usWest1InstanceTypes).SortedValues(),
		jc.DeepEquals,
		[]string{"cc2.8xlarge", "cg1.4xlarge", "cr1.8xlarge", "hi1.4xlarge", "hs1.8xlarge"},
	)
}
Exemple #3
0
func (s *specSuite) TestFindInstanceSpecNotSetCpuPowerWhenInstanceTypeSet(c *gc.C) {

	instanceConstraint := &instances.InstanceConstraint{
		Region:      "test",
		Series:      series.LatestLts(),
		Constraints: constraints.MustParse("instance-type=t2.medium"),
	}

	c.Check(instanceConstraint.Constraints.CpuPower, gc.IsNil)
	findInstanceSpec(
		false, // non-controller
		TestImageMetadata,
		ec2instancetypes.RegionInstanceTypes("test"),
		instanceConstraint,
	)

	c.Check(instanceConstraint.Constraints.CpuPower, gc.IsNil)
}
Exemple #4
0
func (s *specSuite) TestFindInstanceSpecErrors(c *gc.C) {
	for i, t := range findInstanceSpecErrorTests {
		c.Logf("test %d", i)
		// We need to filter the image metadata to the test's
		// arches and series; the provisioner and bootstrap
		// code will do this.
		imageMetadata := filterImageMetadata(
			c, TestImageMetadata, t.series, t.arches,
		)
		_, err := findInstanceSpec(
			false, // non-controller
			imageMetadata,
			ec2instancetypes.RegionInstanceTypes("test"),
			&instances.InstanceConstraint{
				Region:      "test",
				Series:      t.series,
				Arches:      t.arches,
				Constraints: constraints.MustParse(t.cons),
			})
		c.Check(err, gc.ErrorMatches, t.err)
	}
}
Exemple #5
0
func (s *InstanceTypesSuite) TestRegionInstanceTypes(c *gc.C) {
	// This is the set of instance type names we had hard coded previously.
	knownInstanceTypes := set.NewStrings(
		"m1.small", "m1.medium", "m1.large", "m1.xlarge",
		"m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge",
		"m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
		"c1.medium", "c1.xlarge", "cc2.8xlarge",
		"c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
		"cg1.4xlarge",
		"g2.2xlarge",
		"m2.xlarge", "m2.2xlarge", "m2.4xlarge", "cr1.8xlarge",
		"r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
		"hi1.4xlarge",
		"i2.xlarge", "i2.2xlarge", "i2.8xlarge", "hs1.8xlarge",
		"t1.micro",
		"t2.micro", "t2.small", "t2.medium",
		"c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
	)
	seen := make(map[string]bool)
	var unknownInstanceTypes []string
	instanceTypes := ec2instancetypes.RegionInstanceTypes("us-east-1")
	for _, instanceType := range instanceTypes {
		c.Assert(instanceType.Cost, gc.Not(gc.Equals), 0)
		c.Assert(seen[instanceType.Name], jc.IsFalse) // no duplicates
		seen[instanceType.Name] = true

		if !knownInstanceTypes.Contains(instanceType.Name) {
			unknownInstanceTypes = append(unknownInstanceTypes, instanceType.Name)
		} else {
			knownInstanceTypes.Remove(instanceType.Name)
		}
	}
	c.Assert(knownInstanceTypes, gc.HasLen, 0) // all accounted for
	if len(unknownInstanceTypes) > 0 {
		c.Logf("unknown instance types: %s", unknownInstanceTypes)
	}
}
Exemple #6
0
func (s *InstanceTypesSuite) TestRegionInstanceTypesUnknownRegion(c *gc.C) {
	instanceTypes := ec2instancetypes.RegionInstanceTypes("cn-north-1")
	c.Assert(instanceTypes, jc.DeepEquals, ec2instancetypes.RegionInstanceTypes("us-east-1"))
}