X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/032450eaf50691bd981a5abb3d7fc73a75c62881..aab9cf1b5d30c5e49152bff09dc1ee18d38973dc:/lib/cloud/ec2/ec2_test.go diff --git a/lib/cloud/ec2/ec2_test.go b/lib/cloud/ec2/ec2_test.go index e7534a7b69..ede7f9de5d 100644 --- a/lib/cloud/ec2/ec2_test.go +++ b/lib/cloud/ec2/ec2_test.go @@ -57,15 +57,19 @@ type testConfig struct { } type ec2stub struct { - c *check.C - reftime time.Time + c *check.C + reftime time.Time + importKeyPairCalls []*ec2.ImportKeyPairInput + describeKeyPairsCalls []*ec2.DescribeKeyPairsInput } func (e *ec2stub) ImportKeyPair(input *ec2.ImportKeyPairInput) (*ec2.ImportKeyPairOutput, error) { + e.importKeyPairCalls = append(e.importKeyPairCalls, input) return nil, nil } func (e *ec2stub) DescribeKeyPairs(input *ec2.DescribeKeyPairsInput) (*ec2.DescribeKeyPairsOutput, error) { + e.describeKeyPairsCalls = append(e.describeKeyPairsCalls, input) return &ec2.DescribeKeyPairsOutput{}, nil } @@ -85,13 +89,13 @@ func (e *ec2stub) DescribeInstances(input *ec2.DescribeInstancesInput) (*ec2.Des InstanceLifecycle: aws.String("spot"), InstanceType: aws.String("t2.micro"), PrivateIpAddress: aws.String("10.1.2.3"), - State: &ec2.InstanceState{Name: aws.String("running")}, + State: &ec2.InstanceState{Name: aws.String("running"), Code: aws.Int64(16)}, }, { InstanceId: aws.String("i-124"), InstanceLifecycle: aws.String("spot"), InstanceType: aws.String("t2.micro"), PrivateIpAddress: aws.String("10.1.2.4"), - State: &ec2.InstanceState{Name: aws.String("running")}, + State: &ec2.InstanceState{Name: aws.String("running"), Code: aws.Int64(16)}, }}, }}, }, nil @@ -150,7 +154,7 @@ func (e *ec2stub) TerminateInstances(input *ec2.TerminateInstancesInput) (*ec2.T return nil, nil } -func GetInstanceSet(c *check.C) (cloud.InstanceSet, cloud.ImageID, arvados.Cluster) { +func GetInstanceSet(c *check.C) (*ec2InstanceSet, cloud.ImageID, arvados.Cluster) { cluster := arvados.Cluster{ InstanceTypes: arvados.InstanceTypeMap(map[string]arvados.InstanceType{ "tiny": { @@ -188,10 +192,9 @@ func GetInstanceSet(c *check.C) (cloud.InstanceSet, cloud.ImageID, arvados.Clust ap, err := newEC2InstanceSet(exampleCfg.DriverParameters, "test123", nil, logrus.StandardLogger()) c.Assert(err, check.IsNil) - return ap, cloud.ImageID(exampleCfg.ImageIDForTestSuite), cluster + return ap.(*ec2InstanceSet), cloud.ImageID(exampleCfg.ImageIDForTestSuite), cluster } ap := ec2InstanceSet{ - ec2config: ec2InstanceSetConfig{}, instanceSetID: "test123", logger: logrus.StandardLogger(), client: &ec2stub{c: c, reftime: time.Now().UTC()}, @@ -214,16 +217,18 @@ func (*EC2InstanceSetSuite) TestCreate(c *check.C) { c.Check(tags["TestTagName"], check.Equals, "test tag value") c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags) + if *live == "" { + c.Check(ap.client.(*ec2stub).describeKeyPairsCalls, check.HasLen, 1) + c.Check(ap.client.(*ec2stub).importKeyPairCalls, check.HasLen, 1) + } } func (*EC2InstanceSetSuite) TestCreateWithExtraScratch(c *check.C) { ap, img, cluster := GetInstanceSet(c) - pk, _ := test.LoadTestKey(c, "../../dispatchcloud/test/sshkey_dispatch") - inst, err := ap.Create(cluster.InstanceTypes["tiny-with-extra-scratch"], img, map[string]string{ "TestTagName": "test tag value", - }, "umask 0600; echo -n test-file-data >/var/run/test-file", pk) + }, "umask 0600; echo -n test-file-data >/var/run/test-file", nil) c.Assert(err, check.IsNil) @@ -231,6 +236,12 @@ func (*EC2InstanceSetSuite) TestCreateWithExtraScratch(c *check.C) { c.Check(tags["TestTagName"], check.Equals, "test tag value") c.Logf("inst.String()=%v Address()=%v Tags()=%v", inst.String(), inst.Address(), tags) + if *live == "" { + // Should not have called key pair APIs, because + // publickey arg was nil + c.Check(ap.client.(*ec2stub).describeKeyPairsCalls, check.HasLen, 0) + c.Check(ap.client.(*ec2stub).importKeyPairCalls, check.HasLen, 0) + } } func (*EC2InstanceSetSuite) TestCreatePreemptible(c *check.C) { @@ -297,6 +308,8 @@ func (*EC2InstanceSetSuite) TestInstancePriceHistory(c *check.C) { } }() + ap.ec2config.SpotPriceUpdateInterval = arvados.Duration(time.Hour) + ap.ec2config.EBSPrice = 0.1 // $/GiB/month inst1, err := ap.Create(cluster.InstanceTypes["tiny-preemptible"], img, tags, "true", pk) c.Assert(err, check.IsNil) defer inst1.Destroy() @@ -315,7 +328,8 @@ func (*EC2InstanceSetSuite) TestInstancePriceHistory(c *check.C) { instances, err = ap.Instances(tags) running := 0 for _, inst := range instances { - if *inst.(*ec2Instance).instance.InstanceLifecycle == "spot" { + ec2i := inst.(*ec2Instance).instance + if *ec2i.InstanceLifecycle == "spot" && *ec2i.State.Code&16 != 0 { running++ } } @@ -323,19 +337,24 @@ func (*EC2InstanceSetSuite) TestInstancePriceHistory(c *check.C) { c.Logf("instances are running, and identifiable as spot instances") break } - c.Logf("waiting for instances to be identifiable as spot instances...") + c.Logf("waiting for instances to reach running state so their availability zone becomes visible...") time.Sleep(10 * time.Second) } for _, inst := range instances { - hist := inst.PriceHistory() + hist := inst.PriceHistory(arvados.InstanceType{}) c.Logf("%s price history: %v", inst.ID(), hist) c.Check(len(hist) > 0, check.Equals, true) + + histWithScratch := inst.PriceHistory(arvados.InstanceType{AddedScratch: 640 << 30}) + c.Logf("%s price history with 640 GiB scratch: %v", inst.ID(), histWithScratch) + for i, ip := range hist { c.Check(ip.Price, check.Not(check.Equals), 0.0) if i > 0 { c.Check(ip.StartTime.Before(hist[i-1].StartTime), check.Equals, true) } + c.Check(ip.Price < histWithScratch[i].Price, check.Equals, true) } } }