Exemple #1
0
 def test_available(self):
     '''
     Test to check that the given service is available
     '''
     mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])
     with patch.object(systemd, '_systemctl_status', mock):
         self.assertTrue(systemd.available('sshd.service'))
         self.assertFalse(systemd.available('foo.service'))
Exemple #2
0
    def test_available(self):
        '''
            Test to check that the given service is available
        '''
        mock = MagicMock(side_effect=["a", "@", "c"])
        with patch.object(systemd, '_canonical_template_unit_name', mock):
            mock = MagicMock(side_effect=[{"a": "z", "b": "z"},
                                          {"@": "z", "b": "z"},
                                          {"a": "z", "b": "z"}])
            with patch.object(systemd, 'get_all', mock):
                self.assertTrue(systemd.available("sshd"))

                self.assertTrue(systemd.available("sshd"))

                self.assertFalse(systemd.available("sshd"))
Exemple #3
0
    def test_available(self):
        '''
            Test to check that the given service is available
        '''
        mock = MagicMock(side_effect=["a", "@", "c"])
        with patch.object(systemd, '_canonical_template_unit_name', mock):
            mock = MagicMock(side_effect=[{"a": "z", "b": "z"},
                                          {"@": "z", "b": "z"},
                                          {"a": "z", "b": "z"}])
            with patch.object(systemd, 'get_all', mock):
                self.assertTrue(systemd.available("sshd"))

                self.assertTrue(systemd.available("sshd"))

                self.assertFalse(systemd.available("sshd"))
Exemple #4
0
    def test_available(self):
        '''
            Test to check that the given service is available
        '''
        name = 'thing1'

        mock_stdout = MagicMock(return_value=name)
        with patch.dict(systemd.__salt__, {'cmd.run_stdout': mock_stdout}):
            self.assertTrue(systemd.available(name))

        mock_stdout = MagicMock(side_effect=['', ''])
        with patch.dict(systemd.__salt__, {'cmd.run_stdout': mock_stdout}):
            self.assertFalse(systemd.available(name))

        mock_stdout = MagicMock(side_effect=['', name])
        with patch.dict(systemd.__salt__, {'cmd.run_stdout': mock_stdout}):
            self.assertTrue(systemd.available(name))
Exemple #5
0
    def test_available(self):
        '''
        Test to check that the given service is available
        '''
        available = (
            'sshd.service - OpenSSH server daemon\n'
            '   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)\n'
            '   Active: inactive (dead) since Thu 2015-12-17 15:33:06 CST; 19h ago\n'
            ' Main PID: 230 (code=exited, status=0/SUCCESS)\n')
        not_available = (
            'asdf.service\n'
            '   Loaded: not-found (Reason: No such file or directory)\n'
            '   Active: inactive (dead)\n')
        mock_stdout = MagicMock(return_value=available)
        with patch.dict(systemd.__salt__, {'cmd.run': mock_stdout}):
            self.assertTrue(systemd.available('sshd'))

        mock_stdout = MagicMock(return_value=not_available)
        with patch.dict(systemd.__salt__, {'cmd.run': mock_stdout}):
            self.assertFalse(systemd.available('asdf'))
Exemple #6
0
    def test_available(self):
        '''
        Test to check that the given service is available
        '''
        mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])

        # systemd < 231
        with patch.dict(systemd.__context__,
                        {'salt.utils.systemd.version': 230}):
            with patch.object(systemd, '_systemctl_status', mock):
                self.assertTrue(systemd.available('sshd.service'))
                self.assertFalse(systemd.available('foo.service'))

        # systemd >= 231
        with patch.dict(systemd.__context__,
                        {'salt.utils.systemd.version': 231}):
            with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
                with patch.object(systemd, '_systemctl_status', mock):
                    self.assertTrue(systemd.available('sshd.service'))
                    self.assertFalse(systemd.available('bar.service'))

        # systemd < 231 with retcode/output changes backported (e.g. RHEL 7.3)
        with patch.dict(systemd.__context__,
                        {'salt.utils.systemd.version': 219}):
            with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
                with patch.object(systemd, '_systemctl_status', mock):
                    self.assertTrue(systemd.available('sshd.service'))
                    self.assertFalse(systemd.available('bar.service'))
Exemple #7
0
    def test_available(self):
        '''
        Test to check that the given service is available
        '''
        mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])

        # systemd < 231
        with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 230}):
            with patch.object(systemd, '_systemctl_status', mock):
                self.assertTrue(systemd.available('sshd.service'))
                self.assertFalse(systemd.available('foo.service'))

        # systemd >= 231
        with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 231}):
            with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
                with patch.object(systemd, '_systemctl_status', mock):
                    self.assertTrue(systemd.available('sshd.service'))
                    self.assertFalse(systemd.available('bar.service'))

        # systemd < 231 with retcode/output changes backported (e.g. RHEL 7.3)
        with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 219}):
            with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
                with patch.object(systemd, '_systemctl_status', mock):
                    self.assertTrue(systemd.available('sshd.service'))
                    self.assertFalse(systemd.available('bar.service'))
Exemple #8
0
    def test_available(self):
        '''
        Test to check that the given service is available
        '''
        available = (
            'sshd.service - OpenSSH server daemon\n'
            '   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)\n'
            '   Active: inactive (dead) since Thu 2015-12-17 15:33:06 CST; 19h ago\n'
            ' Main PID: 230 (code=exited, status=0/SUCCESS)\n'
        )
        not_available = (
            'asdf.service\n'
            '   Loaded: not-found (Reason: No such file or directory)\n'
            '   Active: inactive (dead)\n'
        )
        mock_stdout = MagicMock(return_value=available)
        with patch.dict(systemd.__salt__, {'cmd.run': mock_stdout}):
            self.assertTrue(systemd.available('sshd'))

        mock_stdout = MagicMock(return_value=not_available)
        with patch.dict(systemd.__salt__, {'cmd.run': mock_stdout}):
            self.assertFalse(systemd.available('asdf'))