Exemplo n.º 1
0
    def test_zone_compare_equal(self):
        etc_localtime = self.create_tempfile_with_contents("a")
        zone_path = self.create_tempfile_with_contents("a")

        with patch(GET_ZONE_FILE, lambda p: zone_path.name):
            with patch(GET_LOCALTIME_PATH, lambda: etc_localtime.name):

                self.assertTrue(timezone.zone_compare("foo"))
Exemplo n.º 2
0
    def test_zone_compare_unequal(self):
        etc_localtime = self.create_tempfile_with_contents('a')
        zone_path = self.create_tempfile_with_contents('b')

        with patch(GET_ZONE_FILE, lambda p: zone_path.name):
            with patch(GET_ETC_LOCALTIME_PATH, lambda: etc_localtime.name):

                self.assertFalse(timezone.zone_compare('foo'))
Exemplo n.º 3
0
    def test_zone_compare(self):
        '''
        Test to checks the hash sum between the given timezone, and the
        one set in /etc/localtime.
        '''
        with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}):
            self.assertEqual(timezone.zone_compare('timezone'),
                             'Not implemented for Solaris family')

        with patch.dict(timezone.__grains__, {'os_family': 'Sola'}):
            with patch.object(os.path, 'exists', return_value=False):
                self.assertEqual(timezone.zone_compare('timezone'),
                                 'Error: /etc/localtime does not exist.')

        with patch.object(os.path, 'exists', return_value=True):
            with patch.dict(timezone.__grains__, {'os_family': 'Sola'}):
                with patch.dict(timezone.__opts__, {'hash_type': 'md5'}):
                    with patch.object(salt.utils,
                                      'get_hash',
                                      side_effect=IOError('foo')):
                        self.assertRaises(SaltInvocationError,
                                          timezone.zone_compare, 't')

                    with patch.object(salt.utils,
                                      'get_hash',
                                      side_effect=['A', IOError('foo')]):
                        self.assertRaises(CommandExecutionError,
                                          timezone.zone_compare, 't')

                    with patch.object(salt.utils,
                                      'get_hash',
                                      side_effect=['A', 'A']):
                        self.assertTrue(timezone.zone_compare('timezone'))

                    with patch.object(salt.utils,
                                      'get_hash',
                                      side_effect=['A', 'B']):
                        self.assertFalse(timezone.zone_compare('timezone'))
Exemplo n.º 4
0
    def test_zone_compare(self):
        '''
        Test to checks the hash sum between the given timezone, and the
        one set in /etc/localtime.
        '''
        with patch.object(timezone, 'get_zone', return_value='US/Central'):
            with patch.dict(timezone.__grains__, {'os_family': 'Solaris'}):
                self.assertEqual(timezone.zone_compare('Antarctica/Mawson'),
                                 'Not implemented for Solaris family')

            with patch.object(os.path, 'exists', return_value=False):
                with patch.dict(timezone.__grains__, {'os_family': 'Sola'}):
                    self.assertFalse(timezone.zone_compare('America/New_York'))

                    self.assertEqual(timezone.zone_compare('US/Central'),
                                     'Error: /etc/localtime does not exist.')

            with patch.object(os.path, 'exists', return_value=True):
                with patch.dict(timezone.__grains__, {'os_family': 'Sola'}):
                    self.assertFalse(timezone.zone_compare('America/New_York'))
                    with patch.dict(timezone.__opts__, {'hash_type': 'md5'}):
                        with patch.object(salt.utils, 'get_hash',
                                          side_effect=IOError('foo')):
                            self.assertRaises(SaltInvocationError,
                                              timezone.zone_compare, 'US/Central')

                        with patch.object(salt.utils, 'get_hash',
                                          side_effect=['A', IOError('foo')]):
                            self.assertRaises(CommandExecutionError,
                                              timezone.zone_compare, 'US/Central')

                        with patch.object(salt.utils, 'get_hash',
                                          side_effect=['A', 'A']):
                            self.assertTrue(timezone.zone_compare('US/Central'))

                        with patch.object(salt.utils, 'get_hash',
                                          side_effect=['A', 'B']):
                            self.assertFalse(timezone.zone_compare('US/Central'))