From 6cf24baebb55e273c310e8a8286fa9ecb6982dbb Mon Sep 17 00:00:00 2001 From: mprahl Date: Tue, 31 Oct 2017 16:23:25 -0400 Subject: [PATCH] Don't allow a user to resubmit a module build that is already in the init state --- module_build_service/utils.py | 8 +++----- tests/test_build/test_build.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 32b9128d..ef4c8ecc 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -963,11 +963,9 @@ def submit_module_build(username, url, mmd, scm, yaml, optional_params=None): log.debug('Checking whether module build already exist.') # TODO: make this configurable, we might want to allow # resubmitting any stuck build on DEV no matter the state - if module.state not in (models.BUILD_STATES['failed'], - models.BUILD_STATES['init']): - err_msg = ('Module (state=%s) already exists. ' - 'Only new build or resubmission of build in "init" or ' - '"failed" state is allowed.' % module.state) + if module.state != models.BUILD_STATES['failed']: + err_msg = ('Module (state=%s) already exists. Only a new build or resubmission of ' + 'a failed build is allowed.' % module.state) log.error(err_msg) raise Conflict(err_msg) log.debug('Resuming existing module build %r' % module) diff --git a/tests/test_build/test_build.py b/tests/test_build/test_build.py index 9acb62da..a334dc83 100644 --- a/tests/test_build/test_build.py +++ b/tests/test_build/test_build.py @@ -840,6 +840,32 @@ class TestBuild(unittest.TestCase): self.assertTrue(build.module_build.state in [models.BUILD_STATES["done"], models.BUILD_STATES["ready"]]) + @patch('module_build_service.auth.get_user', return_value=user) + @patch('module_build_service.scm.SCM') + def test_submit_build_resume_init_fail(self, mocked_scm, mocked_get_user, conf_system, dbg): + """ + Tests that resuming the build fails when the build is in init state + """ + FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + # Post so a module is in the init phase + rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( + {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' + 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + self.assertEqual(rv.status_code, 201) + # Post again and make sure it fails + rv2 = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( + {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' + 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + data = json.loads(rv2.data) + expected = { + 'error': 'Conflict', + 'message': ('Module (state=0) already exists. Only a new build or resubmission of a ' + 'failed build is allowed.'), + 'status': 409 + } + self.assertEqual(data, expected) + @patch("module_build_service.config.Config.system", new_callable=PropertyMock, return_value="test")