diff options
author | Sagar Ratnakara Nikam <nikam@hp.com> | 2014-07-02 20:21:24 +0530 |
---|---|---|
committer | Sagar Ratnakara Nikam <nikam@hp.com> | 2014-08-20 17:09:58 +0530 |
commit | a41543820a8f0686612213b12ab07cf70b3d997f (patch) | |
tree | 18a8a21791eb61ffc3fa9e881f45cbcf1bf4068b /nova/tests/virt/hyperv | |
parent | 7aea056a4016603281cee58222cb728d0cf29ac3 (diff) | |
download | nova-a41543820a8f0686612213b12ab07cf70b3d997f.tar.gz |
HyperV Driver - Fix to implement hypervisor-uptime
The hyperv driver currently does not return the hypervisor-uptime.
This fix does the necessary changes to return the hypervisor-uptime.
The uptime returned is in similar format to libvirt driver uptime
The uptime is calculated using the windows function GetTickCount64
More details about this function available at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724411%28v=vs.85%29.aspx
The function GetTickCount64 returns in millisecs the time since the host
is up.
Change-Id: Ib3cd90b17f64e369badaddb764ac9e6b9f6c1a4b
Closes-Bug: #1335559
Diffstat (limited to 'nova/tests/virt/hyperv')
-rw-r--r-- | nova/tests/virt/hyperv/test_hostutils.py | 34 | ||||
-rw-r--r-- | nova/tests/virt/hyperv/test_hypervapi.py | 30 |
2 files changed, 64 insertions, 0 deletions
diff --git a/nova/tests/virt/hyperv/test_hostutils.py b/nova/tests/virt/hyperv/test_hostutils.py new file mode 100644 index 0000000000..9deeb816a7 --- /dev/null +++ b/nova/tests/virt/hyperv/test_hostutils.py @@ -0,0 +1,34 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from nova import test +from nova.virt.hyperv import hostutils + + +class HostUtilsTestCase(test.NoDBTestCase): + """Unit tests for the Hyper-V hostutils class.""" + + def setUp(self): + self._hostutils = hostutils.HostUtils() + self._hostutils._conn_cimv2 = mock.MagicMock() + super(HostUtilsTestCase, self).setUp() + + @mock.patch('nova.virt.hyperv.hostutils.ctypes') + def test_get_host_tick_count64(self, mock_ctypes): + tick_count64 = "100" + mock_ctypes.windll.kernel32.GetTickCount64.return_value = tick_count64 + response = self._hostutils.get_host_tick_count64() + self.assertEqual(tick_count64, response) diff --git a/nova/tests/virt/hyperv/test_hypervapi.py b/nova/tests/virt/hyperv/test_hypervapi.py index 99b717e65e..3817d5369a 100644 --- a/nova/tests/virt/hyperv/test_hypervapi.py +++ b/nova/tests/virt/hyperv/test_hypervapi.py @@ -17,6 +17,7 @@ Test suite for the Hyper-V driver and related APIs. """ import contextlib +import datetime import io import os import platform @@ -50,6 +51,7 @@ from nova.virt import driver from nova.virt.hyperv import basevolumeutils from nova.virt.hyperv import constants from nova.virt.hyperv import driver as driver_hyperv +from nova.virt.hyperv import hostops from nova.virt.hyperv import hostutils from nova.virt.hyperv import livemigrationutils from nova.virt.hyperv import networkutils @@ -341,6 +343,13 @@ class HyperVAPITestCase(HyperVAPIBaseTestCase, self.assertEqual(instances, fake_instances) + def test_get_host_uptime(self): + fake_host = "fake_host" + with mock.patch.object(self._conn._hostops, + "get_host_uptime") as mock_uptime: + self._conn._hostops.get_host_uptime(fake_host) + mock_uptime.assert_called_once_with(fake_host) + def test_get_info(self): self._instance_data = self._get_instance_data() @@ -1828,3 +1837,24 @@ class VolumeOpsTestCase(HyperVAPIBaseTestCase): self.assertRaises(vmutils.HyperVException, self.volumeops._get_free_controller_slot, fake_scsi_controller_path) + + +class HostOpsTestCase(HyperVAPIBaseTestCase): + """Unit tests for the Hyper-V hostops class.""" + + def setUp(self): + self._hostops = hostops.HostOps() + self._hostops._hostutils = mock.MagicMock() + self._hostops.time = mock.MagicMock() + super(HostOpsTestCase, self).setUp() + + @mock.patch('nova.virt.hyperv.hostops.time') + def test_host_uptime(self, mock_time): + self._hostops._hostutils.get_host_tick_count64.return_value = 100 + mock_time.strftime.return_value = "01:01:01" + + result_uptime = "01:01:01 up %s, 0 users, load average: 0, 0, 0" % ( + str(datetime.timedelta( + milliseconds = long(100)))) + actual_uptime = self._hostops.get_host_uptime() + self.assertEqual(result_uptime, actual_uptime) |