From 710df01255c39b57d0cd90b2b6775b1e4f5052a1 Mon Sep 17 00:00:00 2001 From: Otto Liljalaakso Date: Feb 05 2024 23:57:22 +0000 Subject: Fix copr-build command with results_dir=subdir option Command copr-build was always assuming to find the srpm in the project root directory. However, srpm command is a dependency for copr-build, and that command does respect results_dir option. This led copr-build to fail when results_dir=subdir was set: Error: File rust-retry-1.3.1-5.fc40.src.rpm not found Fix by using srcrpmdir parameter from the project's Layout to find the srpm. Signed-off-by: Otto Liljalaakso --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 621df32..5b74a26 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -2384,7 +2384,8 @@ class cliClient(object): self.extra_args = None self.srpm() self.extra_args = extra_args_backup - srpm_name = '%s.src.rpm' % self.cmd.nvr + srpm_name = os.path.join(self.cmd.layout.srcrpmdir, + '%s.src.rpm' % self.cmd.nvr) self.cmd.copr_build(self.args.project[0], srpm_name, self.args.nowait, diff --git a/tests/fixtures/rpkg-results_dir-subdir.conf b/tests/fixtures/rpkg-results_dir-subdir.conf new file mode 100644 index 0000000..4bf702d --- /dev/null +++ b/tests/fixtures/rpkg-results_dir-subdir.conf @@ -0,0 +1,21 @@ +# Same as rpkg.conf, with results_dir = subdir +[rpkg] +lookaside = http://localhost/repo/pkgs +lookasidehash = md5 +lookaside_cgi = https://localhost/repo/pkgs/upload.cgi +gitbaseurl = ssh://%(user)s@localhost/%(repo)s +anongiturl = git://localhost/%(repo)s +branchre = f\d$|f\d\d$|el\d$|olpc\d$|master$ +kojiprofile = koji +build_client = koji +clone_config_rpms = + bz.default-component %(repo)s +results_dir = subdir + +[rpkg.mbs] +auth_method = oidc +api_url = https://mbs.fedoraproject.org/module-build-service/ +oidc_id_provider = https://id.fedoraproject.org/openidc/ +oidc_client_id = mbs-authorizer +oidc_client_secret = notsecret +oidc_scopes = openid,https://id.fedoraproject.org/scope/groups,https://mbs.fedoraproject.org/oidc/submit-build diff --git a/tests/test_cli.py b/tests/test_cli.py index 712a395..75425d4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2037,9 +2037,9 @@ class TestCoprBuild(CliTestCase): self.nvr_patcher.stop() super(TestCoprBuild, self).tearDown() - def assert_copr_build(self, cli_cmd, expected_copr_cli): + def assert_copr_build(self, cli_cmd, expected_copr_cli, cfg=None): with patch('sys.argv', new=cli_cmd): - cli = self.new_cli() + cli = self.new_cli(cfg) cli.copr_build() self.mock_srpm.assert_called_once() @@ -2051,7 +2051,7 @@ class TestCoprBuild(CliTestCase): self.assert_copr_build(cli_cmd, [ 'copr-cli', 'build', 'user/project', - '{0}.src.rpm'.format(self.mock_nvr.return_value) + '{0}/{1}.src.rpm'.format(self.cloned_repo_path, self.mock_nvr.return_value) ]) def test_copr_build_no_wait(self): @@ -2060,7 +2060,7 @@ class TestCoprBuild(CliTestCase): self.assert_copr_build(cli_cmd, [ 'copr-cli', 'build', '--nowait', 'user/project', - '{0}.src.rpm'.format(self.mock_nvr.return_value) + '{0}/{1}.src.rpm'.format(self.cloned_repo_path, self.mock_nvr.return_value) ]) def test_copr_build_with_alternative_config_file(self): @@ -2071,9 +2071,19 @@ class TestCoprBuild(CliTestCase): self.assert_copr_build(cli_cmd, [ 'copr-cli', '--config', '/path/to/alternative/config', 'build', 'user/project', - '{0}.src.rpm'.format(self.mock_nvr.return_value) + '{0}/{1}.src.rpm'.format(self.cloned_repo_path, self.mock_nvr.return_value) ]) + def test_copr_build_with_results_dir(self): + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, + 'copr-build', 'user/project'] + conf_file = self.get_absolute_conf_filename('rpkg-results_dir-subdir.conf') + + self.assert_copr_build(cli_cmd, [ + 'copr-cli', 'build', 'user/project', + '{0}/results/{1}.src.rpm'.format(self.cloned_repo_path, self.mock_nvr.return_value) + ], conf_file) + class TestMockConfig(CliTestCase): """Test mockconfig command"""