Merge "Simplify usage of db_api.get_item_by_id"
This commit is contained in:
commit
d546e73253
|
@ -368,8 +368,7 @@ class AddressEngineNeutron(object):
|
|||
association_id=association_id)
|
||||
|
||||
address = db_api.get_item_by_id(
|
||||
context, 'eipalloc', ec2utils.change_ec2_id_kind(association_id,
|
||||
'eipalloc'))
|
||||
context, ec2utils.change_ec2_id_kind(association_id, 'eipalloc'))
|
||||
if address is None or not _is_address_valid(context, neutron, address):
|
||||
raise exception.InvalidAssociationIDNotFound(
|
||||
id=association_id)
|
||||
|
|
|
@ -136,7 +136,7 @@ def associate_dhcp_options(context, dhcp_options_id, vpc_id):
|
|||
os_ports = neutron.list_ports()['ports']
|
||||
network_interfaces = db_api.get_items(context, 'eni')
|
||||
rollback_dhcp_options_object = (
|
||||
db_api.get_item_by_id(context, 'dopt', rollback_dhcp_options_id)
|
||||
db_api.get_item_by_id(context, rollback_dhcp_options_id)
|
||||
if dhcp_options_id is not None else
|
||||
None)
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
|
|
|
@ -195,9 +195,10 @@ def get_db_item(context, ec2_id, expected_kind=None):
|
|||
Returns:
|
||||
The DB item.
|
||||
"""
|
||||
kind = expected_kind or get_ec2_id_kind(ec2_id)
|
||||
item = db_api.get_item_by_id(context, kind, ec2_id)
|
||||
if item is None:
|
||||
item = db_api.get_item_by_id(context, ec2_id)
|
||||
if (item is None or
|
||||
expected_kind and get_ec2_id_kind(ec2_id) != expected_kind):
|
||||
kind = expected_kind or get_ec2_id_kind(ec2_id)
|
||||
params = {'id': ec2_id}
|
||||
raise NOT_FOUND_EXCEPTION_MAP[kind](**params)
|
||||
return item
|
||||
|
|
|
@ -1031,7 +1031,7 @@ class InstanceEngineNeutron(object):
|
|||
network_interface_id=ec2_network_interface_id)
|
||||
# TODO(ft): receive network_interface from a
|
||||
# create_network_interface sub-function
|
||||
network_interface = db_api.get_item_by_id(context, 'eni',
|
||||
network_interface = db_api.get_item_by_id(context,
|
||||
ec2_network_interface_id)
|
||||
data['network_interface'] = network_interface
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ def create_network_interface(context, subnet_id,
|
|||
if secondary_private_ip_address_count > 0:
|
||||
for _i in range(secondary_private_ip_address_count):
|
||||
fixed_ips.append({'subnet_id': os_subnet['id']})
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', subnet['vpc_id'])
|
||||
vpc = db_api.get_item_by_id(context, subnet['vpc_id'])
|
||||
vpc_id = vpc['id']
|
||||
dhcp_options_id = vpc.get('dhcp_options_id', None)
|
||||
if not security_group_id:
|
||||
|
@ -145,7 +145,7 @@ def create_network_interface(context, subnet_id,
|
|||
if dhcp_options_id:
|
||||
dhcp_options._add_dhcp_opts_to_port(
|
||||
context,
|
||||
db_api.get_item_by_id(context, 'dopt', dhcp_options_id),
|
||||
db_api.get_item_by_id(context, dhcp_options_id),
|
||||
network_interface,
|
||||
os_port)
|
||||
security_groups = security_group_api._format_security_groups_ids_names(
|
||||
|
@ -236,8 +236,7 @@ def assign_private_ip_addresses(context, network_interface_id,
|
|||
allow_reassignment=False):
|
||||
# TODO(Alex): allow_reassignment is not supported at the moment
|
||||
network_interface = ec2utils.get_db_item(context, network_interface_id)
|
||||
subnet = db_api.get_item_by_id(context, 'subnet',
|
||||
network_interface['subnet_id'])
|
||||
subnet = db_api.get_item_by_id(context, network_interface['subnet_id'])
|
||||
neutron = clients.neutron(context)
|
||||
os_subnet = neutron.show_subnet(subnet['os_id'])['subnet']
|
||||
os_port = neutron.show_port(network_interface['os_id'])['port']
|
||||
|
@ -390,7 +389,7 @@ def attach_network_interface(context, network_interface_id,
|
|||
|
||||
def detach_network_interface(context, attachment_id, force=None):
|
||||
network_interface = db_api.get_item_by_id(
|
||||
context, 'eni', ec2utils.change_ec2_id_kind(attachment_id, 'eni'))
|
||||
context, ec2utils.change_ec2_id_kind(attachment_id, 'eni'))
|
||||
if not network_interface or 'instance_id' not in network_interface:
|
||||
raise exception.InvalidAttachmentIDNotFound(id=attachment_id)
|
||||
if network_interface['device_index'] == 0:
|
||||
|
|
|
@ -98,9 +98,8 @@ def associate_route_table(context, route_table_id, subnet_id):
|
|||
msg = msg % {'rtb_id': route_table_id}
|
||||
raise exception.ResourceAlreadyAssociated(msg)
|
||||
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', subnet['vpc_id'])
|
||||
main_route_table = db_api.get_item_by_id(context, 'rtb',
|
||||
vpc['route_table_id'])
|
||||
vpc = db_api.get_item_by_id(context, subnet['vpc_id'])
|
||||
main_route_table = db_api.get_item_by_id(context, vpc['route_table_id'])
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
_associate_subnet_item(context, subnet, route_table['id'])
|
||||
cleaner.addCleanup(_disassociate_subnet_item, context, subnet)
|
||||
|
@ -117,15 +116,14 @@ def replace_route_table_association(context, association_id, route_table_id):
|
|||
route_table = ec2utils.get_db_item(context, route_table_id)
|
||||
if route_table['vpc_id'] == ec2utils.change_ec2_id_kind(association_id,
|
||||
'vpc'):
|
||||
vpc = db_api.get_item_by_id(context, 'vpc',
|
||||
ec2utils.change_ec2_id_kind(association_id,
|
||||
'vpc'))
|
||||
vpc = db_api.get_item_by_id(
|
||||
context, ec2utils.change_ec2_id_kind(association_id, 'vpc'))
|
||||
if vpc is None:
|
||||
raise exception.InvalidAssociationIDNotFound(
|
||||
id=association_id)
|
||||
|
||||
rollabck_route_table_object = db_api.get_item_by_id(
|
||||
context, 'rtb', vpc['route_table_id'])
|
||||
context, vpc['route_table_id'])
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
_associate_vpc_item(context, vpc, route_table['id'])
|
||||
cleaner.addCleanup(_associate_vpc_item, context, vpc,
|
||||
|
@ -138,8 +136,7 @@ def replace_route_table_association(context, association_id, route_table_id):
|
|||
rollabck_route_table_object, is_main=True)
|
||||
else:
|
||||
subnet = db_api.get_item_by_id(
|
||||
context, 'subnet',
|
||||
ec2utils.change_ec2_id_kind(association_id, 'subnet'))
|
||||
context, ec2utils.change_ec2_id_kind(association_id, 'subnet'))
|
||||
if subnet is None or 'route_table_id' not in subnet:
|
||||
raise exception.InvalidAssociationIDNotFound(
|
||||
id=association_id)
|
||||
|
@ -151,7 +148,7 @@ def replace_route_table_association(context, association_id, route_table_id):
|
|||
raise exception.InvalidParameterValue(msg)
|
||||
|
||||
rollabck_route_table_object = db_api.get_item_by_id(
|
||||
context, 'rtb', subnet['route_table_id'])
|
||||
context, subnet['route_table_id'])
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
_associate_subnet_item(context, subnet, route_table['id'])
|
||||
cleaner.addCleanup(_associate_subnet_item, context, subnet,
|
||||
|
@ -165,13 +162,11 @@ def replace_route_table_association(context, association_id, route_table_id):
|
|||
|
||||
|
||||
def disassociate_route_table(context, association_id):
|
||||
subnet = db_api.get_item_by_id(context, 'subnet',
|
||||
ec2utils.change_ec2_id_kind(association_id,
|
||||
'subnet'))
|
||||
subnet = db_api.get_item_by_id(
|
||||
context, ec2utils.change_ec2_id_kind(association_id, 'subnet'))
|
||||
if not subnet:
|
||||
vpc = db_api.get_item_by_id(context, 'vpc',
|
||||
ec2utils.change_ec2_id_kind(association_id,
|
||||
'vpc'))
|
||||
vpc = db_api.get_item_by_id(
|
||||
context, ec2utils.change_ec2_id_kind(association_id, 'vpc'))
|
||||
if vpc is None:
|
||||
raise exception.InvalidAssociationIDNotFound(
|
||||
id=association_id)
|
||||
|
@ -183,10 +178,9 @@ def disassociate_route_table(context, association_id):
|
|||
id=association_id)
|
||||
|
||||
rollback_route_table_object = db_api.get_item_by_id(
|
||||
context, 'rtb', subnet['route_table_id'])
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', subnet['vpc_id'])
|
||||
main_route_table = db_api.get_item_by_id(
|
||||
context, 'rtb', vpc['route_table_id'])
|
||||
context, subnet['route_table_id'])
|
||||
vpc = db_api.get_item_by_id(context, subnet['vpc_id'])
|
||||
main_route_table = db_api.get_item_by_id(context, vpc['route_table_id'])
|
||||
with common.OnCrashCleaner() as cleaner:
|
||||
_disassociate_subnet_item(context, subnet)
|
||||
cleaner.addCleanup(_associate_subnet_item, context, subnet,
|
||||
|
@ -201,7 +195,7 @@ def disassociate_route_table(context, association_id):
|
|||
|
||||
def delete_route_table(context, route_table_id):
|
||||
route_table = ec2utils.get_db_item(context, route_table_id)
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', route_table['vpc_id'])
|
||||
vpc = db_api.get_item_by_id(context, route_table['vpc_id'])
|
||||
_delete_route_table(context, route_table['id'], vpc)
|
||||
return True
|
||||
|
||||
|
@ -277,7 +271,7 @@ def _delete_route_table(context, route_table_id, vpc=None, cleaner=None):
|
|||
"be deleted.") % {'rtb_id': route_table_id}
|
||||
raise exception.DependencyViolation(msg)
|
||||
if cleaner:
|
||||
route_table = db_api.get_item_by_id(context, 'rtb', route_table_id)
|
||||
route_table = db_api.get_item_by_id(context, route_table_id)
|
||||
db_api.delete_item(context, route_table_id)
|
||||
if cleaner and route_table:
|
||||
cleaner.addCleanup(db_api.restore_item, context, 'rtb', route_table)
|
||||
|
@ -287,7 +281,7 @@ def _set_route(context, route_table_id, destination_cidr_block,
|
|||
gateway_id, instance_id, network_interface_id,
|
||||
vpc_peering_connection_id, do_replace):
|
||||
route_table = ec2utils.get_db_item(context, route_table_id)
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', route_table['vpc_id'])
|
||||
vpc = db_api.get_item_by_id(context, route_table['vpc_id'])
|
||||
vpc_ipnet = netaddr.IPNetwork(vpc['cidr_block'])
|
||||
route_ipnet = netaddr.IPNetwork(destination_cidr_block)
|
||||
if route_ipnet in vpc_ipnet:
|
||||
|
@ -429,7 +423,7 @@ def _format_route_table(context, route_table, is_main=False,
|
|||
None)
|
||||
state = 'blackhole'
|
||||
if instance_id:
|
||||
instance = db_api.get_item_by_id(context, 'i', instance_id)
|
||||
instance = db_api.get_item_by_id(context, instance_id)
|
||||
if instance:
|
||||
try:
|
||||
os_instance = nova.servers.get(instance['os_id'])
|
||||
|
@ -467,7 +461,7 @@ def _update_routes_in_associated_subnets(context, route_table, cleaner,
|
|||
rollabck_route_table_object,
|
||||
is_main=None):
|
||||
if is_main is None:
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', route_table['vpc_id'])
|
||||
vpc = db_api.get_item_by_id(context, route_table['vpc_id'])
|
||||
is_main = vpc['route_table_id'] == route_table['id']
|
||||
if is_main:
|
||||
appropriate_rtb_ids = (route_table['id'], None)
|
||||
|
@ -502,11 +496,10 @@ def _update_subnet_host_routes(context, subnet, route_table, cleaner=None,
|
|||
|
||||
def _get_router_objects(context, route_table):
|
||||
return dict((route['gateway_id'],
|
||||
db_api.get_item_by_id(context, 'igw', route['gateway_id']))
|
||||
db_api.get_item_by_id(context, route['gateway_id']))
|
||||
if route.get('gateway_id') else
|
||||
(route['network_interface_id'],
|
||||
db_api.get_item_by_id(context, 'eni',
|
||||
route['network_interface_id']))
|
||||
db_api.get_item_by_id(context, route['network_interface_id']))
|
||||
for route in route_table['routes']
|
||||
if route.get('gateway_id') or 'network_interface_id' in route)
|
||||
|
||||
|
@ -519,16 +512,15 @@ def _get_subnet_host_routes(context, route_table, gateway_ip,
|
|||
if gateway_id:
|
||||
gateway = (router_objects[route['gateway_id']]
|
||||
if router_objects else
|
||||
db_api.get_item_by_id(context, 'igw', gateway_id))
|
||||
db_api.get_item_by_id(context, gateway_id))
|
||||
if (not gateway or
|
||||
gateway.get('vpc_id') != route_table['vpc_id']):
|
||||
return '127.0.0.1'
|
||||
return gateway_ip
|
||||
network_interface = (router_objects[route['network_interface_id']]
|
||||
if router_objects else
|
||||
db_api.get_item_by_id(
|
||||
context, 'eni',
|
||||
route['network_interface_id']))
|
||||
network_interface = (
|
||||
router_objects[route['network_interface_id']]
|
||||
if router_objects else
|
||||
db_api.get_item_by_id(context, route['network_interface_id']))
|
||||
if not network_interface:
|
||||
return '127.0.0.1'
|
||||
return network_interface['private_ip_address']
|
||||
|
|
|
@ -48,8 +48,7 @@ def create_subnet(context, vpc_id, cidr_block,
|
|||
raise exception.InvalidSubnetRange(cidr_block=cidr_block)
|
||||
|
||||
gateway_ip = str(netaddr.IPAddress(subnet_ipnet.first + 1))
|
||||
main_route_table = db_api.get_item_by_id(context, 'rtb',
|
||||
vpc['route_table_id'])
|
||||
main_route_table = db_api.get_item_by_id(context, vpc['route_table_id'])
|
||||
host_routes = route_table_api._get_subnet_host_routes(
|
||||
context, main_route_table, gateway_ip)
|
||||
neutron = clients.neutron(context)
|
||||
|
@ -90,7 +89,7 @@ def create_subnet(context, vpc_id, cidr_block,
|
|||
|
||||
def delete_subnet(context, subnet_id):
|
||||
subnet = ec2utils.get_db_item(context, subnet_id)
|
||||
vpc = db_api.get_item_by_id(context, 'vpc', subnet['vpc_id'])
|
||||
vpc = db_api.get_item_by_id(context, subnet['vpc_id'])
|
||||
network_interfaces = network_interface_api.describe_network_interfaces(
|
||||
context,
|
||||
filter=[{'name': 'subnet-id',
|
||||
|
|
|
@ -103,8 +103,8 @@ def get_items(context, kind):
|
|||
return IMPL.get_items(context, kind)
|
||||
|
||||
|
||||
def get_item_by_id(context, kind, item_id):
|
||||
return IMPL.get_item_by_id(context, kind, item_id)
|
||||
def get_item_by_id(context, item_id):
|
||||
return IMPL.get_item_by_id(context, item_id)
|
||||
|
||||
|
||||
def get_items_by_ids(context, kind, item_ids):
|
||||
|
|
|
@ -189,12 +189,11 @@ def get_items(context, kind):
|
|||
|
||||
|
||||
@require_context
|
||||
def get_item_by_id(context, kind, item_id):
|
||||
return _unpack_item_data(model_query(context, models.Item).
|
||||
def get_item_by_id(context, item_id):
|
||||
return (_unpack_item_data(model_query(context, models.Item).
|
||||
filter_by(project_id=context.project_id,
|
||||
id=item_id).
|
||||
filter(models.Item.id.like('%s-%%' % kind)).
|
||||
first())
|
||||
first()))
|
||||
|
||||
|
||||
@require_context
|
||||
|
|
|
@ -20,6 +20,7 @@ import uuid
|
|||
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from ec2api.api import ec2utils
|
||||
from ec2api.tests.unit import tools
|
||||
|
||||
|
||||
|
@ -40,13 +41,13 @@ def get_db_api_add_item(item_id_dict):
|
|||
|
||||
|
||||
def get_db_api_get_items(results_dict_by_kind):
|
||||
def db_api_get_items(context, kind, *args):
|
||||
def db_api_get_items(context, kind):
|
||||
return results_dict_by_kind.get(kind)
|
||||
return db_api_get_items
|
||||
|
||||
|
||||
def get_db_api_get_item_by_id(results_dict_by_id):
|
||||
def db_api_get_item_by_id(context, kind, item_id):
|
||||
def db_api_get_item_by_id(context, item_id):
|
||||
item = results_dict_by_id.get(item_id)
|
||||
if item is not None:
|
||||
item = copy.deepcopy(item)
|
||||
|
@ -54,6 +55,24 @@ def get_db_api_get_item_by_id(results_dict_by_id):
|
|||
return db_api_get_item_by_id
|
||||
|
||||
|
||||
def get_db_api_get_items_by_ids(items):
|
||||
def db_api_get_items_by_ids(context, kind, item_ids):
|
||||
return [copy.deepcopy(item)
|
||||
for item in items
|
||||
if (ec2utils.get_ec2_id_kind(item['id']) == kind and
|
||||
not item_ids or item['id'] in item_ids)]
|
||||
return db_api_get_items_by_ids
|
||||
|
||||
|
||||
def get_db_api_get_item_ids(items):
|
||||
def db_api_get_item_ids(context, kind, item_os_ids):
|
||||
return [(item['id'], item['os_id'])
|
||||
for item in items
|
||||
if (item['os_id'] in item_os_ids and
|
||||
ec2utils.get_ec2_id_kind(item['id']) == kind)]
|
||||
return db_api_get_item_ids
|
||||
|
||||
|
||||
def get_neutron_create(kind, os_id, addon={}):
|
||||
def neutron_create(body):
|
||||
body = copy.deepcopy(body)
|
||||
|
|
|
@ -87,7 +87,7 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
self.assertThat(item, matchers.DictMatches(new_item,
|
||||
orderless_lists=True))
|
||||
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item_id)
|
||||
item = db_api.get_item_by_id(self.context, item_id)
|
||||
new_item['id'] = item_id
|
||||
self.assertThat(item, matchers.DictMatches(new_item,
|
||||
orderless_lists=True))
|
||||
|
@ -143,7 +143,7 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
os_id = fakes.random_os_id()
|
||||
item_id = db_api.add_item_id(self.context, 'fake', os_id)
|
||||
self.assertTrue(validator.validate_ec2_id(item_id, '', ['fake']))
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item_id)
|
||||
item = db_api.get_item_by_id(self.context, item_id)
|
||||
self.assertIsNone(item)
|
||||
item = db_api.add_item(self.context, 'fake', {'os_id': os_id})
|
||||
self.assertThat(item, matchers.DictMatches({'id': item_id,
|
||||
|
@ -167,7 +167,7 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
item['key2'] = 'val'
|
||||
item_id = item['id']
|
||||
db_api.update_item(self.context, item)
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item_id)
|
||||
item = db_api.get_item_by_id(self.context, item_id)
|
||||
self.assertThat(item, matchers.DictMatches({'id': item_id,
|
||||
'os_id': None,
|
||||
'vpc_id': None,
|
||||
|
@ -184,7 +184,7 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
def test_delete_item(self):
|
||||
item = db_api.add_item(self.context, 'fake', {})
|
||||
db_api.delete_item(self.context, item['id'])
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item['id'])
|
||||
item = db_api.get_item_by_id(self.context, item['id'])
|
||||
self.assertIsNone(item)
|
||||
|
||||
# NOTE(ft): delete not existing item should pass quitely
|
||||
|
@ -192,7 +192,7 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
|
||||
item = db_api.add_item(self.context, 'fake', {})
|
||||
db_api.delete_item(self.other_context, item['id'])
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item['id'])
|
||||
item = db_api.get_item_by_id(self.context, item['id'])
|
||||
self.assertIsNotNone(item)
|
||||
|
||||
def _setup_items(self):
|
||||
|
@ -218,18 +218,13 @@ class DbApiTestCase(test_base.BaseTestCase):
|
|||
item_id = db_api.get_items(self.context, 'fake')[0]['id']
|
||||
other_item_id = db_api.get_items(self.other_context, 'fake')[0]['id']
|
||||
|
||||
item = db_api.get_item_by_id(self.context, 'fake', item_id)
|
||||
item = db_api.get_item_by_id(self.context, item_id)
|
||||
self.assertThat(item, matchers.DictMatches({'id': item_id,
|
||||
'os_id': None,
|
||||
'vpc_id': None}))
|
||||
item = db_api.get_item_by_id(self.context, 'fake1', item_id)
|
||||
item = db_api.get_item_by_id(self.context, other_item_id)
|
||||
self.assertIsNone(item)
|
||||
item = db_api.get_item_by_id(self.context, 'fake0', item_id)
|
||||
self.assertIsNone(item)
|
||||
item = db_api.get_item_by_id(self.context, 'fake', other_item_id)
|
||||
self.assertIsNone(item)
|
||||
item = db_api.get_item_by_id(self.context, 'fake',
|
||||
fakes.random_ec2_id('fake'))
|
||||
item = db_api.get_item_by_id(self.context, fakes.random_ec2_id('fake'))
|
||||
|
||||
def test_get_items_by_ids(self):
|
||||
self._setup_items()
|
||||
|
|
|
@ -35,7 +35,7 @@ class EC2UtilsTestCase(testtools.TestCase):
|
|||
res = ec2utils.get_db_item('fake_context', ec2_id)
|
||||
self.assertThat(res, matchers.DictMatches(item))
|
||||
db_api.get_item_by_id.assert_called_once_with('fake_context',
|
||||
kind, ec2_id)
|
||||
ec2_id)
|
||||
db_api.reset_mock()
|
||||
|
||||
check_normal_flow('vpc', 'vpc-001234af')
|
||||
|
@ -47,7 +47,7 @@ class EC2UtilsTestCase(testtools.TestCase):
|
|||
ec2utils.get_db_item,
|
||||
'fake_context', ec2_id)
|
||||
db_api.get_item_by_id.assert_called_once_with('fake_context',
|
||||
kind, ec2_id)
|
||||
ec2_id)
|
||||
db_api.reset_mock()
|
||||
|
||||
db_api.get_item_by_id.return_value = None
|
||||
|
@ -164,7 +164,7 @@ class EC2UtilsTestCase(testtools.TestCase):
|
|||
os_image,
|
||||
ec2utils.get_os_image(fake_context, fakes.ID_EC2_IMAGE_1))
|
||||
db_api.get_item_by_id.assert_called_with(
|
||||
mock.ANY, 'ami', fakes.ID_EC2_IMAGE_1)
|
||||
mock.ANY, fakes.ID_EC2_IMAGE_1)
|
||||
glance.images.get.assert_called_with(fakes.ID_OS_IMAGE_1)
|
||||
|
||||
# NOTE(ft): check normal flow for a public image
|
||||
|
|
|
@ -120,7 +120,7 @@ class ImageTestCase(base.ApiTestCase):
|
|||
'imageId': image_id},
|
||||
resp)
|
||||
self.db_api.get_item_by_id.assert_called_once_with(
|
||||
mock.ANY, 'i', fakes.ID_EC2_INSTANCE_2)
|
||||
mock.ANY, fakes.ID_EC2_INSTANCE_2)
|
||||
self.nova_servers.get.assert_called_once_with(fakes.ID_OS_INSTANCE_2)
|
||||
is_ebs_instance.assert_called_once_with(mock.ANY, os_instance)
|
||||
self.db_api.add_item.assert_called_once_with(
|
||||
|
@ -384,29 +384,18 @@ class ImageTestCase(base.ApiTestCase):
|
|||
fakes.ID_EC2_IMAGE_1: fakes.DB_IMAGE_1,
|
||||
fakes.ID_EC2_IMAGE_2: fakes.DB_IMAGE_2}))
|
||||
self.db_api.get_items_by_ids.side_effect = (
|
||||
fakes.get_db_api_get_items({
|
||||
'ami': [fakes.DB_IMAGE_1, fakes.DB_IMAGE_2],
|
||||
'ari': [],
|
||||
'aki': []}))
|
||||
fakes.get_db_api_get_items_by_ids(
|
||||
[fakes.DB_IMAGE_1, fakes.DB_IMAGE_2]))
|
||||
self.db_api.get_items.side_effect = (
|
||||
fakes.get_db_api_get_items({
|
||||
'snap': [fakes.DB_SNAPSHOT_1, fakes.DB_SNAPSHOT_2]}))
|
||||
self.db_api.get_public_items.return_value = []
|
||||
|
||||
self.db_api.get_item_ids.side_effect = (
|
||||
fakes.get_db_api_get_item_by_id({
|
||||
(fakes.ID_OS_IMAGE_ARI_1,): [(fakes.ID_EC2_IMAGE_ARI_1,
|
||||
fakes.ID_OS_IMAGE_ARI_1)],
|
||||
(fakes.ID_OS_IMAGE_AKI_1,): [(fakes.ID_EC2_IMAGE_AKI_1,
|
||||
fakes.ID_OS_IMAGE_AKI_1)],
|
||||
(fakes.ID_OS_SNAPSHOT_1,): [(fakes.ID_EC2_SNAPSHOT_1,
|
||||
fakes.ID_OS_SNAPSHOT_1)],
|
||||
(fakes.ID_OS_SNAPSHOT_2,): [(fakes.ID_EC2_SNAPSHOT_2,
|
||||
fakes.ID_OS_SNAPSHOT_2)],
|
||||
(fakes.ID_OS_VOLUME_1,): [(fakes.ID_EC2_VOLUME_1,
|
||||
fakes.ID_OS_VOLUME_1)],
|
||||
(fakes.ID_OS_VOLUME_2,): [(fakes.ID_EC2_VOLUME_2,
|
||||
fakes.ID_OS_VOLUME_2)]}))
|
||||
fakes.get_db_api_get_item_ids(
|
||||
[fakes.DB_IMAGE_AKI_1, fakes.DB_IMAGE_ARI_1,
|
||||
fakes.DB_SNAPSHOT_1, fakes.DB_SNAPSHOT_2,
|
||||
fakes.DB_VOLUME_1, fakes. DB_VOLUME_2]))
|
||||
|
||||
self.glance.images.list.side_effect = (
|
||||
lambda: [fakes.OSImage(fakes.OS_IMAGE_1),
|
||||
|
@ -515,11 +504,8 @@ class S3TestCase(base.ApiTestCase):
|
|||
|
||||
def test_s3_parse_manifest(self):
|
||||
self.db_api.get_public_items.side_effect = (
|
||||
fakes.get_db_api_get_items({
|
||||
'aki': ({'id': fakes.ID_EC2_IMAGE_AKI_1,
|
||||
'os_id': fakes.ID_OS_IMAGE_AKI_1},),
|
||||
'ari': ({'id': fakes.ID_EC2_IMAGE_ARI_1,
|
||||
'os_id': fakes.ID_OS_IMAGE_ARI_1},)}))
|
||||
fakes.get_db_api_get_items_by_ids(
|
||||
[fakes.DB_IMAGE_AKI_1, fakes.DB_IMAGE_ARI_1]))
|
||||
self.db_api.get_item_by_id.return_value = None
|
||||
self.glance.images.get.side_effect = (
|
||||
fakes.get_by_1st_arg_getter({
|
||||
|
|
|
@ -76,11 +76,8 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
copy.deepcopy(fakes.DB_NETWORK_INTERFACE_1),
|
||||
fakes.ID_EC2_IMAGE_1: fakes.DB_IMAGE_1}))
|
||||
self.db_api.get_item_ids.side_effect = (
|
||||
fakes.get_db_api_get_item_by_id({
|
||||
(fakes.ID_OS_IMAGE_ARI_1,): [(fakes.ID_EC2_IMAGE_ARI_1,
|
||||
fakes.ID_OS_IMAGE_ARI_1)],
|
||||
(fakes.ID_OS_IMAGE_AKI_1,): [(fakes.ID_EC2_IMAGE_AKI_1,
|
||||
fakes.ID_OS_IMAGE_AKI_1)]}))
|
||||
fakes.get_db_api_get_item_ids(
|
||||
[fakes.DB_IMAGE_ARI_1, fakes.DB_IMAGE_AKI_1]))
|
||||
self.glance.images.get.return_value = fakes.OSImage(fakes.OS_IMAGE_1)
|
||||
self.network_interface_api.create_network_interface.return_value = (
|
||||
{'networkInterface': fakes.EC2_NETWORK_INTERFACE_1})
|
||||
|
@ -848,7 +845,7 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
key: 'fake_data'},
|
||||
resp)
|
||||
self.db_api.get_item_by_id.assert_called_once_with(
|
||||
mock.ANY, 'i', fakes.ID_EC2_INSTANCE_2)
|
||||
mock.ANY, fakes.ID_EC2_INSTANCE_2)
|
||||
self.nova_servers.get.assert_called_once_with(fakes.ID_OS_INSTANCE_2)
|
||||
getter.assert_called_once_with(fakes.OS_INSTANCE_2)
|
||||
|
||||
|
@ -875,11 +872,8 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
'vol': [fakes.DB_VOLUME_1, fakes.DB_VOLUME_2,
|
||||
fakes.DB_VOLUME_3]}))
|
||||
self.db_api.get_item_ids.side_effect = (
|
||||
fakes.get_db_api_get_item_by_id({
|
||||
(fakes.ID_OS_IMAGE_ARI_1,): [(fakes.ID_EC2_IMAGE_ARI_1,
|
||||
fakes.ID_OS_IMAGE_ARI_1)],
|
||||
(fakes.ID_OS_IMAGE_AKI_1,): [(fakes.ID_EC2_IMAGE_AKI_1,
|
||||
fakes.ID_OS_IMAGE_AKI_1)]}))
|
||||
fakes.get_db_api_get_item_ids(
|
||||
[fakes.DB_IMAGE_ARI_1, fakes.DB_IMAGE_AKI_1]))
|
||||
self.nova_servers.list.return_value = [fakes.OS_INSTANCE_1,
|
||||
fakes.OS_INSTANCE_2]
|
||||
self.novadb.instance_get_by_uuid.side_effect = (
|
||||
|
@ -1138,11 +1132,8 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
fakes.ID_EC2_INSTANCE_1: fakes.DB_INSTANCE_1,
|
||||
fakes.ID_EC2_INSTANCE_2: fakes.DB_INSTANCE_2}))
|
||||
self.db_api.get_item_ids.side_effect = (
|
||||
fakes.get_db_api_get_item_by_id({
|
||||
(fakes.ID_OS_IMAGE_AKI_1,): [(fakes.ID_EC2_IMAGE_AKI_1,
|
||||
fakes.ID_OS_IMAGE_AKI_1)],
|
||||
(fakes.ID_OS_IMAGE_ARI_1,): [(fakes.ID_EC2_IMAGE_ARI_1,
|
||||
fakes.ID_OS_IMAGE_ARI_1)]}))
|
||||
fakes.get_db_api_get_item_ids(
|
||||
[fakes.DB_IMAGE_ARI_1, fakes.DB_IMAGE_AKI_1]))
|
||||
self.nova_servers.get.side_effect = (
|
||||
fakes.get_by_1st_arg_getter({
|
||||
fakes.ID_OS_INSTANCE_1: fakes.OS_INSTANCE_1,
|
||||
|
|
|
@ -61,9 +61,9 @@ class IgwTestCase(base.ApiTestCase):
|
|||
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY, 'igw',
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY,
|
||||
fakes.ID_EC2_IGW_2)
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY, 'vpc',
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY,
|
||||
fakes.ID_EC2_VPC_2)
|
||||
self.db_api.get_items.assert_called_once_with(mock.ANY, 'igw')
|
||||
self.db_api.update_item.assert_called_once_with(
|
||||
|
@ -150,9 +150,9 @@ class IgwTestCase(base.ApiTestCase):
|
|||
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY, 'igw',
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY,
|
||||
fakes.ID_EC2_IGW_1)
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY, 'vpc',
|
||||
self.db_api.get_item_by_id.assert_any_call(mock.ANY,
|
||||
fakes.ID_EC2_VPC_1)
|
||||
self.db_api.update_item.assert_called_once_with(
|
||||
mock.ANY, self.DB_IGW_1_DETACHED)
|
||||
|
@ -234,7 +234,7 @@ class IgwTestCase(base.ApiTestCase):
|
|||
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY, 'igw',
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY,
|
||||
fakes.ID_EC2_IGW_2)
|
||||
self.db_api.delete_item.assert_called_once_with(mock.ANY,
|
||||
fakes.ID_EC2_IGW_2)
|
||||
|
|
|
@ -217,7 +217,7 @@ class NetworkInterfaceTestCase(base.ApiTestCase):
|
|||
'CreateNetworkInterface',
|
||||
{'SubnetId': fakes.ID_EC2_SUBNET_2})
|
||||
self.db_api.get_item_by_id.assert_called_once_with(
|
||||
mock.ANY, 'subnet', fakes.ID_EC2_SUBNET_2)
|
||||
mock.ANY, fakes.ID_EC2_SUBNET_2)
|
||||
check_response(resp, 'InvalidSubnetID.NotFound')
|
||||
|
||||
self.db_api.get_item_by_id.return_value = fakes.DB_SUBNET_1
|
||||
|
|
|
@ -46,7 +46,7 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
'routes': [{'destination_cidr_block': fakes.CIDR_VPC_1,
|
||||
'gateway_id': None}]})
|
||||
self.db_api.get_item_by_id.assert_called_once_with(
|
||||
mock.ANY, 'vpc', fakes.ID_EC2_VPC_1)
|
||||
mock.ANY, fakes.ID_EC2_VPC_1)
|
||||
|
||||
def test_route_table_create_invalid_parameters(self):
|
||||
self.db_api.get_item_by_id.return_value = None
|
||||
|
@ -705,15 +705,14 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
('association.route-table-id', fakes.ID_EC2_ROUTE_TABLE_1),
|
||||
('association.subnet-id', fakes.ID_EC2_SUBNET_2),
|
||||
# TODO(ft): support filtering by a boolean value
|
||||
# ('association.main', True),
|
||||
# ('association.main', True),
|
||||
('route-table-id', fakes.ID_EC2_ROUTE_TABLE_1),
|
||||
('route.destination-cidr-block', fakes.CIDR_EXTERNAL_NETWORK),
|
||||
('route.gateway-id', 'local'),
|
||||
('route.instance-id', fakes.ID_EC2_INSTANCE_1),
|
||||
('route.origin', 'CreateRouteTable'),
|
||||
('route.state', 'active'),
|
||||
('vpc-id', fakes.ID_EC2_VPC_1)
|
||||
])
|
||||
('vpc-id', fakes.ID_EC2_VPC_1)])
|
||||
self.check_tag_support(
|
||||
'DescribeRouteTables', 'routeTableSet',
|
||||
fakes.ID_EC2_ROUTE_TABLE_1, 'routeTableId')
|
||||
|
@ -795,7 +794,7 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
'main': False}]
|
||||
self.assertThat(resp['routeTableSet'],
|
||||
matchers.ListMatches([ec2_route_table_1,
|
||||
ec2_route_table_2]))
|
||||
ec2_route_table_2]))
|
||||
|
||||
def test_get_subnet_host_routes(self):
|
||||
self.db_api.get_item_by_id.side_effect = (
|
||||
|
@ -894,8 +893,7 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
{'fake': 'table'})
|
||||
|
||||
self.db_api.get_item_by_id.assert_called_once_with(
|
||||
mock.ANY, 'vpc',
|
||||
fakes.ID_EC2_VPC_1)
|
||||
mock.ANY, fakes.ID_EC2_VPC_1)
|
||||
routes_updater.assert_called_once_with(
|
||||
mock.ANY, subnet_rtb_2, fakes.DB_ROUTE_TABLE_2,
|
||||
cleaner='fake_cleaner',
|
||||
|
|
|
@ -74,7 +74,7 @@ class SecurityGroupTestCase(base.ApiTestCase):
|
|||
{'VpcId': fakes.ID_EC2_VPC_1,
|
||||
'GroupName': 'groupname',
|
||||
'GroupDescription': 'Group description'})
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY, 'vpc',
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY,
|
||||
fakes.ID_EC2_VPC_1)
|
||||
check_response(resp, 'InvalidVpcID.NotFound')
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class SubnetTestCase(base.ApiTestCase):
|
|||
self.db_api.get_item_by_id.return_value = None
|
||||
resp = self.execute('CreateSubnet', {'VpcId': fakes.ID_EC2_VPC_1,
|
||||
'CidrBlock': fakes.CIDR_SUBNET_1})
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY, 'vpc',
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY,
|
||||
fakes.ID_EC2_VPC_1)
|
||||
check_response(resp, 'InvalidVpcID.NotFound')
|
||||
|
||||
|
@ -101,7 +101,7 @@ class SubnetTestCase(base.ApiTestCase):
|
|||
|
||||
resp = self.execute('CreateSubnet', {'VpcId': fakes.ID_EC2_VPC_1,
|
||||
'CidrBlock': '10.20.0.0/24'})
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY, 'vpc',
|
||||
self.db_api.get_item_by_id.assert_called_once_with(mock.ANY,
|
||||
fakes.ID_EC2_VPC_1)
|
||||
check_response(resp, 'InvalidSubnet.Range')
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class VolumeTestCase(base.ApiTestCase):
|
|||
('create-time', fakes.TIME_CREATE_VOLUME_2),
|
||||
# TODO(ft): support filtering by a number value
|
||||
# NOTE(ft): declare a constant for the volume size in fakes
|
||||
# ('size', 1),
|
||||
# ('size', 1),
|
||||
('snapshot-id', fakes.ID_EC2_SNAPSHOT_1),
|
||||
('status', 'available'),
|
||||
('volume-id', fakes.ID_EC2_VOLUME_1)])
|
||||
|
|
|
@ -244,7 +244,7 @@ class VpcTestCase(base.ApiTestCase):
|
|||
[('cidr', fakes.CIDR_VPC_1),
|
||||
('dhcp-options-id', 'default'),
|
||||
# TODO(ft): support filtering by a boolean value
|
||||
# ('is-default', False),
|
||||
# ('is-default', False),
|
||||
('state', 'available'),
|
||||
('vpc-id', fakes.ID_EC2_VPC_1)])
|
||||
self.check_tag_support(
|
||||
|
|
Loading…
Reference in New Issue