Merge "Fix up instance flavor usage in compute and network tests"

This commit is contained in:
Jenkins 2015-06-23 00:11:00 +00:00 committed by Gerrit Code Review
commit c0625a4e93
7 changed files with 45 additions and 36 deletions

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_config import cfg
from nova.api.metadata import password
@ -65,7 +67,8 @@ class ServerPasswordTestV21(test.NoDBTestCase):
self.assertEqual(res['password'], 'fakepass')
def test_reset_password(self):
eval(self.delete_call)(self.fake_req, 'fake')
with mock.patch('nova.objects.Instance._save_flavor'):
eval(self.delete_call)(self.fake_req, 'fake')
self.assertEqual(eval(self.delete_call).wsgi_code, 204)
res = self.controller.index(self.fake_req, 'fake')

View File

@ -295,7 +295,9 @@ class BaseTestCase(test.TestCase):
inst.updated_at = timeutils.utcnow()
inst.launched_at = timeutils.utcnow()
inst.security_groups = objects.SecurityGroupList(objects=[])
flavors.save_flavor_info(inst.system_metadata, flavor)
inst.flavor = flavor
inst.old_flavor = None
inst.new_flavor = None
if params:
inst.update(params)
if services:
@ -9085,10 +9087,10 @@ class ComputeAPITestCase(BaseTestCase):
def test_attach_interface(self):
new_type = flavors.get_flavor_by_flavor_id('4')
sys_meta = flavors.save_flavor_info({}, new_type)
instance = objects.Instance(image_ref='foo',
system_metadata=sys_meta)
system_metadata={},
flavor=new_type)
self.mox.StubOutWithMock(self.compute.network_api,
'allocate_port_for_instance')
nwinfo = [fake_network_cache_model.new_vif()]
@ -9109,9 +9111,9 @@ class ComputeAPITestCase(BaseTestCase):
def test_attach_interface_failed(self):
new_type = flavors.get_flavor_by_flavor_id('4')
sys_meta = flavors.save_flavor_info({}, new_type)
instance = objects.Instance(uuid='fake_id', image_ref='foo',
system_metadata=sys_meta)
system_metadata={},
flavor=new_type)
nwinfo = [fake_network_cache_model.new_vif()]
network_id = nwinfo[0]['network']['id']
port_id = nwinfo[0]['id']

View File

@ -101,9 +101,28 @@ def fake_db_instance(**updates):
def fake_instance_obj(context, **updates):
expected_attrs = updates.pop('expected_attrs', None)
return objects.Instance._from_db_object(context,
flavor = updates.pop('flavor', None)
if not flavor:
flavor = objects.Flavor(id=1, name='flavor1',
memory_mb=256, vcpus=1,
root_gb=1, ephemeral_gb=1,
flavorid='1',
swap=0, rxtx_factor=1.0,
vcpu_weight=1,
disabled=False,
is_public=True,
extra_specs={},
projects=[])
flavor.obj_reset_changes()
inst = objects.Instance._from_db_object(context,
objects.Instance(), fake_db_instance(**updates),
expected_attrs=expected_attrs)
if flavor:
inst.flavor = flavor
inst.old_flavor = None
inst.new_flavor = None
inst.obj_reset_changes()
return inst
def fake_fault_obj(context, instance_uuid, code=404,

View File

@ -38,9 +38,7 @@ from nova import policy
from nova import test
from nova.tests.unit import fake_instance
from nova.tests.unit.objects import test_fixed_ip
from nova.tests.unit.objects import test_flavor
from nova.tests.unit.objects import test_virtual_interface
from nova import utils
FAKE_UUID = 'a47ae74e-ab08-547f-9eee-ffd23fc46c16'
@ -179,11 +177,9 @@ class ApiTestCase(test.TestCase):
self.mox.ReplayAll()
flavor = flavors.get_default_flavor()
flavor['rxtx_factor'] = 0
sys_meta = flavors.save_flavor_info({}, flavor)
instance = dict(id=1, uuid='uuid', project_id='project_id',
host='host', system_metadata=utils.dict_to_metadata(sys_meta))
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'], **instance)
instance = objects.Instance(id=1, uuid='uuid', project_id='project_id',
host='host', system_metadata={},
flavor=flavor)
self.network_api.allocate_for_instance(
self.context, instance, 'vpn', 'requested_networks', macs=macs)
@ -292,12 +288,12 @@ class ApiTestCase(test.TestCase):
def _stub_migrate_instance_calls(self, method, multi_host, info):
fake_flavor = flavors.get_default_flavor()
fake_flavor['rxtx_factor'] = 1.21
sys_meta = flavors.save_flavor_info({}, fake_flavor)
fake_instance = objects.Instance(
uuid=uuid.uuid4().hex,
project_id='fake_project_id',
instance_type_id=fake_flavor['id'],
system_metadata=sys_meta)
flavor=fake_flavor,
system_metadata={})
fake_migration = {'source_compute': 'fake_compute_source',
'dest_compute': 'fake_compute_dest'}
@ -469,29 +465,20 @@ class ApiTestCase(test.TestCase):
self.assertFalse(nwinfo_mock.called)
def test_allocate_for_instance_refresh_cache(self):
sys_meta = flavors.save_flavor_info({}, test_flavor.fake_flavor)
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'],
system_metadata=sys_meta)
instance = fake_instance.fake_instance_obj(self.context)
vpn = 'fake-vpn'
requested_networks = 'fake-networks'
self._test_refresh_cache('allocate_for_instance', self.context,
instance, vpn, requested_networks)
def test_add_fixed_ip_to_instance_refresh_cache(self):
sys_meta = flavors.save_flavor_info({}, test_flavor.fake_flavor)
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'],
system_metadata=sys_meta)
instance = fake_instance.fake_instance_obj(self.context)
network_id = 'fake-network-id'
self._test_refresh_cache('add_fixed_ip_to_instance', self.context,
instance, network_id)
def test_remove_fixed_ip_from_instance_refresh_cache(self):
sys_meta = flavors.save_flavor_info({}, test_flavor.fake_flavor)
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=['system_metadata'],
system_metadata=sys_meta)
instance = fake_instance.fake_instance_obj(self.context)
address = 'fake-address'
self._test_refresh_cache('remove_fixed_ip_from_instance', self.context,
instance, address)

View File

@ -345,8 +345,8 @@ class VmCommandsTestCase(test.TestCase):
get.return_value = objects.InstanceList(
objects=[fake_instance.fake_instance_obj(
context.get_admin_context(), host='foo-host',
instance_type=self.fake_flavor,
expected_attrs=('flavor'))])
flavor=self.fake_flavor,
system_metadata={})])
self.commands.list()
sys.stdout = sys.__stdout__
@ -363,8 +363,8 @@ class VmCommandsTestCase(test.TestCase):
get.return_value = objects.InstanceList(
objects=[fake_instance.fake_instance_obj(
context.get_admin_context(),
instance_type=self.fake_flavor,
expected_attrs=('flavor'))])
flavor=self.fake_flavor,
system_metadata={})])
self.commands.list(host='fake-host')
sys.stdout = sys.__stdout__

View File

@ -66,7 +66,7 @@ class ConfigDriveTestCase(test.NoDBTestCase):
'ramdisk_id': '1',
'mac_addresses': [{'address': 'de:ad:be:ef:be:ef'}],
'memory_mb': 8192,
'flavor': 'm1.large',
'flavor': objects.Flavor(extra_specs={}),
'instance_type_id': 0,
'vcpus': 4,
'root_gb': 80,
@ -82,7 +82,6 @@ class ConfigDriveTestCase(test.NoDBTestCase):
}
self.test_instance = fake_instance.fake_instance_obj(self.context,
**instance_values)
self.test_instance.flavor = objects.Flavor(extra_specs={})
(image_service, image_id) = glance.get_remote_image_service(context,
image_ref)

View File

@ -350,7 +350,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
'kernel_id': "fake_kernel_uuid",
'ramdisk_id': "fake_ramdisk_uuid",
'mac_address': "de:ad:be:ef:be:ef",
'flavor': instance_type,
'flavor': objects.Flavor(**self.type_data),
'node': node,
'memory_mb': self.type_data['memory_mb'],
'root_gb': self.type_data['root_gb'],
@ -365,7 +365,6 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self.uuid = uuid
self.instance = fake_instance.fake_instance_obj(
self.context, **values)
self.instance.flavor = objects.Flavor(**self.type_data)
def _create_vm(self, node=None, num_instances=1, uuid=None,
instance_type='m1.large', powered_on=True,