Remove uses of instance['instance_type'] from nova/api
This removes a test that attempted to delete the data from the instance['instance_type'] structure and confirm that the flavor can still be fetched. Since this data is no longer consulted in that action (and will be removed altogether soon), this test is removed. This is one change in a series aimed at removing the use of instance-linked instance_type objects, in favor of the decoupled type data in system_metadata. See bug 1140119 for more details. Change-Id: I3ba56f9419aece5b9269a181264d09b117ecdb81
This commit is contained in:
@@ -1084,10 +1084,8 @@ class CloudController(object):
|
||||
|
||||
@staticmethod
|
||||
def _format_instance_type(instance, result):
|
||||
if instance['instance_type']:
|
||||
result['instanceType'] = instance['instance_type'].get('name')
|
||||
else:
|
||||
result['instanceType'] = None
|
||||
instance_type = instance_types.extract_instance_type(instance)
|
||||
result['instanceType'] = instance_type['name']
|
||||
|
||||
@staticmethod
|
||||
def _format_group_set(instance, result):
|
||||
|
||||
@@ -28,6 +28,7 @@ from oslo.config import cfg
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.api.metadata import password
|
||||
from nova import block_device
|
||||
from nova.compute import instance_types
|
||||
from nova import conductor
|
||||
from nova import context
|
||||
from nova import network
|
||||
@@ -210,7 +211,8 @@ class InstanceMetadata():
|
||||
meta_data['product-codes'] = []
|
||||
|
||||
if self._check_version('2007-08-29', version):
|
||||
meta_data['instance-type'] = self.instance['instance_type']['name']
|
||||
instance_type = instance_types.extract_instance_type(self.instance)
|
||||
meta_data['instance-type'] = instance_type['name']
|
||||
|
||||
if False and self._check_version('2007-10-10', version):
|
||||
# TODO(vish): store ancestor ids
|
||||
|
||||
@@ -22,6 +22,7 @@ from nova.api.openstack import common
|
||||
from nova.api.openstack.compute.views import addresses as views_addresses
|
||||
from nova.api.openstack.compute.views import flavors as views_flavors
|
||||
from nova.api.openstack.compute.views import images as views_images
|
||||
from nova.compute import instance_types
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import timeutils
|
||||
|
||||
@@ -180,7 +181,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
return ""
|
||||
|
||||
def _get_flavor(self, request, instance):
|
||||
instance_type = instance["instance_type"]
|
||||
instance_type = instance_types.extract_instance_type(instance)
|
||||
if not instance_type:
|
||||
LOG.warn(_("Instance has had its instance_type removed "
|
||||
"from the DB"), instance=instance)
|
||||
|
||||
@@ -26,6 +26,7 @@ from oslo.config import cfg
|
||||
from nova.api.ec2 import cloud
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova import context
|
||||
from nova import db
|
||||
@@ -383,14 +384,18 @@ class CinderCloudTestCase(test.TestCase):
|
||||
|
||||
def _setUpBlockDeviceMapping(self):
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
inst1 = db.instance_create(self.context,
|
||||
{'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'root_device_name': '/dev/sdb1'})
|
||||
'root_device_name': '/dev/sdb1',
|
||||
'system_metadata': sys_meta})
|
||||
inst2 = db.instance_create(self.context,
|
||||
{'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'root_device_name': '/dev/sdc1'})
|
||||
'root_device_name': '/dev/sdc1',
|
||||
'system_metadata': sys_meta})
|
||||
|
||||
instance_uuid = inst1['uuid']
|
||||
mappings0 = [
|
||||
|
||||
@@ -33,6 +33,7 @@ from nova.api.ec2 import ec2utils
|
||||
from nova.api.ec2 import inst_state
|
||||
from nova.api.metadata import password
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
@@ -759,18 +760,22 @@ class CloudTestCase(test.TestCase):
|
||||
self._stub_instance_get_with_fixed_ips('get')
|
||||
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host1',
|
||||
'hostname': 'server-1234',
|
||||
'vm_state': 'active'})
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta})
|
||||
inst2 = db.instance_create(self.context, {'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host2',
|
||||
'hostname': 'server-4321',
|
||||
'vm_state': 'active'})
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta})
|
||||
comp1 = db.service_create(self.context, {'host': 'host1',
|
||||
'topic': "compute"})
|
||||
agg = db.aggregate_create(self.context,
|
||||
@@ -849,11 +854,14 @@ class CloudTestCase(test.TestCase):
|
||||
self._stub_instance_get_with_fixed_ips('get')
|
||||
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
inst_base = {
|
||||
'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'vm_state': 'active'
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta,
|
||||
}
|
||||
|
||||
inst1_kwargs = {}
|
||||
@@ -901,9 +909,12 @@ class CloudTestCase(test.TestCase):
|
||||
def test_instance_state(expected_code, expected_name,
|
||||
power_state_, vm_state_, values=None):
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
values = values or {}
|
||||
values.update({'image_ref': image_uuid, 'instance_type_id': 1,
|
||||
'power_state': power_state_, 'vm_state': vm_state_})
|
||||
'power_state': power_state_, 'vm_state': vm_state_,
|
||||
'system_metadata': sys_meta})
|
||||
inst = db.instance_create(self.context, values)
|
||||
|
||||
instance_id = ec2utils.id_to_ec2_inst_id(inst['uuid'])
|
||||
@@ -933,11 +944,14 @@ class CloudTestCase(test.TestCase):
|
||||
self._stub_instance_get_with_fixed_ips('get')
|
||||
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'hostname': 'server-1234',
|
||||
'vm_state': 'active'})
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta})
|
||||
comp1 = db.service_create(self.context, {'host': 'host1',
|
||||
'topic': "compute"})
|
||||
result = self.cloud.describe_instances(self.context)
|
||||
@@ -957,17 +971,21 @@ class CloudTestCase(test.TestCase):
|
||||
|
||||
def test_describe_instances_deleted(self):
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
args1 = {'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host1',
|
||||
'vm_state': 'active'}
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta}
|
||||
inst1 = db.instance_create(self.context, args1)
|
||||
args2 = {'reservation_id': 'b',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host1',
|
||||
'vm_state': 'active'}
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta}
|
||||
inst2 = db.instance_create(self.context, args2)
|
||||
db.instance_destroy(self.context, inst1['uuid'])
|
||||
result = self.cloud.describe_instances(self.context)
|
||||
@@ -978,17 +996,21 @@ class CloudTestCase(test.TestCase):
|
||||
|
||||
def test_describe_instances_with_image_deleted(self):
|
||||
image_uuid = 'aebef54a-ed67-4d10-912f-14455edce176'
|
||||
sys_meta = instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_instance_type(1))
|
||||
args1 = {'reservation_id': 'a',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host1',
|
||||
'vm_state': 'active'}
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta}
|
||||
inst1 = db.instance_create(self.context, args1)
|
||||
args2 = {'reservation_id': 'b',
|
||||
'image_ref': image_uuid,
|
||||
'instance_type_id': 1,
|
||||
'host': 'host1',
|
||||
'vm_state': 'active'}
|
||||
'vm_state': 'active',
|
||||
'system_metadata': sys_meta}
|
||||
inst2 = db.instance_create(self.context, args2)
|
||||
result = self.cloud.describe_instances(self.context)
|
||||
self.assertEqual(len(result['reservationSet']), 2)
|
||||
@@ -2048,18 +2070,22 @@ class CloudTestCase(test.TestCase):
|
||||
self._fake_bdm_get)
|
||||
|
||||
def fake_get(ctxt, instance_id):
|
||||
inst_type = instance_types.get_default_instance_type()
|
||||
inst_type['name'] = 'fake_type'
|
||||
sys_meta = instance_types.save_instance_type_info({}, inst_type)
|
||||
sys_meta = utils.dict_to_metadata(sys_meta)
|
||||
return {
|
||||
'id': 0,
|
||||
'uuid': 'e5fe5518-0288-4fa3-b0c4-c79764101b85',
|
||||
'root_device_name': '/dev/sdh',
|
||||
'security_groups': [{'name': 'fake0'}, {'name': 'fake1'}],
|
||||
'vm_state': vm_states.STOPPED,
|
||||
'instance_type': {'name': 'fake_type'},
|
||||
'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175',
|
||||
'ramdisk_id': '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
|
||||
'user_data': 'fake-user data',
|
||||
'shutdown_terminate': False,
|
||||
'disable_terminate': False,
|
||||
'system_metadata': sys_meta,
|
||||
}
|
||||
self.stubs.Set(self.cloud.compute_api, 'get', fake_get)
|
||||
|
||||
|
||||
@@ -3952,11 +3952,6 @@ class ServersViewBuilderTest(test.TestCase):
|
||||
result = self.view_builder._get_flavor(self.request, self.instance)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_get_flavor_deleted_instance_type(self):
|
||||
self.instance['instance_type'] = {}
|
||||
result = self.view_builder._get_flavor(self.request, self.instance)
|
||||
self.assertEqual(result, {})
|
||||
|
||||
def test_build_server(self):
|
||||
self_link = "http://localhost/v2/fake/servers/%s" % self.uuid
|
||||
bookmark_link = "http://localhost/fake/servers/%s" % self.uuid
|
||||
|
||||
@@ -32,6 +32,7 @@ from nova.api.metadata import base
|
||||
from nova.api.metadata import handler
|
||||
from nova.api.metadata import password
|
||||
from nova import block_device
|
||||
from nova.compute import instance_types
|
||||
from nova.conductor import api as conductor_api
|
||||
from nova import db
|
||||
from nova.db.sqlalchemy import api
|
||||
@@ -39,6 +40,7 @@ from nova import exception
|
||||
from nova.network import api as network_api
|
||||
from nova import test
|
||||
from nova.tests import fake_network
|
||||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -68,6 +70,12 @@ INSTANCES = (
|
||||
)
|
||||
|
||||
|
||||
def get_default_sys_meta():
|
||||
return utils.dict_to_metadata(
|
||||
instance_types.save_instance_type_info(
|
||||
{}, instance_types.get_default_instance_type()))
|
||||
|
||||
|
||||
def return_non_existing_address(*args, **kwarg):
|
||||
raise exception.NotFound()
|
||||
|
||||
@@ -119,6 +127,7 @@ class MetadataTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(MetadataTestCase, self).setUp()
|
||||
self.instance = INSTANCES[0]
|
||||
self.instance['system_metadata'] = get_default_sys_meta()
|
||||
self.flags(use_local=True, group='conductor')
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
@@ -250,6 +259,7 @@ class OpenStackMetadataTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(OpenStackMetadataTestCase, self).setUp()
|
||||
self.instance = INSTANCES[0]
|
||||
self.instance['system_metadata'] = get_default_sys_meta()
|
||||
self.flags(use_local=True, group='conductor')
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
@@ -386,6 +396,7 @@ class MetadataHandlerTestCase(test.TestCase):
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
self.instance = INSTANCES[0]
|
||||
self.instance['system_metadata'] = get_default_sys_meta()
|
||||
self.flags(use_local=True, group='conductor')
|
||||
self.mdinst = fake_InstanceMetadata(self.stubs, self.instance,
|
||||
address=None, sgroups=None)
|
||||
@@ -552,6 +563,7 @@ class MetadataPasswordTestCase(test.TestCase):
|
||||
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
|
||||
spectacular=True)
|
||||
self.instance = copy.copy(INSTANCES[0])
|
||||
self.instance['system_metadata'] = get_default_sys_meta()
|
||||
self.flags(use_local=True, group='conductor')
|
||||
self.mdinst = fake_InstanceMetadata(self.stubs, self.instance,
|
||||
address=None, sgroups=None)
|
||||
|
||||
Reference in New Issue
Block a user