def test_purge_stale_running_commands(self): with session.begin(): distro_tree = data_setup.create_distro_tree(osmajor=u'Fedora') # Helper to build the commands def _make_command(lc=None, creation_date=None): job = data_setup.create_job(distro_tree=distro_tree) recipe = job.recipesets[0].recipes[0] system = data_setup.create_system(lab_controller=lc) data_setup.mark_recipe_waiting(recipe, system=system) command = CommandActivity( user=None, service=u'testdata', action=u'on', status=CommandStatus.running, callback=u'bkr.server.model.auto_cmd_handler') if creation_date is not None: command.created = command.updated = creation_date system.command_queue.append(command) return recipe.tasks[0], command # Normal command for the current LC recent_task, recent_command = _make_command(lc=self.lc) # Old command for a different LC backdated = datetime.datetime.utcnow() backdated -= datetime.timedelta(days=1, minutes=1) old_task, old_command = _make_command(creation_date=backdated) self.server.auth.login_password(self.lc.user.user_name, u'logmein') self.server.labcontrollers.clear_running_commands(u'Staleness') with session.begin(): session.expire_all() # Recent commands have their callback invoked self.assertEquals(recent_command.status, CommandStatus.aborted) self.assertEquals(recent_task.status, TaskStatus.aborted) # Stale commands just get dropped on the floor self.assertEquals(old_command.status, CommandStatus.aborted) self.assertEquals(old_task.status, TaskStatus.waiting)
def test_panic_not_doubly_detected(self): # Write a panic string to the console log and wait for panic. oops_line = 'Oops: 0002 [#1] PREEMPT SMP\n' open(self.console_log, 'w').write(oops_line) wait_for_condition(self.check_console_log_registered) wait_for_condition(lambda: self.check_cached_log_contents(oops_line)) self.assert_panic_detected(u'Oops: ') # Now check our kill_time session.expire_all() with session.begin(): kill_time1 = self.recipe.watchdog.kill_time # Add another panic entry open(self.console_log, 'a+').write(oops_line) wait_for_condition( lambda: self.check_cached_log_contents(oops_line * 2)) session.expire_all() with session.begin(): # Ensure that there are no new panic results self.assertEquals(len(self.recipe.tasks[0].results), 1) # Ensure that our kill time has not been extended again! kill_time2 = self.recipe.watchdog.kill_time self.assertEquals(kill_time1, kill_time2)
def test_authenticated_user_can_comment_recipetask(self): with session.begin(): recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes([recipe]) recipetask = recipe.tasks[0] # no special permissions required to comment user = data_setup.create_user(password=u'otheruser') comment_text = u'comments are fun' b = self.browser login(b, user=user.user_name, password='******') go_to_recipe_view(b, recipe, tab='Tasks') tab = b.find_element_by_id('tasks') tab.find_element_by_xpath('//div[@class="task-comments"]' '/div/a[@class="comments-link"]').click() popover = b.find_element_by_class_name('popover') popover.find_element_by_name('comment').send_keys(comment_text) popover.find_element_by_tag_name('form').submit() # check if the commit is in the comments list indicating the comment is submitted popover.find_element_by_xpath('//div[@class="comments"]//div[@class="comment"]' '/p[2][text()="%s"]' % comment_text) self.assertEqual(popover.find_element_by_name('comment').text, '') with session.begin(): session.expire_all() self.assertEqual(recipetask.comments[0].user, user) self.assertEqual(recipetask.comments[0].comment, comment_text) # comments link should indicate the new comment comments_link = tab.find_element_by_xpath('//div[@class="task-comments"]' '/div/a[@class="comments-link"]').text self.assertEqual(comments_link, '1')
def test_set_job_whiteboard(self): out = run_client(['bkr', 'job-modify', self.job.t_id, '--whiteboard', 'Gregor Samsa awoke']) self.assertIn('Successfully modified jobs %s' % self.job.t_id, out) with session.begin(): session.expire_all() self.assertEquals(self.job.whiteboard, u'Gregor Samsa awoke')
def test_recovers_running_job_with_completed_recipes(self): # job with two recipes, both Completed, but job is Running # and systems are still assigned job = data_setup.create_job(num_recipes=2) data_setup.mark_job_running(job) systems = [r.resource.system for r in job.all_recipes] job.recipesets[0].recipes[0].tasks[-1].stop() job.recipesets[0].recipes[0]._update_status() job.recipesets[0].recipes[1].tasks[-1].stop() job.recipesets[0].recipes[1]._update_status() session.flush() self.assertEquals(job.recipesets[0].recipes[0].status, TaskStatus.completed) self.assertEquals(job.recipesets[0].recipes[1].status, TaskStatus.completed) self.assertEquals(job.recipesets[0].status, TaskStatus.running) self.assertEquals(job.status, TaskStatus.running) self.assert_(systems[0].open_reservation is not None) self.assert_(systems[1].open_reservation is not None) job.update_status() session.flush() session.expire_all() self.assertEquals(systems[0].open_reservation, None) self.assertEquals(systems[1].open_reservation, None) self.assertEquals(job.recipesets[0].status, TaskStatus.completed) self.assertEquals(job.status, TaskStatus.completed)
def test_change_files(self): with session.begin(): job = data_setup.create_completed_job() recipe = job.recipesets[0].recipes[0] self.server.auth.login_password(self.lc.user.user_name, u'logmein') # beaker-transfer calls something like this, after it finishes copying # the logs from the LC cache to the archive server self.server.recipes.change_files( recipe.id, 'http://archive.example.com/beaker-logs', '/var/www/html/beaker-logs') with session.begin(): session.expire_all() # The actual value of .server and .basepath will depend on the date # and database IDs, so let's just check that it starts with the new # expected location. for log in [ recipe.logs[0], recipe.tasks[0].logs[0], recipe.tasks[0].results[0].logs[0] ]: self.assert_( log.server.startswith( 'http://archive.example.com/beaker-logs/'), log.server) self.assert_( log.basepath.startswith('/var/www/html/beaker-logs/'), log.basepath)
def test_recovers_running_job_with_completed_recipes(self): # job with two recipes, both Completed, but job is Running # and systems are still assigned job = data_setup.create_job(num_recipes=2) data_setup.mark_job_running(job) systems = [r.resource.system for r in job.all_recipes] job.recipesets[0].recipes[0].tasks[-1].stop() job.recipesets[0].recipes[0]._update_status() job.recipesets[0].recipes[1].tasks[-1].stop() job.recipesets[0].recipes[1]._update_status() session.flush() self.assertEquals(job.recipesets[0].recipes[0].status, TaskStatus.completed) self.assertEquals(job.recipesets[0].recipes[1].status, TaskStatus.completed) self.assertEquals(job.recipesets[0].status, TaskStatus.running) self.assertEquals(job.status, TaskStatus.running) self.assert_(systems[0].open_reservation is not None) self.assert_(systems[1].open_reservation is not None) job._mark_dirty() # in reality, we did this by hand job.update_status() session.flush() session.expire_all() self.assertEquals(systems[0].open_reservation, None) self.assertEquals(systems[1].open_reservation, None) self.assertEquals(job.recipesets[0].status, TaskStatus.completed) self.assertEquals(job.status, TaskStatus.completed)
def test_inverted_group_modify_grant_owner(self): with session.begin(): group = data_setup.create_group(owner=self.user, membership_type=GroupMembershipType.inverted) user1 = data_setup.create_user() group.add_member(user1) user2 = data_setup.create_user() group.add_member(user2) # user3 is not associated but can also be set as the group owner. user3 = data_setup.create_user() out = run_client(['bkr', 'group-modify', '--grant-owner', user1.user_name, '--grant-owner', user2.user_name, '--grant-owner', user3.user_name, group.group_name], config = self.client_config) with session.begin(): session.expire_all() self.assertTrue(group.has_owner(user1)) self.assertTrue(group.has_owner(user2)) self.assertTrue(group.has_owner(user3)) self.assertEquals(group.activity[-1].action, u'Added') self.assertEquals(group.activity[-1].field_name, u'Owner') self.assertEquals(group.activity[-1].new_value, user3.user_name) self.assertEquals(group.activity[-1].service, u'HTTP')
def test_inverted_group_modify_grant_owner(self): with session.begin(): group = data_setup.create_group( owner=self.user, membership_type=GroupMembershipType.inverted) user1 = data_setup.create_user() group.add_member(user1) user2 = data_setup.create_user() group.add_member(user2) # user3 is not associated but can also be set as the group owner. user3 = data_setup.create_user() out = run_client([ 'bkr', 'group-modify', '--grant-owner', user1.user_name, '--grant-owner', user2.user_name, '--grant-owner', user3.user_name, group.group_name ], config=self.client_config) with session.begin(): session.expire_all() self.assertTrue(group.has_owner(user1)) self.assertTrue(group.has_owner(user2)) self.assertTrue(group.has_owner(user3)) self.assertEquals(group.activity[-1].action, u'Added') self.assertEquals(group.activity[-1].field_name, u'Owner') self.assertEquals(group.activity[-1].new_value, user3.user_name) self.assertEquals(group.activity[-1].service, u'HTTP')
def test_activity_created_with_expire(self): self.server.auth.login_password(self.user.user_name, u'password') self.server.distros.expire(self.distro.name, 'CUSTOMSERVICE') session.expire_all() with session.begin(): activity = self.distro_tree.activity[0] self.assertEquals(activity.service, u'CUSTOMSERVICE')
def test_purge_stale_running_commands(self): with session.begin(): distro_tree = data_setup.create_distro_tree(osmajor=u'Fedora20') # Helper to build the commands def _make_command(lc=None, creation_date=None): job = data_setup.create_job(distro_tree=distro_tree) recipe = job.recipesets[0].recipes[0] system = data_setup.create_system(lab_controller=lc) data_setup.mark_recipe_waiting(recipe, system=system) command = CommandActivity( user=None, service=u'testdata', action=u'on', status=CommandStatus.running, callback=u'bkr.server.model.auto_cmd_handler') if creation_date is not None: command.created = command.updated = creation_date system.command_queue.append(command) return recipe.tasks[0], command # Normal command for the current LC recent_task, recent_command = _make_command(lc=self.lc) # Old command for a different LC backdated = datetime.datetime.utcnow() backdated -= datetime.timedelta(days=1, minutes=1) old_task, old_command = _make_command(creation_date=backdated) self.server.auth.login_password(self.lc.user.user_name, u'logmein') self.server.labcontrollers.clear_running_commands(u'Staleness') with session.begin(): session.expire_all() # Recent commands have their callback invoked self.assertEquals(recent_command.status, CommandStatus.aborted) self.assertEquals(recent_task.status, TaskStatus.aborted) # Stale commands just get dropped on the floor self.assertEquals(old_command.status, CommandStatus.aborted) self.assertEquals(old_task.status, TaskStatus.waiting)
def test_power_commands_are_not_run_twice(self): # We will make the dummy power script sleep for this long: power_sleep = 4 # To reproduce this bug, we need to queue up three commands for the # same system (so they are run in sequence by beaker-provision), where # the commands take enough time that the second one will still be # running on the next iteration of the polling loop. The third command # will be run twice. assert power_sleep < get_conf().get('SLEEP_TIME') assert 2 * power_sleep > get_conf().get('SLEEP_TIME') with session.begin(): system = data_setup.create_system(lab_controller=self.get_lc()) system.power.power_type = PowerType.lazy_create(name=u'dummy') system.power.power_id = power_sleep # make power script sleep system.action_power(action=u'off', service=u'testdata') system.action_power(action=u'off', service=u'testdata') system.action_power(action=u'off', service=u'testdata') wait_for_commands_to_finish(system, timeout=5 * power_sleep) with session.begin(): session.expire_all() self.assertEquals(system.command_queue[0].status, CommandStatus.completed) self.assertEquals(system.command_queue[1].status, CommandStatus.completed) self.assertEquals(system.command_queue[2].status, CommandStatus.completed) # The bug manifests as two "Completed" records for the power # command which ran twice self.assertEquals(system.dyn_activity .filter_by(field_name=u'Power', new_value=u'Completed') .count(), 3)
def test_nak_job(self): out = run_client(['bkr', 'job-modify', self.job.t_id, '--response', 'nak']) self.assert_(out == 'Successfully modified jobs %s\n' % self.job.t_id) with session.begin(): session.expire_all() for rs in self.job.recipesets: self.assertEqual(rs.waived, True)
def test_concurrent_recipe_completion(self): # This test simulates two recipes finishing at the same time. So we # have two concurrent transactions both updating the respective task states. # Previously there was no separate job.update_status() step, so the two # transactions would update the job status using out-of-date values in # both transactions, leaving the job running. with session.begin(): recipe1 = data_setup.create_recipe() recipe2 = data_setup.create_recipe() job = data_setup.create_job_for_recipes([recipe1, recipe2]) assert len(recipe1.tasks) == 1 assert len(recipe2.tasks) == 1 data_setup.mark_recipe_running(recipe1) data_setup.mark_recipe_running(recipe2) recipe1.tasks[-1].pass_(u"/", 0, u"Pass") recipe2.tasks[-1].pass_(u"/", 0, u"Pass") # Complete the recipes "concurrently" in two separate transactions class RecipeCompletionThread(Thread): def __init__(self, recipe_id=None, **kwargs): super(RecipeCompletionThread, self).__init__(**kwargs) self.recipe_id = recipe_id self.ready_evt = Event() self.continue_evt = Event() def run(self): session.begin() recipe = Recipe.by_id(self.recipe_id) self.ready_evt.set() self.continue_evt.wait() recipe.tasks[-1].stop() session.commit() thread1 = RecipeCompletionThread(name="recipe1", recipe_id=recipe1.id) thread2 = RecipeCompletionThread(name="recipe2", recipe_id=recipe2.id) thread1.start() thread2.start() # Wait for both threads to start their transactions thread1.ready_evt.wait() thread2.ready_evt.wait() # Allow recipe 1 to complete thread1.continue_evt.set() thread1.join() with session.begin(): session.expire_all() job.update_status() self.assertEquals(recipe1.status, TaskStatus.completed) self.assertEquals(recipe1.ptasks, 1) self.assertEquals(job.status, TaskStatus.running) self.assertEquals(job.ptasks, 1) # Now recipe 2 completes thread2.continue_evt.set() thread2.join() with session.begin(): session.expire_all() job.update_status() self.assertEquals(recipe2.status, TaskStatus.completed) self.assertEquals(recipe2.ptasks, 1) self.assertEquals(job.status, TaskStatus.completed) self.assertEquals(job.ptasks, 2)
def test_rolls_back_on_error(self): # The bug was that a row contained invalid data, which meant it was # being discarded, but changes to system_status_duration were # nevertheless being committed. # To reproduce, we upload a CSV which changes 'status' successfully # (thereby causing a row to be added to system_status_duration) but # then errors out on 'secret' which does not accept empty string. with session.begin(): self.assertEquals(len(self.system.status_durations), 1) self.assertEquals(self.system.status_durations[0].status, SystemStatus.automated) self.assertEquals(self.system.status_durations[0].finish_time, None) login(self.browser) self.import_csv( (u'csv_type,id,status,secret\n' u'system,%s,Manual,\n' % self.system.id).encode('utf8')) import_log = self.browser.find_element_by_xpath( '//table[@id="csv-import-log"]//td').text self.assertIn('Invalid secret None', import_log) with session.begin(): session.expire_all() self.assertEquals(self.system.status, SystemStatus.automated) self.assertEquals(len(self.system.status_durations), 1) self.assertEquals(self.system.status_durations[0].finish_time, None)
def test_export_xml(self): b = self.browser # Make sure the Export button is present in the jobs grid. We can't # actually click it because it triggers a download, which WebDriver # can't handle. b.get(get_server_base() + 'jobs/') b.find_element_by_name('simplesearch').send_keys( unicode(self.job_to_export.whiteboard)) b.find_element_by_name('jobsearch_simple').submit() b.find_element_by_xpath('//tr[normalize-space(string(./td[1]))="%s"]' '//a[text()="Export"]' % self.job_to_export.t_id) # Fetch the exported XML directly. response = requests.get(get_server_base() + 'to_xml?taskid=%s&pretty=False' % self.job_to_export.t_id) actual = response.content with session.begin(): # Expire the job, otherwise the exported job XML (read from the # Python instance) will have a duration attribute while the export # from the view will have not since our database stores only seconds session.expire_all() job = Job.by_id(self.job_to_export.id) expected = lxml.etree.tostring(job.to_xml(), pretty_print=True, encoding='utf8') self.assertMultiLineEqual(expected, actual)
def test_set_active_policy_to_custom_policy(self): with session.begin(): user1 = data_setup.create_user() user2 = data_setup.create_user() self.system.custom_access_policy.add_rule( permission=SystemPermission.edit_system, user=user1) pool = data_setup.create_system_pool() pool.access_policy.add_rule( permission=SystemPermission.edit_system, user=user2) self.system.active_access_policy = pool.access_policy self.assertFalse(self.system.active_access_policy.grants (user1, SystemPermission.edit_system)) self.assertTrue(self.system.active_access_policy.grants (user2, SystemPermission.edit_system)) s = requests.Session() s.post(get_server_base() + 'login', data={'user_name': self.owner.user_name, 'password': '******'}).raise_for_status() response = patch_json(get_server_base() + 'systems/%s/' % self.system.fqdn, session=s, data={'active_access_policy': {'custom': True}}, ) response.raise_for_status() with session.begin(): session.expire_all() self.assertTrue(self.system.active_access_policy.grants \ (user1, SystemPermission.edit_system))
def test_update_lab_controller_with_lab_controller_object(self): with session.begin(): system = data_setup.create_system() lc = data_setup.create_labcontroller() s = requests.Session() s.post(get_server_base() + 'login', data={ 'user_name': data_setup.ADMIN_USER, 'password': data_setup.ADMIN_PASSWORD }).raise_for_status() response = patch_json( get_server_base() + 'systems/%s/' % system.fqdn, session=s, data={'lab_controller': { 'fqdn': lc.fqdn }}, ) response.raise_for_status() with session.begin(): session.expire_all() self.assertTrue(system.lab_controller, lc) self.assertEquals(system.activity[-1].field_name, 'Lab Controller') self.assertEquals(system.activity[-1].action, 'Changed') self.assertEquals(system.activity[-1].old_value, None) self.assertEquals(system.activity[-1].new_value, lc.fqdn)
def test_concurrent_recipe_completion(self): # This test simulates two recipes finishing at the same time. So we # have two concurrent transactions both updating the respective task states. # Previously there was no separate job.update_status() step, so the two # transactions would update the job status using out-of-date values in # both transactions, leaving the job running. with session.begin(): recipe1 = data_setup.create_recipe() recipe2 = data_setup.create_recipe() job = data_setup.create_job_for_recipes([recipe1, recipe2]) assert len(recipe1.tasks) == 1 assert len(recipe2.tasks) == 1 data_setup.mark_recipe_running(recipe1) data_setup.mark_recipe_running(recipe2) recipe1.tasks[-1].pass_(u'/', 0, u'Pass') recipe2.tasks[-1].pass_(u'/', 0, u'Pass') # Complete the recipes "concurrently" in two separate transactions class RecipeCompletionThread(Thread): def __init__(self, recipe_id=None, **kwargs): super(RecipeCompletionThread, self).__init__(**kwargs) self.recipe_id = recipe_id self.ready_evt = Event() self.continue_evt = Event() def run(self): session.begin() recipe = Recipe.by_id(self.recipe_id) self.ready_evt.set() self.continue_evt.wait() recipe.tasks[-1].stop() session.commit() thread1 = RecipeCompletionThread(name='recipe1', recipe_id=recipe1.id) thread2 = RecipeCompletionThread(name='recipe2', recipe_id=recipe2.id) thread1.start() thread2.start() # Wait for both threads to start their transactions thread1.ready_evt.wait() thread2.ready_evt.wait() # Allow recipe 1 to complete thread1.continue_evt.set() thread1.join() with session.begin(): session.expire_all() job.update_status() self.assertEquals(recipe1.status, TaskStatus.completed) self.assertEquals(recipe1.ptasks, 1) self.assertEquals(job.status, TaskStatus.running) self.assertEquals(job.ptasks, 1) # Now recipe 2 completes thread2.continue_evt.set() thread2.join() with session.begin(): session.expire_all() job.update_status() self.assertEquals(recipe2.status, TaskStatus.completed) self.assertEquals(recipe2.ptasks, 1) self.assertEquals(job.status, TaskStatus.completed) self.assertEquals(job.ptasks, 2)
def test_activity_created_with_expire(self): self.server.auth.login_password(data_setup.ADMIN_USER, data_setup.ADMIN_PASSWORD) self.server.distros.expire(self.distro.name, 'CUSTOMSERVICE') session.expire_all() with session.begin(): activity = self.distro_tree.activity[0] self.assertEquals(activity.service, u'CUSTOMSERVICE')
def test_successful_add_tag_for_all_distros(self): with session.begin(): self.distro = data_setup.create_distro() out = run_client(['bkr', 'distros-tag', '--name=%', 'addAll']) with session.begin(): session.expire_all() for distro in Distro.query: self.assertIn(u'addAll', distro.tags)
def test_rhel6_defaults_recipe(self): recipe = self._create_recipe() session.expire_all() generated_ks = self._run_create_kickstart( ['--recipe-id', str(recipe.id)]) compare_expected( 'RedHatEnterpriseLinux6-scheduler-defaults-beaker-create-kickstart', recipe.id, generated_ks)
def test_set_recipe_whiteboard(self): recipe = self.job.recipesets[0].recipes[0] out = run_client(['bkr', 'job-modify', recipe.t_id, '--whiteboard', 'found himself transformed']) self.assertIn('Successfully modified jobs %s' % recipe.t_id, out) with session.begin(): session.expire_all() self.assertEquals(recipe.whiteboard, u'found himself transformed')
def test_disable_the_lab_controller(self): with session.begin(): lc = data_setup.create_labcontroller() user = data_setup.create_user() run_client(['bkr', 'labcontroller-modify', '--disable', lc.fqdn]) with session.begin(): session.expire_all() self.assertTrue(lc.disabled)
def test_remove_account(self): with session.begin(): user = data_setup.create_user() job = data_setup.create_job(owner=user) data_setup.mark_job_running(job) owned_system = data_setup.create_system(owner=user) loaned_system = data_setup.create_system() loaned_system.loaned = user reserved_system = data_setup.create_system(status=u"Manual") reserved_system.reserve_manually(service=u"testdata", user=user) reserved_system.custom_access_policy.add_rule(SystemPermission.reserve, user=user) group = data_setup.create_group(owner=user) run_client(["bkr", "remove-account", user.user_name]) with session.begin(): session.expire_all() self.assertIsNotNone(user.removed) # running jobs should be cancelled job.update_status() self.assertEquals(job.status, TaskStatus.cancelled) self.assertIn("User %s removed" % user.user_name, job.recipesets[0].recipes[0].tasks[0].results[0].log) # reservations should be released self.assertIsNone(reserved_system.user) self.assertEqual(reserved_system.activity[1].user.user_name, data_setup.ADMIN_USER) self.assertEqual(reserved_system.activity[1].field_name, u"User") self.assertEqual(reserved_system.activity[1].action, u"Returned") self.assertEqual(reserved_system.activity[1].old_value, user.user_name) self.assertEqual(reserved_system.activity[1].new_value, u"") # loans should be returned self.assertIsNone(loaned_system.loaned) self.assertEqual(loaned_system.activity[0].user.user_name, data_setup.ADMIN_USER) self.assertEqual(loaned_system.activity[0].field_name, u"Loaned To") self.assertEqual(loaned_system.activity[0].action, u"Changed") self.assertEqual(loaned_system.activity[0].old_value, user.user_name) self.assertEqual(loaned_system.activity[0].new_value, None) # access policy rules should be removed self.assertEqual([], [rule for rule in reserved_system.custom_access_policy.rules if rule.user == user]) self.assertEqual(reserved_system.activity[0].user.user_name, data_setup.ADMIN_USER) self.assertEqual(reserved_system.activity[0].field_name, u"Access Policy Rule") self.assertEqual(reserved_system.activity[0].action, u"Removed") self.assertEqual(reserved_system.activity[0].old_value, u"<grant reserve to %s>" % user.user_name) self.assertEqual(reserved_system.activity[0].new_value, None) # systems owned by the user should be transferred to the caller self.assertEqual(owned_system.owner.user_name, data_setup.ADMIN_USER) self.assertEqual(owned_system.activity[0].user.user_name, data_setup.ADMIN_USER) self.assertEqual(owned_system.activity[0].field_name, u"Owner") self.assertEqual(owned_system.activity[0].action, u"Changed") self.assertEqual(owned_system.activity[0].old_value, user.user_name) self.assertEqual(owned_system.activity[0].new_value, data_setup.ADMIN_USER) # group membership/ownership should be removed self.assertNotIn(group, user.groups) self.assertNotIn(user, group.users) self.assertFalse(group.has_owner(user)) self.assertEqual(group.activity[-1].user.user_name, data_setup.ADMIN_USER) self.assertEqual(group.activity[-1].field_name, u"User") self.assertEqual(group.activity[-1].action, u"Removed") self.assertEqual(group.activity[-1].old_value, user.user_name) self.assertEqual(group.activity[-1].new_value, None)
def test_change_user_name(self): with session.begin(): lc = data_setup.create_labcontroller() user = data_setup.create_user() run_client( ['bkr', 'labcontroller-modify', '--user', user.user_name, lc.fqdn]) with session.begin(): session.expire_all() self.assertEqual(lc.user.user_name, user.user_name)
def test_change_password(self): with session.begin(): lc = data_setup.create_labcontroller() run_client(['bkr', 'labcontroller-modify', '--password', u'newpassword', lc.fqdn]) with session.begin(): session.expire_all() self.assertTrue(lc.user.check_password(u'newpassword'))
def test_records_activity_on_changing_access_policy(self): with session.begin(): system = data_setup.create_system() pool = data_setup.create_system_pool() pool.systems.append(system) # change the system active access policy to pool access policy s = requests.Session() s.post(get_server_base() + 'login', data={ 'user_name': data_setup.ADMIN_USER, 'password': data_setup.ADMIN_PASSWORD }).raise_for_status() response = patch_json( get_server_base() + 'systems/%s/' % system.fqdn, session=s, data={'active_access_policy': { 'pool_name': pool.name }}, ) response.raise_for_status() with session.begin(): session.expire_all() self.assertTrue(system.active_access_policy, pool.access_policy) self.assertEquals(system.activity[-1].field_name, 'Active Access Policy') self.assertEquals(system.activity[-1].action, 'Changed') self.assertEquals(system.activity[-1].old_value, 'Custom access policy') self.assertEquals(system.activity[-1].new_value, 'Pool policy: %s' % unicode(pool)) # change the system active access policy back to custom access policy s = requests.Session() s.post(get_server_base() + 'login', data={ 'user_name': data_setup.ADMIN_USER, 'password': data_setup.ADMIN_PASSWORD }).raise_for_status() response = patch_json( get_server_base() + 'systems/%s/' % system.fqdn, session=s, data={'active_access_policy': { 'custom': True }}, ) response.raise_for_status() with session.begin(): session.expire_all() self.assertTrue(system.active_access_policy, system.custom_access_policy) self.assertEquals(system.activity[-2].field_name, 'Active Access Policy') self.assertEquals(system.activity[-2].action, 'Changed') self.assertEquals(system.activity[-2].old_value, 'Pool policy: %s' % unicode(pool)) self.assertEquals(system.activity[-2].new_value, 'Custom access policy')
def test_increase_priority(self): out = run_client(['bkr', 'job-modify', self.job.t_id, '--priority', 'High']) self.assertIn('Successfully modified jobs %s' % self.job.t_id, out) with session.begin(): session.expire_all() for rs in self.job.recipesets: self.assertEquals(rs.priority.value, 'High') self.assertEquals(self.job.recipesets[0].activity[0].action, u'Changed') self.assertEquals(self.job.recipesets[0].activity[0].field_name, 'Priority') self.assertEquals(self.job.recipesets[0].activity[0].new_value, 'High')
def test_task_update_disable_normal_user_fail(self): req_sess = requests.Session() requests_login(req_sess, self.normal_user.user_name, 'secret') self.assertEqual(self.my_task.valid, True) response = patch_json(get_server_base() + 'tasks/%s' % self.my_task.id, session=req_sess, data={'disabled': True}) self.assertEqual(response.status_code, 403) with session.begin(): session.expire_all() self.assertEqual(self.my_task.valid, True)
def test_multiple_response_recipeset(self): out = run_client(['bkr', 'job-modify', self.job.recipesets[0].t_id, self.job_for_rs.recipesets[0].t_id, '--response', 'nak']) self.assert_('Successfully modified jobs' in out and \ self.job_for_rs.recipesets[0].t_id in out and \ self.job.recipesets[0].t_id in out,) with session.begin(): session.expire_all() self.assertEqual(self.job.recipesets[0].waived, True) self.assertEqual(self.job_for_rs.recipesets[0].waived, True)
def test_change_email_address(self): with session.begin(): lc = data_setup.create_labcontroller() user = data_setup.create_user() run_client(['bkr', 'labcontroller-modify', '--email', u'*****@*****.**', lc.fqdn]) with session.begin(): session.expire_all() self.assertEqual(lc.user.email_address, u'*****@*****.**')
def _assert_logs_not_in_db(self, job): with session.begin(): session.expire_all() for rs in job.recipesets: for r in rs.recipes: self.assert_(r.logs == []) for rt in r.tasks: self.assert_(rt.logs == []) for rtr in rt.results: self.assert_(rtr.logs == [])
def test_recipe_task_result_rows_are_deleted(self): with session.begin(): self.job_to_delete.deleted = datetime.datetime.utcnow() recipe = self.job_to_delete.recipesets[0].recipes[0] recipetask = recipe.tasks[0] self.assertEqual(len(recipetask.results), 1) run_command('log_delete.py', 'beaker-log-delete') with session.begin(): session.expire_all() self.assertEqual(len(recipetask.results), 0)
def test_post_comment_to_recipeset(self): with session.begin(): recipe = self.job.recipesets[0] comment_text = u'Never gonna give you up' out = run_client(['bkr', 'job-comment', recipe.t_id, '--message', comment_text]) with session.begin(): session.expire_all() self.assertEqual(recipe.comments[0].comment, comment_text)
def test_change_user_name(self): with session.begin(): lc = data_setup.create_labcontroller() user = data_setup.create_user() run_client(['bkr', 'labcontroller-modify', '--user', user.user_name, lc.fqdn]) with session.begin(): session.expire_all() self.assertEqual(lc.user.user_name, user.user_name)
def test_close_account_transfer_ownership(self): with session.begin(): new_owner = data_setup.create_user() user = data_setup.create_user() system = data_setup.create_system(owner=user) run_client(['bkr', 'remove-account', '--new-owner=%s' % new_owner.user_name, user.user_name]) with session.begin(): session.expire_all() self.assertEqual(system.owner, new_owner)
def test_rendered_kickstart_is_deleted(self): with session.begin(): self.job_to_delete.to_delete = datetime.datetime.utcnow() recipe = self.job_to_delete.recipesets[0].recipes[0] ks = RenderedKickstart(kickstart=u'This is not a real kickstart.') recipe.installation.rendered_kickstart = ks log_delete.log_delete() with session.begin(): session.expire_all() self.assertEqual(recipe.installation.rendered_kickstart, None) self.assertRaises(NoResultFound, RenderedKickstart.by_id, ks.id)
def test_can_clear_reviewed_state(self): with session.begin(): self.recipe.set_reviewed_state(self.owner, True) s = requests.Session() requests_login(s, user=self.owner, password=u'theowner') response = patch_json(get_server_base() + 'recipes/%s' % self.recipe.id, session=s, data={'reviewed': False}) response.raise_for_status() with session.begin(): session.expire_all() self.assertEqual(self.recipe.get_reviewed_state(self.owner), False)
def test_task_update_disable_successful(self): req_sess = requests.Session() requests_login(req_sess, data_setup.ADMIN_USER, data_setup.ADMIN_PASSWORD) self.assertEqual(self.my_task.valid, True) response = patch_json(get_server_base() + 'tasks/%s' % self.my_task.id, session=req_sess, data={'disabled': True}) response.raise_for_status() self.assertEqual(response.json()['valid'], False) with session.begin(): session.expire_all() self.assertEqual(self.my_task.valid, False)
def test_post_comment_to_recipetask(self): with session.begin(): recipe = self.job.recipesets[0].recipes[0] task = recipe.tasks[0] comment_text = u'Never gonna let you down' out = run_client(['bkr', 'job-comment', task.t_id, '--message', comment_text]) with session.begin(): session.expire_all() self.assertEqual(task.comments[0].comment, comment_text)
def test_can_set_zero_quiescent_period(self): with session.begin(): system = data_setup.create_system() s = requests.Session() s.post(get_server_base() + 'login', data={'user_name': data_setup.ADMIN_USER, 'password': data_setup.ADMIN_PASSWORD}).raise_for_status() response = patch_json(get_server_base() + 'systems/%s/' % system.fqdn, session=s, data={'power_quiescent_period': 0}) response.raise_for_status() with session.begin(): session.expire_all() self.assertEquals(system.power.power_quiescent_period, 0)
def test_processes_all_arguments_even_if_one_fails(self): # This behaviour is actually contrary to what the other subcommands do, # but it's what we have, so let's test it anyway... p = start_client(['bkr', 'job-modify', 'J:thiswillfail', self.job.t_id, '--whiteboard', 'uneasy dreams']) out, err = p.communicate() self.assertEquals(p.returncode, 1) self.assertIn('Failed to modify J:thiswillfail', err) self.assertEquals(out, 'Successfully modified jobs %s\n' % self.job.t_id) with session.begin(): session.expire_all() self.assertEquals(self.job.whiteboard, u'uneasy dreams')
def test_rhel6_defaults_no_recipe(self): with session.begin(): lc = create_lab_controller() system = create_x86_64_automated(lc) self.rhel62_server_x86_64 = create_rhel62_server_x86_64(lab_controller=lc) user = create_user() session.expire_all() distro_tree_id = self.rhel62_server_x86_64.id generated_ks = self._run_create_kickstart(['--distro-tree-id', str(distro_tree_id), '--system', system.fqdn, '--user', user.user_name]) compare_expected('RedHatEnterpriseLinux6-manual-defaults-beaker-create-kickstart', None, generated_ks)