test_playbookrunner.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:edi 作者: lueschem 项目源码 文件源码
def test_lxd_connection(config_files, monkeypatch):
    def fake_ansible_playbook_run(*popenargs, **kwargs):
        if get_command(popenargs) == 'ansible-playbook':
            assert 'lxd' == get_command_parameter(popenargs, '--connection')
            verify_inventory(get_command_parameter(popenargs, '--inventory'))
            verify_extra_vars(get_command_parameter(popenargs, '--extra-vars').lstrip('@'))
            # TODO: verify --user for ssh connection
            return subprocess.CompletedProcess("fakerun", 0, '')
        else:
            return subprocess.run(*popenargs, **kwargs)

    monkeypatch.setattr(mockablerun, 'run_mockable', fake_ansible_playbook_run)

    def fakechown(*_):
        pass

    monkeypatch.setattr(shutil, 'chown', fakechown)

    with open(config_files, "r") as main_file:
        parser = ConfigurationParser(main_file)
        runner = PlaybookRunner(parser, "fake-container", "lxd")

        playbooks = runner.run_all()

        expected_playbooks = ['10_base_system', '20_networking', '30_foo']
        assert playbooks == expected_playbooks
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号