Beispiel #1
0
def test_command_context():
    assert ConfigurationParser.command_context.get(
        'edi_create_distributable_image') is False
    with command_context({'edi_create_distributable_image': True}):
        assert ConfigurationParser.command_context.get(
            'edi_create_distributable_image') is True
        with command_context({'edi_current_context': 'bingo'}):
            assert ConfigurationParser.command_context.get(
                'edi_create_distributable_image') is True
            assert ConfigurationParser.command_context.get(
                'edi_current_context') == 'bingo'
            with command_context({'edi_create_distributable_image': False}):
                assert ConfigurationParser.command_context.get(
                    'edi_create_distributable_image') is False
                assert ConfigurationParser.command_context.get(
                    'edi_current_context') == 'bingo'
            assert ConfigurationParser.command_context.get(
                'edi_create_distributable_image') is True
        assert ConfigurationParser.command_context.get(
            'edi_create_distributable_image') is True
        assert ConfigurationParser.command_context.get(
            'edi_current_context') is None
    assert ConfigurationParser.command_context.get(
        'edi_create_distributable_image') is False
    assert ConfigurationParser.command_context.get(
        'edi_current_context') is None
Beispiel #2
0
def test_no_shared_folders_for_distributable_image(config_files, monkeypatch):
    with mocked_executable('lxc'):
        with mocked_lxd_version_check():
            with open(config_files, "r") as main_file:
                with command_context({'edi_create_distributable_image': True}):
                    parser = ConfigurationParser(main_file)

                    coordinator = SharedFolderCoordinator(parser)

                    def fake_os_path_exists(*_):
                        return False

                    monkeypatch.setattr(os.path, 'exists', fake_os_path_exists)

                    def fake_run(*popenargs, **kwargs):
                        # We should not run anything!
                        assert False

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

                    coordinator.create_host_folders()
                    coordinator.verify_container_mountpoints('does-not-exist')
                    assert coordinator.get_mountpoints() == []
                    assert coordinator.get_pre_config_profiles() == []
                    assert coordinator.get_post_config_profiles() == []
Beispiel #3
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()

            if os.path.isfile(self._result()):
                logging.info(("{0} is already there. "
                              "Delete it to regenerate it."
                              ).format(self._result()))
                return self._result()

            image_name = Publish().run(config_file)

            print("Going to export lxc image from image store.")

            export_image(image_name, self._image_without_extension())

            if (os.path.isfile(self._image_without_extension()) and
                    not os.path.isfile(self._result())):
                # Workaround for https://github.com/lxc/lxd/issues/3869
                logging.info("Fixing file extension of exported image.")
                os.rename(self._image_without_extension(), self._result())

            print_success("Exported lxc image as {}.".format(self._result()))

        return self._result()
Beispiel #4
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()
Beispiel #5
0
def main():
    try:
        cli_interface = _setup_command_line_interface()
        cli_args = cli_interface.parse_args(sys.argv[1:])
        _setup_logging(cli_args)

        if cli_args.command_name is None:
            raise FatalError("Missing command. Use 'edi --help' for help.")

        command_name = "{0}.{1}".format(EdiCommand._get_command_name(),
                                        cli_args.command_name)
        with command_context({'edi_debug_mode': cli_args.debug}):
            get_command(command_name)().run_cli(cli_args)
    except FatalError as fatal_error:
        print_error_and_exit(fatal_error.message)
    except KeyboardInterrupt:
        print_error_and_exit("Command interrupted by user.")
    except CalledProcessError as subprocess_error:
        print_error_and_exit("{}\nFor more information increase the log level.".format(subprocess_error))
    except requests.exceptions.SSLError as ssl_error:
        print_error_and_exit("{}\nPlease verify your ssl/proxy setup.".format(ssl_error))
    except requests.exceptions.ConnectionError as connection_error:
        print_error_and_exit(("{}\nPlease verify your internet connectivity and the requested url."
                              ).format(connection_error))
Beispiel #6
0
    def clean(self, config_file):
        self._dispatch(config_file, run_method=self._clean)

        with command_context({'edi_create_distributable_image': True}):
            self._dispatch(config_file, run_method=self._clean)
Beispiel #7
0
 def _dispatch(self, config_file, run_method):
     with command_context({'edi_create_distributable_image': True}):
         self._setup_parser(config_file)
         return run_method()
Beispiel #8
0
 def _dispatch(self, ip_address, config_file, run_method):
     with command_context({'edi_configure_remote_target': True}):
         self._setup_parser(config_file)
         self.ip_address = ip_address
         return run_method()