Enable AWS testcases in Omni tox run with required fixes
Closes-Bug: #1704149 Change-Id: Ib42e1130411bb519cb9d172641a4056c8668bb08
This commit is contained in:
parent
264939cfb5
commit
249f707233
|
@ -13,31 +13,26 @@ under the License.
|
|||
"""
|
||||
|
||||
import base64
|
||||
import boto
|
||||
import contextlib
|
||||
import mock
|
||||
|
||||
import boto
|
||||
import mock
|
||||
from moto import mock_cloudwatch
|
||||
from moto import mock_ec2
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from nova.compute import task_states
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova.image.glance import GlanceImageServiceV2
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.tests.unit import matchers
|
||||
from nova.virt.ec2 import EC2Driver
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
if hasattr(glance, "GlanceImageService"):
|
||||
from nova.image.glance import GlanceImageService
|
||||
else:
|
||||
from nova.image.glance import GlanceImageServiceV2 as GlanceImageService
|
||||
|
||||
|
||||
class EC2DriverTestCase(test.NoDBTestCase):
|
||||
|
||||
@mock_ec2
|
||||
@mock_cloudwatch
|
||||
def setUp(self):
|
||||
|
@ -49,7 +44,9 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
self.flags(access_key=self.fake_access_key,
|
||||
secret_key=self.fake_secret_key,
|
||||
# Region name cannot be fake
|
||||
region_name=self.region_name, group='AWS')
|
||||
region_name=self.region_name,
|
||||
group='AWS')
|
||||
self.flags(api_servers=['http://localhost:9292'], group='glance')
|
||||
self.conn = EC2Driver(None, False)
|
||||
self.type_data = None
|
||||
self.project_id = 'fake'
|
||||
|
@ -58,8 +55,8 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
self.uuid = None
|
||||
self.instance = None
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.fake_vpc_conn = boto.vpc.VPCConnection(
|
||||
region=self.region, aws_access_key_id=self.fake_access_key,
|
||||
self.fake_vpc_conn = boto.connect_vpc(
|
||||
aws_access_key_id=self.fake_access_key,
|
||||
aws_secret_access_key=self.fake_secret_key)
|
||||
self.fake_ec2_conn = boto.ec2.EC2Connection(
|
||||
aws_access_key_id=self.fake_access_key,
|
||||
|
@ -72,10 +69,11 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
def reset(self):
|
||||
instance_list = self.conn.ec2_conn.get_only_instances()
|
||||
# terminated instances are considered deleted and hence ignore them
|
||||
instance_id_list = [x.id for x in instance_list if x.state !=
|
||||
'terminated']
|
||||
self.conn.ec2_conn.stop_instances(instance_ids=instance_id_list,
|
||||
force=True)
|
||||
instance_id_list = [
|
||||
x.id for x in instance_list if x.state != 'terminated'
|
||||
]
|
||||
self.conn.ec2_conn.stop_instances(
|
||||
instance_ids=instance_id_list, force=True)
|
||||
self.conn.ec2_conn.terminate_instances(instance_ids=instance_id_list)
|
||||
self.type_data = None
|
||||
self.instance = None
|
||||
|
@ -84,7 +82,7 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
|
||||
@mock_ec2
|
||||
def test_list_instances(self):
|
||||
for x in range(0, 5):
|
||||
for _ in range(0, 5):
|
||||
self.conn.ec2_conn.run_instances('ami-1234abc')
|
||||
fake_list = self.conn.list_instances()
|
||||
self.assertEqual(5, len(fake_list))
|
||||
|
@ -96,8 +94,8 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
fake_key_data = 'abcdefgh'
|
||||
self.conn.ec2_conn.import_key_pair(fake_key, fake_key_data)
|
||||
with contextlib.nested(
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'get_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'import_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'get_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'import_key_pair'),
|
||||
) as (fake_get, fake_import):
|
||||
fake_get.return_value = True
|
||||
self.conn._add_ssh_keys(fake_key, fake_key_data)
|
||||
|
@ -109,8 +107,8 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
fake_key = 'fake_key'
|
||||
fake_key_data = 'abcdefgh'
|
||||
with contextlib.nested(
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'get_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'import_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'get_key_pair'),
|
||||
mock.patch.object(boto.ec2.EC2Connection, 'import_key_pair'),
|
||||
) as (fake_get, fake_import):
|
||||
fake_get.return_value = False
|
||||
self.conn._add_ssh_keys(fake_key, fake_key_data)
|
||||
|
@ -118,85 +116,88 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
fake_import.assert_called_once_with(fake_key, fake_key_data)
|
||||
|
||||
def test_process_network_info(self):
|
||||
fake_network_info = [
|
||||
{
|
||||
'profile': {},
|
||||
'ovs_interfaceid': None,
|
||||
'preserve_on_delete': False,
|
||||
'network': {
|
||||
'bridge': None,
|
||||
'subnets': [{
|
||||
'ips': [{
|
||||
'meta': {},
|
||||
'version': 4,
|
||||
'type': 'fixed',
|
||||
'floating_ips': [],
|
||||
'address': u'192.168.100.5'}],
|
||||
'version': 4,
|
||||
'meta': {},
|
||||
'dns': [],
|
||||
'routes': [],
|
||||
'cidr': u'192.168.100.0/24',
|
||||
'gateway': {
|
||||
'meta': {},
|
||||
'version': 4,
|
||||
'type': 'gateway',
|
||||
'address': u'192.168.100.1'}}],
|
||||
'meta': {
|
||||
'injected': True,
|
||||
'tenant_id': '135b1a036a51414ea1f989ab59fefde5'},
|
||||
'id': '4f8ad58d-de60-4b52-94ba-8b988a9b7f33',
|
||||
'label': 'test'},
|
||||
'devname': 'tapa9a90cf6-62',
|
||||
'vnic_type': 'normal',
|
||||
'qbh_params': None,
|
||||
'meta': {},
|
||||
'details': '{"subnet_id": "subnet-0107db5a",'
|
||||
' "ip_address": "192.168.100.5"}',
|
||||
'address': 'fa:16:3e:23:65:2c',
|
||||
'active': True,
|
||||
'type': 'vip_type_a',
|
||||
'id': 'a9a90cf6-627c-46f3-829d-c5a2ae07aaf0',
|
||||
'qbg_params': None
|
||||
}
|
||||
]
|
||||
fake_network_info = [{
|
||||
'profile': {},
|
||||
'ovs_interfaceid': None,
|
||||
'preserve_on_delete': False,
|
||||
'network': {
|
||||
'bridge': None,
|
||||
'subnets': [{
|
||||
'ips': [{'meta': {},
|
||||
'version': 4,
|
||||
'type': 'fixed',
|
||||
'floating_ips': [],
|
||||
'address': u'192.168.100.5'}],
|
||||
'version': 4,
|
||||
'meta': {},
|
||||
'dns': [],
|
||||
'routes': [],
|
||||
'cidr': u'192.168.100.0/24',
|
||||
'gateway': {'meta': {},
|
||||
'version': 4,
|
||||
'type': 'gateway',
|
||||
'address': u'192.168.100.1'}}],
|
||||
'meta': {'injected': True,
|
||||
'tenant_id': '135b1a036a51414ea1f989ab59fefde5'},
|
||||
'id': '4f8ad58d-de60-4b52-94ba-8b988a9b7f33',
|
||||
'label': 'test'},
|
||||
'devname': 'tapa9a90cf6-62',
|
||||
'vnic_type': 'normal',
|
||||
'qbh_params': None,
|
||||
'meta': {},
|
||||
'details': '{"subnet_id": "subnet-0107db5a",'
|
||||
' "ip_address": "192.168.100.5"}',
|
||||
'address': 'fa:16:3e:23:65:2c',
|
||||
'active': True,
|
||||
'type': 'vip_type_a',
|
||||
'id': 'a9a90cf6-627c-46f3-829d-c5a2ae07aaf0',
|
||||
'qbg_params': None
|
||||
}]
|
||||
aws_subnet_id, aws_fixed_ip, port_id, network_id = \
|
||||
self.conn._process_network_info(fake_network_info)
|
||||
self.assertEqual('subnet-0107db5a', aws_subnet_id)
|
||||
self.assertEqual('192.168.100.5', aws_fixed_ip)
|
||||
self.assertEqual('a9a90cf6-627c-46f3-829d-c5a2ae07aaf0', port_id)
|
||||
self.assertEqual('4f8ad58d-de60-4b52-94ba-8b988a9b7f33', network_id)
|
||||
self.assertEqual(aws_subnet_id, 'subnet-0107db5a')
|
||||
self.assertEqual(aws_fixed_ip, '192.168.100.5')
|
||||
self.assertEqual(port_id, 'a9a90cf6-627c-46f3-829d-c5a2ae07aaf0')
|
||||
self.assertEqual(network_id, '4f8ad58d-de60-4b52-94ba-8b988a9b7f33')
|
||||
|
||||
def _get_instance_flavor_details(self):
|
||||
return {
|
||||
'memory_mb': 2048.0, 'root_gb': 0, 'deleted_at': None,
|
||||
'name': 't2.small', 'deleted': 0, 'created_at': None,
|
||||
'ephemeral_gb': 0, 'updated_at': None, 'disabled': False,
|
||||
'vcpus': 1, 'extra_specs': {}, 'swap': 0, 'rxtx_factor': 1.0,
|
||||
'is_public': True, 'flavorid': '1', 'vcpu_weight': None, 'id': 2
|
||||
}
|
||||
return {'memory_mb': 2048.0,
|
||||
'root_gb': 0,
|
||||
'deleted_at': None,
|
||||
'name': 't2.small',
|
||||
'deleted': 0,
|
||||
'created_at': None,
|
||||
'ephemeral_gb': 0,
|
||||
'updated_at': None,
|
||||
'disabled': False,
|
||||
'vcpus': 1,
|
||||
'extra_specs': {},
|
||||
'swap': 0,
|
||||
'rxtx_factor': 1.0,
|
||||
'is_public': True,
|
||||
'flavorid': '1',
|
||||
'vcpu_weight': None,
|
||||
'id': 2}
|
||||
|
||||
def _create_instance(self, key_name=None, key_data=None, user_data=None):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
self.type_data = self._get_instance_flavor_details()
|
||||
values = {
|
||||
'name': 'fake_instance',
|
||||
'id': 1,
|
||||
'uuid': uuid,
|
||||
'project_id': self.project_id,
|
||||
'user_id': self.user_id,
|
||||
'kernel_id': 'fake_kernel_id',
|
||||
'ramdisk_id': 'fake_ramdisk_id',
|
||||
'flavor': objects.flavor.Flavor(**self.type_data),
|
||||
'node': 'fake_node',
|
||||
'memory_mb': self.type_data['memory_mb'],
|
||||
'root_gb': self.type_data['root_gb'],
|
||||
'ephemeral_gb': self.type_data['ephemeral_gb'],
|
||||
'vpcus': self.type_data['vcpus'],
|
||||
'swap': self.type_data['swap'],
|
||||
'expected_attrs': ['system_metadata', 'metadata'],
|
||||
'display_name': 'fake_instance',
|
||||
}
|
||||
values = {'name': 'fake_instance',
|
||||
'id': 1,
|
||||
'uuid': uuid,
|
||||
'project_id': self.project_id,
|
||||
'user_id': self.user_id,
|
||||
'kernel_id': 'fake_kernel_id',
|
||||
'ramdisk_id': 'fake_ramdisk_id',
|
||||
'flavor': objects.flavor.Flavor(**self.type_data),
|
||||
'node': 'fake_node',
|
||||
'memory_mb': self.type_data['memory_mb'],
|
||||
'root_gb': self.type_data['root_gb'],
|
||||
'ephemeral_gb': self.type_data['ephemeral_gb'],
|
||||
'vpcus': self.type_data['vcpus'],
|
||||
'swap': self.type_data['swap'],
|
||||
'expected_attrs': ['system_metadata', 'metadata'],
|
||||
'display_name': 'fake_instance'}
|
||||
if key_name and key_data:
|
||||
values['key_name'] = key_name
|
||||
values['key_data'] = key_data
|
||||
|
@ -232,15 +233,15 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
mock_secgrp.return_value = []
|
||||
self._create_nova_vm()
|
||||
fake_instances = self.fake_ec2_conn.get_only_instances()
|
||||
self.assertEqual(1, len(fake_instances))
|
||||
self.assertEqual(len(fake_instances), 1)
|
||||
inst = fake_instances[0]
|
||||
self.assertEqual(inst.vpc_id, self.vpc.id)
|
||||
self.assertEqual(self.subnet_id, inst.subnet_id)
|
||||
self.assertEqual('fake_instance', inst.tags['Name'])
|
||||
self.assertEqual(inst.tags['Name'], 'fake_instance')
|
||||
self.assertEqual(inst.tags['openstack_id'], self.uuid)
|
||||
self.assertEqual('ami-1234abc', inst.img_id)
|
||||
self.assertEqual(inst.image_id, 'ami-1234abc')
|
||||
self.assertEqual(inst.region.name, self.region_name)
|
||||
self.assertEqual('None', inst.key_name)
|
||||
self.assertEqual(inst.key_name, 'None')
|
||||
self.assertEqual(inst.instance_type, 't2.small')
|
||||
self.reset()
|
||||
|
||||
|
@ -259,9 +260,9 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
mock_secgrp.return_value = []
|
||||
self._create_nova_vm()
|
||||
fake_instances = self.fake_ec2_conn.get_only_instances()
|
||||
self.assertEqual(1, len(fake_instances))
|
||||
self.assertEqual(len(fake_instances), 1)
|
||||
inst = fake_instances[0]
|
||||
self.assertEqual('fake_key', inst.key_name)
|
||||
self.assertEqual(inst.key_name, 'fake_key')
|
||||
self.reset()
|
||||
|
||||
@mock_ec2
|
||||
|
@ -289,12 +290,11 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
fake_run_instance_op
|
||||
self._create_nova_vm()
|
||||
fake_instances = self.fake_ec2_conn.get_only_instances()
|
||||
self.assertEqual(1, len(fake_instances))
|
||||
self.assertEqual(len(fake_instances), 1)
|
||||
boto.ec2.EC2Connection.run_instances.assert_called_once_with(
|
||||
instance_type='t2.small', key_name=None,
|
||||
image_id='ami-1234abc', user_data=userdata,
|
||||
subnet_id=self.subnet_id,
|
||||
private_ip_address='192.168.10.5',
|
||||
subnet_id=self.subnet_id, private_ip_address='192.168.10.5',
|
||||
security_group_ids=[])
|
||||
self.reset()
|
||||
|
||||
|
@ -364,23 +364,21 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
@mock_ec2
|
||||
def test_snapshot(self):
|
||||
self._create_vm_in_aws_nova()
|
||||
GlanceImageService.update = mock.Mock()
|
||||
expected_calls = [
|
||||
{'args': (),
|
||||
'kwargs':
|
||||
{'task_state': task_states.IMAGE_UPLOADING,
|
||||
'expected_state': task_states.IMAGE_SNAPSHOT}}]
|
||||
GlanceImageServiceV2.update = mock.Mock()
|
||||
expected_calls = [{'args': (),
|
||||
'kwargs': {
|
||||
'task_state': task_states.IMAGE_UPLOADING,
|
||||
'expected_state': task_states.IMAGE_SNAPSHOT}}]
|
||||
func_call_matcher = matchers.FunctionCallMatcher(expected_calls)
|
||||
self.conn.snapshot(self.context, self.instance, 'test-snapshot',
|
||||
func_call_matcher.call)
|
||||
self.assertIsNone(func_call_matcher.match())
|
||||
context, snapshot_name, metadata = \
|
||||
GlanceImageService.update.call_args[0]
|
||||
_, snapshot_name, metadata = GlanceImageServiceV2.update.call_args[0]
|
||||
aws_imgs = self.fake_ec2_conn.get_all_images()
|
||||
self.assertEqual(1, len(aws_imgs))
|
||||
aws_img = aws_imgs[0]
|
||||
self.assertEqual('test-snapshot', snapshot_name)
|
||||
self.assertEqual('test-snapshot', aws_img.name)
|
||||
self.assertEqual(snapshot_name, 'test-snapshot')
|
||||
self.assertEqual(aws_img.name, 'test-snapshot')
|
||||
self.assertEqual(aws_img.id, metadata['properties']['ec2_image_id'])
|
||||
self.reset()
|
||||
|
||||
|
@ -388,12 +386,11 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
def test_snapshot_instance_not_found(self):
|
||||
boto.ec2.EC2Connection.create_image = mock.Mock()
|
||||
self._create_instance()
|
||||
GlanceImageService.update = mock.Mock()
|
||||
expected_calls = [
|
||||
{'args': (),
|
||||
'kwargs':
|
||||
{'task_state': task_states.IMAGE_UPLOADING,
|
||||
'expected_state': task_states.IMAGE_SNAPSHOT}}]
|
||||
GlanceImageServiceV2.update = mock.Mock()
|
||||
expected_calls = [{'args': (),
|
||||
'kwargs': {
|
||||
'task_state': task_states.IMAGE_UPLOADING,
|
||||
'expected_state': task_states.IMAGE_SNAPSHOT}}]
|
||||
func_call_matcher = matchers.FunctionCallMatcher(expected_calls)
|
||||
self.assertRaises(exception.InstanceNotFound, self.conn.snapshot,
|
||||
self.context, self.instance, 'test-snapshot',
|
||||
|
@ -445,10 +442,10 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
def test_power_off(self):
|
||||
self._create_vm_in_aws_nova()
|
||||
fake_inst = self.fake_ec2_conn.get_only_instances()[0]
|
||||
self.assertEqual('running', fake_inst.state)
|
||||
self.assertEqual(fake_inst.state, 'running')
|
||||
self.conn.power_off(self.instance)
|
||||
fake_inst = self.fake_ec2_conn.get_only_instances()[0]
|
||||
self.assertEqual('stopped', fake_inst.state)
|
||||
self.assertEqual(fake_inst.state, 'stopped')
|
||||
self.reset()
|
||||
|
||||
@mock_ec2
|
||||
|
@ -465,7 +462,7 @@ class EC2DriverTestCase(test.NoDBTestCase):
|
|||
self.fake_ec2_conn.stop_instances(instance_ids=[fake_inst.id])
|
||||
self.conn.power_on(self.context, self.instance, None, None)
|
||||
fake_inst = self.fake_ec2_conn.get_only_instances()[0]
|
||||
self.assertEqual('running', fake_inst.state)
|
||||
self.assertEqual(fake_inst.state, 'running')
|
||||
self.reset()
|
||||
|
||||
@mock_ec2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
google-api-python-client>=1.4.2 # Apache-2.0
|
||||
moto
|
||||
moto==0.4.27
|
||||
boto>=2.32.1 # MIT
|
||||
ipaddr
|
||||
google_compute_engine
|
||||
|
|
|
@ -24,6 +24,7 @@ WORKSPACE=$(pwd)
|
|||
DIRECTORY="$WORKSPACE/openstack"
|
||||
GCE_TEST="test_gce"
|
||||
AWS_TEST="test_ec2"
|
||||
AWS_NOVA_TEST="test_ec2.EC2DriverTestCase"
|
||||
declare -A results
|
||||
declare -i fail
|
||||
declare -i pass
|
||||
|
@ -83,8 +84,8 @@ copy_glance_files
|
|||
copy_neutron_files
|
||||
|
||||
echo "============Running tests============"
|
||||
run_tests cinder "$GCE_TEST" &
|
||||
run_tests nova "$GCE_TEST" &
|
||||
run_tests cinder "$GCE_TEST|$AWS_TEST" &
|
||||
run_tests nova "$GCE_TEST|$AWS_NOVA_TEST" &
|
||||
run_tests glance_store "$GCE_TEST" &
|
||||
run_tests neutron "$GCE_TEST" &
|
||||
wait
|
||||
|
|
Loading…
Reference in New Issue