예제 #1
0
 def test_watchdog_time_remaining_display(self):
     b = self.browser
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe], owner=self.user)
         data_setup.mark_job_running(job)
         recipe.watchdog.kill_time = (
             datetime.datetime.utcnow() +
             datetime.timedelta(seconds=83 * 60 + 30))
     self.go_to_recipe_view(recipe)
     b.find_element_by_link_text('Show Results').click()
     duration = b.find_element_by_xpath(
         '//tr[contains(@class, "recipe_%s")][1]'
         '//div[@class="task-duration"]' % recipe.id)
     self.assertRegexpMatches(duration.text, r'^Time Remaining 1:23:\d\d$')
     with session.begin():
         recipe.watchdog.kill_time = (
             datetime.datetime.utcnow() +
             datetime.timedelta(days=2, seconds=83 * 60 + 30))
     self.go_to_recipe_view(recipe)
     duration = b.find_element_by_xpath(
         '//tr[contains(@class, "recipe_%s")][1]'
         '//div[@class="task-duration"]' % recipe.id)
     self.assertRegexpMatches(duration.text,
                              r'^Time Remaining 2 days, 1:23:\d\d$')
예제 #2
0
 def test_page_works(self):
     # make sure we have at least one watchdog to see
     with session.begin():
         data_setup.mark_job_running(data_setup.create_job())
     b = self.browser
     b.get(get_server_base() + "watchdogs/")
     self.assertEquals(b.title, "Watchdogs")
예제 #3
0
 def setUpClass(cls):
     cls.running_job = data_setup.create_job()
     cls.queued_job = data_setup.create_job()
     cls.completed_job = data_setup.create_completed_job()
     data_setup.mark_job_queued(cls.queued_job)
     data_setup.mark_job_running(cls.running_job)
     cls.browser = cls.get_browser()
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    def test_remove_user_job_cancel(self):
        with session.begin():
            user = data_setup.create_user(user_name =
                                          data_setup.unique_name('aaaaa%s'))
            job = data_setup.create_job(owner=user)
            data_setup.mark_job_running(job)

        b = self.browser
        login(b)
        b.get(get_server_base() + 'users')
        b.find_element_by_xpath('//a[@href="remove?id=%d"]' %user.user_id).click()
        # XXX: not necessary, but doing it here to buy time, since sometimes the
        # job cancellation seems to take a while
        logout(b)

        # reflect the change in recipe task status when
        # update_dirty_jobs() is called
        session.expunge_all()
        beakerd.update_dirty_jobs()

        with session.begin():
            job = Job.by_id(job.id)
            self.assertEquals(job.status, TaskStatus.cancelled)
            self.assertIn('User %s removed' % user.user_name,
                          job.recipesets[0].recipes[0].tasks[0].results[0].log)
예제 #7
0
    def test_remove_user_job_cancel(self):
        with session.begin():
            user = data_setup.create_user(user_name =
                                          data_setup.unique_name('aaaaa%s'))
            job = data_setup.create_job(owner=user)
            data_setup.mark_job_running(job)

        b = self.browser
        login(b)
        b.get(get_server_base() + 'users')
        b.find_element_by_xpath('//a[@href="remove?id=%d"]' %user.user_id).click()
        # XXX: not necessary, but doing it here to buy time, since sometimes the
        # job cancellation seems to take a while
        logout(b)

        # reflect the change in recipe task status when
        # update_dirty_jobs() is called
        session.expunge_all()
        beakerd.update_dirty_jobs()

        with session.begin():
            job = Job.by_id(job.id)
            self.assertEquals(job.status, TaskStatus.cancelled)
            self.assertIn('User %s removed' % user.user_name,
                          job.recipesets[0].recipes[0].tasks[0].results[0].log)
예제 #8
0
 def test_page_works(self):
     # make sure we have at least one watchdog to see
     with session.begin():
         data_setup.mark_job_running(data_setup.create_job())
     b = self.browser
     b.get(get_server_base() + 'watchdogs/')
     self.assertEquals(b.title, 'Watchdogs')
예제 #9
0
파일: test_users.py 프로젝트: walbon/beaker
 def test_user_resource_counts_are_accurate_when_removing(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
         owned_pool = data_setup.create_system_pool(owning_user=user)
         group = data_setup.create_group(owner=user)
     s = requests.Session()
     requests_login(s)
     response = s.get(get_server_base() + 'users/%s' % user.user_name,
             headers={'Accept': 'application/json'})
     response.raise_for_status()
     self.assertEquals(response.json()['job_count'], 1)
     self.assertEquals(response.json()['reservation_count'], 1)
     self.assertEquals(response.json()['loan_count'], 1)
     self.assertEquals(response.json()['owned_system_count'], 1)
     self.assertEquals(response.json()['owned_pool_count'], 1)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
             data={'removed': 'now'}, session=s)
     response.raise_for_status()
     # The bug was that the counts in the PATCH response would still show 
     # their old values, because the queries for producing the counts were 
     # being run before all the removals were flushed to the database.
     # Note that job_count stays as 1, because the job has been cancelled 
     # but it will still be running until the next iteration of beakerd's 
     # update_dirty_jobs.
     self.assertEquals(response.json()['job_count'], 1)
     self.assertEquals(response.json()['reservation_count'], 0)
     self.assertEquals(response.json()['loan_count'], 0)
     self.assertEquals(response.json()['owned_system_count'], 0)
     self.assertEquals(response.json()['owned_pool_count'], 0)
예제 #10
0
 def setUpClass(cls):
     cls.running_job = data_setup.create_job()
     cls.queued_job = data_setup.create_job()
     cls.completed_job = data_setup.create_completed_job()
     data_setup.mark_job_queued(cls.queued_job)
     data_setup.mark_job_running(cls.running_job)
     cls.selenium = cls.get_selenium()
     cls.selenium.start()
예제 #11
0
 def setUp(self):
     with session.begin():
         self.running_job = data_setup.create_job()
         self.queued_job = data_setup.create_job()
         self.completed_job = data_setup.create_completed_job()
         data_setup.mark_job_queued(self.queued_job)
         data_setup.mark_job_running(self.running_job)
     self.browser = self.get_browser()
예제 #12
0
 def setUp(self):
     with session.begin():
         self.running_job = data_setup.create_job()
         self.queued_job = data_setup.create_job()
         self.completed_job = data_setup.create_completed_job()
         data_setup.mark_job_queued(self.queued_job)
         data_setup.mark_job_running(self.running_job)
     self.browser = self.get_browser()
예제 #13
0
 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=SystemStatus.manual)
         reserved_system.reserve_manually(service=u'testdata', user=user)
         reserved_system.custom_access_policy.add_rule(
                 SystemPermission.reserve, user=user)
         owned_pool = data_setup.create_system_pool(owning_user=user)
         group = data_setup.create_group(owner=user)
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
             data={'removed': 'now'}, session=s)
     response.raise_for_status()
     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)
         # loans should be returned
         self.assertIsNone(loaned_system.loaned)
         # 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].field_name, u'Access Policy Rule')
         self.assertEqual(reserved_system.activity[0].action, u'Removed')
         self.assertEqual(reserved_system.activity[0].old_value,
                 u'User:%s:reserve' % user.user_name)
         # 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].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)
         # pools owned by the user should be transferred to the caller
         self.assertEqual(owned_pool.owner.user_name, data_setup.ADMIN_USER)
         self.assertEqual(owned_pool.activity[0].field_name, u'Owner')
         self.assertEqual(owned_pool.activity[0].action, u'Changed')
         self.assertEqual(owned_pool.activity[0].old_value, user.user_name)
         self.assertEqual(owned_pool.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].field_name, u'User')
         self.assertEqual(group.activity[-1].action, u'Removed')
         self.assertEqual(group.activity[-1].old_value, user.user_name)
예제 #14
0
 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=SystemStatus.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)
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'removed': 'now'},
                           session=s)
     response.raise_for_status()
     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)
         # loans should be returned
         self.assertIsNone(loaned_system.loaned)
         # 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].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)
         # 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].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].field_name, u'User')
         self.assertEqual(group.activity[-1].action, u'Removed')
         self.assertEqual(group.activity[-1].old_value, user.user_name)
예제 #15
0
 def test_cannot_review_unfinished_recipesets(self):
     with session.begin():
         owner = data_setup.create_user(password=u'owner')
         job = data_setup.create_job(owner=owner)
         data_setup.mark_job_running(job)
     b = self.browser
     login(b, user=owner.user_name, password='******')
     b.get(get_server_base() + 'jobs/%s' % job.id)
     self.check_cannot_review()
예제 #16
0
 def test_cannot_update_reservation_request_if_duration_too_long(self):
     with session.begin():
         data_setup.mark_job_running(self.job)
     s = requests.Session()
     requests_login(s, user=self.owner, password=u'theowner')
     response = patch_json(get_server_base() +
             'recipes/%s/reservation-request' % self.recipe_with_reservation_request.id,
             session=s, data={'reserve': True, 'duration': 605000})
     self.assertEquals(response.status_code, 400)
예제 #17
0
 def test_cannot_update_reservation_request_if_duration_too_long(self):
     with session.begin():
         data_setup.mark_job_running(self.job)
     s = requests.Session()
     requests_login(s, user=self.owner, password=u'theowner')
     response = patch_json(get_server_base() +
             'recipes/%s/reservation-request' % self.recipe_with_reservation_request.id,
             session=s, data={'reserve': True, 'duration': 605000})
     self.assertEquals(response.status_code, 400)
예제 #18
0
 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)
예제 #19
0
 def test_cannot_review_unfinished_recipesets(self):
     with session.begin():
         owner = data_setup.create_user(password=u'owner')
         job = data_setup.create_job(owner=owner)
         data_setup.mark_job_running(job)
     b = self.browser
     login(b, user=owner.user_name, password='******')
     b.get(get_server_base() + 'jobs/%s' % job.id)
     self.check_cannot_review()
 def test_system_in_use_by_another_user(self):
     with session.begin():
         system = data_setup.create_system(status=SystemStatus.automated,
                 shared=True, lab_controller=self.lc)
         job = data_setup.create_job()
         data_setup.mark_job_running(job, system=system)
     b = self.browser
     login(b)
     self.check_system_is_available(system)
     self.check_system_is_not_free(system)
예제 #21
0
    def test_show_failed_results(self):
        # To check correct display of failed results
        #   - create 3 recipes with 2 tasks each
        #   - for each recipe, mark the first task as failed in some way
        #     (Fail, Warn, Panic)
        #   - check clicking "Show Failed Results" tab shows only the first
        #   - check clicking "Hide" hides the loaded task
        status_result_pairs = []
        for result in (TaskResult.fail, TaskResult.warn, TaskResult.panic):
            for status in (TaskStatus.completed, TaskStatus.cancelled,
                            TaskStatus.aborted):
                status_result_pairs.append((status, result))

        with session.begin():
            recipes = []
            for __ in status_result_pairs:
                tasks = [data_setup.create_task() for i in range(2)]
                recipe = data_setup.create_recipe(task_list=tasks)
                recipes.append(recipe)
            job = data_setup.create_job_for_recipes(recipes, owner=self.user)
            data_setup.mark_job_queued(job)
            data_setup.mark_job_running(job)
            for recipe, (status, result) in zip(recipes, status_result_pairs):
                task_result = RecipeTaskResult(path=u'failure_result',
                                                result=result)
                recipe.tasks[0].results = [task_result]
                recipe.tasks[0].status = status
                recipe.tasks[1].start()
            job.update_status()

        b = self.browser
        for recipe in recipes:
            failed, incomplete = recipe.tasks
            expected_result = failed.results[0].result
            # These assertions ensure the task setup code above is correct
            self.assertEqual(recipe.status, TaskStatus.running)
            self.assertEqual(recipe.result, expected_result)
            self.assertEqual(failed.result, expected_result)
            self.assertEqual(incomplete.result, TaskResult.new)
            self.go_to_recipe_view(recipe)
            # Tasks should only be loaded on demand
            for t in recipe.tasks:
                self.check_task_not_loaded(recipe, t)
            # Failed result tab should only load the first task
            b.find_element_by_xpath(
                '//div[@id="recipe%s"]//a[text()="Show Failed Results"]'
                    % recipe.id).click()
            self.check_task_visible(recipe, failed)
            self.check_task_not_loaded(recipe, incomplete)
            # Clicking "Hide" should hide the loaded task
            b.find_element_by_xpath(
                    '//div[@id="recipe%s"]//a[text()="Hide"]'
                    % recipe.id).click()
            self.check_task_hidden(recipe, failed)
            self.check_task_not_loaded(recipe, incomplete)
예제 #22
0
 def setUp(self):
     with session.begin():
         dt = data_setup.create_distro_tree()
         self.system = data_setup. \
             create_system(lab_controller=self.get_lc())
         self.system_recipe = data_setup.create_recipe()
         self.guest_recipe = data_setup. \
             create_guestrecipe(host=self.system_recipe)
         self.job = data_setup.create_job_for_recipes(
             [self.system_recipe, self.guest_recipe])
         data_setup.mark_job_running(self.job)
예제 #23
0
 def test_current_job(self):
     sel = self.selenium
     self.login()
     with session.begin():
         job = data_setup.create_job(owner=self.system.owner, distro_tree=self.distro_tree)
         data_setup.mark_job_running(job, system=self.system)
         job_id = job.id
     self.go_to_system_view()
     sel.click("link=(Current Job)")
     sel.wait_for_page_to_load("30000")
     self.assert_("J:%s" % job_id in sel.get_title())
예제 #24
0
 def setUp(self):
     with session.begin():
         dt = data_setup.create_distro_tree()
         self.system = data_setup. \
             create_system(lab_controller=self.get_lc())
         self.system_recipe = data_setup.create_recipe()
         self.guest_recipe = data_setup. \
             create_guestrecipe(host=self.system_recipe)
         self.job = data_setup.create_job_for_recipes([self.system_recipe,
             self.guest_recipe])
         data_setup.mark_job_running(self.job)
예제 #25
0
 def test_system_in_use_by_another_user(self):
     with session.begin():
         system = data_setup.create_system(status=SystemStatus.automated,
                                           shared=True,
                                           lab_controller=self.lc)
         job = data_setup.create_job()
         data_setup.mark_job_running(job, system=system)
     b = self.browser
     login(b)
     self.check_system_is_available(system)
     self.check_system_is_not_free(system)
예제 #26
0
 def test_current_job(self):
     b = self.browser
     login(b)
     with session.begin():
         job = data_setup.create_job(owner=self.system.owner,
                 distro_tree=self.distro_tree)
         data_setup.mark_job_running(job, system=self.system)
         job_id = job.id
     self.go_to_system_view()
     b.find_element_by_link_text('(Current Job)').click()
     b.find_element_by_xpath('//title[contains(text(), "J:%s")]' % job_id)
예제 #27
0
 def test_worker_info(self):
     with session.begin():
         job = data_setup.create_job(owner=self.user)
         data_setup.mark_job_running(job)
         recipe = job.recipesets[0].recipes[0]
         system = recipe.resource.system
     self.assertEquals(
         self.server.taskactions.task_info(recipe.t_id)['worker'],
         {'name': system.fqdn})
     self.assertEquals(
         self.server.taskactions.task_info(recipe.tasks[0].t_id)['worker'],
         {'name': system.fqdn})
 def test_worker_info(self):
     with session.begin():
         job = data_setup.create_job(owner=self.user)
         data_setup.mark_job_running(job)
         recipe = job.recipesets[0].recipes[0]
         system = recipe.resource.system
     self.assertEquals(self.server.taskactions.task_info(
             recipe.t_id)['worker'],
             {'name': system.fqdn})
     self.assertEquals(self.server.taskactions.task_info(
             recipe.tasks[0].t_id)['worker'],
             {'name': system.fqdn})
예제 #29
0
    def test_recovers_completed_recipe_with_running_tasks(self):
        job = data_setup.create_job()
        data_setup.mark_job_running(job)
        job.abort()
        job.update_status()
        job.recipesets[0].recipes[0].tasks[-1].status = TaskStatus.running
        session.flush()

        job.update_status()
        self.assertEquals(job.status, TaskStatus.aborted)
        self.assertEquals(job.recipesets[0].recipes[0].status, TaskStatus.aborted)
        self.assertEquals(job.recipesets[0].recipes[0].tasks[-1].status, TaskStatus.aborted)
예제 #30
0
    def test_recovers_completed_recipe_with_running_tasks(self):
        job = data_setup.create_job()
        data_setup.mark_job_running(job)
        job.abort()
        job.update_status()
        job.recipesets[0].recipes[0].tasks[-1].status = TaskStatus.running
        session.flush()

        job._mark_dirty() # in reality, we did this by hand
        job.update_status()
        self.assertEquals(job.status, TaskStatus.aborted)
        self.assertEquals(job.recipesets[0].recipes[0].status, TaskStatus.aborted)
        self.assertEquals(job.recipesets[0].recipes[0].tasks[-1].status, TaskStatus.aborted)
예제 #31
0
 def test_running_status(self):
     with session.begin():
         job = data_setup.create_job(owner=self.user)
         data_setup.mark_job_running(job)
     self.assertEquals(self.server.taskactions.task_info(job.t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].recipes[0].t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].recipes[0].tasks[0].t_id)['state'],
             'Running')
 def test_running_status(self):
     with session.begin():
         job = data_setup.create_job(owner=self.user)
         data_setup.mark_job_running(job)
     self.assertEquals(self.server.taskactions.task_info(job.t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].recipes[0].t_id)['state'],
             'Running')
     self.assertEquals(self.server.taskactions.task_info(
             job.recipesets[0].recipes[0].tasks[0].t_id)['state'],
             'Running')
 def test_system_in_use_by_another_group_member(self):
     with session.begin():
         user = data_setup.create_user(password=u'testing')
         group = data_setup.create_group()
         system = data_setup.create_system(status=SystemStatus.automated,
                 shared=False, lab_controller=self.lc)
         group.add_member(user)
         system.custom_access_policy.add_rule(
                 permission=SystemPermission.reserve, group=group)
         user2 = data_setup.create_user()
         group.add_member(user2)
         job = data_setup.create_job(owner=user2)
         data_setup.mark_job_running(job, system=system)
     b = self.browser
     login(b, user=user.user_name, password=u'testing')
     self.check_system_is_available(system)
     self.check_system_is_not_free(system)
예제 #34
0
 def test_watchdog_time_remaining_display(self):
     b = self.browser
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe], owner=self.user)
         data_setup.mark_job_running(job)
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(seconds=83 * 60 + 30))
     go_to_recipe_view(b, recipe)
     duration = b.find_element_by_class_name('recipe-watchdog-time-remaining')
     self.assertRegexpMatches(duration.text, r'^Remaining watchdog time: 01:\d\d:\d\d')
     with session.begin():
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(days=2, seconds=83 * 60 + 30))
     go_to_recipe_view(b, recipe)
     duration = b.find_element_by_class_name('recipe-watchdog-time-remaining')
     self.assertRegexpMatches(duration.text, r'^Remaining watchdog time: 49:\d\d:\d\d')
예제 #35
0
 def test_watchdog_time_remaining_display(self):
     b = self.browser
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe], owner=self.user)
         data_setup.mark_job_running(job)
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(seconds=83 * 60 + 30))
     go_to_recipe_view(b, recipe)
     duration = b.find_element_by_class_name('recipe-watchdog-time-remaining')
     self.assertRegexpMatches(duration.text, r'^Remaining watchdog time: 01:\d\d:\d\d')
     with session.begin():
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(days=2, seconds=83 * 60 + 30))
     go_to_recipe_view(b, recipe)
     duration = b.find_element_by_class_name('recipe-watchdog-time-remaining')
     self.assertRegexpMatches(duration.text, r'^Remaining watchdog time: 49:\d\d:\d\d')
예제 #36
0
 def test_system_in_use_by_another_group_member(self):
     with session.begin():
         user = data_setup.create_user(password=u'testing')
         group = data_setup.create_group()
         system = data_setup.create_system(status=SystemStatus.automated,
                                           shared=False,
                                           lab_controller=self.lc)
         group.add_member(user)
         system.custom_access_policy.add_rule(
             permission=SystemPermission.reserve, group=group)
         user2 = data_setup.create_user()
         group.add_member(user2)
         job = data_setup.create_job(owner=user2)
         data_setup.mark_job_running(job, system=system)
     b = self.browser
     login(b, user=user.user_name, password=u'testing')
     self.check_system_is_available(system)
     self.check_system_is_not_free(system)
예제 #37
0
    def test_account_close_job_cancel(self):
        with session.begin():
            user1 = data_setup.create_user()
            job = data_setup.create_job(owner=user1)
            data_setup.mark_job_running(job)

        run_client(['bkr', 'remove-account', user1.user_name])

        # reflect the change in recipe task status when
        # update_dirty_jobs() is called
        session.expunge_all()
        beakerd.update_dirty_jobs()

        with session.begin():
            job = Job.by_id(job.id)
            self.assertEquals(job.status, TaskStatus.cancelled)
            self.assertIn('User %s removed' % user1.user_name,
                          job.recipesets[0].recipes[0].tasks[0].results[0].log)
예제 #38
0
    def test_account_close_job_cancel(self):
        with session.begin():
            user1 = data_setup.create_user()
            job = data_setup.create_job(owner=user1)
            data_setup.mark_job_running(job)

        run_client(['bkr', 'remove-account', user1.user_name])

        # reflect the change in recipe task status when
        # update_dirty_jobs() is called
        session.expunge_all()
        beakerd.update_dirty_jobs()

        with session.begin():
            job = Job.by_id(job.id)
            self.assertEquals(job.status, TaskStatus.cancelled)
            self.assertIn('User %s removed' % user1.user_name,
                          job.recipesets[0].recipes[0].tasks[0].results[0].log)
예제 #39
0
    def test_can_update_reservation_request_to_not_reserve_the_system(self):
        with session.begin():
            data_setup.mark_job_running(self.job)
        s = requests.Session()
        requests_login(s, user=self.owner, password=u'theowner')
        response = patch_json(get_server_base() +
                'recipes/%s/reservation-request' % self.recipe_with_reservation_request.id,
                session=s, data={'reserve': False})
        response.raise_for_status()

        with session.begin():
            session.expire_all()
            self.assertFalse(self.recipe_with_reservation_request.reservation_request)
            self.assertEquals(self.recipe_with_reservation_request.activity[0].field_name,
                    u'Reservation Request')
            self.assertEquals(self.recipe_with_reservation_request.activity[0].action,
                    u'Changed')
            self.assertEquals(self.recipe_with_reservation_request.activity[0].new_value,
                    None)
예제 #40
0
    def test_can_update_reservation_request_to_not_reserve_the_system(self):
        with session.begin():
            data_setup.mark_job_running(self.job)
        s = requests.Session()
        requests_login(s, user=self.owner, password=u'theowner')
        response = patch_json(get_server_base() +
                'recipes/%s/reservation-request' % self.recipe_with_reservation_request.id,
                session=s, data={'reserve': False})
        response.raise_for_status()

        with session.begin():
            session.expire_all()
            self.assertFalse(self.recipe_with_reservation_request.reservation_request)
            self.assertEquals(self.recipe_with_reservation_request.activity[0].field_name,
                    u'Reservation Request')
            self.assertEquals(self.recipe_with_reservation_request.activity[0].action,
                    u'Changed')
            self.assertEquals(self.recipe_with_reservation_request.activity[0].new_value,
                    None)
예제 #41
0
 def test_watchdog_time_remaining_display(self):
     b = self.browser
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe], owner=self.user)
         data_setup.mark_job_running(job)
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(seconds=83 * 60 + 30))
     self.go_to_recipe_view(recipe)
     b.find_element_by_link_text('Show Results').click()
     duration = b.find_element_by_xpath('//tr[contains(@class, "recipe_%s")][1]'
             '//div[@class="task-duration"]' % recipe.id)
     self.assertRegexpMatches(duration.text, r'^Time Remaining 1:23:\d\d$')
     with session.begin():
         recipe.watchdog.kill_time = (datetime.datetime.utcnow() +
                 datetime.timedelta(days=2, seconds=83 * 60 + 30))
     self.go_to_recipe_view(recipe)
     duration = b.find_element_by_xpath('//tr[contains(@class, "recipe_%s")][1]'
             '//div[@class="task-duration"]' % recipe.id)
     self.assertRegexpMatches(duration.text, r'^Time Remaining 2 days, 1:23:\d\d$')
예제 #42
0
 def test_authenticated_user_can_request_reservation(self):
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_job_running(job)
     b = self.browser
     login(b)
     go_to_recipe_view(b, recipe, tab='Reservation')
     tab = b.find_element_by_id('reservation')
     tab.find_element_by_xpath('.//button[contains(text(), "Edit")]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_xpath('.//button[text()="Yes"]').click()
     modal.find_element_by_name('reserve_duration').clear()
     modal.find_element_by_name('reserve_duration').send_keys('300')
     modal.find_element_by_xpath('.//button[text()="Save changes"]').click()
     b.find_element_by_xpath('//body[not(.//div[contains(@class, "modal")])]')
     self.assertIn('The system will be reserved for 00:05:00 at the end of the recipe',
         tab.text)
     with session.begin():
         session.expire_all()
         self.assertEqual(recipe.reservation_request.duration, 300)
예제 #43
0
 def test_authenticated_user_can_request_reservation(self):
     with session.begin():
         recipe = data_setup.create_recipe()
         job = data_setup.create_job_for_recipes([recipe])
         data_setup.mark_job_running(job)
     b = self.browser
     login(b)
     go_to_recipe_view(b, recipe, tab='Reservation')
     tab = b.find_element_by_id('reservation')
     tab.find_element_by_xpath('.//button[contains(text(), "Edit")]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_xpath('.//button[text()="Yes"]').click()
     modal.find_element_by_name('reserve_duration').clear()
     modal.find_element_by_name('reserve_duration').send_keys('300')
     modal.find_element_by_xpath('.//button[text()="Save changes"]').click()
     b.find_element_by_xpath('//body[not(.//div[contains(@class, "modal")])]')
     self.assertIn('The system will be reserved for 00:05:00 at the end of the recipe',
         tab.text)
     with session.begin():
         session.expire_all()
         self.assertEqual(recipe.reservation_request.duration, 300)
예제 #44
0
    def test_reserve_with_recipe(self):
        with session.begin():
            recipe = data_setup.create_recipe()
            job = data_setup.create_job_for_recipes([recipe])
            data_setup.mark_job_running(job)
            recipe = Recipe.by_id(recipe.id)
            fqdn = recipe.resource.system.fqdn
            user = recipe.resource.system.user
            recipe.resource.system.loaned = user
            recipe.resource.system.loan_comment = u'Amy, must I jujitsu my ma?'
        system = recipe.resource.system
        # JSON output
        json_out = run_client(['bkr', 'system-status', fqdn, '--format',
            'json'])
        json_out = loads(json_out)
        current_reservation = json_out.get('current_reservation')
        self.assertEqual(current_reservation.get('user_name'),
            unicode(system.user))
        self.assertEqual(current_reservation.get('recipe_id'), '%s' % \
            system.open_reservation.recipe.id)
        self.assertEqual(json_out.get('condition'), '%s' % system.status)

        # Human friendly output
        human_out = run_client(['bkr', 'system-status', fqdn])
        expected_out = textwrap.dedent('''\
            Condition: %s
            Current reservation:
                User: %s
                Recipe ID: %s
                Start time: %s UTC
            Current loan:
                User: %s
                Comment: Amy, must I jujitsu my ma?''' % \
            (system.status, system.user, system.open_reservation.recipe.id,
            system.open_reservation.recipe.start_time.strftime('%Y-%m-%d %H:%M:%S'),
            system.loaned))
        human_out = human_out.rstrip('\n')
        self.assertEqual(human_out, expected_out, human_out)
예제 #45
0
    def test_reserve_with_recipe(self):
        with session.begin():
            recipe = data_setup.create_recipe()
            job = data_setup.create_job_for_recipes([recipe])
            data_setup.mark_job_running(job)
            recipe = Recipe.by_id(recipe.id)
            fqdn = recipe.resource.system.fqdn
            user = recipe.resource.system.user
            recipe.resource.system.loaned = user
            recipe.resource.system.loan_comment = 'Amy, must I jujitsu my ma?'
        system = recipe.resource.system
        # JSON output
        json_out = run_client(
            ['bkr', 'system-status', fqdn, '--format', 'json'])
        json_out = loads(json_out)
        current_reservation = json_out.get('current_reservation')
        self.assertEqual(current_reservation.get('user_name'),
                         unicode(system.user))
        self.assertEqual(current_reservation.get('recipe_id'), '%s' % \
            system.open_reservation.recipe.id)
        self.assertEqual(json_out.get('condition'), '%s' % system.status)

        # Human friendly output
        human_out = run_client(['bkr', 'system-status', fqdn])
        expected_out = textwrap.dedent('''\
            Condition: %s
            Current reservation:
                User: %s
                Recipe ID: %s
                Start time: %s UTC
            Current loan:
                User: %s
                Comment: Amy, must I jujitsu my ma?''' % \
            (system.status, system.user, system.open_reservation.recipe.id,
            system.open_reservation.recipe.start_time.strftime('%Y-%m-%d %H:%M:%S'),
            system.loaned))
        human_out = human_out.rstrip('\n')
        self.assertEqual(human_out, expected_out, human_out)
예제 #46
0
 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=SystemStatus.manual)
         reserved_system.reserve_manually(service=u'testdata', user=user)
         reserved_system.custom_access_policy.add_rule(
             SystemPermission.reserve, user=user)
         owned_pool = data_setup.create_system_pool(owning_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'User:%s:reserve' % 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)
         # pools owned by the user should be transferred to the caller
         self.assertEqual(owned_pool.owner.user_name, data_setup.ADMIN_USER)
         self.assertEqual(owned_pool.activity[0].user.user_name,
                          data_setup.ADMIN_USER)
         self.assertEqual(owned_pool.activity[0].field_name, u'Owner')
         self.assertEqual(owned_pool.activity[0].action, u'Changed')
         self.assertEqual(owned_pool.activity[0].old_value, user.user_name)
         self.assertEqual(owned_pool.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)
예제 #47
0
 def setUp(self):
     with session.begin():
         self.recipe = data_setup.create_recipe(reservesys=True)
         self.job = data_setup.create_job_for_recipes([self.recipe])
         data_setup.mark_job_running(self.job)
     self.browser = self.get_browser()
예제 #48
0
 def setUp(self):
     with session.begin():
         self.recipe = data_setup.create_recipe(reservesys=True)
         self.job = data_setup.create_job_for_recipes([self.recipe])
         data_setup.mark_job_running(self.job)
     self.browser = self.get_browser()