From 08bbe74abcb61bafbca11a8a7ca4dfe106bc95d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Wed, 17 Aug 2016 16:26:35 +0200 Subject: [PATCH] Added --ignore-repos for build and prepare tasks The option allows to ignore all repos configured in the XML description. This allows to specify a complete set of repositories via the commandline --- kiwi/tasks/system_build.py | 6 ++++++ kiwi/tasks/system_prepare.py | 6 ++++++ kiwi/xml_state.py | 6 ++++++ test/unit/cli_test.py | 1 + test/unit/tasks_system_build_test.py | 11 +++++++++++ test/unit/tasks_system_prepare_test.py | 8 ++++++++ test/unit/xml_state_test.py | 4 ++++ 7 files changed, 42 insertions(+) diff --git a/kiwi/tasks/system_build.py b/kiwi/tasks/system_build.py index 681dee27..95b07eea 100644 --- a/kiwi/tasks/system_build.py +++ b/kiwi/tasks/system_build.py @@ -18,6 +18,7 @@ """ usage: kiwi system build -h | --help kiwi system build --description= --target-dir= + [--ignore-repos] [--set-repo=] [--add-repo=...] [--obs-repo-internal] @@ -42,6 +43,8 @@ options: --description= the description must be a directory containing a kiwi XML description and optional metadata files + --ignore-repos + ignore all repos from the XML configuration --obs-repo-internal when using obs:// repos resolve them using the SUSE internal buildservice. This only works if access to SUSE's internal @@ -103,6 +106,9 @@ class SystemBuildTask(CliTask): self.command_args['--target-dir'] ) + if self.command_args['--ignore-repos']: + self.xml_state.delete_repository_sections() + if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) diff --git a/kiwi/tasks/system_prepare.py b/kiwi/tasks/system_prepare.py index 9715a867..c858e12b 100644 --- a/kiwi/tasks/system_prepare.py +++ b/kiwi/tasks/system_prepare.py @@ -19,6 +19,7 @@ usage: kiwi system prepare -h | --help kiwi system prepare --description= --root= [--allow-existing-root] + [--ignore-repos] [--set-repo=] [--add-repo=...] [--obs-repo-internal] @@ -46,6 +47,8 @@ options: --description= the description must be a directory containing a kiwi XML description and optional metadata files + --ignore-repos + ignore all repos from the XML configuration --obs-repo-internal when using obs:// repos resolve them using the SUSE internal buildservice. This only works if access to SUSE's internal @@ -96,6 +99,9 @@ class SystemPrepareTask(CliTask): self.command_args['--root'] ) + if self.command_args['--ignore-repos']: + self.xml_state.delete_repository_sections() + if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) diff --git a/kiwi/xml_state.py b/kiwi/xml_state.py index ba47cf6e..b86fa220 100644 --- a/kiwi/xml_state.py +++ b/kiwi/xml_state.py @@ -781,6 +781,12 @@ class XMLState(object): self.xml_data.get_repository() ) + def delete_repository_sections(self): + """ + Delete all repository sections matching configured profiles + """ + self.xml_data.set_repository([]) + def translate_obs_to_ibs_repositories(self): """ Change obs:// repotype to ibs:// type diff --git a/test/unit/cli_test.py b/test/unit/cli_test.py index 0654a2eb..f8366983 100644 --- a/test/unit/cli_test.py +++ b/test/unit/cli_test.py @@ -30,6 +30,7 @@ class TestCli(object): '--allow-existing-root': False, '--description': 'description', '--help': False, + '--ignore-repos': False, '--obs-repo-internal': False, '--root': 'directory', '--set-repo': None, diff --git a/test/unit/tasks_system_build_test.py b/test/unit/tasks_system_build_test.py index e09d1dcc..c28ac3dd 100644 --- a/test/unit/tasks_system_build_test.py +++ b/test/unit/tasks_system_build_test.py @@ -72,6 +72,7 @@ class TestSystemBuildTask(object): self.task.command_args['--add-repo'] = [] self.task.command_args['--add-package'] = [] self.task.command_args['--delete-package'] = [] + self.task.command_args['--ignore-repos'] = False @patch('kiwi.logger.Logger.set_logfile') def test_process_system_build(self, mock_log): @@ -185,3 +186,13 @@ class TestSystemBuildTask(object): self.task.manual.show.assert_called_once_with( 'kiwi::system::build' ) + + @patch('kiwi.xml_state.XMLState.delete_repository_sections') + @patch('kiwi.logger.Logger.set_logfile') + def test_process_system_prepare_ignore_repos( + self, mock_log, mock_delete_repos + ): + self._init_command_args() + self.task.command_args['--ignore-repos'] = True + self.task.process() + mock_delete_repos.assert_called_once_with() diff --git a/test/unit/tasks_system_prepare_test.py b/test/unit/tasks_system_prepare_test.py index f8e445f9..3aa6fab9 100644 --- a/test/unit/tasks_system_prepare_test.py +++ b/test/unit/tasks_system_prepare_test.py @@ -61,6 +61,7 @@ class TestSystemPrepareTask(object): self.task.command_args['--obs-repo-internal'] = False self.task.command_args['--add-package'] = [] self.task.command_args['--delete-package'] = [] + self.task.command_args['--ignore-repos'] = False def test_process_system_prepare(self): self._init_command_args() @@ -156,3 +157,10 @@ class TestSystemPrepareTask(object): self.task.manual.show.assert_called_once_with( 'kiwi::system::prepare' ) + + @patch('kiwi.xml_state.XMLState.delete_repository_sections') + def test_process_system_prepare_delete_repos(self, mock_delete_repos): + self._init_command_args() + self.task.command_args['--ignore-repos'] = True + self.task.process() + mock_delete_repos.assert_called_once_with() diff --git a/test/unit/xml_state_test.py b/test/unit/xml_state_test.py index 01274aa9..5cdbdd1d 100644 --- a/test/unit/xml_state_test.py +++ b/test/unit/xml_state_test.py @@ -433,3 +433,7 @@ class TestXMLState(object): ): mock_boot.return_value = 'invalid' self.state.get_distribution_name_from_boot_attribute() + + def test_delete_repository_sections(self): + self.state.delete_repository_sections() + assert self.state.get_repository_sections() == []