def test_task_roles_visible_between_hosts_and_guests(self): # Hosts and guests can all see each others' task roles now. Previously # they were not visible to each other. with session.begin(): hostrecipe = data_setup.create_recipe() guestrecipe_server = data_setup.create_guestrecipe(host=hostrecipe) guestrecipe_client = data_setup.create_guestrecipe(host=hostrecipe) job = data_setup.create_job_for_recipes([hostrecipe, guestrecipe_server, guestrecipe_client]) hostrecipe.tasks[0].role = u'SERVERS' guestrecipe_server.tasks[0].role = u'SERVERS' guestrecipe_client.tasks[0].role = u'CLIENTS' system = data_setup.create_system(fqdn=u'host.bz960434') data_setup.mark_recipe_running(hostrecipe, system=system) data_setup.mark_recipe_running(guestrecipe_server, fqdn=u'guestserver.bz960434') data_setup.mark_recipe_running(guestrecipe_client, fqdn=u'guestclient.bz960434') self.server.auth.login_password(self.lc.user.user_name, u'logmein') expected_peer_roles = { 'SERVERS': ['host.bz960434', 'guestserver.bz960434'], 'CLIENTS': ['guestclient.bz960434'], 'STANDALONE': ['host.bz960434', 'guestserver.bz960434', 'guestclient.bz960434'], } for recipe in [hostrecipe, guestrecipe_server, guestrecipe_client]: self.assertEquals( self.server.recipes.tasks.peer_roles(recipe.tasks[0].id), expected_peer_roles)
def test_install_duration_by_resource(self): system_recipe = data_setup.create_recipe() guest_recipe = data_setup.create_guestrecipe(host=system_recipe) data_setup.mark_job_complete( data_setup.create_job_for_recipes([system_recipe, guest_recipe])) virt_recipe = data_setup.create_recipe() data_setup.create_job_for_recipes([virt_recipe]) virt_recipe2 = data_setup.create_recipe() data_setup.create_job_for_recipes([virt_recipe2]) data_setup.mark_recipe_complete(virt_recipe, virt=True) data_setup.mark_recipe_complete(virt_recipe2, virt=True) system_recipe2 = data_setup.create_recipe() guest_recipe2 = data_setup.create_guestrecipe(host=system_recipe2) job2 = data_setup.create_job_for_recipes( [system_recipe2, guest_recipe2]) data_setup.mark_job_complete(job2, system=system_recipe.resource.system) one_hour = datetime.timedelta(hours=1) two_hours = datetime.timedelta(hours=2) three_hours = datetime.timedelta(hours=3) virt_recipe.installation.install_finished = virt_recipe.installation.install_started + one_hour virt_recipe2.installation.install_finished = virt_recipe2.installation.install_started + two_hours guest_recipe.installation.install_finished = guest_recipe.installation.install_started + two_hours guest_recipe2.installation.install_finished = guest_recipe2.installation.install_started + three_hours system_recipe.installation.install_finished = system_recipe.installation.install_started + one_hour system_recipe2.installation.install_finished = system_recipe2.installation.install_started + three_hours session.flush() rows = self.execute_reporting_query('install-duration-by-resource') all_rows = rows.fetchall() guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] system_rows = [ row for row in all_rows if row.fqdn == system_recipe.resource.fqdn ] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(virt_rows[0].min_install_hours, 1) self.assertEquals(virt_rows[0].max_install_hours, 2) self.assertEquals(virt_rows[0].avg_install_hours, Decimal('1.5')) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(guest_rows[0].min_install_hours, 2) self.assertEquals(guest_rows[0].max_install_hours, 3) self.assertEquals(guest_rows[0].avg_install_hours, Decimal('2.5')) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].min_install_hours, 1) self.assertEquals(system_rows[0].max_install_hours, 3) self.assertEquals(system_rows[0].avg_install_hours, Decimal('2.0'))
def test_install_duration_by_resource(self): system_recipe = data_setup.create_recipe() guest_recipe = data_setup.create_guestrecipe(host=system_recipe) data_setup.mark_job_complete( data_setup.create_job_for_recipes([system_recipe, guest_recipe])) virt_recipe = data_setup.create_recipe() data_setup.create_job_for_recipes([virt_recipe]) virt_recipe2 = data_setup.create_recipe() data_setup.create_job_for_recipes([virt_recipe2]) data_setup.mark_recipe_complete(virt_recipe, virt=True) data_setup.mark_recipe_complete(virt_recipe2, virt=True) system_recipe2 = data_setup.create_recipe() guest_recipe2 = data_setup.create_guestrecipe(host=system_recipe2) job2 = data_setup.create_job_for_recipes([system_recipe2, guest_recipe2]) data_setup.mark_job_complete(job2, system=system_recipe.resource.system) one_hour = datetime.timedelta(hours=1) two_hours = datetime.timedelta(hours=2) three_hours = datetime.timedelta(hours=3) virt_recipe.installation.install_finished = virt_recipe.installation.install_started + one_hour virt_recipe2.installation.install_finished = virt_recipe2.installation.install_started + two_hours guest_recipe.installation.install_finished = guest_recipe.installation.install_started + two_hours guest_recipe2.installation.install_finished = guest_recipe2.installation.install_started + three_hours system_recipe.installation.install_finished = system_recipe.installation.install_started + one_hour system_recipe2.installation.install_finished = system_recipe2.installation.install_started + three_hours session.flush() rows = self.execute_reporting_query('install-duration-by-resource') all_rows = rows.fetchall() guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] system_rows = [row for row in all_rows if row.fqdn == system_recipe.resource.fqdn] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(virt_rows[0].min_install_hours, 1) self.assertEquals(virt_rows[0].max_install_hours, 2) self.assertEquals(virt_rows[0].avg_install_hours, Decimal('1.5')) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(guest_rows[0].min_install_hours, 2) self.assertEquals(guest_rows[0].max_install_hours, 3) self.assertEquals(guest_rows[0].avg_install_hours, Decimal('2.5')) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].min_install_hours, 1) self.assertEquals(system_rows[0].max_install_hours, 3) self.assertEquals(system_rows[0].avg_install_hours, Decimal('2.0'))
def test_unknown_fqdns_dont_appear(self): # If we have a recipe where the FQDN is not known (for example # a guest that hasn't finished installing yet), previously it would # appear as the string 'None'. Now it's just not included. with session.begin(): hostrecipe = data_setup.create_recipe(role=u'SERVERS') guestrecipe = data_setup.create_guestrecipe(host=hostrecipe, role=u'CLIENTS') data_setup.create_job_for_recipes([hostrecipe, guestrecipe]) system = data_setup.create_system(fqdn=u'host.bz952948') data_setup.mark_recipe_running(hostrecipe, system=system) data_setup.mark_recipe_waiting(guestrecipe) self.assertEquals(guestrecipe.resource.fqdn, None) self.server.auth.login_password(self.lc.user.user_name, u'logmein') self.assertEquals( self.server.recipes.tasks.peer_roles(hostrecipe.tasks[0].id), { 'SERVERS': ['host.bz952948'], 'STANDALONE': ['host.bz952948'], 'CLIENTS': [] }) self.assertEquals( self.server.recipes.tasks.peer_roles(guestrecipe.tasks[0].id), { 'SERVERS': ['host.bz952948'], 'STANDALONE': [], 'CLIENTS': [] })
def test_unknown_fqdns_dont_appear(self): # If we have a recipe where the FQDN is not known (for example # a guest that hasn't finished installing yet), previously it would # appear as the string 'None'. Now it's just not included. with session.begin(): hostrecipe = data_setup.create_recipe(role=u'SERVERS') guestrecipe = data_setup.create_guestrecipe(host=hostrecipe, role=u'CLIENTS') data_setup.create_job_for_recipes([hostrecipe, guestrecipe]) system = data_setup.create_system(fqdn=u'host.bz952948', lab_controller=self.lc) data_setup.mark_recipe_running(hostrecipe, system=system) data_setup.mark_recipe_waiting(guestrecipe) self.assertEquals(guestrecipe.resource.fqdn, None) self.server.auth.login_password(self.lc.user.user_name, u'logmein') self.assertEquals(self.server.recipes.tasks.peer_roles( hostrecipe.tasks[0].id), {'SERVERS': ['host.bz952948'], 'STANDALONE': ['host.bz952948'], 'CLIENTS': []}) self.assertEquals(self.server.recipes.tasks.peer_roles( guestrecipe.tasks[0].id), {'SERVERS': ['host.bz952948'], 'STANDALONE': ['host.bz952948'], 'CLIENTS': []})
def test_resource_install_failures(self): # Get existing state to later compare against rows = self.execute_reporting_query('install-failure-count-by-resource') all_rows = [row for row in rows] guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] existing_failed_guests = guest_rows[0].failed_recipes existing_failed_virt = virt_rows[0].failed_recipes system_recipe = data_setup.create_recipe() guest_recipe = data_setup.create_guestrecipe(host=system_recipe) virt_recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes([guest_recipe, virt_recipe, system_recipe]) data_setup.mark_recipe_installing(virt_recipe, virt=True) data_setup.mark_recipe_installing(system_recipe) data_setup.mark_recipe_installing(guest_recipe) session.flush() # Test we don't count runinng recipes rows = self.execute_reporting_query('install-failure-count-by-resource') all_rows = [row for row in rows] system_rows = [row for row in all_rows if row.fqdn == system_recipe.resource.fqdn] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(existing_failed_virt, virt_rows[0].failed_recipes) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(existing_failed_guests, guest_rows[0].failed_recipes) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].failed_recipes, 0) # Test completed recipes job.abort() job.update_status() session.flush() rows = self.execute_reporting_query('install-failure-count-by-resource') all_rows = [row for row in rows] guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] system_rows = [row for row in all_rows if row.fqdn == system_recipe.resource.fqdn] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(virt_rows[0].failed_recipes, existing_failed_virt + 1) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(guest_rows[0].failed_recipes, existing_failed_guests + 1) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].failed_recipes, 1)
def test_install_done_updates_resource_fqdn(self): with session.begin(): distro_tree = data_setup.create_distro_tree() recipe = data_setup.create_recipe(distro_tree=distro_tree) guestrecipe = data_setup.create_guestrecipe( host=recipe, distro_tree=distro_tree) data_setup.create_job_for_recipes([recipe, guestrecipe]) data_setup.mark_recipe_running(recipe) data_setup.mark_recipe_waiting(guestrecipe) fqdn = 'theguestname' result = self.server.recipes.install_done(guestrecipe.id, fqdn) self.assertEqual(result, fqdn) with session.begin(): session.expire(guestrecipe.resource) self.assertEqual(guestrecipe.resource.fqdn, fqdn)
def test_install_done_updates_resource_fqdn(self): with session.begin(): distro_tree = data_setup.create_distro_tree() recipe = data_setup.create_recipe(distro_tree=distro_tree) guestrecipe = data_setup.create_guestrecipe(host=recipe, distro_tree=distro_tree) data_setup.create_job_for_recipes([recipe, guestrecipe]) data_setup.mark_recipe_running(recipe) data_setup.mark_recipe_waiting(guestrecipe) fqdn = 'theguestname' result = self.server.recipes.install_done(guestrecipe.id, fqdn) self.assertEqual(result, fqdn) with session.begin(): session.expire(guestrecipe.resource) self.assertEqual(guestrecipe.resource.fqdn, fqdn)
def test_executed_tasks_guest_filter(self): with session.begin(): task = data_setup.create_task() fqdn = 'test_executed_tasks_guest_fqdn_filter.invalid' distro_tree = data_setup.create_distro_tree() recipe = data_setup.create_recipe(distro_tree=distro_tree) guestrecipe = data_setup.create_guestrecipe(host=recipe, task_name=task.name, distro_tree=distro_tree) data_setup.create_job_for_recipes([recipe, guestrecipe]) data_setup.mark_recipe_running(recipe) data_setup.mark_recipe_running(guestrecipe, fqdn=fqdn) b = self.browser b.get(get_server_base() + 'tasks/%d' % task.id) b.find_element_by_id('form_system').click() b.find_element_by_id('form_system').send_keys(fqdn) b.find_element_by_id('form').submit() self.check_recipetask_present_in_results(guestrecipe.tasks[0])
def test_executed_tasks_guest_filter(self): with session.begin(): task = data_setup.create_task() fqdn = 'test_executed_tasks_guest_fqdn_filter.invalid' distro_tree = data_setup.create_distro_tree() recipe = data_setup.create_recipe(distro_tree=distro_tree) guestrecipe = data_setup.create_guestrecipe( host=recipe, task_name=task.name, distro_tree=distro_tree) data_setup.create_job_for_recipes([recipe, guestrecipe]) data_setup.mark_recipe_running(recipe) data_setup.mark_recipe_running(guestrecipe, fqdn=fqdn) b = self.browser b.get(get_server_base() + 'tasks/%d' % task.id) b.find_element_by_id('form_system').click() b.find_element_by_id('form_system').send_keys(fqdn) b.find_element_by_id('form').submit() self.check_recipetask_present_in_results(guestrecipe.tasks[0])
def setUp(self): with session.begin(): self.system = data_setup.create_system( lab_controller=self.get_lc()) self.recipe = data_setup.create_recipe() self.guest_recipe = data_setup.create_guestrecipe(self.recipe) job = data_setup.create_job_for_recipes( [self.recipe, self.guest_recipe]) self.addCleanup(self.cleanup_job, job) data_setup.mark_recipe_running(self.recipe, system=self.system) data_setup.mark_recipe_installing(self.guest_recipe, system=self.system) self.console_log = os.path.join(get_conf().get('CONSOLE_LOGS'), self.system.fqdn) self.cached_console_log = os.path.join( get_conf().get('CACHEPATH'), 'recipes', str(self.recipe.id // 1000) + '+', str(self.recipe.id), 'console.log') self.first_line = 'Here is the first line of the log file.\n' open(self.console_log, 'w').write(self.first_line) self.watchdog = Watchdog() self.monitor = Monitor( { 'recipe_id': self.recipe.id, 'is_virt_recipe': False, 'system': self.system.fqdn }, self.watchdog) self.monitor_guest = Monitor( { 'recipe_id': self.guest_recipe.id, 'is_virt_recipe': False, 'system': None }, self.watchdog)
def test_resource_install_failures(self): # Get existing state to later compare against rows = self.execute_reporting_query( 'install-failure-count-by-resource') all_rows = [row for row in rows] guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] existing_failed_guests = guest_rows[0].failed_recipes existing_failed_virt = virt_rows[0].failed_recipes system_recipe = data_setup.create_recipe() guest_recipe = data_setup.create_guestrecipe(host=system_recipe) virt_recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes( [guest_recipe, virt_recipe, system_recipe]) data_setup.mark_recipe_installing(virt_recipe, virt=True) data_setup.mark_recipe_installing(system_recipe) data_setup.mark_recipe_installing(guest_recipe) session.flush() # Test we don't count runinng recipes rows = self.execute_reporting_query( 'install-failure-count-by-resource') all_rows = [row for row in rows] system_rows = [ row for row in all_rows if row.fqdn == system_recipe.resource.fqdn ] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(existing_failed_virt, virt_rows[0].failed_recipes) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(existing_failed_guests, guest_rows[0].failed_recipes) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].failed_recipes, 0) # Test completed recipes job.abort() job.update_status() session.flush() rows = self.execute_reporting_query( 'install-failure-count-by-resource') all_rows = [row for row in rows] guest_rows = [row for row in all_rows if row.fqdn == 'All Guest'] virt_rows = [row for row in all_rows if row.fqdn == 'All OpenStack'] system_rows = [ row for row in all_rows if row.fqdn == system_recipe.resource.fqdn ] self.assertEquals(len(virt_rows), 1, virt_rows) self.assertEquals(virt_rows[0].failed_recipes, existing_failed_virt + 1) self.assertEquals(len(guest_rows), 1, guest_rows) self.assertEquals(guest_rows[0].failed_recipes, existing_failed_guests + 1) self.assertEquals(len(system_rows), 1, system_rows) self.assertEquals(system_rows[0].failed_recipes, 1)