Ed & Cam | Don't sleep in tests and skip tests that don't work with moto if using moto
This commit is contained in:
parent
8760d36da5
commit
159964e2f1
|
@ -144,12 +144,9 @@ class EC2Driver(driver.ComputeDriver):
|
|||
port=port,
|
||||
region = moto_region,
|
||||
is_secure=secure)
|
||||
self.cloudwatch_conn = None
|
||||
|
||||
# self.cloudwatch_conn = ec2.cloudwatch.connect_to_region(
|
||||
# aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
|
||||
|
||||
# self.reservation = self.ec2_conn.get_all_reservations()
|
||||
self.cloudwatch_conn = ec2.cloudwatch.connect_to_region(
|
||||
aws_region, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
|
||||
|
||||
self.security_group_lock = Lock()
|
||||
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import unittest
|
||||
import time
|
||||
from boto.regioninfo import RegionInfo
|
||||
|
||||
from novaclient.v1_1 import client
|
||||
from ..credentials import get_nova_creds
|
||||
|
||||
from boto import ec2
|
||||
from ..ec2driver_config import *
|
||||
import urllib2
|
||||
|
||||
from boto.regioninfo import RegionInfo
|
||||
from novaclient.v1_1 import client
|
||||
from boto import ec2
|
||||
|
||||
from ..credentials import get_nova_creds
|
||||
from ..ec2driver_config import *
|
||||
|
||||
|
||||
def sleep_if_ec2_not_mocked(seconds):
|
||||
if not os.environ.get('TEST'):
|
||||
time.sleep(seconds)
|
||||
|
||||
|
||||
class EC2DriverTest(unittest.TestCase):
|
||||
_multiprocess_shared_ = True
|
||||
|
@ -16,8 +21,6 @@ class EC2DriverTest(unittest.TestCase):
|
|||
@classmethod
|
||||
def setUp(self):
|
||||
print "Establishing connection with AWS"
|
||||
# self.ec2_conn = ec2.connect_to_region(aws_region, aws_access_key_id=aws_access_key_id,
|
||||
# aws_secret_access_key=aws_secret_access_key)
|
||||
|
||||
moto_region = RegionInfo(name=aws_region, endpoint=aws_endpoint)
|
||||
self.ec2_conn = ec2.EC2Connection(aws_access_key_id=aws_access_key_id,
|
||||
|
@ -27,7 +30,6 @@ class EC2DriverTest(unittest.TestCase):
|
|||
region = moto_region,
|
||||
is_secure=secure)
|
||||
|
||||
|
||||
self.creds = get_nova_creds()
|
||||
self.nova = client.Client(**self.creds)
|
||||
|
||||
|
@ -48,7 +50,7 @@ class EC2DriverTest(unittest.TestCase):
|
|||
name="cirros-test", image=image.id, flavor=flavor.id)
|
||||
instance = self.nova.servers.get(server.id)
|
||||
while instance.status != 'ACTIVE':
|
||||
# time.sleep(10)
|
||||
sleep_if_ec2_not_mocked(10)
|
||||
instance = self.nova.servers.get(server.id)
|
||||
self.servers.append(instance)
|
||||
return instance, server.id
|
||||
|
@ -73,16 +75,14 @@ class EC2DriverTest(unittest.TestCase):
|
|||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id])[0]
|
||||
# EC2 statecode: 16->Running, 32->Shutting Down
|
||||
while ec2_instance.state != "running":
|
||||
# time.sleep(10)
|
||||
print "1"
|
||||
sleep_if_ec2_not_mocked(10)
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id])[0]
|
||||
instance.delete()
|
||||
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id])[0]
|
||||
# EC2 statecode: 16->Running, 32->Shutting Down
|
||||
# while ec2_instance[0].state != "shutting-down" or ec2_instance[0].state != "terminated":
|
||||
while ec2_instance.state not in ("shutting-down", "terminated"):
|
||||
# time.sleep(10)
|
||||
sleep_if_ec2_not_mocked(10)
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[ec2_id])[0]
|
||||
|
||||
self.assertTrue(ec2_instance.state in ("shutting-down", "terminated"))
|
||||
|
@ -95,7 +95,7 @@ class EC2DriverTest(unittest.TestCase):
|
|||
self.nova.servers.stop(instance)
|
||||
|
||||
while instance.status != 'SHUTOFF':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
# assert power off
|
||||
|
@ -116,7 +116,7 @@ class EC2DriverTest(unittest.TestCase):
|
|||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
while instance.status != 'ACTIVE':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
#assert restarted
|
||||
|
@ -132,11 +132,11 @@ class EC2DriverTest(unittest.TestCase):
|
|||
# we are waiting for the status to actually get to 'Hard Reboot' before
|
||||
# beginning to wait for it to go to 'Active' status
|
||||
while instance.status != 'HARD_REBOOT':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
while instance.status != 'ACTIVE':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
#assert restarted
|
||||
|
@ -149,8 +149,6 @@ class EC2DriverTest(unittest.TestCase):
|
|||
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[instance.metadata['ec2_id']])[0]
|
||||
|
||||
# ip_before_resize = ec2_instance.ip_address
|
||||
|
||||
ip_before_resize = self.ec2_conn.get_all_addresses(addresses=instance.metadata['public_ip_address'])[0]
|
||||
|
||||
self.assertEqual(ec2_instance.instance_type, "t2.micro")
|
||||
|
@ -163,14 +161,14 @@ class EC2DriverTest(unittest.TestCase):
|
|||
# wait for the status to actually go to Verify_Resize, before
|
||||
# confirming the resize.
|
||||
while instance.status != 'VERIFY_RESIZE':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
# Confirm the resize
|
||||
self.nova.servers.confirm_resize(instance)
|
||||
|
||||
while instance.status != 'ACTIVE':
|
||||
# time.sleep(5)
|
||||
sleep_if_ec2_not_mocked(5)
|
||||
instance = self.nova.servers.get(instance.id)
|
||||
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[instance.metadata['ec2_id']])[0]
|
||||
|
@ -181,45 +179,47 @@ class EC2DriverTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual(ip_before_resize.public_ip, ip_after_resize.public_ip)
|
||||
|
||||
# def test_user_data(self):
|
||||
# """To test the spawn method by providing a file user_data for config drive.
|
||||
# Will bring up a LAMP server.
|
||||
# """
|
||||
# content = open('user_data', 'r')
|
||||
# user_data_content = content.read()
|
||||
# image = self.nova.images.find(name="cirros-0.3.1-x86_64-uec")
|
||||
# flavor = self.nova.flavors.find(name="m1.tiny")
|
||||
# server = self.nova.servers.create(name="cirros-test", image=image.id, flavor=flavor.id,
|
||||
# userdata=user_data_content)
|
||||
# instance = self.nova.servers.get(server.id)
|
||||
# while instance.status != 'ACTIVE' and 'ec2_id' not in instance.metadata:
|
||||
# time.sleep(10)
|
||||
# instance = self.nova.servers.get(server.id)
|
||||
# self.servers.append(instance)
|
||||
#
|
||||
# ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[instance.metadata['ec2_id']], filters=None,
|
||||
# dry_run=False, max_results=None)
|
||||
# print ec2_instance
|
||||
# print ec2_instance[0].ip_address
|
||||
# #getting the public ip of the ec2 instance
|
||||
# url = "http://"+ec2_instance[0].ip_address+"/phpinfo.php"
|
||||
#
|
||||
# #wait for the instance to downalod all the dependencies for a LAMP server
|
||||
# time.sleep(300)
|
||||
# print url
|
||||
# raw_response = urllib2.urlopen(url)
|
||||
# print raw_response
|
||||
# self.assertEqual(raw_response.code, 200)
|
||||
@unittest.skipIf(os.environ.get('TEST'), 'Not supported by moto')
|
||||
def test_user_data(self):
|
||||
"""To test the spawn method by providing a file user_data for config drive.
|
||||
Will bring up a LAMP server.
|
||||
"""
|
||||
content = open('user_data', 'r')
|
||||
user_data_content = content.read()
|
||||
image = self.nova.images.find(name="cirros-0.3.1-x86_64-uec")
|
||||
flavor = self.nova.flavors.find(name="m1.tiny")
|
||||
server = self.nova.servers.create(name="cirros-test", image=image.id, flavor=flavor.id,
|
||||
userdata=user_data_content)
|
||||
instance = self.nova.servers.get(server.id)
|
||||
while instance.status != 'ACTIVE' and 'ec2_id' not in instance.metadata:
|
||||
sleep_if_ec2_not_mocked(10)
|
||||
instance = self.nova.servers.get(server.id)
|
||||
self.servers.append(instance)
|
||||
|
||||
# def test_diagnostics(self):
|
||||
# print "******* Diagnostics Test ***********"
|
||||
# instance, instance_ref = self.spawn_ec2_instance()
|
||||
# print "instance_ref: ", instance_ref
|
||||
#
|
||||
# diagnostics = instance.diagnostics()[1]
|
||||
#
|
||||
# self.assertEqual(diagnostics['instance.instance_type'], 't2.micro')
|
||||
# self.assertEqual(diagnostics['instance._state'], 'running(16)')
|
||||
ec2_instance = self.ec2_conn.get_only_instances(instance_ids=[instance.metadata['ec2_id']], filters=None,
|
||||
dry_run=False, max_results=None)
|
||||
print ec2_instance
|
||||
print ec2_instance[0].ip_address
|
||||
#getting the public ip of the ec2 instance
|
||||
url = "http://"+ec2_instance[0].ip_address+"/phpinfo.php"
|
||||
|
||||
#wait for the instance to downalod all the dependencies for a LAMP server
|
||||
sleep_if_ec2_not_mocked(300)
|
||||
print url
|
||||
raw_response = urllib2.urlopen(url)
|
||||
print raw_response
|
||||
self.assertEqual(raw_response.code, 200)
|
||||
|
||||
@unittest.skipIf(os.environ.get('TEST'), 'Not supported by moto')
|
||||
def test_diagnostics(self):
|
||||
print "******* Diagnostics Test ***********"
|
||||
instance, instance_ref = self.spawn_ec2_instance()
|
||||
print "instance_ref: ", instance_ref
|
||||
|
||||
diagnostics = instance.diagnostics()[1]
|
||||
|
||||
self.assertEqual(diagnostics['instance.instance_type'], 't2.micro')
|
||||
self.assertEqual(diagnostics['instance._state'], 'running(16)')
|
||||
|
||||
def test_attach_volume(self):
|
||||
volume = self.nova_volume.volumes.create(1, snapshot_id=None, display_name='test', display_description=None, volume_type=None, availability_zone=None, imageRef=None)
|
||||
|
|
Loading…
Reference in New Issue