From 9a806048f27973223fa97e92d731e6285ec0c272 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: May 08 2018 07:32:31 +0000 Subject: [PATCH 1/2] Raise error if rpm command returns non-zero If rpm command fails to parse a SPEC file, which is probably because a non-existing file or something else, the return code from rpm must be non-zero. So, raise error to terminate immediately, which is able to avoid subsequent code works against invalid output from rpm. Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index c6ef8b2..de0e035 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -686,6 +686,10 @@ class Commands(object): self.log.debug('Errors occoured while running following command to get N-V-R-E:') self.log.debug(joined_cmd) self.log.error(err) + if proc.returncode > 0: + raise rpkgError('Could not get n-v-r-e from %s' + % os.path.join(self.path, self.spec)) + # Get just the output, then split it by ??, grab the first and split # again to get ver and rel first_line_output = output.split('??')[1] From 988cf52f027cc611e7094b84e16f0396d1a2d495 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: May 08 2018 07:39:38 +0000 Subject: [PATCH 2/2] Add a test for 3f93433 Signed-off-by: Chenxiong Qi --- diff --git a/tests/test_commands.py b/tests/test_commands.py index 55d7376..e2ad992 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -137,6 +137,17 @@ class LoadNameVerRelTest(CommandTestCase): """ self.assertRaises(rpkgError, self.cmd.load_nameverrel) + def test_load_when_echo_text_from_spec(self): + import utils + self.write_file(os.path.join(self.cloned_repo_path, self.spec_file), + content=utils.spec_file_echo_text) + + self.cmd.load_nameverrel() + self.assertEqual('docpkg', self.cmd._module_name_spec) + self.assertEqual('0', self.cmd._epoch) + self.assertEqual('1.2', self.cmd._ver) + self.assertEqual('2.el6', self.cmd._rel) + class LoadBranchMergeTest(CommandTestCase): """Test case for testing Commands.load_branch_merge""" diff --git a/tests/utils.py b/tests/utils.py index 5a4ac91..631ba14 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -56,6 +56,30 @@ rm -rf $$RPM_BUILD_ROOT - Initial version ''' +spec_file_echo_text = ''' +Summary: Dummy summary +Name: docpkg +Version: 1.2 +Release: 2%{dist} +License: GPL +%{echo:some text} +%{echo:other pkg info} +%description +Dummy docpkg for tests +%prep +%check +%build +touch README.rst +%clean +%install +%files +%defattr(-,root,root,-) +%doc README.rst +%changelog +* Thu Apr 21 2016 Tester - 1.2-2 +- Initial version +''' + class Assertions(object):