Venu & Kashyap | Added polling to OpenStack and EC2 for tests to pass consistently

This commit is contained in:
Kashyap Kopparam
2014-08-26 14:41:34 +05:30
parent 63af287e21
commit e71cb10704

View File

@@ -26,15 +26,24 @@ class TestSpawn(unittest.TestCase):
self.server = nova.servers.create(name = "cirros-test",
image = image.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)
self.assertTrue(len(instance) == 1)
def tearDown(self):
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()
class TestDestroy(unittest.TestCase):
@@ -52,15 +61,37 @@ class TestDestroy(unittest.TestCase):
server = nova.servers.create(name = "cirros-test",
image = image.id,
flavor = flavor.id)
time.sleep(20)
ec2_id = server.metadata['ec2_id']
server.delete()
instance = nova.servers.get(server.id)
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']
time.sleep(10)
instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None)
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
self.assertEquals(instance[0].state_code, shutting_down_state_code)
self.assertEquals(ec2_instance[0].state_code, shutting_down_state_code)
if __name__ == '__main__':
unittest.main()