From 6222385d837f90f769c94f21d003999741c4f800 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Fri, 29 Jun 2012 17:17:04 -0500 Subject: Get hypervisor uptime. Adds a call to retrieve the current uptime on a specific hypervisor. This version of the patch only adds the XenAPI variant; other virt drivers will raise a NotImplementedError until they implement the get_host_uptime() method. Change-Id: Ie259589757a460fcd91a49a8dd8099e4d91524e7 --- .../openstack/compute/contrib/test_hypervisors.py | 41 ++++++++++++++++++++++ nova/tests/compute/test_compute.py | 13 +++++++ nova/tests/compute/test_rpcapi.py | 3 ++ nova/tests/test_virt_drivers.py | 4 +++ nova/tests/test_xenapi.py | 4 +++ 5 files changed, 65 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py index b00497ecc..6a9a1fc25 100644 --- a/nova/tests/api/openstack/compute/contrib/test_hypervisors.py +++ b/nova/tests/api/openstack/compute/contrib/test_hypervisors.py @@ -231,6 +231,36 @@ class HypervisorsTest(test.TestCase): cpu_info='cpu_info', disk_available_least=100))) + def test_uptime_noid(self): + req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/3') + self.assertRaises(exc.HTTPNotFound, self.controller.show, req, '3') + + def test_uptime_notimplemented(self): + def fake_get_host_uptime(context, hyp): + raise exc.HTTPNotImplemented() + + self.stubs.Set(self.controller.api, 'get_host_uptime', + fake_get_host_uptime) + + req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/1') + self.assertRaises(exc.HTTPNotImplemented, + self.controller.uptime, req, '1') + + def test_uptime_implemented(self): + def fake_get_host_uptime(context, hyp): + return "fake uptime" + + self.stubs.Set(self.controller.api, 'get_host_uptime', + fake_get_host_uptime) + + req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/1') + result = self.controller.uptime(req, '1') + + self.assertEqual(result, dict(hypervisor=dict( + id=1, + hypervisor_hostname="hyper1", + uptime="fake uptime"))) + def test_search(self): req = fakes.HTTPRequest.blank('/v2/fake/os-hypervisors/hyper/search') result = self.controller.search(req, 'hyper') @@ -374,6 +404,17 @@ class HypervisorsSerializersTest(test.TestCase): self.compare_to_exemplar(exemplar['hypervisor'], tree) + def test_uptime_serializer(self): + serializer = hypervisors.HypervisorUptimeTemplate() + exemplar = dict(hypervisor=dict( + hypervisor_hostname="hyper1", + id=1, + uptime='fake uptime')) + text = serializer.serialize(exemplar) + tree = etree.fromstring(text) + + self.compare_to_exemplar(exemplar['hypervisor'], tree) + def test_servers_serializer(self): serializer = hypervisors.HypervisorServersTemplate() exemplar = dict(hypervisors=[ diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index bf4a20cf3..a7307cd1c 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -4057,6 +4057,19 @@ class ComputeHostAPITestCase(BaseTestCase): 'args': {'enabled': 'fake_enabled'}, 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}) + def test_get_host_uptime(self): + ctxt = context.RequestContext('fake', 'fake') + call_info = {} + self._rpc_call_stub(call_info) + + self.host_api.get_host_uptime(ctxt, 'fake_host') + self.assertEqual(call_info['context'], ctxt) + self.assertEqual(call_info['topic'], 'compute.fake_host') + self.assertEqual(call_info['msg'], + {'method': 'get_host_uptime', + 'args': {}, + 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}) + def test_host_power_action(self): ctxt = context.RequestContext('fake', 'fake') call_info = {} diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py index 37427477f..4f606c7b5 100644 --- a/nova/tests/compute/test_rpcapi.py +++ b/nova/tests/compute/test_rpcapi.py @@ -281,6 +281,9 @@ class ComputeRpcAPITestCase(test.TestCase): self._test_compute_api('set_host_enabled', 'call', enabled='enabled', host='host') + def test_get_host_uptime(self): + self._test_compute_api('get_host_uptime', 'call', host='host') + def test_snapshot_instance(self): self._test_compute_api('snapshot_instance', 'cast', instance=self.fake_instance, image_id='id', image_type='type', diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 6443c6721..c15061f48 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -516,6 +516,10 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): def test_set_host_enabled(self): self.connection.set_host_enabled('a useless argument?', True) + @catch_notimplementederror + def test_get_host_uptime(self): + self.connection.get_host_uptime('a useless argument?') + @catch_notimplementederror def test_host_power_action_reboot(self): self.connection.host_power_action('a useless argument?', 'reboot') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index c4b3262f5..dd480f347 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -1174,6 +1174,10 @@ class XenAPIHostTestCase(test.TestCase): def test_set_enable_host_disable(self): self._test_host_action(self.conn.set_host_enabled, False, 'disabled') + def test_get_host_uptime(self): + result = self.conn.get_host_uptime('host') + self.assertEqual(result, 'fake uptime') + class XenAPIAutoDiskConfigTestCase(test.TestCase): def setUp(self): -- cgit