Remove uses of instance['instance_type'] from nova/notifications
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: Iebbb0fa0bf306d6a7c8b83594e13a4b99f27c404
This commit is contained in:
committed by
Gerrit Code Review
parent
666ffe34ac
commit
bd5a9b87a7
@@ -21,6 +21,7 @@ the system.
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
from nova.compute import instance_types
|
||||||
import nova.context
|
import nova.context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova.image import glance
|
from nova.image import glance
|
||||||
@@ -283,7 +284,8 @@ def info_from_instance(context, instance_ref, network_info,
|
|||||||
|
|
||||||
image_ref_url = glance.generate_image_url(instance_ref['image_ref'])
|
image_ref_url = glance.generate_image_url(instance_ref['image_ref'])
|
||||||
|
|
||||||
instance_type_name = instance_ref.get('instance_type', {}).get('name', '')
|
instance_type = instance_types.extract_instance_type(instance_ref)
|
||||||
|
instance_type_name = instance_type.get('name', '')
|
||||||
|
|
||||||
if system_metadata is None:
|
if system_metadata is None:
|
||||||
system_metadata = utils.metadata_to_dict(
|
system_metadata = utils.metadata_to_dict(
|
||||||
|
|||||||
@@ -260,14 +260,16 @@ class UsageInfoTestCase(test.TestCase):
|
|||||||
|
|
||||||
def _create_instance(self, params={}):
|
def _create_instance(self, params={}):
|
||||||
"""Create a test instance."""
|
"""Create a test instance."""
|
||||||
|
instance_type = instance_types.get_instance_type_by_name('m1.tiny')
|
||||||
|
sys_meta = instance_types.save_instance_type_info({}, instance_type)
|
||||||
inst = {}
|
inst = {}
|
||||||
inst['image_ref'] = 1
|
inst['image_ref'] = 1
|
||||||
inst['reservation_id'] = 'r-fakeres'
|
inst['reservation_id'] = 'r-fakeres'
|
||||||
inst['launch_time'] = '10'
|
inst['launch_time'] = '10'
|
||||||
inst['user_id'] = self.user_id
|
inst['user_id'] = self.user_id
|
||||||
inst['project_id'] = self.project_id
|
inst['project_id'] = self.project_id
|
||||||
type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
|
inst['instance_type_id'] = instance_type['id']
|
||||||
inst['instance_type_id'] = type_id
|
inst['system_metadata'] = sys_meta
|
||||||
inst['ami_launch_index'] = 0
|
inst['ami_launch_index'] = 0
|
||||||
inst['root_gb'] = 0
|
inst['root_gb'] = 0
|
||||||
inst['ephemeral_gb'] = 0
|
inst['ephemeral_gb'] = 0
|
||||||
|
|||||||
@@ -71,18 +71,20 @@ class NotificationsTestCase(test.TestCase):
|
|||||||
self.instance = self._wrapped_create()
|
self.instance = self._wrapped_create()
|
||||||
|
|
||||||
def _wrapped_create(self, params=None):
|
def _wrapped_create(self, params=None):
|
||||||
|
instance_type = instance_types.get_instance_type_by_name('m1.tiny')
|
||||||
|
sys_meta = instance_types.save_instance_type_info({}, instance_type)
|
||||||
inst = {}
|
inst = {}
|
||||||
inst['image_ref'] = 1
|
inst['image_ref'] = 1
|
||||||
inst['user_id'] = self.user_id
|
inst['user_id'] = self.user_id
|
||||||
inst['project_id'] = self.project_id
|
inst['project_id'] = self.project_id
|
||||||
type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
|
inst['instance_type_id'] = instance_type['id']
|
||||||
inst['instance_type_id'] = type_id
|
|
||||||
inst['root_gb'] = 0
|
inst['root_gb'] = 0
|
||||||
inst['ephemeral_gb'] = 0
|
inst['ephemeral_gb'] = 0
|
||||||
inst['access_ip_v4'] = '1.2.3.4'
|
inst['access_ip_v4'] = '1.2.3.4'
|
||||||
inst['access_ip_v6'] = 'feed:5eed'
|
inst['access_ip_v6'] = 'feed:5eed'
|
||||||
inst['display_name'] = 'test_instance'
|
inst['display_name'] = 'test_instance'
|
||||||
inst['hostname'] = 'test_instance_hostname'
|
inst['hostname'] = 'test_instance_hostname'
|
||||||
|
inst['system_metadata'] = sys_meta
|
||||||
if params:
|
if params:
|
||||||
inst.update(params)
|
inst.update(params)
|
||||||
return db.instance_create(self.context, inst)
|
return db.instance_create(self.context, inst)
|
||||||
|
|||||||
Reference in New Issue
Block a user