Switch nova.api.* to use instance dot notation
nova.compute.manager should use instance objects with the field access dot notation everywhere. Essentially we use instance.key instead of instance['key']. Also switch on want_objects=True in calls to compute_api.get(). Change-Id: Idfdaeb60ecbcc0d8ae082ed471c58868f3d621a8
This commit is contained in:
parent
30557e2fea
commit
44280a2d53
|
@ -958,18 +958,18 @@ class CloudController(object):
|
|||
def _format_attr_block_device_mapping(instance, result):
|
||||
tmp = {}
|
||||
self._format_instance_root_device_name(instance, tmp)
|
||||
self._format_instance_bdm(context, instance['uuid'],
|
||||
self._format_instance_bdm(context, instance.uuid,
|
||||
tmp['rootDeviceName'], result)
|
||||
|
||||
def _format_attr_disable_api_termination(instance, result):
|
||||
result['disableApiTermination'] = instance['disable_terminate']
|
||||
result['disableApiTermination'] = instance.disable_terminate
|
||||
|
||||
def _format_attr_group_set(instance, result):
|
||||
CloudController._format_group_set(instance, result)
|
||||
|
||||
def _format_attr_instance_initiated_shutdown_behavior(instance,
|
||||
result):
|
||||
if instance['shutdown_terminate']:
|
||||
if instance.shutdown_terminate:
|
||||
result['instanceInitiatedShutdownBehavior'] = 'terminate'
|
||||
else:
|
||||
result['instanceInitiatedShutdownBehavior'] = 'stop'
|
||||
|
@ -990,7 +990,7 @@ class CloudController(object):
|
|||
_unsupported_attribute(instance, result)
|
||||
|
||||
def _format_attr_user_data(instance, result):
|
||||
result['userData'] = base64.b64decode(instance['user_data'])
|
||||
result['userData'] = base64.b64decode(instance.user_data)
|
||||
|
||||
attribute_formatter = {
|
||||
'blockDeviceMapping': _format_attr_block_device_mapping,
|
||||
|
@ -1057,9 +1057,10 @@ class CloudController(object):
|
|||
previous_state['shutdown_terminate'])
|
||||
try:
|
||||
instance_uuid = ec2utils.ec2_inst_id_to_uuid(context, ec2_id)
|
||||
instance = self.compute_api.get(context, instance_uuid)
|
||||
i['currentState'] = _state_description(instance['vm_state'],
|
||||
instance['shutdown_terminate'])
|
||||
instance = self.compute_api.get(context, instance_uuid,
|
||||
want_objects=True)
|
||||
i['currentState'] = _state_description(instance.vm_state,
|
||||
instance.shutdown_terminate)
|
||||
except exception.NotFound:
|
||||
i['currentState'] = _state_description(
|
||||
inst_state.SHUTTING_DOWN, True)
|
||||
|
@ -1143,7 +1144,7 @@ class CloudController(object):
|
|||
def _format_group_set(instance, result):
|
||||
security_group_names = []
|
||||
if instance.get('security_groups'):
|
||||
for security_group in instance['security_groups']:
|
||||
for security_group in instance.security_groups:
|
||||
security_group_names.append(security_group['name'])
|
||||
result['groupSet'] = utils.convert_to_list_dict(
|
||||
security_group_names, 'groupId')
|
||||
|
@ -1188,18 +1189,18 @@ class CloudController(object):
|
|||
|
||||
for instance in instances:
|
||||
if not context.is_admin:
|
||||
if pipelib.is_vpn_image(instance['image_ref']):
|
||||
if pipelib.is_vpn_image(instance.image_ref):
|
||||
continue
|
||||
i = {}
|
||||
instance_uuid = instance['uuid']
|
||||
instance_uuid = instance.uuid
|
||||
ec2_id = ec2utils.id_to_ec2_inst_id(instance_uuid)
|
||||
i['instanceId'] = ec2_id
|
||||
image_uuid = instance['image_ref']
|
||||
image_uuid = instance.image_ref
|
||||
i['imageId'] = ec2utils.glance_id_to_ec2_id(context, image_uuid)
|
||||
self._format_kernel_id(context, instance, i, 'kernelId')
|
||||
self._format_ramdisk_id(context, instance, i, 'ramdiskId')
|
||||
i['instanceState'] = _state_description(
|
||||
instance['vm_state'], instance['shutdown_terminate'])
|
||||
instance.vm_state, instance.shutdown_terminate)
|
||||
|
||||
fixed_ip = None
|
||||
floating_ip = None
|
||||
|
@ -1213,12 +1214,12 @@ class CloudController(object):
|
|||
if CONF.ec2_private_dns_show_ip:
|
||||
i['privateDnsName'] = fixed_ip
|
||||
else:
|
||||
i['privateDnsName'] = instance['hostname']
|
||||
i['privateDnsName'] = instance.hostname
|
||||
i['privateIpAddress'] = fixed_ip
|
||||
if floating_ip is not None:
|
||||
i['ipAddress'] = floating_ip
|
||||
i['dnsName'] = floating_ip
|
||||
i['keyName'] = instance['key_name']
|
||||
i['keyName'] = instance.key_name
|
||||
i['tagSet'] = []
|
||||
|
||||
for k, v in utils.instance_meta(instance).iteritems():
|
||||
|
@ -1230,27 +1231,27 @@ class CloudController(object):
|
|||
|
||||
if context.is_admin:
|
||||
i['keyName'] = '%s (%s, %s)' % (i['keyName'],
|
||||
instance['project_id'],
|
||||
instance['host'])
|
||||
instance.project_id,
|
||||
instance.host)
|
||||
i['productCodesSet'] = utils.convert_to_list_dict([],
|
||||
'product_codes')
|
||||
self._format_instance_type(instance, i)
|
||||
i['launchTime'] = instance['created_at']
|
||||
i['amiLaunchIndex'] = instance['launch_index']
|
||||
i['launchTime'] = instance.created_at
|
||||
i['amiLaunchIndex'] = instance.launch_index
|
||||
self._format_instance_root_device_name(instance, i)
|
||||
self._format_instance_bdm(context, instance['uuid'],
|
||||
self._format_instance_bdm(context, instance.uuid,
|
||||
i['rootDeviceName'], i)
|
||||
zone = availability_zones.get_instance_availability_zone(context,
|
||||
instance)
|
||||
i['placement'] = {'availabilityZone': zone}
|
||||
if instance['reservation_id'] not in reservations:
|
||||
if instance.reservation_id not in reservations:
|
||||
r = {}
|
||||
r['reservationId'] = instance['reservation_id']
|
||||
r['ownerId'] = instance['project_id']
|
||||
r['reservationId'] = instance.reservation_id
|
||||
r['ownerId'] = instance.project_id
|
||||
self._format_group_set(instance, r)
|
||||
r['instancesSet'] = []
|
||||
reservations[instance['reservation_id']] = r
|
||||
reservations[instance['reservation_id']]['instancesSet'].append(i)
|
||||
reservations[instance.reservation_id] = r
|
||||
reservations[instance.reservation_id]['instancesSet'].append(i)
|
||||
|
||||
return list(reservations.values())
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ def get_ip_info_for_instance(context, instance):
|
|||
nw_info = instance.info_cache.network_info
|
||||
else:
|
||||
# FIXME(comstud): Temporary as we transition to objects.
|
||||
info_cache = instance['info_cache'] or {}
|
||||
info_cache = instance.info_cache or {}
|
||||
nw_info = info_cache.get('network_info')
|
||||
# Make sure empty response is turned into the model
|
||||
if not nw_info:
|
||||
|
|
|
@ -226,12 +226,12 @@ class InstanceMetadata(object):
|
|||
|
||||
meta_data = {
|
||||
'ami-id': self.ec2_ids['ami-id'],
|
||||
'ami-launch-index': self.instance['launch_index'],
|
||||
'ami-launch-index': self.instance.launch_index,
|
||||
'ami-manifest-path': 'FIXME',
|
||||
'instance-id': self.ec2_ids['instance-id'],
|
||||
'hostname': hostname,
|
||||
'local-ipv4': fixed_ip or self.address,
|
||||
'reservation-id': self.instance['reservation_id'],
|
||||
'reservation-id': self.instance.reservation_id,
|
||||
'security-groups': fmt_sgroups}
|
||||
|
||||
# public keys are strangely rendered in ec2 metadata service
|
||||
|
@ -243,10 +243,10 @@ class InstanceMetadata(object):
|
|||
# meta-data/public-keys/ : '0=%s' % keyname
|
||||
# meta-data/public-keys/0/ : 'openssh-key'
|
||||
# meta-data/public-keys/0/openssh-key : '%s' % publickey
|
||||
if self.instance['key_name']:
|
||||
if self.instance.key_name:
|
||||
meta_data['public-keys'] = {
|
||||
'0': {'_name': "0=" + self.instance['key_name'],
|
||||
'openssh-key': self.instance['key_data']}}
|
||||
'0': {'_name': "0=" + self.instance.key_name,
|
||||
'openssh-key': self.instance.key_data}}
|
||||
|
||||
if self._check_version('2007-01-19', version):
|
||||
meta_data['local-hostname'] = hostname
|
||||
|
@ -305,13 +305,13 @@ class InstanceMetadata(object):
|
|||
metadata.update(self.extra_md)
|
||||
if self.network_config:
|
||||
metadata['network_config'] = self.network_config
|
||||
if self.instance['key_name']:
|
||||
if self.instance.key_name:
|
||||
metadata['public_keys'] = {
|
||||
self.instance['key_name']: self.instance['key_data']
|
||||
self.instance.key_name: self.instance.key_data
|
||||
}
|
||||
metadata['hostname'] = self._get_hostname()
|
||||
metadata['name'] = self.instance['display_name']
|
||||
metadata['launch_index'] = self.instance['launch_index']
|
||||
metadata['name'] = self.instance.display_name
|
||||
metadata['launch_index'] = self.instance.launch_index
|
||||
metadata['availability_zone'] = self.availability_zone
|
||||
|
||||
if self._check_os_version(GRIZZLY, version):
|
||||
|
@ -362,7 +362,7 @@ class InstanceMetadata(object):
|
|||
return self._check_version(required, requested, OPENSTACK_VERSIONS)
|
||||
|
||||
def _get_hostname(self):
|
||||
return "%s%s%s" % (self.instance['hostname'],
|
||||
return "%s%s%s" % (self.instance.hostname,
|
||||
'.' if CONF.dhcp_domain else '',
|
||||
CONF.dhcp_domain)
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ class MetadataRequestHandler(wsgi.Application):
|
|||
if meta_data is None:
|
||||
LOG.error(_LE('Failed to get metadata for instance id: %s'),
|
||||
instance_id)
|
||||
elif meta_data.instance['project_id'] != tenant_id:
|
||||
elif meta_data.instance.project_id != tenant_id:
|
||||
LOG.warning(_LW("Tenant_id %(tenant_id)s does not match tenant_id "
|
||||
"of instance %(instance_id)s."),
|
||||
{'tenant_id': tenant_id, 'instance_id': instance_id})
|
||||
|
|
|
@ -54,10 +54,11 @@ class CloudpipeController(object):
|
|||
def _get_all_cloudpipes(self, context):
|
||||
"""Get all cloudpipes."""
|
||||
instances = self.compute_api.get_all(context,
|
||||
search_opts={'deleted': False})
|
||||
search_opts={'deleted': False},
|
||||
want_objects=True)
|
||||
return [instance for instance in instances
|
||||
if pipelib.is_vpn_image(instance['image_ref'])
|
||||
and instance['vm_state'] != vm_states.DELETED]
|
||||
if pipelib.is_vpn_image(instance.image_ref)
|
||||
and instance.vm_state != vm_states.DELETED]
|
||||
|
||||
def _get_cloudpipe_for_project(self, context):
|
||||
"""Get the cloudpipe instance for a project from context."""
|
||||
|
@ -70,8 +71,8 @@ class CloudpipeController(object):
|
|||
if not instance:
|
||||
rv['state'] = 'pending'
|
||||
return rv
|
||||
rv['instance_id'] = instance['uuid']
|
||||
rv['created_at'] = timeutils.isotime(instance['created_at'])
|
||||
rv['instance_id'] = instance.uuid
|
||||
rv['created_at'] = timeutils.isotime(instance.created_at)
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
if not nw_info:
|
||||
return rv
|
||||
|
@ -126,7 +127,7 @@ class CloudpipeController(object):
|
|||
msg = _("Unable to claim IP for VPN instances, ensure it "
|
||||
"isn't running, and try again in a few minutes")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
return {'instance_id': instance['uuid']}
|
||||
return {'instance_id': instance.uuid}
|
||||
|
||||
def index(self, req):
|
||||
"""List running cloudpipe instances."""
|
||||
|
|
|
@ -31,7 +31,7 @@ class ExtendedAZController(wsgi.Controller):
|
|||
# Likely hasn't reached a viable compute node yet so give back the
|
||||
# desired availability_zone that *may* exist in the instance
|
||||
# record itself.
|
||||
az = instance['availability_zone']
|
||||
az = instance.availability_zone
|
||||
server[key] = az
|
||||
|
||||
@wsgi.extends
|
||||
|
|
|
@ -24,7 +24,7 @@ authorize = extensions.soft_extension_authorizer('compute',
|
|||
class ExtendedServerAttributesController(wsgi.Controller):
|
||||
def _extend_server(self, context, server, instance):
|
||||
key = "%s:hypervisor_hostname" % Extended_server_attributes.alias
|
||||
server[key] = instance['node']
|
||||
server[key] = instance.node
|
||||
|
||||
for attr in ['host', 'name']:
|
||||
if attr == 'name':
|
||||
|
|
|
@ -29,7 +29,7 @@ class ExtendedVolumesController(wsgi.Controller):
|
|||
|
||||
def _extend_server(self, context, server, instance):
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
volume_ids = [bdm.volume_id for bdm in bdms if bdm.volume_id]
|
||||
key = "%s:volumes_attached" % Extended_volumes.alias
|
||||
server[key] = [{'id': volume_id} for volume_id in volume_ids]
|
||||
|
|
|
@ -263,8 +263,8 @@ class FloatingIPActionController(wsgi.Controller):
|
|||
if (instance and
|
||||
floating_ip.get('fixed_ip_id') and
|
||||
(uuidutils.is_uuid_like(id) and
|
||||
[instance['uuid'] == id] or
|
||||
[instance['id'] == id])[0]):
|
||||
[instance.uuid == id] or
|
||||
[instance.id == id])[0]):
|
||||
try:
|
||||
disassociate_floating_ip(self, context, instance, address)
|
||||
except exception.FloatingIpNotAssociated:
|
||||
|
|
|
@ -324,9 +324,10 @@ class ServerSecurityGroupController(SecurityGroupControllerBase):
|
|||
self.security_group_api.ensure_default(context)
|
||||
|
||||
with translate_exceptions():
|
||||
instance = self.compute_api.get(context, server_id)
|
||||
instance = self.compute_api.get(context, server_id,
|
||||
want_objects=True)
|
||||
groups = self.security_group_api.get_instance_security_groups(
|
||||
context, instance['uuid'], True)
|
||||
context, instance.uuid, True)
|
||||
|
||||
result = [self._format_security_group(context, group)
|
||||
for group in groups]
|
||||
|
|
|
@ -243,9 +243,10 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
authorize_attach(context, action='show')
|
||||
|
||||
volume_id = id
|
||||
instance = common.get_instance(self.compute_api, context, server_id)
|
||||
instance = common.get_instance(self.compute_api, context, server_id,
|
||||
want_objects=True)
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
|
||||
if not bdms:
|
||||
msg = _("Instance %s is not attached.") % server_id
|
||||
|
@ -264,7 +265,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
|
||||
return {'volumeAttachment': _translate_attachment_detail_view(
|
||||
volume_id,
|
||||
instance['uuid'],
|
||||
instance.uuid,
|
||||
assigned_mountpoint)}
|
||||
|
||||
def _validate_volume_id(self, volume_id):
|
||||
|
@ -398,7 +399,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
volume = self.volume_api.get(context, volume_id)
|
||||
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
if not bdms:
|
||||
msg = _("Instance %s is not attached.") % server_id
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
@ -436,10 +437,11 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
context = req.environ['nova.context']
|
||||
authorize(context)
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, server_id)
|
||||
instance = common.get_instance(self.compute_api, context, server_id,
|
||||
want_objects=True)
|
||||
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
limited_list = common.limited(bdms, req)
|
||||
results = []
|
||||
|
||||
|
|
|
@ -59,10 +59,11 @@ class CloudpipeController(wsgi.Controller):
|
|||
def _get_all_cloudpipes(self, context):
|
||||
"""Get all cloudpipes."""
|
||||
instances = self.compute_api.get_all(context,
|
||||
search_opts={'deleted': False})
|
||||
search_opts={'deleted': False},
|
||||
want_objects=True)
|
||||
return [instance for instance in instances
|
||||
if pipelib.is_vpn_image(instance['image_ref'])
|
||||
and instance['vm_state'] != vm_states.DELETED]
|
||||
if pipelib.is_vpn_image(instance.image_ref)
|
||||
and instance.vm_state != vm_states.DELETED]
|
||||
|
||||
def _get_cloudpipe_for_project(self, context):
|
||||
"""Get the cloudpipe instance for a project from context."""
|
||||
|
@ -75,8 +76,8 @@ class CloudpipeController(wsgi.Controller):
|
|||
if not instance:
|
||||
rv['state'] = 'pending'
|
||||
return rv
|
||||
rv['instance_id'] = instance['uuid']
|
||||
rv['created_at'] = timeutils.isotime(instance['created_at'])
|
||||
rv['instance_id'] = instance.uuid
|
||||
rv['created_at'] = timeutils.isotime(instance.created_at)
|
||||
nw_info = compute_utils.get_nw_info_for_instance(instance)
|
||||
if not nw_info:
|
||||
return rv
|
||||
|
@ -133,7 +134,7 @@ class CloudpipeController(wsgi.Controller):
|
|||
msg = _("Unable to claim IP for VPN instances, ensure it "
|
||||
"isn't running, and try again in a few minutes")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
return {'instance_id': instance['uuid']}
|
||||
return {'instance_id': instance.uuid}
|
||||
|
||||
@extensions.expected_errors((400, 403, 404))
|
||||
def index(self, req):
|
||||
|
|
|
@ -33,7 +33,7 @@ class ExtendedAZController(wsgi.Controller):
|
|||
# Likely hasn't reached a viable compute node yet so give back the
|
||||
# desired availability_zone that *may* exist in the instance
|
||||
# record itself.
|
||||
az = instance['availability_zone']
|
||||
az = instance.availability_zone
|
||||
server[key] = az
|
||||
|
||||
@wsgi.extends
|
||||
|
|
|
@ -25,7 +25,7 @@ authorize = extensions.soft_extension_authorizer('compute', 'v3:' + ALIAS)
|
|||
class ExtendedServerAttributesController(wsgi.Controller):
|
||||
def _extend_server(self, context, server, instance):
|
||||
key = "OS-EXT-SRV-ATTR:hypervisor_hostname"
|
||||
server[key] = instance['node']
|
||||
server[key] = instance.node
|
||||
|
||||
for attr in ['host', 'name']:
|
||||
if attr == 'name':
|
||||
|
|
|
@ -44,7 +44,7 @@ class ExtendedVolumesController(wsgi.Controller):
|
|||
|
||||
def _extend_server(self, context, server, instance):
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
volume_ids = [bdm['volume_id'] for bdm in bdms if bdm['volume_id']]
|
||||
key = "%s:volumes_attached" % ExtendedVolumes.alias
|
||||
server[key] = [{'id': volume_id} for volume_id in volume_ids]
|
||||
|
|
|
@ -270,8 +270,8 @@ class FloatingIPActionController(wsgi.Controller):
|
|||
if (instance and
|
||||
floating_ip.get('fixed_ip_id') and
|
||||
(uuidutils.is_uuid_like(id) and
|
||||
[instance['uuid'] == id] or
|
||||
[instance['id'] == id])[0]):
|
||||
[instance.uuid == id] or
|
||||
[instance.id == id])[0]):
|
||||
try:
|
||||
disassociate_floating_ip(self, context, instance, address)
|
||||
except exception.FloatingIpNotAssociated:
|
||||
|
|
|
@ -335,9 +335,10 @@ class ServerSecurityGroupController(SecurityGroupControllerBase):
|
|||
self.security_group_api.ensure_default(context)
|
||||
|
||||
try:
|
||||
instance = self.compute_api.get(context, server_id)
|
||||
instance = self.compute_api.get(context, server_id,
|
||||
want_objects=True)
|
||||
groups = self.security_group_api.get_instance_security_groups(
|
||||
context, instance['uuid'], True)
|
||||
context, instance.uuid, True)
|
||||
except (exception.SecurityGroupNotFound,
|
||||
exception.InstanceNotFound) as exp:
|
||||
msg = exp.format_message()
|
||||
|
|
|
@ -989,7 +989,7 @@ class ServersController(wsgi.Controller):
|
|||
try:
|
||||
if self.compute_api.is_volume_backed_instance(context, instance,
|
||||
bdms):
|
||||
img = instance['image_ref']
|
||||
img = instance.image_ref
|
||||
if not img:
|
||||
properties = bdms.root_metadata(
|
||||
context, self.compute_api.image_api,
|
||||
|
|
|
@ -241,7 +241,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
want_objects=True)
|
||||
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
|
||||
if not bdms:
|
||||
msg = _("Instance %s is not attached.") % server_id
|
||||
|
@ -260,7 +260,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
|
||||
return {'volumeAttachment': _translate_attachment_detail_view(
|
||||
volume_id,
|
||||
instance['uuid'],
|
||||
instance.uuid,
|
||||
assigned_mountpoint)}
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
|
@ -376,7 +376,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
if not bdms:
|
||||
msg = _("Instance %s is not attached.") % server_id
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
|
@ -419,7 +419,7 @@ class VolumeAttachmentController(wsgi.Controller):
|
|||
want_objects=True)
|
||||
|
||||
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
|
||||
context, instance['uuid'])
|
||||
context, instance.uuid)
|
||||
limited_list = common.limited(bdms, req)
|
||||
results = []
|
||||
|
||||
|
|
|
@ -1062,7 +1062,7 @@ class Controller(wsgi.Controller):
|
|||
try:
|
||||
if self.compute_api.is_volume_backed_instance(context, instance,
|
||||
bdms):
|
||||
img = instance['image_ref']
|
||||
img = instance.image_ref
|
||||
if not img:
|
||||
properties = bdms.root_metadata(
|
||||
context, self.compute_api.image_api,
|
||||
|
|
|
@ -23,6 +23,7 @@ from nova.api.openstack.compute.contrib import cloudpipe as cloudpipe_v2
|
|||
from nova.api.openstack.compute.plugins.v3 import cloudpipe as cloudpipe_v21
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit import fake_network
|
||||
|
@ -38,18 +39,17 @@ uuid = str(uuid_lib.uuid4())
|
|||
|
||||
|
||||
def fake_vpn_instance():
|
||||
return {
|
||||
'id': 7, 'image_ref': CONF.vpn_image_id, 'vm_state': 'active',
|
||||
'created_at': timeutils.parse_strtime('1981-10-20T00:00:00.000000'),
|
||||
'uuid': uuid, 'project_id': project_id,
|
||||
}
|
||||
return objects.Instance(
|
||||
id=7, image_ref=CONF.vpn_image_id, vm_state='active',
|
||||
created_at=timeutils.parse_strtime('1981-10-20T00:00:00.000000'),
|
||||
uuid=uuid, project_id=project_id)
|
||||
|
||||
|
||||
def compute_api_get_all_empty(context, search_opts=None):
|
||||
def compute_api_get_all_empty(context, search_opts=None, want_objects=True):
|
||||
return []
|
||||
|
||||
|
||||
def compute_api_get_all(context, search_opts=None):
|
||||
def compute_api_get_all(context, search_opts=None, want_objects=True):
|
||||
return [fake_vpn_instance()]
|
||||
|
||||
|
||||
|
|
|
@ -29,12 +29,15 @@ from nova import context
|
|||
from nova import db
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova import objects
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
from nova.tests.unit import fake_network
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
TEST_INST = 1
|
||||
WRONG_INST = 9999
|
||||
|
||||
|
||||
def network_api_get_floating_ip(self, context, id):
|
||||
|
@ -53,7 +56,8 @@ def network_api_get_floating_ips_by_project(self, context):
|
|||
'pool': 'nova',
|
||||
'fixed_ip': {'address': '10.0.0.1',
|
||||
'instance_uuid': FAKE_UUID,
|
||||
'instance': {'uuid': FAKE_UUID}}},
|
||||
'instance': objects.Instance(
|
||||
**{'uuid': FAKE_UUID})}},
|
||||
{'id': 2,
|
||||
'pool': 'nova', 'interface': 'eth0',
|
||||
'address': '10.10.10.11',
|
||||
|
@ -62,7 +66,8 @@ def network_api_get_floating_ips_by_project(self, context):
|
|||
|
||||
def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
want_objects=False):
|
||||
return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
|
||||
return objects.Instance(uuid=FAKE_UUID, id=instance_id,
|
||||
instance_type_id=1, host='bob')
|
||||
|
||||
|
||||
def network_api_allocate(self, context):
|
||||
|
@ -86,12 +91,12 @@ def network_api_disassociate(self, context, instance, floating_address):
|
|||
|
||||
|
||||
def fake_instance_get(context, instance_id):
|
||||
return {
|
||||
return objects.Instance(**{
|
||||
"id": 1,
|
||||
"uuid": uuid.uuid4(),
|
||||
"name": 'fake',
|
||||
"user_id": 'fakeuser',
|
||||
"project_id": '123'}
|
||||
"project_id": '123'})
|
||||
|
||||
|
||||
def stub_nw_info(stubs):
|
||||
|
@ -486,7 +491,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
fake_associate_floating_ip)
|
||||
body = dict(addFloatingIp=dict(address=self.floating_ip))
|
||||
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, 'test_inst',
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST,
|
||||
body=body)
|
||||
self.assertEqual(202, rsp.status_int)
|
||||
|
||||
|
@ -516,7 +521,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(addFloatingIp=dict(address=floating_ip))
|
||||
ex = self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.manager._add_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
self.assertIn("floating ip not found", ex.explanation)
|
||||
|
||||
|
@ -526,7 +531,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(addFloatingIp=dict(address='10.10.10.11'))
|
||||
self.assertRaises(webob.exc.HTTPForbidden,
|
||||
self.manager._add_floating_ip, self.fake_req,
|
||||
'test_inst', body=body)
|
||||
TEST_INST, body=body)
|
||||
|
||||
def test_associate_floating_ip_bad_address_key(self):
|
||||
body = dict(addFloatingIp=dict(bad_address='10.10.10.11'))
|
||||
|
@ -545,14 +550,14 @@ class FloatingIpTestV21(test.TestCase):
|
|||
def test_floating_ip_disassociate(self):
|
||||
def get_instance_by_floating_ip_addr(self, context, address):
|
||||
if address == '10.10.10.10':
|
||||
return 'test_inst'
|
||||
return TEST_INST
|
||||
|
||||
self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
|
||||
get_instance_by_floating_ip_addr)
|
||||
|
||||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||
|
||||
rsp = self.manager._remove_floating_ip(self.fake_req, 'test_inst',
|
||||
rsp = self.manager._remove_floating_ip(self.fake_req, TEST_INST,
|
||||
body=body)
|
||||
self.assertEqual(202, rsp.status_int)
|
||||
|
||||
|
@ -578,7 +583,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(addFloatingIp=dict(address='1.1.1.1'))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.manager._add_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
def test_floating_ip_disassociate_non_existent_ip(self):
|
||||
def network_api_get_floating_ip_by_address(self, context,
|
||||
|
@ -594,12 +599,12 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(removeFloatingIp=dict(address='1.1.1.1'))
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.manager._remove_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
def test_floating_ip_disassociate_wrong_instance_uuid(self):
|
||||
def get_instance_by_floating_ip_addr(self, context, address):
|
||||
if address == '10.10.10.10':
|
||||
return 'test_inst'
|
||||
return TEST_INST
|
||||
|
||||
self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
|
||||
get_instance_by_floating_ip_addr)
|
||||
|
@ -614,7 +619,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
def test_floating_ip_disassociate_wrong_instance_id(self):
|
||||
def get_instance_by_floating_ip_addr(self, context, address):
|
||||
if address == '10.10.10.10':
|
||||
return 'wrong_inst'
|
||||
return WRONG_INST
|
||||
|
||||
self.stubs.Set(network.api.API, "get_instance_id_by_floating_address",
|
||||
get_instance_by_floating_ip_addr)
|
||||
|
@ -623,7 +628,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
|
||||
self.assertRaises(webob.exc.HTTPConflict,
|
||||
self.manager._remove_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
def test_floating_ip_disassociate_auto_assigned(self):
|
||||
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
|
||||
|
@ -632,7 +637,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
|
||||
def get_instance_by_floating_ip_addr(self, context, address):
|
||||
if address == '10.10.10.10':
|
||||
return 'test_inst'
|
||||
return TEST_INST
|
||||
|
||||
def network_api_disassociate(self, context, instance,
|
||||
floating_address):
|
||||
|
@ -647,7 +652,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||
self.assertRaises(webob.exc.HTTPForbidden,
|
||||
self.manager._remove_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
def test_floating_ip_disassociate_map_authorization_exc(self):
|
||||
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
|
||||
|
@ -656,7 +661,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
|
||||
def get_instance_by_floating_ip_addr(self, context, address):
|
||||
if address == '10.10.10.10':
|
||||
return 'test_inst'
|
||||
return TEST_INST
|
||||
|
||||
def network_api_disassociate(self, context, instance, address):
|
||||
raise exception.Forbidden()
|
||||
|
@ -670,7 +675,7 @@ class FloatingIpTestV21(test.TestCase):
|
|||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||
self.assertRaises(webob.exc.HTTPForbidden,
|
||||
self.manager._remove_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
# these are a few bad param tests
|
||||
|
||||
|
@ -679,21 +684,21 @@ class FloatingIpTestV21(test.TestCase):
|
|||
|
||||
self.assertRaises(self.validation_error,
|
||||
self.manager._remove_floating_ip, self.fake_req,
|
||||
'test_inst', body=body)
|
||||
TEST_INST, body=body)
|
||||
|
||||
def test_missing_dict_param_in_remove_floating_ip(self):
|
||||
body = dict(removeFloatingIp='11.0.0.1')
|
||||
|
||||
self.assertRaises(self.validation_error,
|
||||
self.manager._remove_floating_ip, self.fake_req,
|
||||
'test_inst', body=body)
|
||||
TEST_INST, body=body)
|
||||
|
||||
def test_missing_dict_param_in_add_floating_ip(self):
|
||||
body = dict(addFloatingIp='11.0.0.1')
|
||||
|
||||
self.assertRaises(self.validation_error,
|
||||
self.manager._add_floating_ip, self.fake_req,
|
||||
'test_inst', body=body)
|
||||
TEST_INST, body=body)
|
||||
|
||||
|
||||
class FloatingIpTestV2(FloatingIpTestV21):
|
||||
|
@ -715,7 +720,7 @@ class FloatingIpTestV2(FloatingIpTestV21):
|
|||
body = dict(addFloatingIp=dict(address=self.floating_ip,
|
||||
fixed_address=fixed_address_requested))
|
||||
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, 'test_inst', body)
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST, body)
|
||||
self.assertEqual(202, rsp.status_int)
|
||||
|
||||
def test_floatingip_delete_invalid_id(self):
|
||||
|
@ -797,7 +802,7 @@ class ExtendedFloatingIpTestV21(test.TestCase):
|
|||
body = dict(addFloatingIp=dict(address=self.floating_ip,
|
||||
fixed_address=fixed_address))
|
||||
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, 'test_inst',
|
||||
rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST,
|
||||
body=body)
|
||||
self.assertEqual(202, rsp.status_int)
|
||||
|
||||
|
@ -812,7 +817,7 @@ class ExtendedFloatingIpTestV21(test.TestCase):
|
|||
|
||||
ex = self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.manager._add_floating_ip,
|
||||
self.fake_req, 'test_inst', body=body)
|
||||
self.fake_req, TEST_INST, body=body)
|
||||
|
||||
self.assertIn("Specified fixed address not assigned to instance",
|
||||
ex.explanation)
|
||||
|
|
Loading…
Reference in New Issue