|
@@ -56,8 +56,8 @@ func TestEcsInstance(t *testing.T) {
|
|
|
// wait
|
|
// wait
|
|
|
waitForEcsInstance(t, ecsClient, instanceId, EcsInstanceStatusStopped, 600)
|
|
waitForEcsInstance(t, ecsClient, instanceId, EcsInstanceStatusStopped, 600)
|
|
|
|
|
|
|
|
- // delete all test instance
|
|
|
|
|
- //deleteAllTestEcsInstance(t, ecsClient)
|
|
|
|
|
|
|
+ //delete all test instance
|
|
|
|
|
+ deleteAllTestEcsInstance(t, ecsClient)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func getDemoEcsInstanceAttributes(t *testing.T, client *ecs.Client) *ecs.DescribeInstanceAttributeResponse {
|
|
func getDemoEcsInstanceAttributes(t *testing.T, client *ecs.Client) *ecs.DescribeInstanceAttributeResponse {
|
|
@@ -124,24 +124,30 @@ func deleteAllTestEcsInstance(t *testing.T, client *ecs.Client) {
|
|
|
response, err := client.DescribeInstances(request)
|
|
response, err := client.DescribeInstances(request)
|
|
|
assertErrorNil(t, err, "Failed to list all ecs instances ")
|
|
assertErrorNil(t, err, "Failed to list all ecs instances ")
|
|
|
assert.Equal(t, 200, response.GetHttpStatus(), response.GetHttpContentString())
|
|
assert.Equal(t, 200, response.GetHttpStatus(), response.GetHttpContentString())
|
|
|
- fmt.Printf("success! TotalCount = %s\n", response.TotalCount)
|
|
|
|
|
|
|
+ fmt.Printf("success! TotalCount = %s\n", strconv.Itoa(response.TotalCount))
|
|
|
|
|
|
|
|
for _, instanceInfo := range response.Instances.Instance {
|
|
for _, instanceInfo := range response.Instances.Instance {
|
|
|
if strings.HasPrefix(instanceInfo.InstanceName, InstanceNamePrefix) {
|
|
if strings.HasPrefix(instanceInfo.InstanceName, InstanceNamePrefix) {
|
|
|
- fmt.Printf("found undeleted ecs instance(%s), status=%s, try to delete it.\n",
|
|
|
|
|
- instanceInfo.Status, instanceInfo.InstanceId)
|
|
|
|
|
- if instanceInfo.Status == EcsInstanceStatusRunning {
|
|
|
|
|
- // stop
|
|
|
|
|
- stopEcsInstance(t, client, instanceInfo.InstanceId)
|
|
|
|
|
- } else if instanceInfo.Status == EcsInstanceStatusStopped {
|
|
|
|
|
- // delete
|
|
|
|
|
- deleteEcsInstance(t, client, instanceInfo.InstanceId)
|
|
|
|
|
- // wait
|
|
|
|
|
- waitForEcsInstance(t, client, instanceInfo.InstanceId, EcsInstanceStatusDeleted, 600)
|
|
|
|
|
|
|
+ createTime, err := strconv.ParseInt(instanceInfo.InstanceName[26:len(instanceInfo.InstanceName)], 10, 64)
|
|
|
|
|
+ assertErrorNil(t, err, "Parse instance create time failed: "+instanceInfo.InstanceName)
|
|
|
|
|
+ if (time.Now().Unix() - createTime) < (5 * 60) {
|
|
|
|
|
+ fmt.Printf("found undeleted ecs instance(%s) but created in 5 minutes, try to delete next time\n",instanceInfo.InstanceName)
|
|
|
|
|
+ return
|
|
|
|
|
+ }else{
|
|
|
|
|
+ fmt.Printf("found undeleted ecs instance(%s), status=%s, try to delete it.\n",
|
|
|
|
|
+ instanceInfo.Status, instanceInfo.InstanceId)
|
|
|
|
|
+ if instanceInfo.Status == EcsInstanceStatusRunning {
|
|
|
|
|
+ // stop
|
|
|
|
|
+ stopEcsInstance(t, client, instanceInfo.InstanceId)
|
|
|
|
|
+ } else if instanceInfo.Status == EcsInstanceStatusStopped {
|
|
|
|
|
+ // delete
|
|
|
|
|
+ deleteEcsInstance(t, client, instanceInfo.InstanceId)
|
|
|
|
|
+ // wait
|
|
|
|
|
+ waitForEcsInstance(t, client, instanceInfo.InstanceId, EcsInstanceStatusDeleted, 600)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func waitForEcsInstance(t *testing.T, client *ecs.Client, instanceId string, targetStatus string, timeout int) {
|
|
func waitForEcsInstance(t *testing.T, client *ecs.Client, instanceId string, targetStatus string, timeout int) {
|
|
@@ -152,10 +158,6 @@ func waitForEcsInstance(t *testing.T, client *ecs.Client, instanceId string, tar
|
|
|
request := ecs.CreateDescribeInstanceAttributeRequest()
|
|
request := ecs.CreateDescribeInstanceAttributeRequest()
|
|
|
request.InstanceId = instanceId
|
|
request.InstanceId = instanceId
|
|
|
response, err := client.DescribeInstanceAttribute(request)
|
|
response, err := client.DescribeInstanceAttribute(request)
|
|
|
- response.GetHttpStatus()
|
|
|
|
|
- response.GetHttpHeaders()
|
|
|
|
|
- response.GetHttpContentBytes()
|
|
|
|
|
- response.GetHttpContentString()
|
|
|
|
|
|
|
|
|
|
if targetStatus == EcsInstanceStatusDeleted {
|
|
if targetStatus == EcsInstanceStatusDeleted {
|
|
|
if response.GetHttpStatus() == 404 || response.Status == EcsInstanceStatusDeleted {
|
|
if response.GetHttpStatus() == 404 || response.Status == EcsInstanceStatusDeleted {
|