Skip to content

Commit

Permalink
Further hack up the n.t.unit.db.fakes module of horribleness
Browse files Browse the repository at this point in the history
This module has long been a thorn in the sides of good people. I hereby
extend the terribleness with further hacks to unstick it from the path
to flavor goodness.

Change-Id: I15b2d87f6a6a25601be0907ef93bd427339e6746
  • Loading branch information
kk7ds committed Apr 1, 2016
1 parent e05acd2 commit 74767a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 17 additions & 11 deletions nova/tests/unit/db/fakes.py
Expand Up @@ -47,10 +47,8 @@ def get(self, name):

def stub_out(test, funcs):
"""Set the stubs in mapping in the db api."""
for func in funcs:
func_name = '_'.join(func.__name__.split('_')[1:])
test.stub_out('nova.db.' + func_name, func)
test.stub_out('nova.db.api.' + func_name, func)
for module, func in funcs.items():
test.stub_out(module, func)


fixed_ip_fields = {'id': 0,
Expand Down Expand Up @@ -339,6 +337,8 @@ def stub_out_db_network_api(test):
fake_network_set_host,
fake_network_update,
fake_project_get_networks]
funcs = {'nova.db.%s' % fn.__name__.replace('fake_', ''): fn
for fn in funcs}

stub_out(test, funcs)

Expand Down Expand Up @@ -430,13 +430,15 @@ def _create_instance_type(**updates):
'address_v6': 'fe80::a00:3',
'network_id': 'fake_flat'}

def fake_flavor_get_all(context, inactive=0, filters=None):
def fake_flavor_get_all(*a, **k):
return INSTANCE_TYPES.values()

def fake_flavor_get_by_name(context, name):
@classmethod
def fake_flavor_get_by_name(cls, context, name):
return INSTANCE_TYPES[name]

def fake_flavor_get(context, id):
@classmethod
def fake_flavor_get(cls, context, id):
for name, inst_type in six.iteritems(INSTANCE_TYPES):
if str(inst_type['id']) == str(id):
return inst_type
Expand All @@ -445,8 +447,12 @@ def fake_flavor_get(context, id):
def fake_fixed_ip_get_by_instance(context, instance_id):
return [FakeModel(fixed_ip_fields)]

funcs = [fake_flavor_get_all,
fake_flavor_get_by_name,
fake_flavor_get,
fake_fixed_ip_get_by_instance]
funcs = {
'nova.objects.flavor._flavor_get_all_from_db': (
fake_flavor_get_all),
'nova.objects.Flavor._flavor_get_by_name_from_db': (
fake_flavor_get_by_name),
'nova.objects.Flavor._flavor_get_from_db': fake_flavor_get,
'nova.db.api.fixed_ip_get_by_instance': fake_fixed_ip_get_by_instance,
}
stub_out(test, funcs)
12 changes: 3 additions & 9 deletions nova/tests/unit/virt/xenapi/test_xenapi.py
Expand Up @@ -610,7 +610,7 @@ def create_vm_record(self, conn, os_type, name):
self.vm = vm

def check_vm_record(self, conn, instance_type_id, check_injection):
flavor = db.flavor_get(conn, instance_type_id)
flavor = objects.Flavor.get_by_id(self.context, instance_type_id)
mem_kib = int(flavor['memory_mb']) << 10
mem_bytes = str(mem_kib << 10)
vcpus = flavor['vcpus']
Expand Down Expand Up @@ -746,10 +746,6 @@ def fake_inject_instance_metadata(self, instance, vm):

flavor = objects.Flavor.get_by_id(self.context,
instance_type_id)
if instance_type_id == 5:
# NOTE(danms): xenapi test stubs have flavor 5 with no
# vcpu_weight
flavor.vcpu_weight = None
instance.flavor = flavor
instance.create()
else:
Expand Down Expand Up @@ -1886,8 +1882,7 @@ def fake_vdi_resize(*args, **kwargs):
def test_migrate_too_many_partitions_no_resize_down(self):
instance = self._create_instance()
xenapi_fake.create_vm(instance['name'], 'Running')
flavor = db.flavor_get_by_name(self.context, 'm1.small')
flavor = fake_flavor.fake_flavor_obj(self.context, **flavor)
flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)

def fake_get_partitions(partition):
Expand All @@ -1904,8 +1899,7 @@ def fake_get_partitions(partition):
def test_migrate_bad_fs_type_no_resize_down(self):
instance = self._create_instance()
xenapi_fake.create_vm(instance['name'], 'Running')
flavor = db.flavor_get_by_name(self.context, 'm1.small')
flavor = fake_flavor.fake_flavor_obj(self.context, **flavor)
flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)

def fake_get_partitions(partition):
Expand Down

0 comments on commit 74767a7

Please sign in to comment.