Skip to content

Commit

Permalink
Merge "Make test_shelve work with CONF.use_neutron=True by default"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 14, 2016
2 parents 75a804d + e01eec4 commit 73f5b1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions nova/tests/unit/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ def fake_show(meh, context, id, **kwargs):
def fake_get_nw_info(cls, ctxt, instance, *args, **kwargs):
return network_model.NetworkInfo()

self.stub_out('nova.network.api.API.get_instance_nw_info',
fake_get_nw_info)
if CONF.use_neutron:
self.stub_out(
'nova.network.neutronv2.api.API.get_instance_nw_info',
fake_get_nw_info)
else:
self.stub_out('nova.network.api.API.get_instance_nw_info',
fake_get_nw_info)

def fake_allocate_for_instance(cls, ctxt, instance, *args, **kwargs):
self.assertFalse(ctxt.is_admin)
Expand Down
12 changes: 8 additions & 4 deletions nova/tests/unit/compute/test_shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import nova.conf
from nova import db
from nova import objects
from nova import test
from nova.tests.unit.compute import test_compute
from nova.tests.unit.image import fake as fake_image
from nova.tests import uuidsentinel as uuids
Expand All @@ -43,8 +44,6 @@ def _fake_resources():


class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
@mock.patch.object(nova.network.api.API,
'cleanup_instance_network_on_host')
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'power_off')
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'snapshot')
@mock.patch.object(nova.compute.manager.ComputeManager, '_get_power_state')
Expand All @@ -53,7 +52,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def _shelve_instance(self, shelved_offload_time, mock_notify,
mock_notify_instance_usage, mock_get_power_state,
mock_snapshot, mock_power_off, mock_cleanup,
mock_snapshot, mock_power_off,
clean_shutdown=True):
mock_get_power_state.return_value = 123

Expand Down Expand Up @@ -103,7 +102,12 @@ def check_save(expected_task_state=None):
else:
self.fail('Unexpected save!')

with mock.patch.object(instance, 'save') as mock_save:
with test.nested(
mock.patch.object(instance, 'save'),
mock.patch.object(self.compute.network_api,
'cleanup_instance_network_on_host')) as (
mock_save, mock_cleanup
):
mock_save.side_effect = check_save
self.compute.shelve_instance(self.context, instance,
image_id=image_id,
Expand Down

0 comments on commit 73f5b1f

Please sign in to comment.