Remove deprecated 'default_flavor' config option
The deprecated 'default_flavor' option has been removed. The following methods in nova/compute/flavors.py have been removed because they are only used in unit tests. * get_default_flavor * get_flavor_by_name Change-Id: If1e461da382f707be2b5ba89f74f77269f0909dd
This commit is contained in:
parent
ce5ef763b5
commit
7cf16e317b
@ -125,23 +125,6 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
|
||||
return flavor
|
||||
|
||||
|
||||
def get_default_flavor():
|
||||
"""Get the default flavor."""
|
||||
name = CONF.default_flavor
|
||||
return get_flavor_by_name(name)
|
||||
|
||||
|
||||
def get_flavor_by_name(name, ctxt=None):
|
||||
"""Retrieves single flavor by name."""
|
||||
if name is None:
|
||||
return get_default_flavor()
|
||||
|
||||
if ctxt is None:
|
||||
ctxt = context.get_admin_context()
|
||||
|
||||
return objects.Flavor.get_by_name(ctxt, name)
|
||||
|
||||
|
||||
# TODO(termie): flavor-specific code should probably be in the API that uses
|
||||
# flavors.
|
||||
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
|
||||
|
@ -33,7 +33,6 @@ from nova.conf import consoleauth
|
||||
from nova.conf import database
|
||||
from nova.conf import devices
|
||||
from nova.conf import ephemeral_storage
|
||||
from nova.conf import flavors
|
||||
from nova.conf import glance
|
||||
from nova.conf import guestfs
|
||||
from nova.conf import hyperv
|
||||
@ -88,7 +87,6 @@ consoleauth.register_opts(CONF)
|
||||
database.register_opts(CONF)
|
||||
devices.register_opts(CONF)
|
||||
ephemeral_storage.register_opts(CONF)
|
||||
flavors.register_opts(CONF)
|
||||
glance.register_opts(CONF)
|
||||
guestfs.register_opts(CONF)
|
||||
hyperv.register_opts(CONF)
|
||||
|
@ -1,38 +0,0 @@
|
||||
# Copyright 2016 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
flavor_opts = [
|
||||
cfg.StrOpt(
|
||||
"default_flavor",
|
||||
default="m1.small",
|
||||
deprecated_for_removal=True,
|
||||
deprecated_since="14.0.0",
|
||||
deprecated_reason="The EC2 API is deprecated.",
|
||||
help="""
|
||||
Default flavor to use for the EC2 API only.
|
||||
The Nova API does not support a default flavor.
|
||||
"""),
|
||||
]
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_opts(flavor_opts)
|
||||
|
||||
|
||||
def list_opts():
|
||||
return {"DEFAULT": flavor_opts}
|
@ -21,9 +21,9 @@ import six
|
||||
|
||||
from nova.api.openstack import compute
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import flavors
|
||||
from nova import context as nova_context
|
||||
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_instance
|
||||
@ -83,7 +83,8 @@ class DiskConfigTestCaseV21(test.TestCase):
|
||||
'vm_state': '',
|
||||
'auto_disk_config': inst_['auto_disk_config'],
|
||||
'security_groups': inst_['security_groups'],
|
||||
'instance_type': flavors.get_default_flavor(),
|
||||
'instance_type': objects.Flavor.get_by_name(context,
|
||||
'm1.small'),
|
||||
})
|
||||
|
||||
return inst
|
||||
|
@ -487,7 +487,8 @@ def stub_instance(id=1, user_id=None, project_id=None, host=None,
|
||||
info_cache = create_info_cache(nw_cache)
|
||||
|
||||
if instance_type is None:
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = objects.Flavor.get_by_name(
|
||||
context.get_admin_context(), 'm1.small')
|
||||
flavorinfo = jsonutils.dumps({
|
||||
'cur': instance_type.obj_to_primitive(),
|
||||
'old': None,
|
||||
|
@ -288,7 +288,7 @@ class BaseTestCase(test.TestCase):
|
||||
def _create_fake_instance_obj(self, params=None, type_name='m1.tiny',
|
||||
services=False, ctxt=None):
|
||||
ctxt = ctxt or self.context
|
||||
flavor = flavors.get_flavor_by_name(type_name)
|
||||
flavor = objects.Flavor.get_by_name(ctxt, type_name)
|
||||
inst = objects.Instance(context=ctxt)
|
||||
inst.vm_state = vm_states.ACTIVE
|
||||
inst.task_state = None
|
||||
@ -1514,6 +1514,9 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.useFixture(fixtures.SynchronousThreadPoolExecutorFixture())
|
||||
|
||||
self.image_api = image_api.API()
|
||||
self.default_flavor = objects.Flavor.get_by_name(self.context,
|
||||
'm1.small')
|
||||
self.tiny_flavor = objects.Flavor.get_by_name(self.context, 'm1.tiny')
|
||||
|
||||
def test_wrap_instance_fault(self):
|
||||
inst = {"uuid": uuids.instance}
|
||||
@ -1703,8 +1706,6 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(768, cn.local_gb_used)
|
||||
|
||||
def test_create_multiple_instance_with_neutron_port(self):
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
def fake_is_neutron():
|
||||
return True
|
||||
self.stub_out('nova.utils.is_neutron', fake_is_neutron)
|
||||
@ -1713,7 +1714,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertRaises(exception.MultiplePortsNotApplicable,
|
||||
self.compute_api.create,
|
||||
self.context,
|
||||
instance_type=instance_type,
|
||||
instance_type=self.default_flavor,
|
||||
image_href=None,
|
||||
max_count=2,
|
||||
requested_networks=requested_networks)
|
||||
@ -2442,8 +2443,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance.uuid)
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
@ -2493,8 +2494,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance.uuid)
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
@ -3079,13 +3080,13 @@ class ComputeTestCase(BaseTestCase,
|
||||
power_state=10003,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
task_state=expected_task,
|
||||
instance_type=flavors.get_default_flavor(),
|
||||
instance_type=self.default_flavor,
|
||||
launched_at=timeutils.utcnow()))
|
||||
updated_dbinstance2 = fake_instance.fake_db_instance(
|
||||
**dict(uuid=uuids.db_instance_2,
|
||||
power_state=10003,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
instance_type=flavors.get_default_flavor(),
|
||||
instance_type=self.default_flavor,
|
||||
task_state=expected_task,
|
||||
launched_at=timeutils.utcnow()))
|
||||
|
||||
@ -4390,10 +4391,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.tiny_flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
self.assertEqual(payload['state'], 'active')
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
@ -4524,10 +4525,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.tiny_flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
@ -4837,10 +4838,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance = self._create_fake_instance_obj(params)
|
||||
image = {}
|
||||
disk_info = 'fake-disk-info'
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = self.default_flavor
|
||||
|
||||
if not resize_instance:
|
||||
old_instance_type = flavors.get_flavor_by_name('m1.tiny')
|
||||
old_instance_type = self.tiny_flavor
|
||||
instance_type['root_gb'] = old_instance_type['root_gb']
|
||||
instance_type['swap'] = old_instance_type['swap']
|
||||
instance_type['ephemeral_gb'] = old_instance_type['ephemeral_gb']
|
||||
@ -5082,7 +5083,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
jsonutils.dumps(connection_info))
|
||||
|
||||
# begin resize
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = self.default_flavor
|
||||
instance.task_state = task_states.RESIZE_PREP
|
||||
instance.save()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
@ -5173,7 +5174,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
old_flavor_name = 'm1.tiny'
|
||||
instance = self._create_fake_instance_obj(type_name=old_flavor_name)
|
||||
|
||||
instance_type = flavors.get_flavor_by_name('m1.small')
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type,
|
||||
@ -5196,7 +5197,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance.refresh()
|
||||
self.assertEqual(vm_states.ERROR, instance.vm_state)
|
||||
|
||||
old_flavor = flavors.get_flavor_by_name(old_flavor_name)
|
||||
old_flavor = objects.Flavor.get_by_name(self.context, old_flavor_name)
|
||||
self.assertEqual(old_flavor['memory_mb'], instance.memory_mb)
|
||||
self.assertEqual(old_flavor['vcpus'], instance.vcpus)
|
||||
self.assertEqual(old_flavor['root_gb'], instance.root_gb)
|
||||
@ -5208,7 +5209,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
old_flavor_name = 'm1.tiny'
|
||||
new_flavor_name = 'm1.small'
|
||||
instance = self._create_fake_instance_obj(type_name=old_flavor_name)
|
||||
new_flavor = flavors.get_flavor_by_name(new_flavor_name)
|
||||
new_flavor = objects.Flavor.get_by_name(self.context, new_flavor_name)
|
||||
|
||||
self.compute._set_instance_info(instance, new_flavor.obj_clone())
|
||||
|
||||
@ -5280,10 +5281,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], inst_ref['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.tiny_flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
@ -5297,7 +5298,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
cur_time = datetime.datetime(2012, 12, 21, 12, 21)
|
||||
time_fixture = self.useFixture(utils_fixture.TimeFixture(old_time))
|
||||
instance = self._create_fake_instance_obj()
|
||||
new_type = flavors.get_flavor_by_name('m1.small')
|
||||
new_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
new_type_id = new_type['id']
|
||||
flavor_id = new_type['flavorid']
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||
@ -5368,9 +5369,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
instance.task_state = task_states.RESIZE_PREP
|
||||
instance.save()
|
||||
|
||||
instance_type = flavors.get_default_flavor()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type, image={},
|
||||
instance_type=self.default_flavor, image={},
|
||||
request_spec={}, filter_properties={}, node=None,
|
||||
clean_shutdown=True, migration=None, host_list=[])
|
||||
db.migration_get_by_instance_and_status(self.context.elevated(),
|
||||
@ -5393,10 +5393,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance.uuid)
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.tiny_flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.tiny_flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
self.assertIn('display_name', payload)
|
||||
self.assertIn('created_at', payload)
|
||||
self.assertIn('launched_at', payload)
|
||||
@ -5406,9 +5406,9 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.compute.terminate_instance(self.context, instance, [])
|
||||
mock_notify.assert_has_calls([
|
||||
mock.call(self.context, instance, 'fake-mini', 'start',
|
||||
instance_type),
|
||||
self.default_flavor),
|
||||
mock.call(self.context, instance, 'fake-mini', 'end',
|
||||
instance_type)])
|
||||
self.default_flavor)])
|
||||
|
||||
def test_prep_resize_instance_migration_error_on_none_host(self):
|
||||
"""Ensure prep_resize raises a migration error if destination host is
|
||||
@ -5420,11 +5420,10 @@ class ComputeTestCase(BaseTestCase,
|
||||
block_device_mapping=[])
|
||||
instance.host = None
|
||||
instance.save()
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
self.assertRaises(exception.MigrationError, self.compute.prep_resize,
|
||||
self.context, instance=instance,
|
||||
instance_type=instance_type, image={},
|
||||
instance_type=self.default_flavor, image={},
|
||||
request_spec={},
|
||||
filter_properties={}, node=None,
|
||||
clean_shutdown=True, migration=mock.Mock(),
|
||||
@ -5441,14 +5440,13 @@ class ComputeTestCase(BaseTestCase,
|
||||
throw_up)
|
||||
|
||||
instance = self._create_fake_instance_obj()
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||
block_device_mapping=[])
|
||||
instance.host = 'foo'
|
||||
instance.save()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type, image={},
|
||||
instance_type=self.default_flavor, image={},
|
||||
request_spec={},
|
||||
filter_properties={}, node=None,
|
||||
clean_shutdown=True, migration=None,
|
||||
@ -5463,7 +5461,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertRaises(test.TestingException, self.compute.resize_instance,
|
||||
self.context, instance=instance,
|
||||
migration=migration, image={},
|
||||
instance_type=jsonutils.to_primitive(instance_type),
|
||||
instance_type=jsonutils.to_primitive(
|
||||
self.default_flavor),
|
||||
clean_shutdown=True)
|
||||
# NOTE(comstud): error path doesn't use objects, so our object
|
||||
# is not updated. Refresh and compare against the DB.
|
||||
@ -5481,13 +5480,12 @@ class ComputeTestCase(BaseTestCase,
|
||||
throw_up)
|
||||
|
||||
instance = self._create_fake_instance_obj()
|
||||
instance_type = flavors.get_default_flavor()
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||
block_device_mapping=[])
|
||||
instance.host = 'foo'
|
||||
instance.save()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type, image={},
|
||||
instance_type=self.default_flavor, image={},
|
||||
request_spec={},
|
||||
filter_properties={}, node=None,
|
||||
migration=None, host_list=[],
|
||||
@ -5502,7 +5500,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertRaises(test.TestingException, self.compute.resize_instance,
|
||||
self.context, instance=instance,
|
||||
migration=migration, image={},
|
||||
instance_type=jsonutils.to_primitive(instance_type),
|
||||
instance_type=jsonutils.to_primitive(
|
||||
self.default_flavor),
|
||||
clean_shutdown=True)
|
||||
# NOTE(comstud): error path doesn't use objects, so our object
|
||||
# is not updated. Refresh and compare against the DB.
|
||||
@ -5514,14 +5513,13 @@ class ComputeTestCase(BaseTestCase,
|
||||
def _test_resize_instance(self, clean_shutdown=True):
|
||||
# Ensure instance can be migrated/resized.
|
||||
instance = self._create_fake_instance_obj()
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||
block_device_mapping=[])
|
||||
instance.host = 'foo'
|
||||
instance.save()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type, image={},
|
||||
instance_type=self.default_flavor, image={},
|
||||
request_spec={}, filter_properties={}, node=None,
|
||||
clean_shutdown=True, migration=None, host_list=[])
|
||||
|
||||
@ -5558,7 +5556,7 @@ class ComputeTestCase(BaseTestCase,
|
||||
mock_check_is_bfv):
|
||||
self.compute.resize_instance(self.context, instance=instance,
|
||||
migration=migration, image={},
|
||||
instance_type=jsonutils.to_primitive(instance_type),
|
||||
instance_type=jsonutils.to_primitive(self.default_flavor),
|
||||
clean_shutdown=clean_shutdown)
|
||||
mock_notify_action.assert_has_calls([
|
||||
mock.call(self.context, instance, 'fake-mini',
|
||||
@ -6141,14 +6139,12 @@ class ComputeTestCase(BaseTestCase,
|
||||
|
||||
instance = self._create_fake_instance_obj()
|
||||
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
self.compute.build_and_run_instance(self.context, instance, {}, {}, {},
|
||||
block_device_mapping=[])
|
||||
instance.host = 'foo'
|
||||
instance.save()
|
||||
self.compute.prep_resize(self.context, instance=instance,
|
||||
instance_type=instance_type,
|
||||
instance_type=self.default_flavor,
|
||||
image={},
|
||||
request_spec={}, filter_properties={},
|
||||
node=None, clean_shutdown=True,
|
||||
@ -6161,7 +6157,8 @@ class ComputeTestCase(BaseTestCase,
|
||||
self.assertRaises(test.TestingException, self.compute.resize_instance,
|
||||
self.context, instance=instance,
|
||||
migration=migration, image={},
|
||||
instance_type=jsonutils.to_primitive(instance_type),
|
||||
instance_type=jsonutils.to_primitive(
|
||||
self.default_flavor),
|
||||
clean_shutdown=True)
|
||||
# NOTE(comstud): error path doesn't use objects, so our object
|
||||
# is not updated. Refresh and compare against the DB.
|
||||
@ -8632,6 +8629,10 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
fake_validate_networks)
|
||||
validate_nets_patch.start()
|
||||
self.addCleanup(validate_nets_patch.stop)
|
||||
self.default_flavor = objects.Flavor.get_by_name(self.context,
|
||||
'm1.small')
|
||||
self.tiny_flavor = objects.Flavor.get_by_name(self.context,
|
||||
'm1.tiny')
|
||||
|
||||
def _run_instance(self, params=None):
|
||||
instance = self._create_fake_instance_obj(params, services=True)
|
||||
@ -8646,7 +8647,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_too_little_ram(self):
|
||||
# Test an instance type with too little memory.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = self.default_flavor
|
||||
inst_type['memory_mb'] = 1
|
||||
|
||||
self.fake_image['min_ram'] = 2
|
||||
@ -8665,7 +8666,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_too_little_disk(self):
|
||||
# Test an instance type with too little disk space.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
|
||||
self.fake_image['min_disk'] = 2
|
||||
@ -8684,7 +8685,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_too_large_image(self):
|
||||
# Test an instance type with too little disk space.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
|
||||
self.fake_image['size'] = '1073741825'
|
||||
@ -8704,7 +8705,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_just_enough_ram_and_disk(self):
|
||||
# Test an instance type with just enough ram and disk space.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 2
|
||||
inst_type['memory_mb'] = 2
|
||||
|
||||
@ -8720,7 +8721,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_no_ram_and_disk_reqs(self):
|
||||
# Test an instance type with no min_ram or min_disk.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
inst_type['memory_mb'] = 1
|
||||
|
||||
@ -8733,8 +8734,6 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_deleted_image(self):
|
||||
# If we're given a deleted image by glance, we should not be able to
|
||||
# build from it
|
||||
inst_type = flavors.get_default_flavor()
|
||||
|
||||
self.fake_image['name'] = 'fake_name'
|
||||
self.fake_image['status'] = 'DELETED'
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
@ -8745,13 +8744,11 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.fake_image['id']})
|
||||
with testtools.ExpectedException(exception.ImageNotActive,
|
||||
expected_message):
|
||||
self.compute_api.create(self.context, inst_type,
|
||||
self.compute_api.create(self.context, self.default_flavor,
|
||||
self.fake_image['id'])
|
||||
|
||||
@mock.patch('nova.virt.hardware.numa_get_constraints')
|
||||
def test_create_with_numa_topology(self, numa_constraints_mock):
|
||||
inst_type = flavors.get_default_flavor()
|
||||
|
||||
numa_topology = objects.InstanceNUMATopology(
|
||||
cells=[objects.InstanceNUMACell(
|
||||
id=0, cpuset=set([1, 2]), memory=512),
|
||||
@ -8760,11 +8757,12 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
numa_topology.obj_reset_changes()
|
||||
numa_constraints_mock.return_value = numa_topology
|
||||
|
||||
instances, resv_id = self.compute_api.create(self.context, inst_type,
|
||||
instances, resv_id = self.compute_api.create(self.context,
|
||||
self.default_flavor,
|
||||
self.fake_image['id'])
|
||||
|
||||
numa_constraints_mock.assert_called_once_with(
|
||||
inst_type, test.MatchType(objects.ImageMeta))
|
||||
self.default_flavor, test.MatchType(objects.ImageMeta))
|
||||
self.assertEqual(
|
||||
numa_topology.cells[0].obj_to_primitive(),
|
||||
instances[0].numa_topology.cells[0].obj_to_primitive())
|
||||
@ -8777,7 +8775,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
cases = [dict(), dict(display_name=None)]
|
||||
for instance in cases:
|
||||
(ref, resv_id) = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
'f5000000-0000-0000-0000-000000000000', **instance)
|
||||
self.assertIsNotNone(ref[0]['display_name'])
|
||||
|
||||
@ -8787,7 +8785,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
'schedule_and_build_instances') as mock_sbi:
|
||||
(ref, resv_id) = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=flavors.get_default_flavor(),
|
||||
instance_type=self.default_flavor,
|
||||
image_href='f5000000-0000-0000-0000-000000000000')
|
||||
|
||||
build_call = mock_sbi.call_args_list[0]
|
||||
@ -8803,16 +8801,16 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_saves_flavor(self):
|
||||
with mock.patch.object(self.compute_api.compute_task_api,
|
||||
'schedule_and_build_instances') as mock_sbi:
|
||||
instance_type = flavors.get_default_flavor()
|
||||
(ref, resv_id) = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=instance_type,
|
||||
instance_type=self.default_flavor,
|
||||
image_href=uuids.image_href_id)
|
||||
|
||||
build_call = mock_sbi.call_args_list[0]
|
||||
instance = build_call[1]['build_requests'][0].instance
|
||||
self.assertIn('flavor', instance)
|
||||
self.assertEqual(instance_type.flavorid, instance.flavor.flavorid)
|
||||
self.assertEqual(self.default_flavor.flavorid,
|
||||
instance.flavor.flavorid)
|
||||
self.assertNotIn('instance_type_id', instance.system_metadata)
|
||||
|
||||
def test_create_instance_associates_security_groups(self):
|
||||
@ -8822,7 +8820,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
'schedule_and_build_instances') as mock_sbi:
|
||||
(ref, resv_id) = self.compute_api.create(
|
||||
self.context,
|
||||
instance_type=flavors.get_default_flavor(),
|
||||
instance_type=self.default_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
security_groups=['testgroup'])
|
||||
|
||||
@ -8833,13 +8831,11 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.assertEqual(group.name, reqspec.security_groups[0].name)
|
||||
|
||||
def test_create_instance_with_invalid_security_group_raises(self):
|
||||
instance_type = flavors.get_default_flavor()
|
||||
|
||||
pre_build_len = len(db.instance_get_all(self.context))
|
||||
self.assertRaises(exception.SecurityGroupNotFoundForProject,
|
||||
self.compute_api.create,
|
||||
self.context,
|
||||
instance_type=instance_type,
|
||||
instance_type=self.default_flavor,
|
||||
image_href=None,
|
||||
security_groups=['this_is_a_fake_sec_group'])
|
||||
self.assertEqual(pre_build_len,
|
||||
@ -8848,21 +8844,16 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
def test_create_with_malformed_user_data(self):
|
||||
# Test an instance type with malformed user data.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
|
||||
self.fake_image['min_ram'] = 2
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
self.fake_show)
|
||||
|
||||
self.assertRaises(exception.InstanceUserDataMalformed,
|
||||
self.compute_api.create, self.context, inst_type,
|
||||
self.compute_api.create, self.context, self.default_flavor,
|
||||
self.fake_image['id'], user_data=b'banana')
|
||||
|
||||
def test_create_with_base64_user_data(self):
|
||||
# Test an instance type with ok much user data.
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
|
||||
self.fake_image['min_ram'] = 2
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
self.fake_show)
|
||||
@ -8870,7 +8861,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
# NOTE(mikal): a string of length 48510 encodes to 65532 characters of
|
||||
# base64
|
||||
(refs, resv_id) = self.compute_api.create(
|
||||
self.context, inst_type, self.fake_image['id'],
|
||||
self.context, self.default_flavor, self.fake_image['id'],
|
||||
user_data=base64.encode_as_text(b'1' * 48510))
|
||||
|
||||
def test_populate_instance_for_create(self, num_instances=1):
|
||||
@ -8880,14 +8871,13 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
'uuid': uuids.instance}
|
||||
instance = objects.Instance()
|
||||
instance.update(base_options)
|
||||
inst_type = flavors.get_flavor_by_name("m1.tiny")
|
||||
instance = self.compute_api._populate_instance_for_create(
|
||||
self.context,
|
||||
instance,
|
||||
self.fake_image,
|
||||
1,
|
||||
security_groups=objects.SecurityGroupList(),
|
||||
instance_type=inst_type,
|
||||
instance_type=self.tiny_flavor,
|
||||
num_instances=num_instances,
|
||||
shutdown_terminate=False)
|
||||
self.assertEqual(str(base_options['image_ref']),
|
||||
@ -8914,7 +8904,6 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
'uuid': uuids.instance}
|
||||
instance = objects.Instance()
|
||||
instance.update(base_options)
|
||||
inst_type = flavors.get_flavor_by_name("m1.tiny")
|
||||
self.compute_api.key_manager = key_manager.API()
|
||||
index = 1
|
||||
instance = self.compute_api._populate_instance_for_create(
|
||||
@ -8923,7 +8912,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.fake_image,
|
||||
index,
|
||||
security_groups=objects.SecurityGroupList(),
|
||||
instance_type=inst_type,
|
||||
instance_type=self.tiny_flavor,
|
||||
num_instances=num_instances,
|
||||
shutdown_terminate=False)
|
||||
self.assertIsNotNone(instance.ephemeral_key_uuid)
|
||||
@ -8946,7 +8935,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
('hello_server', 'hello-server')]
|
||||
for display_name, hostname in cases:
|
||||
(ref, resv_id) = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
display_name=display_name)
|
||||
|
||||
@ -8964,9 +8953,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
group.create()
|
||||
get_group_mock.return_value = group
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
(refs, resv_id) = self.compute_api.create(
|
||||
self.context, inst_type, self.fake_image['id'],
|
||||
self.context, self.default_flavor, self.fake_image['id'],
|
||||
scheduler_hints={'group': group.uuid})
|
||||
self.assertEqual(len(refs), len(group.members))
|
||||
|
||||
@ -8993,9 +8981,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
group.create()
|
||||
get_group_mock.return_value = group
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
self.assertRaises(exception.QuotaError, self.compute_api.create,
|
||||
self.context, inst_type, self.fake_image['id'],
|
||||
self.context, self.default_flavor, self.fake_image['id'],
|
||||
scheduler_hints={'group': group.uuid},
|
||||
check_server_group_quota=True)
|
||||
|
||||
@ -9029,9 +9016,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
group.create()
|
||||
get_group_mock.return_value = group
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
(refs, resv_id) = self.compute_api.create(
|
||||
self.context, inst_type, self.fake_image['id'],
|
||||
self.context, self.default_flavor, self.fake_image['id'],
|
||||
scheduler_hints={'group': group.uuid},
|
||||
check_server_group_quota=True)
|
||||
self.assertEqual(len(refs), len(group.members))
|
||||
@ -9040,8 +9026,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
# members.
|
||||
self.assertEqual(2, check_deltas_mock.call_count)
|
||||
call1 = mock.call(self.context, {'instances': 1,
|
||||
'cores': inst_type.vcpus,
|
||||
'ram': inst_type.memory_mb},
|
||||
'cores': self.default_flavor.vcpus,
|
||||
'ram': self.default_flavor.memory_mb},
|
||||
self.context.project_id,
|
||||
user_id=None,
|
||||
check_project_id=self.context.project_id,
|
||||
@ -9057,12 +9043,11 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
self.fake_show)
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
self.assertRaises(
|
||||
exception.InstanceGroupNotFound,
|
||||
self.compute_api.create,
|
||||
self.context,
|
||||
inst_type,
|
||||
self.default_flavor,
|
||||
self.fake_image['id'],
|
||||
scheduler_hints={'group':
|
||||
'5b674f73-c8cf-40ef-9965-3b6fe4b304b1'})
|
||||
@ -9314,9 +9299,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
|
||||
def test_hostname_create(self):
|
||||
# Ensure instance hostname is set during creation.
|
||||
inst_type = flavors.get_flavor_by_name('m1.tiny')
|
||||
(instances, _) = self.compute_api.create(self.context,
|
||||
inst_type,
|
||||
self.tiny_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
display_name='test host')
|
||||
|
||||
@ -9949,7 +9933,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
matches return value from create.
|
||||
"""
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
image_href=uuids.image_href_id)
|
||||
self.assertEqual(len(refs), 1)
|
||||
self.assertEqual(refs[0]['reservation_id'], resv_id)
|
||||
@ -9960,7 +9944,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
in both instances.
|
||||
"""
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
min_count=2, max_count=2)
|
||||
self.assertEqual(len(refs), 2)
|
||||
@ -9976,7 +9960,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
# cells v1
|
||||
num_instances = 1
|
||||
refs, _ = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
min_count=num_instances, max_count=num_instances,
|
||||
display_name='x')
|
||||
@ -9992,7 +9976,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
# cells v1
|
||||
num_instances = 2
|
||||
refs, _ = self.compute_api.create(self.context,
|
||||
flavors.get_default_flavor(),
|
||||
self.default_flavor,
|
||||
image_href=uuids.image_href_id,
|
||||
min_count=num_instances, max_count=num_instances,
|
||||
display_name='x')
|
||||
@ -11581,8 +11565,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
inst['project_id'] = self.project_id
|
||||
inst['host'] = 'fake_host'
|
||||
inst['node'] = NODENAME
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
inst['instance_type_id'] = type_id
|
||||
inst['instance_type_id'] = self.tiny_flavor.id
|
||||
inst['ami_launch_index'] = 0
|
||||
inst['memory_mb'] = 0
|
||||
inst['vcpus'] = 0
|
||||
@ -12692,7 +12675,7 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(DisabledInstanceTypesTestCase, self).setUp()
|
||||
self.compute_api = compute.API()
|
||||
self.inst_type = flavors.get_default_flavor()
|
||||
self.inst_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
def test_can_build_instance_from_visible_instance_type(self):
|
||||
self.inst_type['disabled'] = False
|
||||
@ -12815,8 +12798,8 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase):
|
||||
super(ComputeRescheduleResizeOrReraiseTestCase, self).setUp()
|
||||
self.instance = self._create_fake_instance_obj()
|
||||
self.instance_uuid = self.instance['uuid']
|
||||
self.instance_type = flavors.get_flavor_by_name(
|
||||
"m1.tiny")
|
||||
self.instance_type = objects.Flavor.get_by_name(
|
||||
context.get_admin_context(), 'm1.tiny')
|
||||
|
||||
@mock.patch('nova.compute.manager.ComputeManager._prep_resize',
|
||||
side_effect=test.TestingException)
|
||||
@ -12938,7 +12921,8 @@ class ComputeInactiveImageTestCase(BaseTestCase):
|
||||
|
||||
def test_create_instance_with_deleted_image(self):
|
||||
# Make sure we can't start an instance with a deleted image.
|
||||
inst_type = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_type = objects.Flavor.get_by_name(context.get_admin_context(),
|
||||
'm1.tiny')
|
||||
self.assertRaises(exception.ImageNotActive,
|
||||
self.compute_api.create,
|
||||
self.context, inst_type, uuids.image_instance)
|
||||
@ -13443,7 +13427,8 @@ class CheckRequestedImageTestCase(test.TestCase):
|
||||
self.context = context.RequestContext(
|
||||
'fake_user_id', 'fake_project_id')
|
||||
|
||||
self.instance_type = flavors.get_default_flavor()
|
||||
self.instance_type = objects.Flavor.get_by_name(self.context,
|
||||
'm1.small')
|
||||
self.instance_type['memory_mb'] = 64
|
||||
self.instance_type['root_gb'] = 1
|
||||
|
||||
|
@ -176,7 +176,7 @@ class CellsComputeAPITestCase(test_compute.ComputeAPITestCase):
|
||||
headroom=fake_headroom, usages=fake_usages)
|
||||
check_deltas_mock.side_effect = [None, exc]
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
# Try to create 3 instances.
|
||||
self.assertRaises(exception.QuotaError, self.compute_api.create,
|
||||
self.context, inst_type, self.fake_image['id'], min_count=3)
|
||||
@ -220,7 +220,7 @@ class CellsComputeAPITestCase(test_compute.ComputeAPITestCase):
|
||||
# Disable recheck_quota.
|
||||
self.flags(recheck_quota=False, group='quota')
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
inst_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type,
|
||||
self.fake_image['id'])
|
||||
@ -550,7 +550,7 @@ class CellsShelveComputeAPITestCase(test_shelve.ShelveComputeAPITestCase):
|
||||
|
||||
def _create_fake_instance_obj(self, params=None, type_name='m1.tiny',
|
||||
services=False, context=None):
|
||||
flavor = flavors.get_flavor_by_name(type_name)
|
||||
flavor = objects.Flavor.get_by_name(self.context, type_name)
|
||||
inst = objects.Instance(context=context or self.context)
|
||||
inst.cell_name = 'api!child'
|
||||
inst.vm_state = vm_states.ACTIVE
|
||||
|
@ -27,7 +27,6 @@ from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from nova.compute import flavors
|
||||
from nova.compute import manager
|
||||
from nova.compute import power_state
|
||||
from nova.compute import task_states
|
||||
@ -60,7 +59,7 @@ CONF = nova.conf.CONF
|
||||
|
||||
def create_instance(context, user_id='fake', project_id='fake', params=None):
|
||||
"""Create a test instance."""
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
flavor = objects.Flavor.get_by_name(context, 'm1.tiny')
|
||||
net_info = model.NetworkInfo([])
|
||||
info_cache = objects.InstanceInfoCache(network_info=net_info)
|
||||
inst = objects.Instance(context=context,
|
||||
@ -410,6 +409,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.user_id = 'fake'
|
||||
self.project_id = 'fake'
|
||||
self.context = context.RequestContext(self.user_id, self.project_id)
|
||||
self.flavor = objects.Flavor.get_by_name(self.context, 'm1.tiny')
|
||||
|
||||
def fake_show(meh, context, id, **kwargs):
|
||||
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}}
|
||||
@ -440,9 +440,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
type_id = self.flavor.id
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor_id = self.flavor.flavorid
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'state_description',
|
||||
@ -473,7 +473,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['uuid'], instance['uuid'])
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavor['name'], 'm1.tiny')
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavorid = self.flavor.flavorid
|
||||
self.assertEqual(str(flavor['flavorid']), str(flavorid))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
@ -504,9 +504,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
type_id = self.flavor.id
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor_id = self.flavor.flavorid
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'state_description',
|
||||
@ -552,9 +552,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['uuid'], instance['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(str(flavor['flavorid']), flavorid)
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'task_state', 'display_description', 'locked',
|
||||
@ -598,7 +598,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual('fake', payload['user_id'])
|
||||
self.assertEqual(instance['uuid'], payload['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavorid = self.flavor.flavorid
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavorid, str(flavor['flavorid']))
|
||||
|
||||
@ -641,9 +641,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual('fake', payload['user_id'])
|
||||
self.assertEqual(instance['uuid'], payload['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavorid, str(flavor['flavorid']))
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
self.assertEqual(0, len(payload['keypairs']))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
@ -680,9 +680,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual('fake', payload['user_id'])
|
||||
self.assertEqual(instance.uuid, payload['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavorid, str(flavor['flavorid']))
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
self.assertEqual(0, len(payload['keypairs']))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
@ -718,9 +718,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(self.user_id, payload['user_id'])
|
||||
self.assertEqual(instance['uuid'], payload['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavorid, str(flavor['flavorid']))
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'task_state'):
|
||||
@ -760,9 +760,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(self.user_id, payload['user_id'])
|
||||
self.assertEqual(instance['uuid'], payload['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(flavorid, str(flavor['flavorid']))
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'task_state'):
|
||||
@ -808,9 +808,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['uuid'], instance['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(str(flavor['flavorid']), flavorid)
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'task_state', 'display_description', 'locked',
|
||||
@ -823,7 +823,7 @@ class UsageInfoTestCase(test.TestCase):
|
||||
def test_notify_about_resize_prep_instance(self):
|
||||
instance = create_instance(self.context)
|
||||
|
||||
new_flavor = flavors.get_flavor_by_name('m1.small')
|
||||
new_flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
compute_utils.notify_about_resize_prep_instance(
|
||||
self.context, instance, 'fake-compute', 'start', new_flavor)
|
||||
@ -842,9 +842,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['uuid'], instance['uuid'])
|
||||
|
||||
flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
flavor = payload['flavor']['nova_object.data']
|
||||
self.assertEqual(str(flavor['flavorid']), flavorid)
|
||||
self.assertEqual(
|
||||
self.flavor.flavorid,
|
||||
str(payload['flavor']['nova_object.data']['flavorid']))
|
||||
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'task_state', 'display_description', 'locked',
|
||||
@ -869,10 +869,10 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.flavor.id),
|
||||
str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'state_description',
|
||||
'bandwidth', 'audit_period_beginning',
|
||||
@ -943,10 +943,9 @@ class UsageInfoTestCase(test.TestCase):
|
||||
self.assertEqual(payload['user_id'], self.user_id)
|
||||
self.assertEqual(payload['instance_id'], instance['uuid'])
|
||||
self.assertEqual(payload['instance_type'], 'm1.tiny')
|
||||
type_id = flavors.get_flavor_by_name('m1.tiny')['id']
|
||||
self.assertEqual(str(payload['instance_type_id']), str(type_id))
|
||||
flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
|
||||
self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
|
||||
self.assertEqual(str(self.flavor.id), str(payload['instance_type_id']))
|
||||
self.assertEqual(str(self.flavor.flavorid),
|
||||
str(payload['instance_flavor_id']))
|
||||
for attr in ('display_name', 'created_at', 'launched_at',
|
||||
'state', 'state_description', 'image_meta'):
|
||||
self.assertIn(attr, payload, "Key %s not in payload" % attr)
|
||||
@ -1299,8 +1298,8 @@ class ComputeUtilsQuotaTestCase(test.TestCase):
|
||||
self.context = context.RequestContext('fake', 'fake')
|
||||
|
||||
def test_upsize_quota_delta(self):
|
||||
old_flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
new_flavor = flavors.get_flavor_by_name('m1.medium')
|
||||
old_flavor = objects.Flavor.get_by_name(self.context, 'm1.tiny')
|
||||
new_flavor = objects.Flavor.get_by_name(self.context, 'm1.medium')
|
||||
|
||||
expected_deltas = {
|
||||
'cores': new_flavor['vcpus'] - old_flavor['vcpus'],
|
||||
|
@ -386,7 +386,7 @@ class _BaseTaskTestCase(object):
|
||||
inst_obj = objects.Instance._from_db_object(
|
||||
self.context, objects.Instance(), inst, [])
|
||||
inst_obj.system_metadata = {'image_hw_disk_bus': 'scsi'}
|
||||
flavor = flavors.get_default_flavor()
|
||||
flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
flavor.extra_specs = {'extra_specs': 'fake'}
|
||||
inst_obj.flavor = flavor
|
||||
|
||||
@ -435,7 +435,7 @@ class _BaseTaskTestCase(object):
|
||||
"""
|
||||
fake_spec = objects.RequestSpec()
|
||||
mock_fp.return_value = fake_spec
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
# NOTE(danms): Avoid datetime timezone issues with converted flavors
|
||||
instance_type.created_at = None
|
||||
instances = [objects.Instance(context=self.context,
|
||||
@ -1651,6 +1651,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
tag = objects.Tag(self.ctxt, tag='tag1')
|
||||
params['tags'] = objects.TagList(objects=[tag])
|
||||
self.params = params
|
||||
self.flavor = objects.Flavor.get_by_name(self.ctxt, 'm1.tiny')
|
||||
|
||||
@mock.patch('nova.availability_zones.get_host_availability_zone')
|
||||
@mock.patch('nova.compute.rpcapi.ComputeAPI.build_and_run_instance')
|
||||
@ -2394,12 +2395,11 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
def test_migrate_server_fails_with_flavor(self, get_im):
|
||||
get_im.return_value.cell_mapping = (
|
||||
objects.CellMappingList.get_all(self.context)[0])
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
instance = fake_instance.fake_instance_obj(self.context,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
flavor=flavor)
|
||||
flavor=self.flavor)
|
||||
self.assertRaises(NotImplementedError, self.conductor.migrate_server,
|
||||
self.context, instance, None, True, False, flavor, None, None)
|
||||
self.context, instance, None, True, False, self.flavor, None, None)
|
||||
|
||||
def _build_request_spec(self, instance):
|
||||
return {
|
||||
@ -2528,15 +2528,14 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
def test_cold_migrate_no_valid_host_back_in_active_state(
|
||||
self, _preallocate_migration, rollback_mock, notify_mock,
|
||||
select_dest_mock, metadata_mock, sig_mock, spec_fc_mock, im_mock):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
vm_state=vm_states.ACTIVE,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID,
|
||||
flavor=flavor,
|
||||
flavor=self.flavor,
|
||||
availability_zone=None,
|
||||
pci_requests=None,
|
||||
numa_topology=None,
|
||||
@ -2557,7 +2556,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
self.assertRaises(exc.NoValidHost,
|
||||
self.conductor._cold_migrate,
|
||||
self.context, inst_obj,
|
||||
flavor, {},
|
||||
self.flavor, {},
|
||||
True, None, None)
|
||||
metadata_mock.assert_called_with({})
|
||||
sig_mock.assert_called_once_with(self.context, fake_spec)
|
||||
@ -2579,15 +2578,14 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
def test_cold_migrate_no_valid_host_back_in_stopped_state(
|
||||
self, _preallocate_migration, rollback_mock, notify_mock,
|
||||
select_dest_mock, metadata_mock, spec_fc_mock, sig_mock, im_mock):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID,
|
||||
flavor=flavor,
|
||||
flavor=self.flavor,
|
||||
numa_topology=None,
|
||||
pci_requests=None,
|
||||
availability_zone=None,
|
||||
@ -2609,7 +2607,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
self.assertRaises(exc.NoValidHost,
|
||||
self.conductor._cold_migrate,
|
||||
self.context, inst_obj,
|
||||
flavor, {},
|
||||
self.flavor, {},
|
||||
True, None, None)
|
||||
metadata_mock.assert_called_with({})
|
||||
sig_mock.assert_called_once_with(self.context, fake_spec)
|
||||
@ -2620,11 +2618,10 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
rollback_mock.assert_called_once_with()
|
||||
|
||||
def test_cold_migrate_no_valid_host_error_msg(self):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID)
|
||||
@ -2643,7 +2640,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
task_rollback_mock):
|
||||
nvh = self.assertRaises(exc.NoValidHost,
|
||||
self.conductor._cold_migrate, self.context,
|
||||
inst_obj, flavor, {},
|
||||
inst_obj, self.flavor, {},
|
||||
True, fake_spec, None)
|
||||
self.assertIn('cold migrate', nvh.message)
|
||||
|
||||
@ -2659,16 +2656,15 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
task_rollback_mock,
|
||||
task_exec_mock,
|
||||
image_mock):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
project_id=fakes.FAKE_PROJECT_ID,
|
||||
user_id=fakes.FAKE_USER_ID,
|
||||
flavor=flavor,
|
||||
flavor=self.flavor,
|
||||
numa_topology=None,
|
||||
pci_requests=None,
|
||||
availability_zone=None)
|
||||
@ -2682,16 +2678,17 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
|
||||
self.assertRaises(exc.UnsupportedPolicyException,
|
||||
self.conductor._cold_migrate, self.context,
|
||||
inst_obj, flavor, {}, True, None, None)
|
||||
inst_obj, self.flavor, {}, True, None, None)
|
||||
|
||||
updates = {'vm_state': vm_states.STOPPED, 'task_state': None}
|
||||
set_vm_mock.assert_called_once_with(self.context, inst_obj.uuid,
|
||||
'migrate_server', updates,
|
||||
exception, fake_spec)
|
||||
spec_fc_mock.assert_called_once_with(
|
||||
self.context, inst_obj.uuid, image, flavor, inst_obj.numa_topology,
|
||||
inst_obj.pci_requests, {}, None, inst_obj.availability_zone,
|
||||
project_id=inst_obj.project_id, user_id=inst_obj.user_id)
|
||||
self.context, inst_obj.uuid, image, self.flavor,
|
||||
inst_obj.numa_topology, inst_obj.pci_requests, {}, None,
|
||||
inst_obj.availability_zone, project_id=inst_obj.project_id,
|
||||
user_id=inst_obj.user_id)
|
||||
|
||||
@mock.patch.object(objects.InstanceMapping, 'get_by_instance_uuid')
|
||||
@mock.patch.object(scheduler_utils, 'setup_instance_group')
|
||||
@ -2707,15 +2704,14 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
self, _preallocate_migration, prep_resize_mock, rollback_mock,
|
||||
notify_mock, select_dest_mock, metadata_mock, spec_fc_mock,
|
||||
sig_mock, im_mock):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID,
|
||||
flavor=flavor,
|
||||
flavor=self.flavor,
|
||||
availability_zone=None,
|
||||
pci_requests=None,
|
||||
numa_topology=None,
|
||||
@ -2738,7 +2734,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
prep_resize_mock.side_effect = exc_info
|
||||
self.assertRaises(test.TestingException,
|
||||
self.conductor._cold_migrate,
|
||||
self.context, inst_obj, flavor,
|
||||
self.context, inst_obj, self.flavor,
|
||||
{}, True, None, None)
|
||||
|
||||
# Filter properties are populated during code execution
|
||||
@ -2753,7 +2749,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
[inst_obj.uuid], return_objects=True, return_alternates=True)
|
||||
prep_resize_mock.assert_called_once_with(
|
||||
self.context, inst_obj, fake_spec.image,
|
||||
flavor, hosts[0]['host'], _preallocate_migration.return_value,
|
||||
self.flavor, hosts[0]['host'], _preallocate_migration.return_value,
|
||||
request_spec=fake_spec,
|
||||
filter_properties=legacy_filter_props,
|
||||
node=hosts[0]['nodename'], clean_shutdown=True, host_list=[])
|
||||
@ -2769,15 +2765,14 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
image_mock,
|
||||
task_exec_mock,
|
||||
spec_save_mock):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID,
|
||||
flavor=flavor,
|
||||
flavor=self.flavor,
|
||||
availability_zone=None,
|
||||
pci_requests=None,
|
||||
numa_topology=None)
|
||||
@ -2787,22 +2782,21 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
|
||||
image_mock.return_value = image
|
||||
# Just make sure we have an original flavor which is different from
|
||||
# the new one
|
||||
self.assertNotEqual(flavor, fake_spec.flavor)
|
||||
self.conductor._cold_migrate(self.context, inst_obj, flavor, {},
|
||||
self.assertNotEqual(self.flavor, fake_spec.flavor)
|
||||
self.conductor._cold_migrate(self.context, inst_obj, self.flavor, {},
|
||||
True, fake_spec, None)
|
||||
|
||||
# Now the RequestSpec should be updated...
|
||||
self.assertEqual(flavor, fake_spec.flavor)
|
||||
self.assertEqual(self.flavor, fake_spec.flavor)
|
||||
# ...and persisted
|
||||
spec_save_mock.assert_called_once_with()
|
||||
|
||||
def test_resize_no_valid_host_error_msg(self):
|
||||
flavor = flavors.get_flavor_by_name('m1.tiny')
|
||||
flavor_new = flavors.get_flavor_by_name('m1.small')
|
||||
flavor_new = objects.Flavor.get_by_name(self.ctxt, 'm1.small')
|
||||
inst_obj = objects.Instance(
|
||||
image_ref='fake-image_ref',
|
||||
vm_state=vm_states.STOPPED,
|
||||
instance_type_id=flavor['id'],
|
||||
instance_type_id=self.flavor.id,
|
||||
system_metadata={},
|
||||
uuid=uuids.instance,
|
||||
user_id=fakes.FAKE_USER_ID)
|
||||
|
@ -22,7 +22,6 @@ import mock
|
||||
from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from nova.compute import flavors
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
@ -140,7 +139,7 @@ class ApiTestCase(test.TestCase):
|
||||
'macs'],
|
||||
itertools.repeat(mock.ANY)))
|
||||
mock_alloc.return_value = []
|
||||
flavor = flavors.get_default_flavor()
|
||||
flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
flavor['rxtx_factor'] = 0
|
||||
instance = objects.Instance(id=1, uuid=uuids.instance,
|
||||
project_id='project_id',
|
||||
@ -254,7 +253,7 @@ class ApiTestCase(test.TestCase):
|
||||
self.context.project_id)
|
||||
|
||||
def _stub_migrate_instance_calls(self, method, multi_host, info):
|
||||
fake_flavor = flavors.get_default_flavor()
|
||||
fake_flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
fake_flavor['rxtx_factor'] = 1.21
|
||||
fake_instance = objects.Instance(
|
||||
uuid=uuidutils.generate_uuid(dashed=False),
|
||||
|
@ -36,7 +36,6 @@ import requests_mock
|
||||
import six
|
||||
from six.moves import range
|
||||
|
||||
from nova.compute import flavors
|
||||
from nova import context
|
||||
from nova.db.sqlalchemy import api as db_api
|
||||
from nova import exception
|
||||
@ -3101,7 +3100,7 @@ class TestNeutronv2WithMock(TestNeutronv2Base):
|
||||
mock_get_client.return_value = mocked_client
|
||||
mocked_client.list_extensions.return_value = {
|
||||
'extensions': [{'name': constants.QOS_QUEUE}]}
|
||||
flavor = flavors.get_default_flavor()
|
||||
flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
flavor['rxtx_factor'] = 1
|
||||
instance = objects.Instance(system_metadata={})
|
||||
instance.flavor = flavor
|
||||
|
@ -22,7 +22,6 @@ from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova.compute import flavors
|
||||
from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
from nova.db import api as db
|
||||
@ -1359,13 +1358,13 @@ class _TestInstanceObject(object):
|
||||
self.assertIsNotNone(instance.pci_requests)
|
||||
|
||||
def test_get_flavor(self):
|
||||
db_flavor = flavors.get_default_flavor()
|
||||
db_flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
inst = objects.Instance(flavor=db_flavor)
|
||||
self.assertEqual(db_flavor['flavorid'],
|
||||
inst.get_flavor().flavorid)
|
||||
|
||||
def test_get_flavor_namespace(self):
|
||||
db_flavor = flavors.get_default_flavor()
|
||||
db_flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
inst = objects.Instance(old_flavor=db_flavor)
|
||||
self.assertEqual(db_flavor['flavorid'],
|
||||
inst.get_flavor('old').flavorid)
|
||||
|
@ -24,25 +24,6 @@ from nova import test
|
||||
|
||||
class InstanceTypeTestCase(test.TestCase):
|
||||
"""Test cases for flavor code."""
|
||||
def test_will_not_get_bad_default_instance_type(self):
|
||||
# ensures error raised on bad default flavor.
|
||||
self.flags(default_flavor='unknown_flavor')
|
||||
self.assertRaises(exception.FlavorNotFound,
|
||||
flavors.get_default_flavor)
|
||||
|
||||
def test_flavor_get_by_None_name_returns_default(self):
|
||||
# Ensure get by name returns default flavor with no name.
|
||||
default = flavors.get_default_flavor()
|
||||
actual = flavors.get_flavor_by_name(None)
|
||||
self.assertIsInstance(default, objects.Flavor)
|
||||
self.assertIsInstance(actual, objects.Flavor)
|
||||
self.assertEqual(default.flavorid, actual.flavorid)
|
||||
|
||||
def test_will_not_get_flavor_with_bad_name(self):
|
||||
# Ensure get by name returns default flavor with bad name.
|
||||
self.assertRaises(exception.FlavorNotFound,
|
||||
flavors.get_flavor_by_name, 10000)
|
||||
|
||||
def test_will_not_get_instance_by_unknown_flavor_id(self):
|
||||
# Ensure get by flavor raises error with wrong flavorid.
|
||||
self.assertRaises(exception.FlavorNotFound,
|
||||
@ -50,7 +31,8 @@ class InstanceTypeTestCase(test.TestCase):
|
||||
'unknown_flavor')
|
||||
|
||||
def test_will_get_instance_by_flavor_id(self):
|
||||
default_instance_type = flavors.get_default_flavor()
|
||||
default_instance_type = objects.Flavor.get_by_name(
|
||||
context.get_admin_context(), 'm1.small')
|
||||
flavorid = default_instance_type.flavorid
|
||||
fetched = flavors.get_flavor_by_flavor_id(flavorid)
|
||||
self.assertIsInstance(fetched, objects.Flavor)
|
||||
@ -58,11 +40,16 @@ class InstanceTypeTestCase(test.TestCase):
|
||||
|
||||
|
||||
class InstanceTypeToolsTest(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(InstanceTypeToolsTest, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
|
||||
def _dict_to_metadata(self, data):
|
||||
return [{'key': key, 'value': value} for key, value in data.items()]
|
||||
|
||||
def _test_extract_flavor(self, prefix):
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
instance_type_p = obj_base.obj_to_primitive(instance_type)
|
||||
|
||||
metadata = {}
|
||||
@ -92,7 +79,7 @@ class InstanceTypeToolsTest(test.TestCase):
|
||||
self._test_extract_flavor('foo_')
|
||||
|
||||
def test_save_flavor_info(self):
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
example = {}
|
||||
example_prefix = {}
|
||||
@ -110,7 +97,7 @@ class InstanceTypeToolsTest(test.TestCase):
|
||||
self.assertEqual(example_prefix, metadata)
|
||||
|
||||
def test_flavor_numa_extras_are_saved(self):
|
||||
instance_type = flavors.get_default_flavor()
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
instance_type['extra_specs'] = {
|
||||
'hw:numa_mem.0': '123',
|
||||
'hw:numa_cpus.0': '456',
|
||||
|
@ -44,7 +44,6 @@ from nova.api.metadata import handler
|
||||
from nova.api.metadata import password
|
||||
from nova.api.metadata import vendordata_dynamic
|
||||
from nova import block_device
|
||||
from nova.compute import flavors
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
@ -101,7 +100,7 @@ def fake_inst_obj(context):
|
||||
inst.info_cache = objects.InstanceInfoCache(context=context,
|
||||
instance_uuid=inst.uuid,
|
||||
network_info=nwinfo)
|
||||
inst.flavor = flavors.get_default_flavor()
|
||||
inst.flavor = objects.Flavor.get_by_name(context, 'm1.small')
|
||||
return inst
|
||||
|
||||
|
||||
|
@ -24,7 +24,6 @@ from oslo_context import fixture as o_fixture
|
||||
from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova.compute import flavors
|
||||
from nova.compute import task_states
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
@ -77,7 +76,7 @@ class NotificationsTestCase(test.TestCase):
|
||||
self.decorated_function_called = False
|
||||
|
||||
def _wrapped_create(self, params=None):
|
||||
instance_type = flavors.get_flavor_by_name('m1.tiny')
|
||||
instance_type = objects.Flavor.get_by_name(self.context, 'm1.tiny')
|
||||
inst = objects.Instance(image_ref=uuids.image_ref,
|
||||
user_id=self.user_id,
|
||||
project_id=self.project_id,
|
||||
|
@ -19,7 +19,6 @@ from oslo_db.sqlalchemy import enginefacade
|
||||
from six.moves import range
|
||||
|
||||
from nova import compute
|
||||
from nova.compute import flavors
|
||||
import nova.conf
|
||||
from nova import context
|
||||
from nova.db import api as db
|
||||
@ -68,6 +67,7 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
self.context = context.RequestContext(self.user_id,
|
||||
self.project_id,
|
||||
is_admin=True)
|
||||
self.inst_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
nova.tests.unit.image.fake.stub_out_image_service(self)
|
||||
|
||||
@ -94,7 +94,7 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
inst.reservation_id = 'r-fakeres'
|
||||
inst.user_id = self.user_id
|
||||
inst.project_id = self.project_id
|
||||
inst.flavor = flavors.get_flavor_by_name(flavor_name)
|
||||
inst.flavor = objects.Flavor.get_by_name(cctxt, flavor_name)
|
||||
# This is needed for instance quota counting until we have the
|
||||
# ability to count allocations in placement.
|
||||
inst.vcpus = inst.flavor.vcpus
|
||||
@ -111,11 +111,10 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
def test_too_many_instances(self):
|
||||
for i in range(CONF.quota.instances):
|
||||
self._create_instance()
|
||||
inst_type = flavors.get_flavor_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
try:
|
||||
self.compute_api.create(self.context, min_count=1, max_count=1,
|
||||
instance_type=inst_type,
|
||||
instance_type=self.inst_type,
|
||||
image_href=image_uuid)
|
||||
except exception.QuotaError as e:
|
||||
expected_kwargs = {'code': 413,
|
||||
@ -129,11 +128,10 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
|
||||
def test_too_many_cores(self):
|
||||
self._create_instance()
|
||||
inst_type = flavors.get_flavor_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
try:
|
||||
self.compute_api.create(self.context, min_count=1, max_count=1,
|
||||
instance_type=inst_type,
|
||||
instance_type=self.inst_type,
|
||||
image_href=image_uuid)
|
||||
except exception.QuotaError as e:
|
||||
expected_kwargs = {'code': 413,
|
||||
@ -199,30 +197,27 @@ class QuotaIntegrationTestCase(test.TestCase):
|
||||
metadata = {}
|
||||
for i in range(CONF.quota.metadata_items + 1):
|
||||
metadata['key%s' % i] = 'value%s' % i
|
||||
inst_type = flavors.get_flavor_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
self.assertRaises(exception.QuotaError, self.compute_api.create,
|
||||
self.context,
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
instance_type=inst_type,
|
||||
instance_type=self.inst_type,
|
||||
image_href=image_uuid,
|
||||
metadata=metadata)
|
||||
|
||||
def _create_with_injected_files(self, files):
|
||||
api = self.compute_api
|
||||
inst_type = flavors.get_flavor_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
api.create(self.context, min_count=1, max_count=1,
|
||||
instance_type=inst_type, image_href=image_uuid,
|
||||
instance_type=self.inst_type, image_href=image_uuid,
|
||||
injected_files=files)
|
||||
|
||||
def test_no_injected_files(self):
|
||||
api = self.compute_api
|
||||
inst_type = flavors.get_flavor_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
api.create(self.context,
|
||||
instance_type=inst_type,
|
||||
instance_type=self.inst_type,
|
||||
image_href=image_uuid)
|
||||
|
||||
def test_max_injected_files(self):
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
upgrade:
|
||||
- The ``[DEFAULT]/default_flavor`` option deprecated in 14.0.0 (Newton)
|
||||
has been removed.
|
Loading…
Reference in New Issue
Block a user