def test_get_hwclock_timedate_utc(self): ''' Test get hwclock UTC/localtime :return: ''' with patch('salt.modules.timezone._timedatectl', MagicMock(return_value={'stdout': 'rtc in local tz'})): assert timezone.get_hwclock() == 'UTC' with patch('salt.modules.timezone._timedatectl', MagicMock(return_value={'stdout': 'rtc in local tz:yes'})): assert timezone.get_hwclock() == 'localtime'
def test_get_hwclock_suse(self): ''' Test get hwclock on SUSE :return: ''' timezone.__grains__['os_family'] = ['Suse'] timezone.get_hwclock() name, args, kwarg = timezone.__salt__['cmd.run'].mock_calls[0] assert args == (['tail', '-n', '1', '/etc/adjtime'],) assert kwarg == {'python_shell': False}
def test_get_hwclock_redhat(self): ''' Test get hwclock on RedHat :return: ''' with patch.dict(timezone.__grains__, {'os_family': ['RedHat']}): timezone.get_hwclock() name, args, kwarg = timezone.__salt__['cmd.run'].mock_calls[0] assert args == (['tail', '-n', '1', '/etc/adjtime'], ) assert kwarg == {'python_shell': False}
def test_get_hwclock_solaris(self): """ Test get hwclock on Solaris :return: """ # Incomplete with patch.dict(timezone.__grains__, {"os_family": ["Solaris"]}): assert timezone.get_hwclock() == "UTC" with patch("salt.utils.files.fopen", mock_open()): assert timezone.get_hwclock() == "localtime"
def test_get_hwclock_solaris(self): ''' Test get hwclock on Solaris :return: ''' # Incomplete with patch.dict(timezone.__grains__, {'os_family': ['Solaris']}): assert timezone.get_hwclock() == 'UTC' with patch('salt.utils.files.fopen', mock_open()): assert timezone.get_hwclock() == 'localtime'
def test_get_hwclock_redhat(self): """ Test get hwclock on RedHat :return: """ with patch.dict(timezone.__grains__, {"os_family": ["RedHat"]}): timezone.get_hwclock() name, args, kwarg = timezone.__salt__["cmd.run"].mock_calls[0] assert args == (["tail", "-n", "1", "/etc/adjtime"], ) assert kwarg == {"python_shell": False}
def test_get_hwclock_solaris(self): ''' Test get hwclock on Solaris :return: ''' # Incomplete timezone.__grains__['os_family'] = ['Solaris'] assert timezone.get_hwclock() == 'UTC' _fopen = MagicMock(return_value=MagicMock(spec=file)) with patch('salt.utils.fopen', _fopen): assert timezone.get_hwclock() == 'localtime'
def test_get_hwclock_slackware_without_adjtime(self): """ Test get hwclock on Slackware without /etc/adjtime present :return: """ with patch.dict(timezone.__grains__, {"os_family": ["Slackware"]}): with patch("salt.utils.files.fopen", mock_open(read_data="UTC")): assert timezone.get_hwclock() == "UTC" with patch("salt.utils.files.fopen", mock_open(read_data="localtime")): assert timezone.get_hwclock() == "localtime"
def _test_get_hwclock_debian(self): # TODO: Enable this when testing environment is working properly ''' Test get hwclock on Debian :return: ''' with patch('salt.utils.which', MagicMock(return_value=False)): with patch('os.path.exists', MagicMock(return_value=True)): with patch('os.unlink', MagicMock()): with patch('os.symlink', MagicMock()): with patch.dict(timezone.__grains__, {'os_family': ['Debian']}): timezone.get_hwclock() name, args, kwarg = timezone.__salt__['cmd.run'].mock_calls[0] assert args == (['tail', '-n', '1', '/etc/adjtime'],) assert kwarg == {'python_shell': False}
def test_get_hwclock_timedate_utc(self): """ Test get hwclock UTC/localtime :return: """ with patch( "salt.modules.timezone._timedatectl", MagicMock(return_value={"stdout": "rtc in local tz"}), ): assert timezone.get_hwclock() == "UTC" with patch( "salt.modules.timezone._timedatectl", MagicMock(return_value={"stdout": "rtc in local tz:yes"}), ): assert timezone.get_hwclock() == "localtime"
def test_get_hwclock_aix(self): ''' Test get hwclock on AIX :return: ''' # Incomplete timezone.__grains__['os_family'] = ['AIX'] assert timezone.get_hwclock() == 'localtime'
def test_get_hwclock_aix(self): ''' Test get hwclock on AIX :return: ''' # Incomplete with patch.dict(timezone.__grains__, {'os_family': ['AIX']}): assert timezone.get_hwclock() == 'localtime'
def test_get_hwclock_aix(self): ''' Test get hwclock on AIX :return: ''' # Incomplete hwclock = 'localtime' if not os.path.isfile('/etc/environment'): hwclock = 'UTC' with patch.dict(timezone.__grains__, {'os_family': ['AIX']}): assert timezone.get_hwclock() == hwclock
def _test_get_hwclock_debian( self, ): # TODO: Enable this when testing environment is working properly """ Test get hwclock on Debian :return: """ with patch("salt.utils.path.which", MagicMock(return_value=False)): with patch("os.path.exists", MagicMock(return_value=True)): with patch("os.unlink", MagicMock()): with patch("os.symlink", MagicMock()): with patch.dict(timezone.__grains__, {"os_family": ["Debian"]}): timezone.get_hwclock() name, args, kwarg = timezone.__salt__[ "cmd.run"].mock_calls[0] assert args == ([ "tail", "-n", "1", "/etc/adjtime" ], ) assert kwarg == {"python_shell": False}
def test_get_hwclock_aix(self): """ Test get hwclock on AIX :return: """ # Incomplete hwclock = "localtime" if not os.path.isfile("/etc/environment"): hwclock = "UTC" with patch.dict(timezone.__grains__, {"os_family": ["AIX"]}): assert timezone.get_hwclock() == hwclock
def test_get_hwclock(self): ''' Test to get current hardware clock setting (UTC or localtime) ''' with patch.object(salt.utils, 'which', return_value=True): with patch.dict( timezone.__salt__, {'cmd.run': MagicMock(return_value='rtc in local tz:yes\n')}): self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.dict( timezone.__salt__, {'cmd.run': MagicMock(return_value='rtc in local tz:No\n')}): self.assertEqual(timezone.get_hwclock(), 'UTC') with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='rtc')}): self.assertRaises(CommandExecutionError, timezone.get_hwclock) with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'RedHat'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(timezone.get_hwclock(), 'A') with patch.dict(timezone.__grains__, {'os_family': 'Suse'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(timezone.get_hwclock(), 'A') with patch.dict(timezone.__grains__, {'os_family': 'Debian'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A=yes')}): self.assertEqual(timezone.get_hwclock(), 'UTC') with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A=no')}): self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(timezone.get_hwclock(), 'A') with patch.dict(timezone.__grains__, {'os_family': 'Gentoo'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A=B')}): self.assertEqual(timezone.get_hwclock(), 'B') mock = MagicMock(return_value=True) with patch.object(os.path, 'isfile', mock): fl_data = 'zone_info=GMT' with patch('salt.utils.fopen', mock_open(read_data=fl_data), create=True) as mfile: mfile.return_value.__iter__.return_value = fl_data.splitlines() with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): self.assertEqual(timezone.get_hwclock(), 'UTC') mock = MagicMock(return_value=True) with patch.object(os.path, 'isfile', mock): fl_data = 'A=GMT' with patch('salt.utils.fopen', mock_open(read_data=fl_data), create=True) as mfile: mfile.return_value.__iter__.return_value = fl_data.splitlines() with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): mock = MagicMock(return_value=False) with patch.object(os.path, 'isfile', mock): self.assertEqual(timezone.get_hwclock(), 'UTC')
def test_get_hwclock(self): ''' Test to get current hardware clock setting (UTC or localtime) ''' mock_t = MagicMock(return_value=True) mock_f = MagicMock(return_value=False) with patch.object(salt.utils, 'which', return_value=True): with patch.object(timezone, '_timedatectl', MagicMock(return_value={'stdout': 'rtc in local tz:yes\n'})): self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.object(timezone, '_timedatectl', MagicMock(return_value={'stdout': 'rtc in local tz:No\n'})): self.assertEqual(timezone.get_hwclock(), 'UTC') with patch.object(timezone, '_timedatectl', MagicMock(return_value={'stdout': 'rtc'})): self.assertRaises(CommandExecutionError, timezone.get_hwclock) with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'RedHat'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(timezone.get_hwclock(), 'A') with patch.dict(timezone.__grains__, {'os_family': 'Suse'}): with patch.dict(timezone.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(timezone.get_hwclock(), 'A') with patch.dict(timezone.__grains__, {'os_family': 'Debian'}): fl_data = 'UTC=yes\n' with patch('salt.utils.fopen', mock_open(read_data=fl_data)) as mfile: mfile.return_value.__iter__.return_value = [fl_data] self.assertEqual(timezone.get_hwclock(), 'UTC') fl_data = 'UTC=no\n' with patch('salt.utils.fopen', mock_open(read_data=fl_data)) as mfile: mfile.return_value.__iter__.return_value = [fl_data] self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.dict(timezone.__grains__, {'os_family': 'Gentoo'}): fl_data = 'clock=UTC\n' with patch('salt.utils.fopen', mock_open(read_data=fl_data)) as mfile: mfile.return_value.__iter__.return_value = [fl_data] self.assertEqual(timezone.get_hwclock(), 'UTC') with patch.object(os.path, 'isfile', mock_t): fl_data = 'zone_info=GMT' with patch('salt.utils.fopen', mock_open(read_data=fl_data), create=True) as mfile: mfile.return_value.__iter__.return_value = fl_data.splitlines() with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): self.assertEqual(timezone.get_hwclock(), 'UTC') with patch.object(os.path, 'isfile', mock_t): fl_data = 'A=GMT' with patch('salt.utils.fopen', mock_open(read_data=fl_data), create=True) as mfile: mfile.return_value.__iter__.return_value = fl_data.splitlines() with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): self.assertEqual(timezone.get_hwclock(), 'localtime') with patch.object(salt.utils, 'which', return_value=False): with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}): with patch.object(os.path, 'isfile', mock_f): self.assertEqual(timezone.get_hwclock(), 'UTC')