Exemplo n.º 1
0
def test_start():
    init()
    service = Service("Test_service")
    service.start()
    with patch.object(ansible_module_runner, 'AnsibleRunner', ansible):
        with pytest.raises(ansible_module_runner.AnsibleModuleNotFound):
            ret = service.start()
    with patch.object(ansible_module_runner.AnsibleRunner, 'run', run):
        ret = service.start()
        assert ret[1] is False
    with patch.object(ansible_module_runner.AnsibleRunner, 'run') as mock_run:
        mock_run.return_value = ansible_run(True)
        ret = service.start()
        assert ret[1] is True
        assert ret[0] == "test_msg"
Exemplo n.º 2
0
def test_start():
    init()
    service = Service("Test_service")
    service.start()
    with patch.object(ansible_module_runner, 'AnsibleRunner', ansible):
        with pytest.raises(ansible_module_runner.AnsibleModuleNotFound):
            ret = service.start()
    with patch.object(ansible_module_runner.AnsibleRunner, 'run', run):
        ret = service.start()
        assert ret[1] is False
    with patch.object(ansible_module_runner.AnsibleRunner, 'run') as mock_run:
        mock_run.return_value = ansible_run(True)
        ret = service.start()
        assert ret[1] is True
        assert ret[0] == "test_msg"
Exemplo n.º 3
0
    def test_service_start(self, monkeypatch):
        def mock_AnsibleRunner_constructor(obj, asnible_module_path, **attr):
            assert attr == {"name": "collectd",
                            "state": "started"}
            return

        monkeypatch.setattr(AnsibleRunner, '__init__',
                            mock_AnsibleRunner_constructor)

        def mock_runner_run(obj):
            result = {
                u'state': u'started',
                u'msg': u'',
                u'invocation': {
                    u'module_args': {
                        u'name': u'collectddd',
                        u'enabled': None,
                        u'daemon_reload': False,
                        u'state': u'started',
                        u'user': False,
                        u'masked': None
                    }
                }
            }
            return result, ""

        monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)

        service = Service("collectd")
        message, success = service.start()
        assert message == ""
        assert success
Exemplo n.º 4
0
    def test_service_start(self, monkeypatch):
        def mock_AnsibleRunner_constructor(obj, ansible_module_path,
                                           exec_path, **attr):
            assert attr == {"name": "collectd",
                            "state": "started"}
            return

        monkeypatch.setattr(AnsibleRunner, '__init__',
                            mock_AnsibleRunner_constructor)

        def mock_runner_run(obj):
            result = {
                u'state': u'started',
                u'msg': u'',
                u'invocation': {
                    u'module_args': {
                        u'name': u'collectddd',
                        u'enabled': None,
                        u'daemon_reload': False,
                        u'state': u'started',
                        u'user': False,
                        u'masked': None
                    }
                }
            }
            return result, ""

        monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)

        service = Service("collectd", "/tmp/")
        message, success = service.start()
        assert message == ""
        assert success
Exemplo n.º 5
0
    def test_service_error(self, monkeypatch):
        def mock_runner_run(obj):
            raise AnsibleExecutableGenerationFailed(
                "module_path", "arg",
                "err message"
            )

        monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)

        service = Service("collectd")
        message, success = service.start()

        assert not success
        assert message == "Executabe could not be generated for module" \
                          " module_path , with arguments arg. Error: err " \
                          "message"
Exemplo n.º 6
0
    def test_service_error(self, monkeypatch):
        def mock_runner_run(obj):
            raise AnsibleExecutableGenerationFailed(
                "module_path", "arg",
                "err message"
            )

        monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)

        service = Service("collectd", "/tmp")
        message, success = service.start()

        assert not success
        assert message == "Executabe could not be generated for module" \
                          " module_path , with arguments arg. Error: err " \
                          "message"