예제 #1
0
파일: stop.py 프로젝트: vraevsky/edi
    def _clean(self):
        if self._delete_container and try_delete_container(
                self._result(), self.config.get_lxc_stop_timeout()):
            print_success("Deleted lxc container {}.".format(self._result()))

        if self.clean_depth > 0:
            Configure().clean_recursive(self._result(),
                                        self.config.get_base_config_file(),
                                        self.clean_depth - 1)
예제 #2
0
파일: stop.py 프로젝트: vraevsky/edi
    def _run(self):
        # configure in any case since the container might be only partially configured
        Configure().run(self._result(), self.config.get_base_config_file())

        print("Going to stop lxc container {}.".format(self._result()))
        stop_container(self._result(),
                       timeout=self.config.get_lxc_stop_timeout())
        print_success("Stopped lxc container {}.".format(self._result()))

        return self._result()
예제 #3
0
def test_config(config_files, capsys):
    # TODO: apply to all introspection aware commands
    parser = edi._setup_command_line_interface()
    cli_args = parser.parse_args(['lxc', 'configure', '--config', 'cname', config_files])

    Configure().run_cli(cli_args)
    out, err = capsys.readouterr()

    assert err == ''
    merged_config = yaml.load(out)
    assert merged_config.get('bootstrap').get('architecture') == 'i386'
예제 #4
0
def test_plugins(config_files, capsys):
    parser = edi._setup_command_line_interface()
    cli_args = parser.parse_args(['lxc', 'configure', '--plugins', 'cname', config_files])

    Configure().run_cli(cli_args)
    out, err = capsys.readouterr()

    assert err == ''
    result = yaml.load(out)
    assert len(result.get('playbooks')) == 3
    base_system = result.get('playbooks')[0].get('10_base_system')
    assert 'plugins/playbooks/foo.yml' in base_system.get('path')
    assert base_system.get('dictionary').get('kernel_package') == 'linux-image-amd64-rt'
    assert base_system.get('dictionary').get('edi_config_directory') == os.path.dirname(config_files)
예제 #5
0
def test_dictionary(config_files, capsys):
    parser = edi._setup_command_line_interface()
    cli_args = parser.parse_args(
        ['lxc', 'configure', '--dictionary', 'cname', config_files])

    Configure().run_cli(cli_args)
    out, err = capsys.readouterr()

    assert err == ''
    dictionary = yaml.load(out)
    assert dictionary.get('edi_config_directory') == os.path.dirname(
        config_files)
    assert dictionary.get('edi_project_plugin_directory') == os.path.join(
        os.path.dirname(config_files), 'plugins')
예제 #6
0
def test_build_stretch_container(capsys):
    print(os.getcwd())
    with workspace():
        edi_exec = os.path.join(get_project_root(), 'bin', 'edi')
        project_name = 'pytest-{}'.format(get_random_string(6))
        config_command = [edi_exec, 'config', 'init', project_name, 'debian-stretch-amd64']
        run(config_command)  # run as non root

        container_name = 'pytest-{}'.format(get_random_string(6))
        parser = edi._setup_command_line_interface()
        cli_args = parser.parse_args(['-v', 'lxc', 'configure', container_name, '{}-develop.yml'.format(project_name)])

        Configure().run_cli(cli_args)
        out, err = capsys.readouterr()
        print(out)
        assert not err

        images = [
            '{}-develop_edicommand_image_bootstrap.tar.gz'.format(project_name),
            '{}-develop_edicommand_image_lxc.tar.gz'.format(project_name)
        ]
        for image in images:
            assert os.path.isfile(image)

        lxc_image_list_cmd = ['lxc', 'image', 'list']
        result = run(lxc_image_list_cmd, stdout=subprocess.PIPE)
        assert project_name in result.stdout

        parser = edi._setup_command_line_interface()
        cli_args = parser.parse_args(['-v', 'clean', '{}-develop.yml'.format(project_name)])
        Clean().run_cli(cli_args)

        for image in images:
            assert not os.path.isfile(image)

        result = run(lxc_image_list_cmd, stdout=subprocess.PIPE)
        assert project_name not in result.stdout

        verification_command = ['lxc', 'exec', container_name, '--', 'cat', '/etc/os-release']
        result = run(verification_command, stdout=subprocess.PIPE)
        assert '''VERSION_ID="9"''' in result.stdout
        assert 'ID=debian' in result.stdout

        stop_command = ['lxc', 'stop', container_name]
        run(stop_command)

        delete_command = ['lxc', 'delete', container_name]
        run(delete_command)
예제 #7
0
    def run(self, config_file, introspection_method=None):
        with command_context({'edi_create_distributable_image': True}):
            self._setup_parser(config_file)

            if introspection_method:
                print(introspection_method())
                return self._result()

            # configure in any case since the container might be only partially configured
            Configure().run(self._result(), config_file)

            print("Going to stop lxc container {}.".format(self._result()))
            stop_container(self._result())
            print_success("Stopped lxc container {}.".format(self._result()))

        return self._result()
예제 #8
0
파일: stop.py 프로젝트: vraevsky/edi
 def _dry_run(self):
     return Configure().dry_run(self._result(),
                                self.config.get_base_config_file())
예제 #9
0
def test_build_stretch_container(capsys, datadir):
    with workspace():
        edi_exec = os.path.join(get_project_root(), 'bin', 'edi')
        project_name = 'pytest-{}'.format(get_random_string(6))
        config_command = [
            edi_exec, 'config', 'init', project_name,
            'debian-stretch-{}'.format(get_debian_architecture())
        ]
        run(config_command)  # run as non root

        # enable ssh server and create a default user
        modify_develop_overlay(project_name)
        # copy pub key into default pub key folder
        prepare_pub_key(datadir)

        container_name = 'pytest-{}'.format(get_random_string(6))
        parser = edi._setup_command_line_interface()
        cli_args = parser.parse_args([
            '-v', 'lxc', 'configure', container_name,
            '{}-develop.yml'.format(project_name)
        ])

        Configure().run_cli(cli_args)
        out, err = capsys.readouterr()
        print(out)
        assert not err

        images = [
            os.path.join(
                get_artifact_dir(),
                '{}-develop_edicommand_image_bootstrap.tar.gz'.format(
                    project_name)),
            os.path.join(
                get_artifact_dir(),
                '{}-develop_edicommand_lxc_prepare.tar.gz'.format(
                    project_name))
        ]
        for image in images:
            assert os.path.isfile(image)

        lxc_image_list_cmd = [lxc_exec(), 'image', 'list']
        result = run(lxc_image_list_cmd, stdout=subprocess.PIPE)
        assert project_name in result.stdout

        parser = edi._setup_command_line_interface()
        cli_args = parser.parse_args(
            ['-v', 'clean', '{}-develop.yml'.format(project_name)])
        Clean().run_cli(cli_args)

        for image in images:
            assert not os.path.isfile(image)

        result = run(lxc_image_list_cmd, stdout=subprocess.PIPE)
        assert project_name not in result.stdout

        verification_command = [
            lxc_exec(), 'exec', container_name, '--', 'cat', '/etc/os-release'
        ]
        result = run(verification_command, stdout=subprocess.PIPE)
        assert '''VERSION_ID="9"''' in result.stdout
        assert 'ID=debian' in result.stdout

        os.chmod(os.path.join(str(datadir), 'keys'), 0o700)
        os.chmod(os.path.join(str(datadir), 'keys', 'test_id_rsa'), 0o600)
        container_ip = get_container_ip_addr(container_name, 'lxcif0')
        ssh_cmd = [
            'ssh', '-i',
            str(os.path.join(str(datadir), 'keys', 'test_id_rsa')), '-o',
            'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no',
            'testuser@{}'.format(container_ip), 'true'
        ]
        # ssh command should work without password due to proper ssh key setup!
        run(ssh_cmd, sudo=True, timeout=5)

        verify_shared_folder(container_name)

        stop_command = [lxc_exec(), 'stop', container_name]
        run(stop_command)

        delete_command = [lxc_exec(), 'delete', container_name]
        run(delete_command)