예제 #1
0
    def test_status(self):
        '''
            Test to display puppet agent status
        '''
        mock_lst = MagicMock(return_value=[])
        with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
            mock = MagicMock(return_value=True)
            with patch.object(puppet, '_check_puppet', mock):
                mock = MagicMock(side_effect=[True])
                with patch.object(os.path, 'isfile', mock):
                    self.assertEqual(puppet.status(),
                                     "Administratively disabled")

                mock = MagicMock(side_effect=[False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open(read_data="1")):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(),
                                             "Applying a catalog")

                mock = MagicMock(side_effect=[False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open()):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Stale lockfile")

                mock = MagicMock(side_effect=[False, False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open(read_data="1")):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Idle daemon")

                mock = MagicMock(side_effect=[False, False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open()):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Stale pidfile")

                mock = MagicMock(side_effect=[False, False, False])
                with patch.object(os.path, 'isfile', mock):
                    self.assertEqual(puppet.status(), "Stopped")
예제 #2
0
파일: puppet_test.py 프로젝트: DaveQB/salt
    def test_status(self):
        '''
            Test to display puppet agent status
        '''
        mock_lst = MagicMock(return_value=[])
        with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
            mock = MagicMock(return_value=True)
            with patch.object(puppet, '_check_puppet', mock):
                mock = MagicMock(side_effect=[True])
                with patch.object(os.path, 'isfile', mock):
                    self.assertEqual(puppet.status(),
                                     "Administratively disabled")

                mock = MagicMock(side_effect=[False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open(read_data="1")):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(),
                                             "Applying a catalog")

                mock = MagicMock(side_effect=[False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open()):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Stale lockfile")

                mock = MagicMock(side_effect=[False, False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open(read_data="1")):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Idle daemon")

                mock = MagicMock(side_effect=[False, False, True])
                with patch.object(os.path, 'isfile', mock):
                    with patch('salt.utils.fopen', mock_open()):
                        mock = MagicMock(return_value=True)
                        with patch.object(os, 'kill', mock):
                            self.assertEqual(puppet.status(), "Stale pidfile")

                mock = MagicMock(side_effect=[False, False, False])
                with patch.object(os.path, 'isfile', mock):
                    self.assertEqual(puppet.status(), "Stopped")
예제 #3
0
def test_status():
    """
    Test to display puppet agent status
    """
    mock_lst = MagicMock(return_value=[])
    with patch.dict(puppet.__salt__, {"cmd.run": mock_lst}):
        mock = MagicMock(side_effect=[True])
        with patch.object(os.path, "isfile", mock):
            assert puppet.status() == "Administratively disabled"

        mock = MagicMock(side_effect=[False, True])
        with patch.object(os.path, "isfile", mock):
            with patch("salt.utils.files.fopen", mock_open(read_data="1")):
                mock = MagicMock(return_value=True)
                with patch.object(os, "kill", mock):
                    assert puppet.status() == "Applying a catalog"

        mock = MagicMock(side_effect=[False, True])
        with patch.object(os.path, "isfile", mock):
            with patch("salt.utils.files.fopen", mock_open()):
                mock = MagicMock(return_value=True)
                with patch.object(os, "kill", mock):
                    assert puppet.status() == "Stale lockfile"

        mock = MagicMock(side_effect=[False, False, True])
        with patch.object(os.path, "isfile", mock):
            with patch("salt.utils.files.fopen", mock_open(read_data="1")):
                mock = MagicMock(return_value=True)
                with patch.object(os, "kill", mock):
                    assert puppet.status() == "Idle daemon"

        mock = MagicMock(side_effect=[False, False, True])
        with patch.object(os.path, "isfile", mock):
            with patch("salt.utils.files.fopen", mock_open()):
                mock = MagicMock(return_value=True)
                with patch.object(os, "kill", mock):
                    assert puppet.status() == "Stale pidfile"

        mock = MagicMock(side_effect=[False, False, False])
        with patch.object(os.path, "isfile", mock):
            assert puppet.status() == "Stopped"