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
def run(self, container_name, config_file, introspection_method=None): self._setup_parser(config_file) self.container_name = container_name if introspection_method: print(introspection_method()) return self._result() Launch().run(container_name, config_file) print("Going to configure container {} - be patient.".format(self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), "lxd") playbook_runner.run_all() sfc = SharedFolderCoordinator(self.config) sfc.create_host_folders() sfc.verify_container_mountpoints(container_name) profiles = Profile().run(config_file, include_post_config_profiles=True) # TODO: stop container if profiles need to be updated apply_profiles(container_name, profiles) # TODO: restart container if needed print_success("Configured container {}.".format(self._result())) return self._result()
def _run(self): print("Going to configure target system ({}) - be patient.".format( self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), "ssh") playbook_runner.run_all() print_success("Configured target system ({}).".format(self._result())) return self._result()
def _dry_run(self): plugins = {} plugins.update(Launch().dry_run(self.container_name, self.config.get_base_config_file())) playbook_runner = PlaybookRunner(self.config, self._result(), self.ansible_connection) plugins.update(playbook_runner.get_plugin_report()) plugins.update(Profile().dry_run(self.config.get_base_config_file(), include_post_config_profiles=True)) return plugins
def run(self, ip_address, config_file): self._setup_parser(config_file) self.ip_address = ip_address print("Going to configure target system ({}) - be patient.".format( self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), "ssh") playbook_runner.run_all() print_success("Configured target system ({}).".format(self._result())) return self._result()
def _run(self): Launch().run(self.container_name, self.config.get_base_config_file()) print("Going to configure container {} - be patient.".format( self._result())) playbook_runner = PlaybookRunner(self.config, self._result(), self.ansible_connection) playbook_runner.run_all() sfc = SharedFolderCoordinator(self.config) sfc.create_host_folders() sfc.verify_container_mountpoints(self.container_name) profiles = Profile().run(self.config.get_base_config_file(), include_post_config_profiles=True) # TODO: stop container if profiles need to be updated apply_profiles(self.container_name, profiles) # TODO: restart container if needed print_success("Configured container {}.".format(self._result())) return self._result()