Example #1
0
    def _test_sys_uptime(self, is_nt_os=False):
        expect_uptime = ("fake_time up 0:00:00,  0 users,  "
                         "load average: 0, 0, 0")
        fake_tick_count = 0
        fake_time = 'fake_time'

        with mock.patch.multiple(hostutils, os=mock.DEFAULT, time=mock.DEFAULT,
                                 ctypes=mock.DEFAULT, utils=mock.DEFAULT,
                                 create=True) as lib_mocks:

            lib_mocks['os'].name = 'nt' if is_nt_os else ''
            lib_mocks['time'].strftime.return_value = fake_time
            lib_mocks['utils'].execute.return_value = (expect_uptime, None)
            tick_count = lib_mocks['ctypes'].windll.kernel32.GetTickCount64
            tick_count.return_value = fake_tick_count

            uptime = hostutils.sys_uptime()

            if is_nt_os:
                tick_count.assert_called_once_with()
                lib_mocks['time'].strftime.assert_called_once_with("%H:%M:%S")
            else:
                lib_mocks['utils'].execute.assert_called_once_with(
                    'env', 'LANG=C', 'uptime')

        self.assertEqual(expect_uptime, uptime)
Example #2
0
    def _test_sys_uptime(self, is_nt_os=False):
        expect_uptime = ("fake_time up 0:00:00,  0 users,  "
                         "load average: 0, 0, 0")
        fake_tick_count = 0
        fake_time = 'fake_time'

        with mock.patch.multiple(hostutils,
                                 os=mock.DEFAULT,
                                 time=mock.DEFAULT,
                                 ctypes=mock.DEFAULT,
                                 utils=mock.DEFAULT,
                                 create=True) as lib_mocks:

            lib_mocks['os'].name = 'nt' if is_nt_os else ''
            lib_mocks['time'].strftime.return_value = fake_time
            lib_mocks['utils'].execute.return_value = (expect_uptime, None)
            tick_count = lib_mocks['ctypes'].windll.kernel32.GetTickCount64
            tick_count.return_value = fake_tick_count

            uptime = hostutils.sys_uptime()

            if is_nt_os:
                tick_count.assert_called_once_with()
                lib_mocks['time'].strftime.assert_called_once_with("%H:%M:%S")
            else:
                lib_mocks['utils'].execute.assert_called_once_with(
                    'env', 'LANG=C', 'uptime')

        self.assertEqual(expect_uptime, uptime)
Example #3
0
 def get_host_uptime(self, host):
     return hostutils.sys_uptime()
Example #4
0
 def get_host_uptime(self):
     return hostutils.sys_uptime()
 def test_sys_uptime(self):
     expect_uptime = "this is my uptime"
     with mock.patch('nova.utils.execute',
                     return_value=(expect_uptime, None)):
         uptime = hostutils.sys_uptime()
         self.assertEqual(expect_uptime, uptime)