Replace mox with mock in novaclient and compute
Replace mox with mock in tests.test_novaclient and tests.compute.test_manager. Change-Id: Ic01fe3fd7510312e1930e87306ccc352d443fb35
This commit is contained in:
parent
fe158993bb
commit
b6636897b1
@ -21,7 +21,7 @@ import mock
|
|||||||
|
|
||||||
from ceilometer.compute import manager
|
from ceilometer.compute import manager
|
||||||
from ceilometer import nova_client
|
from ceilometer import nova_client
|
||||||
from ceilometer.openstack.common.fixture import moxstubout
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
from ceilometer.tests import agentbase
|
from ceilometer.tests import agentbase
|
||||||
|
|
||||||
@ -57,9 +57,14 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
|
|||||||
# of instances to poll we can control the results.
|
# of instances to poll we can control the results.
|
||||||
self.instance = self._fake_instance('faux', 'active')
|
self.instance = self._fake_instance('faux', 'active')
|
||||||
stillborn_instance = self._fake_instance('stillborn', 'error')
|
stillborn_instance = self._fake_instance('stillborn', 'error')
|
||||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
|
||||||
self.stubs.Set(nova_client.Client, 'instance_get_all_by_host',
|
def instance_get_all_by_host(*args):
|
||||||
lambda *x: [self.instance, stillborn_instance])
|
return [self.instance, stillborn_instance]
|
||||||
|
|
||||||
|
self.useFixture(mockpatch.PatchObject(
|
||||||
|
nova_client.Client,
|
||||||
|
'instance_get_all_by_host',
|
||||||
|
side_effect=lambda *x: [self.instance, stillborn_instance]))
|
||||||
|
|
||||||
def test_notifier_task(self):
|
def test_notifier_task(self):
|
||||||
self.mgr.setup_notifier_task()
|
self.mgr.setup_notifier_task()
|
||||||
@ -79,8 +84,8 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
|
|||||||
|
|
||||||
def test_manager_exception_persistency(self):
|
def test_manager_exception_persistency(self):
|
||||||
super(TestRunTasks, self).test_manager_exception_persistency()
|
super(TestRunTasks, self).test_manager_exception_persistency()
|
||||||
self.stubs.Set(nova_client.Client, 'instance_get_all_by_host',
|
with mock.patch.object(nova_client.Client, 'instance_get_all_by_host',
|
||||||
lambda *x: self._raise_exception())
|
side_effect=lambda *x: self._raise_exception()):
|
||||||
mgr = manager.AgentManager()
|
mgr = manager.AgentManager()
|
||||||
polling_task = manager.PollingTask(mgr)
|
polling_task = manager.PollingTask(mgr)
|
||||||
polling_task.poll_and_publish()
|
polling_task.poll_and_publish()
|
||||||
|
@ -18,10 +18,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from mock import patch
|
||||||
import novaclient
|
import novaclient
|
||||||
|
|
||||||
from ceilometer import nova_client
|
from ceilometer import nova_client
|
||||||
from ceilometer.openstack.common.fixture import moxstubout
|
from ceilometer.openstack.common.fixture import mockpatch
|
||||||
from ceilometer.openstack.common import test
|
from ceilometer.openstack.common import test
|
||||||
|
|
||||||
|
|
||||||
@ -30,10 +31,12 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestNovaClient, self).setUp()
|
super(TestNovaClient, self).setUp()
|
||||||
self.nv = nova_client.Client()
|
self.nv = nova_client.Client()
|
||||||
self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
|
self.useFixture(mockpatch.PatchObject(
|
||||||
self.stubs.Set(self.nv.nova_client.flavors, 'get',
|
self.nv.nova_client.flavors, 'get',
|
||||||
self.fake_flavors_get)
|
side_effect=self.fake_flavors_get))
|
||||||
self.stubs.Set(self.nv.nova_client.images, 'get', self.fake_images_get)
|
self.useFixture(mockpatch.PatchObject(
|
||||||
|
self.nv.nova_client.images, 'get',
|
||||||
|
side_effect=self.fake_images_get))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fake_flavors_get(*args, **kwargs):
|
def fake_flavors_get(*args, **kwargs):
|
||||||
@ -87,10 +90,10 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host(self):
|
def test_instance_get_all_by_host(self):
|
||||||
self.stubs.Set(self.nv.nova_client.servers, 'list',
|
with patch.object(self.nv.nova_client.servers, 'list',
|
||||||
self.fake_servers_list)
|
side_effect=self.fake_servers_list):
|
||||||
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
|
||||||
self.assertEqual(len(instances), 1)
|
self.assertEqual(len(instances), 1)
|
||||||
self.assertEqual(instances[0].flavor['name'], 'm1.tiny')
|
self.assertEqual(instances[0].flavor['name'], 'm1.tiny')
|
||||||
self.assertEqual(instances[0].image['name'], 'ubuntu-12.04-x86')
|
self.assertEqual(instances[0].image['name'], 'ubuntu-12.04-x86')
|
||||||
@ -106,10 +109,10 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host_unknown_flavor(self):
|
def test_instance_get_all_by_host_unknown_flavor(self):
|
||||||
self.stubs.Set(self.nv.nova_client.servers, 'list',
|
with patch.object(self.nv.nova_client.servers, 'list',
|
||||||
self.fake_servers_list_unknown_flavor)
|
side_effect=self.fake_servers_list_unknown_flavor):
|
||||||
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
|
||||||
self.assertEqual(len(instances), 1)
|
self.assertEqual(len(instances), 1)
|
||||||
self.assertEqual(instances[0].flavor['name'], 'unknown-id-666')
|
self.assertEqual(instances[0].flavor['name'], 'unknown-id-666')
|
||||||
|
|
||||||
@ -130,10 +133,10 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host_unknown_image(self):
|
def test_instance_get_all_by_host_unknown_image(self):
|
||||||
self.stubs.Set(self.nv.nova_client.servers, 'list',
|
with patch.object(self.nv.nova_client.servers, 'list',
|
||||||
self.fake_servers_list_unknown_image)
|
side_effect=self.fake_servers_list_unknown_image):
|
||||||
|
instances = self.nv.instance_get_all_by_host('foobar')
|
||||||
|
|
||||||
instances = self.nv.instance_get_all_by_host('foobar')
|
|
||||||
self.assertEqual(len(instances), 1)
|
self.assertEqual(len(instances), 1)
|
||||||
self.assertEqual(instances[0].image['name'], 'unknown-id-666')
|
self.assertEqual(instances[0].image['name'], 'unknown-id-666')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user