def HandleClockSync(self, logger): """Sync the software clock with the hypervisor clock. Args: logger: logger object, used to write to SysLog and serial port. """ helpers.CallNtpdate(logger)
def testCallNtpdateError(self, mock_call, mock_check_call): command_status = ['service', 'ntpd', 'status'] command_ntpdate = 'ntpdate `awk \'$1=="server" {print $2}\' /etc/ntp.conf`' mock_logger = mock.Mock() mock_check_call.side_effect = subprocess.CalledProcessError(1, 'Test') helpers.CallNtpdate(mock_logger) mock_call.assert_called_once_with(command_status) mock_check_call.assert_called_once_with(command_ntpdate, shell=True) expected_calls = [mock.call.warning(mock.ANY)] self.assertEqual(mock_logger.mock_calls, expected_calls)
def testCallNtpdateInactive(self, mock_call, mock_check_call): command_status = ['service', 'ntpd', 'status'] command_ntpdate = 'ntpdate `awk \'$1=="server" {print $2}\' /etc/ntp.conf`' mock_logger = mock.Mock() mock_call.return_value = 1 helpers.CallNtpdate(mock_logger) mock_call.assert_called_once_with(command_status) mock_check_call.assert_called_once_with(command_ntpdate, shell=True) expected_calls = [mock.call.info(mock.ANY)] self.assertEqual(mock_logger.mock_calls, expected_calls)