예제 #1
0
        def zone_checking_and_unlinking():
            ret = ('Zone does not exist: /usr/share/lib/zoneinfo/timezone')
            mock_exists = MagicMock(side_effect=[False, True, True])
            with patch.object(os.path, 'exists', mock_exists):
                self.assertEqual(timezone.set_zone('timezone'), ret)

                with patch.object(os, 'unlink', return_value=None):
                    with patch.dict(timezone.__salt__,
                                    {'file.sed':
                                     MagicMock(return_value=None)}):
                        self.assertTrue(timezone.set_zone('timezone'))
예제 #2
0
        def zone_checking_and_unlinking():
            ret = ('Zone does not exist: /usr/share/lib/zoneinfo/timezone')
            mock = MagicMock(side_effect=[False, True, True])
            with patch.object(os.path, 'exists', mock):
                self.assertEqual(timezone.set_zone('timezone'), ret)

                with patch.object(os, 'unlink', return_value=None):
                    with patch.dict(
                            timezone.__salt__,
                        {'file.sed': MagicMock(return_value=None)}):
                        self.assertTrue(timezone.set_zone('timezone'))
예제 #3
0
    def test_set_zone(self):
        '''
        Test to unlinks, then symlinks /etc/localtime to the set timezone.
        '''
        ret = ('Zone does not exist: /usr/share/lib/zoneinfo/timezone')
        mock = MagicMock(side_effect=[False, True, True])
        with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}):
            with patch.object(os.path, 'exists', mock):
                self.assertEqual(timezone.set_zone('timezone'), ret)

                with patch.object(os, 'unlink', return_value=None):
                    with patch.dict(
                            timezone.__salt__,
                        {'file.sed': MagicMock(return_value=None)}):
                        self.assertTrue(timezone.set_zone('timezone'))
예제 #4
0
 def test_set_zone_os_family_allbsd_slackware(self):
     """
     Test zone set on *BSD and Slackware
     :return:
     """
     for osfamily in ["FreeBSD", "OpenBSD", "NetBSD", "Slackware"]:
         with patch.dict(timezone.__grains__, {"os_family": osfamily}):
             assert timezone.set_zone(self.TEST_TZ)
예제 #5
0
 def test_set_zone_redhat(self):
     '''
     Test zone set on RH series
     :return:
     '''
     with patch.dict(timezone.__grains__, {'os_family': ['RedHat']}):
         assert timezone.set_zone(self.TEST_TZ)
         name, args, kwargs = timezone.__salt__['file.sed'].mock_calls[0]
         assert args == ('/etc/sysconfig/clock', '^ZONE=.*', 'ZONE="UTC"')
예제 #6
0
 def test_set_zone_suse(self):
     '''
     Test zone set on SUSE series
     :return:
     '''
     timezone.__grains__['os_family'] = ['Suse']
     assert timezone.set_zone(self.TEST_TZ)
     name, args, kwargs = timezone.__salt__['file.sed'].mock_calls[0]
     assert args == ('/etc/sysconfig/clock', '^TIMEZONE=.*', 'TIMEZONE="UTC"')
예제 #7
0
 def test_set_zone_redhat(self):
     """
     Test zone set on RH series
     :return:
     """
     with patch.dict(timezone.__grains__, {"os_family": ["RedHat"]}):
         assert timezone.set_zone(self.TEST_TZ)
         name, args, kwargs = timezone.__salt__["file.sed"].mock_calls[0]
         assert args == ("/etc/sysconfig/clock", "^ZONE=.*", 'ZONE="UTC"')
예제 #8
0
 def test_set_zone_os_family_nilinuxrt(self):
     """
     Test zone set on NILinuxRT
     :return:
     """
     with patch.dict(timezone.__grains__,
                     {"os_family": ["NILinuxRT"]}), patch.dict(
                         timezone.__grains__, {"lsb_distrib_id": "nilrt"}):
         assert timezone.set_zone(self.TEST_TZ)
예제 #9
0
 def test_set_zone_debian(self):
     """
     Test zone set on Debian series
     :return:
     """
     with patch.dict(timezone.__grains__, {"os_family": ["Debian"]}):
         with patch("salt.utils.files.fopen", mock_open()) as m_open:
             assert timezone.set_zone(self.TEST_TZ)
             fh_ = m_open.filehandles["/etc/timezone"][0]
             assert fh_.call.args == ("/etc/timezone", "w"), fh_.call.args
             assert fh_.write_calls == ["UTC", "\n"], fh_.write_calls
예제 #10
0
 def test_set_zone_debian(self):
     '''
     Test zone set on Debian series
     :return:
     '''
     with patch.dict(timezone.__grains__, {'os_family': ['Debian']}):
         with patch('salt.utils.files.fopen', mock_open()) as m_open:
             assert timezone.set_zone(self.TEST_TZ)
             fh_ = m_open.filehandles['/etc/timezone'][0]
             assert fh_.call.args == ('/etc/timezone', 'w'), fh_.call.args
             assert fh_.write_calls == ['UTC', '\n'], fh_.write_calls
예제 #11
0
 def test_set_zone_debian(self):
     '''
     Test zone set on Debian series
     :return:
     '''
     with patch.dict(timezone.__grains__, {'os_family': ['Debian']}):
         _fopen = mock_open()
         with patch('salt.utils.fopen', _fopen):
             assert timezone.set_zone(self.TEST_TZ)
             name, args, kwargs = _fopen.mock_calls[0]
             assert args == ('/etc/timezone', 'w')
             name, args, kwargs = _fopen.return_value.__enter__.return_value.write.mock_calls[0]
             assert args == ('UTC',)
예제 #12
0
 def test_set_zone_debian(self):
     '''
     Test zone set on Debian series
     :return:
     '''
     timezone.__grains__['os_family'] = ['Debian']
     _fopen = MagicMock(return_value=MagicMock(spec=file))
     with patch('salt.utils.fopen', _fopen):
         assert timezone.set_zone(self.TEST_TZ)
         name, args, kwargs = _fopen.mock_calls[0]
         assert args == ('/etc/timezone', 'w')
         name, args, kwargs = _fopen.return_value.__enter__.return_value.write.mock_calls[0]
         assert args == ('UTC',)
예제 #13
0
 def test_set_zone_gentoo(self):
     '''
     Test zone set on Gentoo series
     :return:
     '''
     with patch.dict(timezone.__grains__, {'os_family': ['Gentoo']}):
         _fopen = MagicMock(return_value=MagicMock(spec=file))
         with patch('salt.utils.fopen', _fopen):
             assert timezone.set_zone(self.TEST_TZ)
             name, args, kwargs = _fopen.mock_calls[0]
             assert args == ('/etc/timezone', 'w')
             name, args, kwargs = _fopen.return_value.__enter__.return_value.write.mock_calls[
                 0]
             assert args == ('UTC', )