def test_frozen_enough(self): """Test frozen enough.""" # already has requests self.assertEqual( self.wf.api.prj_frozen_enough('openSUSE:Factory:Staging:B'), True) self.wf.create_staging('A') # Unfrozen self.assertEqual( self.wf.api.prj_frozen_enough('openSUSE:Factory:Staging:A'), False) self.wf.create_staging('C', freeze=True, rings=1) self.assertEqual( self.wf.api.prj_frozen_enough('openSUSE:Factory:Staging:C'), True) # pretend it's old attribute_value_save(self.wf.apiurl, 'openSUSE:Factory:Staging:C', 'FreezeTime', "2021-03-04T10:23:55.127903") self.assertEqual( self.wf.api.prj_frozen_enough('openSUSE:Factory:Staging:C'), False) # test old method (which still shows it's recent) attribute_value_delete(self.wf.apiurl, 'openSUSE:Factory:Staging:C', 'FreezeTime') self.assertEqual( self.wf.api.prj_frozen_enough('openSUSE:Factory:Staging:C'), True)
def test_get_memoize_reset(self): """Ensure memoize_session_reset() properly forces re-fetch of config.""" self.assertEqual('remote-indeed', Config.get(obs.APIURL, obs.PROJECT)['remote-only']) attribute_value_save(obs.APIURL, obs.PROJECT, 'Config', 'remote-only = new value\n') memoize_session_reset() self.assertEqual('new value', Config.get(obs.APIURL, obs.PROJECT)['remote-only'])
def origin_config_write(self, origins, extra={}): config = { 'origins': origins, 'review-user': self.bot_user, 'fallback-group': self.review_group, } config.update(extra) config = yaml.dump(config, default_flow_style=False) attribute_value_save(self.wf.apiurl, self.target_project, 'OriginConfig', config)
def test_get_memoize_reset(self): """Ensure memoize_session_reset() properly forces re-fetch of config.""" wf = self.setup_vcr() self.assertEqual('remote-indeed', Config.get(wf.apiurl, wf.project)['remote-only']) attribute_value_save(wf.apiurl, wf.project, 'Config', 'remote-only = new value\n') memoize_session_reset() self.assertEqual('new value', Config.get(wf.apiurl, wf.project)['remote-only'])
def test_get_memoize_reset(self): """Ensure memoize_session_reset() properly forces re-fetch of config.""" self.assertEqual('remote-indeed', Config.get(APIURL, PROJECT)['remote-only']) attribute_value_save(APIURL, PROJECT, 'Config', 'remote-only = new value\n') memoize_session_reset() self.assertEqual('new value', Config.get(APIURL, PROJECT)['remote-only'])
def test_config(self): attribute_value_save(self.wf.apiurl, self.target_project, 'OriginConfig', 'origins: []') config = config_load(self.wf.apiurl, self.wf.project) self.assertEqual(config['unknown_origin_wait'], False) self.assertEqual(config['review-user'], NAME) memoize_session_reset() self.origin_config_write([{'fakeProject': {}}, {'*~': {}}]) config = config_load(self.wf.apiurl, self.wf.project) self.assertEqual(config_origin_list(config), ['fakeProject', 'fakeProject~']) for _, values in config_origin_generator(config['origins']): self.assertEqual(values['automatic_updates'], True)
def remote_config_set(self, config, replace_all=False): if not replace_all: config_existing = Config.get(self.apiurl, self.project) config_existing.update(config) config = config_existing config_lines = [] for key, value in config.items(): config_lines.append(f'{key} = {value}') attribute_value_save(APIURL, self.project, 'Config', '\n'.join(config_lines))
def test_remote(self): # Initial config present in fixtures/oscrc and obs.py attribute default. # Local config fixture contains overridden-by-local and should win over # the remote config value. self.assertEqual('local', conf.config[obs.PROJECT]['overridden-by-local']) self.assertEqual('remote-indeed', conf.config[obs.PROJECT]['remote-only']) # Change remote value. attribute_value_save(obs.APIURL, obs.PROJECT, 'Config', 'remote-only = new value\n') self.load_config() self.assertEqual('local', conf.config[obs.PROJECT]['overridden-by-local']) self.assertEqual('new value', conf.config[obs.PROJECT]['remote-only'])
def freeze_prjlinks(self): sources = {} flink = ET.Element('frozenlinks') for lprj in self.projectlinks: fl = ET.SubElement(flink, 'frozenlink', {'project': lprj}) sources = self.receive_sources(lprj, sources, fl) url = self.api.makeurl( ['source', self.prj, '_project', '_frozenlinks'], {'meta': '1'}) self.api.retried_PUT(url, ET.tostring(flink)) attribute_value_save(self.api.apiurl, self.prj, 'FreezeTime', datetime.now(timezone.utc).isoformat())
def __config_origin_manager(self): """Creates the very minimal configuration needed by origin-manager to work""" self.wf.create_attribute_type('OSRT', 'OriginConfig', 1) self.wf.remote_config_set({'originmanager-request-age-min': 0}) config = { 'origins': [{ '<devel>': {} }], 'review-user': '******', 'fallback-group': 'origin-reviewers' } config = yaml.dump(config, default_flow_style=False) attribute_value_save(self.wf.apiurl, PROJECT, 'OriginConfig', config)
def test_remote(self): # Initial config present in fixtures/oscrc and obs.py attribute default. # Local config fixture contains overridden-by-local and should win over # the remote config value. self.assertEqual('local', conf.config[PROJECT]['overridden-by-local']) self.assertEqual('remote-indeed', conf.config[PROJECT]['remote-only']) # Change remote value. attribute_value_save(APIURL, PROJECT, 'Config', 'remote-only = new value\n') self.load_config() self.assertEqual('local', conf.config[PROJECT]['overridden-by-local']) self.assertEqual('new value', conf.config[PROJECT]['remote-only'])
def test_remote(self): wf = self.setup_vcr() # Initial config present in fixtures/oscrc and obs.py attribute default. # Local config fixture contains overridden-by-local and should win over # the remote config value. self.assertEqual('local', conf.config[wf.project]['overridden-by-local']) self.assertEqual('remote-indeed', conf.config[wf.project]['remote-only']) # Change remote value. attribute_value_save(wf.apiurl, wf.project, 'Config', 'remote-only = new value\n') wf.load_config() self.assertEqual('local', conf.config[wf.project]['overridden-by-local']) self.assertEqual('new value', conf.config[wf.project]['remote-only'])
def test_frozen_mtime(self): """Test frozen mtime.""" self.wf.create_staging('A') # unfrozen self.assertTrue( self.wf.api.days_since_last_freeze('openSUSE:Factory:Staging:A') > 1000) # Testing frozen mtime self.wf.create_staging('B', freeze=True, rings=1) self.assertLess( self.wf.api.days_since_last_freeze('openSUSE:Factory:Staging:B'), 1) attribute_value_save(self.wf.apiurl, 'openSUSE:Factory:Staging:B', 'FreezeTime', "2021-03-04T10:23:55.127903") self.assertGreater( self.wf.api.days_since_last_freeze('openSUSE:Factory:Staging:B'), 8)
def remote_config_set(self, config, replace_all=False): """Sets the values of the 'Config' attribute for the target project. That attribute stores a set of values that are useful to influence the behavior of several tools and bots in the context of the given project. For convenience, such a collection of values is usually accessed using a :class:`osclib.Config` object. See :func:`load_config`. :param config: values to write into the attribute :type config: dict[str, str] :param replace_all: whether the previous content of 'Config' should be cleared up :type replace_all: bool """ if not replace_all: config_existing = Config.get(self.apiurl, self.project) config_existing.update(config) config = config_existing config_lines = [] for key, value in config.items(): config_lines.append(f'{key} = {value}') attribute_value_save(APIURL, self.project, 'Config', '\n'.join(config_lines))
def update_version_attribute(self, project, version): version_attr = attribute_value_load(self.api.apiurl, project, 'ProductVersion') if version_attr != version: attribute_value_save(self.api.apiurl, project, 'ProductVersion', version)
def setup_remote_config(self): self.create_target() self.create_attribute_type('OSRT', 'Config', 1) attribute_value_save(APIURL, self.project, 'Config', 'overridden-by-local = remote-nope\n' 'remote-only = remote-indeed\n')
def test_automatic_update_modes(self): self.remote_config_set_age_minimum() upstream1_project = self.randomString('upstream1') package1 = self.randomString('package1') target_package1 = self.wf.create_package(self.target_project, package1) upstream1_package1 = self.wf.create_package(upstream1_project, package1) upstream1_package1.create_commit() copy_package(self.wf.apiurl, upstream1_project, package1, self.wf.apiurl, self.target_project, package1) attribute_value_save(self.wf.apiurl, upstream1_project, 'ApprovedRequestSource', '', 'OBS') self.wf.create_attribute_type('OSRT', 'OriginUpdateSkip', 0) def config_write(delay=0, supersede=True, frequency=0): self.origin_config_write([ {upstream1_project: { 'automatic_updates_delay': delay, 'automatic_updates_supersede': supersede, 'automatic_updates_frequency': frequency, }}, ]) # Default config with fresh commit. config_write() upstream1_package1.create_commit() # Check the full order of precidence available to mode attributes. for project in (upstream1_project, self.target_project): for package in (package1, None): # Ensure no update is triggered due to OSRT:OriginUpdateSkip. attribute_value_save(self.wf.apiurl, project, 'OriginUpdateSkip', '', package=package) self.assertNoUpdate(package1) attribute_value_delete(self.wf.apiurl, project, 'OriginUpdateSkip', package=package) # Configure a delay, make commit, and ensure no update until delayed. delay = 17 # Allow enough time for API speed fluctuation. config_write(delay=delay) upstream1_package1.create_commit() start = datetime.now() self.assertNoUpdate(package1) self.waitDelta(start, delay) request_id_package1_1 = self.assertUpdate(package1) # Configure no supersede and ensure no update generated for new commit. config_write(supersede=False) upstream1_package1.create_commit() self.assertNoUpdate(package1) # Accept request and ensure update since no request to supersede. self.assertReviewBot(request_id_package1_1, self.bot_user, 'new', 'accepted') request_state_change(self.wf.apiurl, request_id_package1_1, 'accepted') request_id_package1_2 = self.assertUpdate(package1) # Track time since last request created for testing frequency. start = datetime.now() # Configure frequency (removes supersede=False). config_write(frequency=delay) upstream1_package1.create_commit() self.assertNoUpdate(package1) # Fresh commit should not impact frequency which only looks at requests. self.waitDelta(start, delay) upstream1_package1.create_commit() request_id_package1_3 = self.assertUpdate(package1)
def test_new_package_submission(self): self.remote_config_set_age_minimum() upstream1_project = self.randomString('upstream1') upstream2_project = self.randomString('upstream2') upstream3_project = self.randomString('upstream3') package1 = self.randomString('package1') package2 = self.randomString('package2') package3 = self.randomString('package3') target_package1 = self.wf.create_package(self.target_project, package1) upstream1_package1 = self.wf.create_package(upstream1_project, package1) upstream2_package1 = self.wf.create_package(upstream2_project, package1) upstream1_package1.create_commit() copy_package(self.wf.apiurl, upstream1_project, package1, self.wf.apiurl, upstream2_project, package1) upstream3_package2 = self.wf.create_package(upstream3_project, package2) upstream3_package2.create_commit() upstream1_package3 = self.wf.create_package(upstream1_project, package3) upstream1_package3.create_commit() attribute_value_save(self.wf.apiurl, upstream1_project, 'ApprovedRequestSource', '', 'OBS') attribute_value_save(self.wf.apiurl, upstream2_project, 'ApprovedRequestSource', '', 'OBS') attribute_value_save(self.wf.apiurl, upstream3_project, 'ApprovedRequestSource', '', 'OBS') self.origin_config_write([ {upstream1_project: { 'automatic_updates_initial': True }}, {upstream2_project: { 'automatic_updates_initial': True }}, {upstream3_project: {}}, ]) self.osc_user(self.bot_user) memoize_session_reset() request_future = origin_update(self.wf.apiurl, self.wf.project, package1) self.assertNotEqual(request_future, False) if request_future: request_id_package1 = request_future.print_and_create() # Ensure a second request is not triggered. memoize_session_reset() request_future = origin_update(self.wf.apiurl, self.wf.project, package1) self.assertEqual(request_future, False) # No new package submission from upstream3 since not automatic_updates_initial. memoize_session_reset() request_future = origin_update(self.wf.apiurl, self.wf.project, package2) self.assertEqual(request_future, False) self.osc_user_pop() upstream2_package2 = self.wf.create_package(upstream2_project, package2) upstream2_package2.create_commit() self.osc_user(self.bot_user) memoize_session_reset() request_future = origin_update(self.wf.apiurl, self.wf.project, package2) self.assertNotEqual(request_future, False) if request_future: request_id_package2 = request_future.print_and_create() self.osc_user_pop() request_state_change(self.wf.apiurl, request_id_package2, 'declined') upstream2_package2.create_commit() self.osc_user(self.bot_user) # No new package submission from upstream2 for new revision since # declined initial package submission. memoize_session_reset() request_future = origin_update(self.wf.apiurl, self.wf.project, package2) self.assertEqual(request_future, False) self.osc_user_pop() # Ensure blacklist prevents initial package submission. self.wf.create_attribute_type('OSRT', 'OriginUpdateInitialBlacklist', 1) attribute_value_save(self.wf.apiurl, self.target_project, 'OriginUpdateInitialBlacklist', package3) self.assertNoUpdate(package3) attribute_value_delete(self.wf.apiurl, self.target_project, 'OriginUpdateInitialBlacklist') self.assertUpdate(package3)
def test_split_product(self): self.remote_config_set_age_minimum() upstream1_project = self.randomString('upstream1') upstream2_project = self.randomString('upstream2') devel_project = self.randomString('devel') package = self.randomString('package') target_package = self.wf.create_package(self.target_project, package) upstream1_package = self.wf.create_package(upstream1_project, package) upstream2_package = self.wf.create_package(upstream2_project, package) devel_package = self.wf.create_package(devel_project, package) upstream1_package.create_commit() upstream2_package.create_commit() devel_package.create_commit() attribute_value_save(self.wf.apiurl, upstream1_project, 'ApprovedRequestSource', '', 'OBS') attribute_value_save(self.wf.apiurl, upstream2_project, 'ApprovedRequestSource', '', 'OBS') attribute_value_save(self.wf.apiurl, devel_project, 'ApprovedRequestSource', '', 'OBS') self.origin_config_write([ {'<devel>': {}}, {upstream1_project: {}}, {upstream2_project: { 'pending_submission_consider': True }}, {'*~': {}}, ], {'unknown_origin_wait': True}) # Simulate branch project from upstream1. copy_package(self.wf.apiurl, upstream1_project, package, self.wf.apiurl, self.target_project, package) memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.target_project, package) self.assertEqual(str(origin_info), upstream1_project) # Create request against upstream2 which considers pending submissions. request_upstream2 = self.wf.submit_package(devel_package, upstream2_project) request_target = self.wf.submit_package(devel_package, self.target_project) self.assertReviewBot(request_target.reqid, self.bot_user, 'new', 'new') comment = [ '<!-- OriginManager state=seen result=None -->', f'Waiting on acceptance of request#{request_upstream2.reqid}.', ] self.assertComment(request_target.reqid, comment) request_upstream2.change_state('accepted') self.assertReviewBot(request_target.reqid, self.bot_user, 'new', 'accepted') self.assertAnnotation(request_target.reqid, { 'origin': upstream2_project, 'origin_old': upstream1_project, }) # Accept fallback review for changing to lower priority origin. self.accept_fallback_review(request_target.reqid) request_target.change_state('accepted') memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.target_project, package) self.assertEqual(str(origin_info), upstream2_project) # Simulate upstream1 incorporating upstream2 version of package. copy_package(self.wf.apiurl, upstream2_project, package, self.wf.apiurl, upstream1_project, package) memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.target_project, package) self.assertEqual(str(origin_info), upstream1_project)
def devel_workflow(self, only_devel): self.remote_config_set_age_minimum() devel_project = self.randomString('devel') package = self.randomString('package') request = self.wf.create_submit_request(devel_project, package) attribute_value_save(self.wf.apiurl, devel_project, 'ApprovedRequestSource', '', 'OBS') if not only_devel: self.assertReviewBot(request.reqid, self.bot_user, 'new', 'new') comment = [ '<!-- OriginManager state=seen result=None -->', 'Source not found in allowed origins:', f'- {self.product_project}', f'Decision may be overridden via `@{self.bot_user} override`.', ] self.assertComment(request.reqid, comment) CommentAPI(self.wf.api.apiurl).add_comment( request_id=request.reqid, comment=f'@{self.bot_user} change_devel') comment = 'change_devel command by {}'.format('Admin') else: comment = 'only devel origin allowed' self.assertReviewBot(request.reqid, self.bot_user, 'new', 'accepted') self.assertAnnotation(request.reqid, { 'comment': comment, 'origin': devel_project, }) request.change_state('accepted') memoize_session_reset() self.osc_user(self.bot_user) request_future = origin_update(self.wf.apiurl, self.wf.project, package) self.assertNotEqual(request_future, False) if request_future: request_id_change_devel = request_future.print_and_create() # Ensure a second request is not triggered. request_future = origin_update(self.wf.apiurl, self.wf.project, package) self.assertEqual(request_future, False) self.osc_user_pop() memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.wf.project, package) self.assertEqual(origin_info, None) self.assertReviewBot(request_id_change_devel, self.bot_user, 'new', 'accepted') self.assertAnnotation(request_id_change_devel, { 'origin': devel_project, }) # Origin should change before request is accepted since it is properly # annotated and without fallback review. memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.wf.project, package) self.assertEqual(str(origin_info), devel_project) self.wf.projects[devel_project].packages[0].create_commit() self.osc_user(self.bot_user) request_future = origin_update(self.wf.apiurl, self.wf.project, package) self.assertNotEqual(request_future, False) if request_future: request_id_update = request_future.print_and_create() request_future = origin_update(self.wf.apiurl, self.wf.project, package) self.assertEqual(request_future, False) self.osc_user_pop() self.assertReviewBot(request_id_update, self.bot_user, 'new', 'accepted') self.assertAnnotation(request_id_update, { 'origin': devel_project, }) memoize_session_reset() devel_project_actual, _ = devel_project_get(self.wf.apiurl, self.wf.project, package) self.assertEqual(devel_project_actual, None) request = get_request(self.wf.apiurl, request_id_change_devel) request_state_change(self.wf.apiurl, request_id_change_devel, 'accepted') memoize_session_reset() devel_project_actual, devel_package_actual = devel_project_get( self.wf.apiurl, self.wf.project, package) self.assertEqual(devel_project_actual, devel_project) self.assertEqual(devel_package_actual, package) request = get_request(self.wf.apiurl, request_id_update) request_state_change(self.wf.apiurl, request_id_update, 'accepted') devel_project_new = self.randomString('develnew') self.wf.create_package(devel_project_new, package) attribute_value_save(self.wf.apiurl, devel_project_new, 'ApprovedRequestSource', '', 'OBS') copy_package(self.wf.apiurl, devel_project, package, self.wf.apiurl, devel_project_new, package) request_future = request_create_change_devel( self.wf.apiurl, devel_project_new, package, self.wf.project) self.assertNotEqual(request_future, False) if request_future: request_id_change_devel_new = request_future.print_and_create() self.assertReviewBot(request_id_change_devel_new, self.bot_user, 'new', 'accepted') self.assertAnnotation(request_id_change_devel_new, { 'origin': devel_project_new, 'origin_old': devel_project, }) self.accept_fallback_review(request_id_change_devel_new) request_state_change(self.wf.apiurl, request_id_change_devel_new, 'accepted') memoize_session_reset() origin_info = origin_find(self.wf.apiurl, self.wf.project, package) self.assertEqual(str(origin_info), devel_project_new)