Venu & Kashyap | Added polling to OpenStack and EC2 for tests to pass consistently
This commit is contained in:
@@ -26,7 +26,10 @@ class TestSpawn(unittest.TestCase):
|
|||||||
self.server = nova.servers.create(name = "cirros-test",
|
self.server = nova.servers.create(name = "cirros-test",
|
||||||
image = image.id,
|
image = image.id,
|
||||||
flavor = flavor.id)
|
flavor = flavor.id)
|
||||||
time.sleep(15)
|
instance = nova.servers.get(self.server.id)
|
||||||
|
while instance.status != 'ACTIVE':
|
||||||
|
time.sleep(10)
|
||||||
|
instance = nova.servers.get(self.server.id)
|
||||||
|
|
||||||
instance = self.ec2_conn.get_only_instances(instance_ids=[self.server.metadata['ec2_id']], filters=None, dry_run=False, max_results=None)
|
instance = self.ec2_conn.get_only_instances(instance_ids=[self.server.metadata['ec2_id']], filters=None, dry_run=False, max_results=None)
|
||||||
|
|
||||||
@@ -34,7 +37,13 @@ class TestSpawn(unittest.TestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
print "Cleanup: Destroying the instance used for testing"
|
print "Cleanup: Destroying the instance used for testing"
|
||||||
time.sleep(15)
|
ec2_id = self.server.metadata['ec2_id']
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
# EC2 statecode: 16->Running, 32->Shutting Down
|
||||||
|
while ec2_instance[0].state_code != 16:
|
||||||
|
time.sleep(10)
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
print ec2_instance[0].state, ec2_instance[0].state_code
|
||||||
self.server.delete()
|
self.server.delete()
|
||||||
|
|
||||||
class TestDestroy(unittest.TestCase):
|
class TestDestroy(unittest.TestCase):
|
||||||
@@ -52,15 +61,37 @@ class TestDestroy(unittest.TestCase):
|
|||||||
server = nova.servers.create(name = "cirros-test",
|
server = nova.servers.create(name = "cirros-test",
|
||||||
image = image.id,
|
image = image.id,
|
||||||
flavor = flavor.id)
|
flavor = flavor.id)
|
||||||
time.sleep(20)
|
|
||||||
ec2_id = server.metadata['ec2_id']
|
|
||||||
server.delete()
|
|
||||||
|
|
||||||
time.sleep(10)
|
instance = nova.servers.get(server.id)
|
||||||
instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
while instance.status != 'ACTIVE':
|
||||||
|
time.sleep(10)
|
||||||
|
instance = nova.servers.get(server.id)
|
||||||
|
|
||||||
|
instance = nova.servers.get(server.id)
|
||||||
|
print instance.status
|
||||||
|
ec2_id = instance.metadata['ec2_id']
|
||||||
|
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
# EC2 statecode: 16->Running, 32->Shutting Down
|
||||||
|
while ec2_instance[0].state_code != 16:
|
||||||
|
time.sleep(10)
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
print ec2_instance[0].state, ec2_instance[0].state_code
|
||||||
|
|
||||||
|
instance.delete()
|
||||||
|
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
# EC2 statecode: 16->Running, 32->Shutting Down
|
||||||
|
while ec2_instance[0].state_code != 32:
|
||||||
|
time.sleep(10)
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
print ec2_instance[0].state, ec2_instance[0].state_code
|
||||||
|
|
||||||
|
|
||||||
|
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
|
||||||
|
|
||||||
shutting_down_state_code = 32
|
shutting_down_state_code = 32
|
||||||
self.assertEquals(instance[0].state_code, shutting_down_state_code)
|
self.assertEquals(ec2_instance[0].state_code, shutting_down_state_code)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in New Issue
Block a user