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()
def test_open_in_demand_systems(self): with session.begin(): # system with waiting recipes system_with_waiting_recipes = data_setup.create_system() data_setup.create_manual_reservation(system_with_waiting_recipes, start=datetime.utcnow() - timedelta(days=self.reservation_length), user=self.user) recipe = data_setup.create_recipe() recipe.systems[:] = [system_with_waiting_recipes] job = data_setup.create_job_for_recipes([recipe]) data_setup.mark_job_queued(job) job.recipesets[0].queue_time = datetime.utcnow() - timedelta(hours=self.waiting_recipe_age) # Create another system with waiting recipes and delete the job recipe_in_deleted_job = data_setup.create_recipe() recipe_in_deleted_job.systems[:] = [system_with_waiting_recipes] deleted_job = data_setup.create_job_for_recipes([recipe_in_deleted_job]) data_setup.mark_job_queued(deleted_job) deleted_job.recipesets[0].queue_time = datetime.utcnow() - timedelta(hours=self.waiting_recipe_age) deleted_job.delete() # system with no waiting recipes system_without_waiting_recipes = data_setup.create_system() data_setup.create_manual_reservation(system_without_waiting_recipes, start=datetime.utcnow() - timedelta(days=self.reservation_length), user=self.user) beaker_usage = BeakerUsage(self.user, self.reservation_expiry, self.reservation_length, self.waiting_recipe_age, self.delayed_job_age) open_in_demand_systems = beaker_usage.open_in_demand_systems() self.assertEqual(len(open_in_demand_systems), 1) self.assertEqual(open_in_demand_systems[0][1], 1) self.assertEqual(open_in_demand_systems[0][2], system_with_waiting_recipes.fqdn)
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()
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()
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)
def _create_delayed_job(self): recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes([recipe]) job.owner = self.user data_setup.mark_job_queued(job) job.recipesets[0].queue_time = datetime.utcnow() - timedelta(days=self.delayed_job_age) email_content = u""" The following jobs you submitted to %s have been queued for more than %s days. Please cancel them if they are no longer relevant, or perhaps arrange a loan of an appropriate system or systems Start time Delayed Job %s %s """ % (absolute_url('/'), self.delayed_job_age, job.recipesets[0].queue_time.strftime('%Y-%m-%d %H:%M:%S'), absolute_url('/jobs/%s') % job.id) return email_content
def test_possible_systems(self): with session.begin(): self.system.user = self.user queued_job = data_setup.create_job(owner=self.user, distro_tree=self.distro_tree) data_setup.mark_job_queued(queued_job) recipe = queued_job.recipesets[0].recipes[0] recipe.systems[:] = [self.system] b = self.browser go_to_recipe_view(b, recipe) b.find_element_by_xpath('//div[@class="recipe-summary"]' '//a[normalize-space(text())="1 possible system"]').click() # Make sure our system link is there b.find_element_by_link_text(self.system.fqdn) # Make sure out user link is there b.find_element_by_link_text(self.system.user.user_name) # Make sure the Reserved column is showing a link to the current user system_rows = b.find_elements_by_xpath('//table[@id="widget"]/tbody/tr') self.assert_(len(system_rows) == 1)
def test_recipe_systems(self): with session.begin(): self.system.user = self.user queued_job = data_setup.create_job(owner=self.user, distro_tree=self.distro_tree) data_setup.mark_job_queued(queued_job) the_recipe = queued_job.recipesets[0].recipes[0] the_recipe.systems[:] = [self.system] b = self.browser self.go_to_recipe_view(the_recipe) b.find_element_by_xpath('//td[preceding-sibling::td/b[text()=' '"Possible Systems"]]/a').click() # Make sure our system link is there b.find_element_by_link_text(self.system.fqdn) # Make sure out user link is there b.find_element_by_link_text(self.system.user.user_name) # Make sure we only have one system against our recipe system_rows = b.find_elements_by_xpath('//table[@id="widget"]/tbody/tr') self.assert_(len(system_rows) == 1)
def test_recipe_systems(self): with session.begin(): self.system.user = self.user queued_job = data_setup.create_job(owner=self.user, distro_tree=self.distro_tree) data_setup.mark_job_queued(queued_job) the_recipe = queued_job.recipesets[0].recipes[0] the_recipe.systems[:] = [self.system] b = self.browser self.go_to_recipe_view(the_recipe) b.find_element_by_xpath('//td[preceding-sibling::th[text()=' '"Possible Systems"]]/a').click() # Make sure our system link is there b.find_element_by_link_text(self.system.fqdn) # Make sure out user link is there b.find_element_by_link_text(self.system.user.user_name) # Make sure we only have one system against our recipe system_rows = b.find_elements_by_xpath('//table[@id="widget"]/tbody/tr') self.assert_(len(system_rows) == 1)
def test_open_in_demand_systems(self): with session.begin(): # system with waiting recipes system_with_waiting_recipes = data_setup.create_system() data_setup.create_manual_reservation( system_with_waiting_recipes, start=datetime.utcnow() - timedelta(days=self.reservation_length), user=self.user) recipe = data_setup.create_recipe() recipe.systems[:] = [system_with_waiting_recipes] job = data_setup.create_job_for_recipes([recipe]) data_setup.mark_job_queued(job) job.recipesets[0].queue_time = datetime.utcnow() - timedelta( hours=self.waiting_recipe_age) # Create another system with waiting recipes and delete the job recipe_in_deleted_job = data_setup.create_recipe() recipe_in_deleted_job.systems[:] = [system_with_waiting_recipes] deleted_job = data_setup.create_job_for_recipes( [recipe_in_deleted_job]) data_setup.mark_job_queued(deleted_job) deleted_job.recipesets[0].queue_time = datetime.utcnow( ) - timedelta(hours=self.waiting_recipe_age) deleted_job.delete() # system with no waiting recipes system_without_waiting_recipes = data_setup.create_system() data_setup.create_manual_reservation( system_without_waiting_recipes, start=datetime.utcnow() - timedelta(days=self.reservation_length), user=self.user) beaker_usage = BeakerUsage(self.user, self.reservation_expiry, self.reservation_length, self.waiting_recipe_age, self.delayed_job_age) open_in_demand_systems = beaker_usage.open_in_demand_systems() self.assertEqual(len(open_in_demand_systems), 1) self.assertEqual(open_in_demand_systems[0][1], 1) self.assertEqual(open_in_demand_systems[0][2], system_with_waiting_recipes.fqdn)
def test_delayed_jobs(self): with session.begin(): # Create a queued job that was submitted a long time ago recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes([recipe]) job.owner = self.user data_setup.mark_job_queued(job) job.recipesets[0].queue_time = datetime.utcnow() - timedelta(days=self.delayed_job_age) # create a job with two recipes, one Queued and one Scheduled # which was submitted a long time ago queued_recipe = data_setup.create_recipe() scheduled_recipe = data_setup.create_recipe() job_with_multiple_recipes = data_setup.create_job_for_recipes([queued_recipe, scheduled_recipe]) job_with_multiple_recipes.owner = self.user # mark recipe Queued queued_recipe.process() queued_recipe.queue() # mark recipe Scheduled scheduled_recipe.process() scheduled_recipe.queue() scheduled_recipe.schedule() data_setup.mark_job_queued(job_with_multiple_recipes) job_with_multiple_recipes.recipesets[0].queue_time = datetime.utcnow()\ - timedelta(days=self.delayed_job_age) # create a new submmited job for just now recently_submmited_job = data_setup.create_job_for_recipes([recipe]) recently_submmited_job.owner = self.user data_setup.mark_job_queued(recently_submmited_job) beaker_usage = BeakerUsage(self.user, self.reservation_expiry, self.reservation_length, self.waiting_recipe_age, self.delayed_job_age) delayed_jobs = beaker_usage.delayed_jobs() self.assertEqual(len(delayed_jobs), 2) self.assertEqual(absolute_url('/jobs/%s' % job.id), delayed_jobs[0][1]) self.assertEqual(absolute_url('/jobs/%s' % job_with_multiple_recipes.id), delayed_jobs[1][1])
def _create_open_reservation(self): system = data_setup.create_system() data_setup.create_manual_reservation(system, start=datetime.utcnow() - timedelta(days=self.reservation_length), user=self.user) recipe = data_setup.create_recipe() recipe.systems[:] = [system] job = data_setup.create_job_for_recipes([recipe]) data_setup.mark_job_queued(job) job.recipesets[0].queue_time = datetime.utcnow() - timedelta(hours=self.waiting_recipe_age) email_content = u""" The following systems have been allocated to you in %s for more than %s days and have other recipes queued for longer than %s hours. Please return them if you are no longer using them. Duration Waiting FQDN %s %s %s """ % (absolute_url('/'), self.reservation_length, self.waiting_recipe_age, "%s days" % (datetime.utcnow() - system.reservations[0].start_time).days, "1 recipe", system.fqdn) return email_content