docker: access system_metadata as a dict
This bit of code causes a problem when moving to objects. The Instance object presents system_metadata as you would normally expect (a dict). The data is in a different format when working with a db instance. Use the handy helper utility to normalize it into a dict. Change-Id: Ieca9ab449a07374ed2c9cdaffdfd54783df7a866
This commit is contained in:
parent
34960bbbcd
commit
431e23c9f0
|
@ -28,6 +28,7 @@ from nova import exception
|
|||
from nova.image import glance
|
||||
from nova.network import minidns
|
||||
from nova.network import model as network_model
|
||||
from nova.objects import instance as instance_obj
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('use_ipv6', 'nova.netconf')
|
||||
|
@ -71,7 +72,7 @@ def get_test_instance_type(context=None, options=None):
|
|||
return instance_type_ref
|
||||
|
||||
|
||||
def get_test_instance(context=None, instance_type=None):
|
||||
def get_test_instance(context=None, instance_type=None, obj=False):
|
||||
if not context:
|
||||
context = get_test_admin_context()
|
||||
|
||||
|
@ -93,8 +94,12 @@ def get_test_instance(context=None, instance_type=None):
|
|||
'system_metadata': metadata,
|
||||
'extra_specs': {}}
|
||||
|
||||
instance_ref = nova.db.instance_create(context, test_instance)
|
||||
return instance_ref
|
||||
if obj:
|
||||
instance = instance_obj.Instance(context, **test_instance)
|
||||
instance.create()
|
||||
else:
|
||||
instance = nova.db.instance_create(context, test_instance)
|
||||
return instance
|
||||
|
||||
|
||||
def get_test_network_info(count=1):
|
||||
|
|
|
@ -165,3 +165,13 @@ class DockerDriverTestCase(_VirtDriverTestCase, test.TestCase):
|
|||
instance_href = utils.get_test_instance()
|
||||
self.connection.destroy(self.context, instance_href,
|
||||
'fake_networkinfo')
|
||||
|
||||
def test_get_memory_limit_from_sys_meta_in_object(self):
|
||||
instance = utils.get_test_instance(obj=True)
|
||||
limit = self.connection._get_memory_limit_bytes(instance)
|
||||
self.assertEqual(2048 * unit.Mi, limit)
|
||||
|
||||
def test_get_memory_limit_from_sys_meta_in_db_instance(self):
|
||||
instance = utils.get_test_instance(obj=False)
|
||||
limit = self.connection._get_memory_limit_bytes(instance)
|
||||
self.assertEqual(2048 * unit.Mi, limit)
|
||||
|
|
|
@ -259,12 +259,8 @@ class DockerDriver(driver.ComputeDriver):
|
|||
undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
|
||||
|
||||
def _get_memory_limit_bytes(self, instance):
|
||||
for metadata in instance.get('system_metadata', []):
|
||||
if metadata['deleted']:
|
||||
continue
|
||||
if metadata['key'] == 'instance_type_memory_mb':
|
||||
return int(metadata['value']) * unit.Mi
|
||||
return 0
|
||||
system_meta = utils.instance_sys_meta(instance)
|
||||
return int(system_meta.get('instance_type_memory_mb', 0)) * unit.Mi
|
||||
|
||||
def _get_image_name(self, context, instance, image):
|
||||
fmt = image['container_format']
|
||||
|
|
Loading…
Reference in New Issue