def test_systems_by_cpu_type(self): vendor = u'AcmeCorp' common_cpu_family = 1 common_cpu_stepping = 2 rare_cpu_family = 3 rare_cpu_stepping = 4 for _ in range(2): data_setup.create_system().cpu = Cpu(vendor=vendor, model=1, family=rare_cpu_family, stepping=rare_cpu_stepping) for _ in range(20): data_setup.create_system().cpu = Cpu(vendor=vendor, model=1, family=common_cpu_family, stepping=common_cpu_stepping) data_setup.create_system(status=SystemStatus.removed).cpu = \ Cpu(vendor=vendor) data_setup.create_system().cpu = None # un-inventoried session.flush() rows = list(self.execute_reporting_query('system-count-by-cpu')) # un-inventoried systems should show up at the top self.assertEquals(rows[0].cpu_vendor, None) self.assertEquals(rows[0].cpu_model, None) self.assertEquals(rows[0].cpu_family, None) self.assertEquals(rows[0].cpu_stepping, None) self.assert_(rows[0].system_count >= 1, rows[0]) # check for fake CPUs created above vendor_rows = [row for row in rows if row.cpu_vendor == vendor] self.assertEquals(len(vendor_rows), 2, vendor_rows) self.assertEquals(vendor_rows[0].cpu_model, 1) self.assertEquals(vendor_rows[0].cpu_family, common_cpu_family) self.assertEquals(vendor_rows[0].cpu_stepping, common_cpu_stepping) self.assertEquals(vendor_rows[0].system_count, 20) self.assertEquals(vendor_rows[1].cpu_model, 1) self.assertEquals(vendor_rows[1].cpu_family, rare_cpu_family) self.assertEquals(vendor_rows[1].cpu_stepping, rare_cpu_stepping) self.assertEquals(vendor_rows[1].system_count, 2)
def setUp(self): self.selenium = self.get_selenium() self.password = '******' # create users self.user_1 = data_setup.create_user(password=self.password) self.user_2 = data_setup.create_user(password=self.password) self.user_3 = data_setup.create_user(password=self.password) # create admin users self.admin_1 = data_setup.create_user(password=self.password) self.admin_1.groups.append(Group.by_name(u'admin')) self.admin_2 = data_setup.create_user(password=self.password) self.admin_2.groups.append(Group.by_name(u'admin')) # create systems self.system_1 = data_setup.create_system(shared=True) self.system_2 = data_setup.create_system(shared=True) self.system_3 = data_setup.create_system(shared=False, owner=self.user_3) # create group and add users/systems to it self.group_1 = data_setup.create_group() self.user_3.groups.append(self.group_1) self.admin_2.groups.append(self.group_1) self.system_2.groups.append(self.group_1) lc = data_setup.create_labcontroller() self.system_1.lab_controller = lc self.system_2.lab_controller = lc self.system_3.lab_controller = lc self.selenium.start()
def test_serial_number_column(self): with session.begin(): system_with_serial = data_setup.create_system() system_with_serial.serial = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ' system_without_serial = data_setup.create_system() system_without_serial.serial = None b = self.browser b.get(get_server_base()) b.find_element_by_link_text('Show Search Options').click() wait_for_animation(b, '#searchform') Select(b.find_element_by_name('systemsearch-0.table'))\ .select_by_visible_text('System/SerialNumber') Select(b.find_element_by_name('systemsearch-0.operation'))\ .select_by_visible_text('is') # This also tests that whitespace does not foil us b.find_element_by_name('systemsearch-0.value').send_keys( ' %s ' % system_with_serial.serial) b.find_element_by_link_text('Toggle Result Columns').click() wait_for_animation(b, '#selectablecolumns') b.find_element_by_link_text('Select None').click() b.find_element_by_name('systemsearch_column_System/Name').click() b.find_element_by_name('systemsearch_column_System/SerialNumber').click() b.find_element_by_id('searchform').submit() check_system_search_results(b, present=[system_with_serial], absent=[system_without_serial]) b.find_element_by_xpath('//table[@id="widget"]' '//td[2][normalize-space(text())="%s"]' % system_with_serial.serial)
def setUpClass(cls): # date times cls.today = datetime.date.today() cls.time_now = datetime.datetime.combine(cls.today, datetime.time(0, 0)) cls.time_delta1 = datetime.datetime.combine(cls.today, datetime.time(0, 30)) cls.time_tomorrow = cls.time_now + datetime.timedelta(days=1) cls.time_yesterday = cls.time_now - datetime.timedelta(days=1) # today date cls.date_yesterday = cls.time_yesterday.date().isoformat() cls.date_today = cls.time_now.date().isoformat() cls.date_tomorrow = cls.time_tomorrow.date().isoformat() with session.begin(): cls.user = data_setup.create_user(password=u'pass') cls.not_inv = data_setup.create_system(loaned=cls.user) cls.inv1 = data_setup.create_system(loaned=cls.user) cls.inv1.date_lastcheckin = cls.time_now cls.inv2 = data_setup.create_system(loaned=cls.user) cls.inv2.date_lastcheckin = cls.time_delta1 cls.inv3 = data_setup.create_system(loaned=cls.user) cls.inv3.date_lastcheckin = cls.time_tomorrow cls.inv4 = data_setup.create_system(loaned=cls.user) cls.inv4.date_lastcheckin = cls.time_yesterday
def test_machine_hours(self): user = data_setup.create_user() # recipes/reservations straddle the boundary of the reporting period # to test we clamp them properly data_setup.create_completed_job(owner=user, distro_tree=data_setup.create_distro_tree(arch=u'ia64'), start_time=datetime.datetime(2012, 9, 30, 23, 0, 0), finish_time=datetime.datetime(2012, 10, 1, 1, 0, 0)) data_setup.create_manual_reservation(user=user, system=data_setup.create_system(arch=u'ia64'), start=datetime.datetime(2012, 10, 31, 22, 30, 0), finish=datetime.datetime(2012, 11, 1, 1, 0, 0)) data_setup.create_completed_job(owner=user, distro_tree=data_setup.create_distro_tree(arch=u'ppc64'), start_time=datetime.datetime(2012, 9, 30, 20, 0, 0), finish_time=datetime.datetime(2012, 10, 1, 2, 0, 0)) data_setup.create_manual_reservation(user=user, system=data_setup.create_system(arch=u'ppc64'), start=datetime.datetime(2012, 10, 31, 23, 0, 0), finish=datetime.datetime(2012, 11, 1, 10, 0, 0)) session.flush() rows = self.execute_reporting_query('machine-hours-by-user-arch') user_rows = [row for row in rows if row.username == user.user_name] self.assertEquals(len(user_rows), 2, user_rows) self.assertEquals(user_rows[0].arch, 'ia64') self.assertEquals(user_rows[0].machine_hours, Decimal('2.5')) self.assertEquals(user_rows[1].arch, 'ppc64') self.assertEquals(user_rows[1].machine_hours, Decimal('3.0'))
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)
def test_group(self): pool_a = data_setup.create_system_pool() pool_b = data_setup.create_system_pool() system_0 = data_setup.create_system() system_a = data_setup.create_system() system_a.pools.append(pool_a) system_ab = data_setup.create_system() system_ab.pools.append(pool_a) system_ab.pools.append(pool_b) system_b = data_setup.create_system() system_b.pools.append(pool_b) self.check_filter(""" <hostRequires> <and> <group op="=" value="%s" /> </and> </hostRequires> """ % pool_a.name, present=[system_a, system_ab], absent=[system_b, system_0]) self.check_filter(""" <hostRequires> <and> <group op="!=" value="%s" /> </and> </hostRequires> """ % pool_a.name, present=[system_b, system_0], absent=[system_a, system_ab]) # https://bugzilla.redhat.com/show_bug.cgi?id=601952 self.check_filter(""" <hostRequires> <and> <group op="==" value="" /> </and> </hostRequires> """, present=[system_0], absent=[system_a, system_ab, system_b]) self.check_filter(""" <hostRequires> <and> <group op="!=" value="" /> </and> </hostRequires> """, present=[system_a, system_ab, system_b], absent=[system_0]) # https://bugzilla.redhat.com/show_bug.cgi?id=1226076 self.check_filter(""" <hostRequires> <or> <group op="=" value="%s" /> <group op="=" value="%s" /> </or> </hostRequires> """ % (pool_a.name, pool_b.name), present=[system_a, system_ab, system_b], absent=[system_0])
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_modify_attributes_policy(self): with session.begin(): system1 = data_setup.create_system(shared=False) system2 = data_setup.create_system(shared=False) new_owner = data_setup.create_user() perm = SystemPermission.reserve user1 = data_setup.create_user() system1.custom_access_policy.add_rule(perm, user=user1) system2.custom_access_policy.add_rule(perm, user=user1) pool = data_setup.create_system_pool(systems=[system1, system2]) user2 = data_setup.create_user() pool.access_policy.add_rule(perm, user=user2) run_client(['bkr', 'system-modify', '--owner', new_owner.user_name, '--condition', 'Manual', '--pool-policy', pool.name, system1.fqdn, system2.fqdn]) with session.begin(): session.expire_all() for s in [system1, system2]: self.assertEquals(s.owner.user_name, new_owner.user_name) self.assertEquals(s.status, SystemStatus.manual) self.assertFalse(s.active_access_policy.grants(user1, perm)) self.assertTrue(s.active_access_policy.grants(user2, perm))
def test_peer_roles(self): with session.begin(): dt = data_setup.create_distro_tree() lc = data_setup.create_labcontroller() systems = [ data_setup.create_system(fqdn=u'server.peer-roles.invalid', lab_controller=lc), data_setup.create_system(fqdn=u'clientone.peer-roles.invalid', lab_controller=lc), data_setup.create_system(fqdn=u'clienttwo.peer-roles.invalid', lab_controller=lc), ] job = data_setup.create_job_for_recipes([ data_setup.create_recipe(distro_tree=dt, role=u'SERVERS'), data_setup.create_recipe(distro_tree=dt, role=u'CLIENTS'), data_setup.create_recipe(distro_tree=dt, role=u'CLIENTS'), ]) job.recipesets[0].recipes[0].tasks[0].role = None # Normally you wouldn't use the same role name with different # meaning at the task level, because that would just get # confusing... but it is possible job.recipesets[0].recipes[1].tasks[0].role = u'SERVERS' job.recipesets[0].recipes[2].tasks[0].role = u'CLIENTTWO' for i in range(3): data_setup.mark_recipe_running(job.recipesets[0].recipes[i], system=systems[i]) self.server.auth.login_password(self.lc.user.user_name, u'logmein') expected = { 'SERVERS': ['server.peer-roles.invalid', 'clientone.peer-roles.invalid'], 'CLIENTS': ['clientone.peer-roles.invalid', 'clienttwo.peer-roles.invalid'], 'None': ['server.peer-roles.invalid'], 'CLIENTTWO': ['clienttwo.peer-roles.invalid'], } for i in range(3): self.assertEquals(self.server.recipes.tasks.peer_roles( job.recipesets[0].recipes[i].tasks[0].id), expected)
def setupClass(cls): cls.two_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=2) cls.three_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=3) cls.just_now = datetime.datetime.utcnow() cls.user_1 = data_setup.create_user() cls.user_2 = data_setup.create_user() cls.system_1 = data_setup.create_system(owner=cls.user_1, shared=True) cls.system_2 = data_setup.create_system(owner=cls.user_1, shared=True) cls.system_3 = data_setup.create_system(owner=cls.user_2, shared=True) cls.subject_header = '[Beaker Reminder]: System' #Shouldn't send #This tests that mail is not sent if user == owner cls.system_1.reserve(service=u'testdata', user=cls.user_1) cls.system_1.reservations[-1].start_time = cls.two_days_ago #Shouldn't send #This tests that threshold value is honoured cls.system_2.reserve(service=u'testdata', user=cls.user_2) cls.system_2.reservations[-1].start_time = cls.just_now #Should send #This tests that with owner != user and taken > threshold, should send nag cls.system_3.reserve(service=u'testdata', user=cls.user_1) cls.system_3.reservations[-1].start_time = cls.three_days_ago
def test_distro_and_system_overrides_recipe(self): with session.begin(): lc = data_setup.create_labcontroller() i386_distro = self._create_i386_distro(lc) system1 = data_setup.create_system(lab_controller=lc, arch=u'x86_64') system2 = data_setup.create_system(lab_controller=lc, arch=u'i386') system2.provisions[system2.arch[0]] = Provision(arch=system2.arch[0], kernel_options_post='usshopper') recipe = self._create_recipe(system1) # recipe uses system1 + x86_64 distro. We pass in system2 and i386 # distro, so we should pick up the provision options of system2 + i386 distro_tree_id = i386_distro.trees[0].id kickstart = self._run_create_kickstart(['--recipe-id', str(recipe.id), '--system', system2.fqdn, '--distro-tree-id', str(distro_tree_id),]) # Make sure we are using the tree from --distro-tree-id self.assertIn('url=http://lab.test-kickstart.example.com/distros/' 'RHEL-6.3/Workstation/i386/os/', kickstart) self.assertIn('usshopper', kickstart) # Make sure we are using system2 self.assertIn(system2.fqdn, kickstart) self.assertNotIn(system1.fqdn, kickstart)
def test_list_systems_lc_disabled(self): with session.begin(): lc1 = data_setup.create_labcontroller() lc2 = data_setup.create_labcontroller() system1 = data_setup.create_system(fqdn=data_setup.unique_name(u'aaaa%s.testdata')) system1.lab_controller = lc1 system2 = data_setup.create_system(fqdn=data_setup.unique_name(u'aaaa%s.testdata')) system2.lab_controller = lc2 # set lc2 to disabled lc2.disabled = True out = run_client(['bkr', 'system-list']) systems = out.splitlines() self.assertIn(system1.fqdn, systems) self.assertIn(system2.fqdn, systems) out = run_client(['bkr', 'system-list', '--free']) systems = out.splitlines() self.assertIn(system1.fqdn, systems) self.assertNotIn(system2.fqdn, systems) out = run_client(['bkr', 'system-list', '--available']) systems = out.splitlines() self.assertIn(system1.fqdn, systems) self.assertIn(system2.fqdn, systems)
def test_can_reserve_manual_system(self): with session.begin(): broken_system = data_setup.create_system( arch=u"i386", shared=True, status=SystemStatus.broken, lab_controller=self.lc ) manual_system = data_setup.create_system( arch=u"i386", shared=True, status=SystemStatus.manual, lab_controller=self.lc ) b = self.browser login(b) # broken system should not be present go_to_reserve_systems(b, distro_tree=self.distro_tree_i386) search_for_system(b, broken_system) check_system_search_results(b, absent=[broken_system]) # provision manual system go_to_reserve_systems(b, distro_tree=self.distro_tree_i386) search_for_system(b, manual_system) row = b.find_element_by_xpath('//tr[normalize-space(string(td))="%s"]' % manual_system.fqdn) row.find_element_by_link_text("Reserve Now").click() b.find_element_by_xpath('//button[normalize-space(text())="Submit job"]').click() # should end up on the job page job_id = b.find_element_by_xpath('//td[preceding-sibling::th/text()="Job ID"]/a').text with session.begin(): job = TaskBase.get_by_t_id(job_id) cloned_job_xml = job.to_xml(clone=True).toxml() # cloning re-parses hostRequires self.assertIn(u'<hostRequires force="%s"/>' % manual_system.fqdn, cloned_job_xml)
def test_or_lab_controller(self): lc1 = data_setup.create_labcontroller(fqdn=u'lab1') lc2 = data_setup.create_labcontroller(fqdn=u'lab2') lc3 = data_setup.create_labcontroller(fqdn=u'lab3') included = data_setup.create_system() included.lab_controller = lc1 excluded = data_setup.create_system() excluded.lab_controller = lc3 self.check_filter(""" <hostRequires> <or> <hostlabcontroller op="=" value="lab1"/> <hostlabcontroller op="=" value="lab2"/> </or> </hostRequires> """, present=[included], absent=[excluded]) self.check_filter(""" <hostRequires> <or> <labcontroller op="=" value="lab1"/> <labcontroller op="=" value="lab2"/> </or> </hostRequires> """, present=[included], absent=[excluded])
def test_group_column(self): with session.begin(): group = data_setup.create_group() system_with_group = data_setup.create_system() system_with_group.groups.append(group) system_without_group = data_setup.create_system() b = self.browser b.get(get_server_base()) b.find_element_by_link_text('Show Search Options').click() wait_for_animation(b, '#searchform') Select(b.find_element_by_name('systemsearch-0.table'))\ .select_by_visible_text('System/Group') Select(b.find_element_by_name('systemsearch-0.operation'))\ .select_by_visible_text('is') b.find_element_by_name('systemsearch-0.value').send_keys(group.group_name) b.find_element_by_link_text('Toggle Result Columns').click() wait_for_animation(b, '#selectablecolumns') b.find_element_by_link_text('Select None').click() b.find_element_by_name('systemsearch_column_System/Name').click() b.find_element_by_name('systemsearch_column_System/Group').click() b.find_element_by_id('searchform').submit() check_system_search_results(b, present=[system_with_group], absent=[system_without_group]) b.find_element_by_xpath('//table[@id="widget"]' '//td[2][normalize-space(text())="%s"]' % group.group_name)
def test_filtering_by_diskspace(self): one_disk = data_setup.create_system() one_disk.disks[:] = [Disk(size=8000000000, sector_size=512, phys_sector_size=512)] two_disks = data_setup.create_system() two_disks.disks[:] = [Disk(size=500000000000, sector_size=512, phys_sector_size=512), Disk(size=8000000000, sector_size=4096, phys_sector_size=4096)] self.check_filter(""" <hostRequires> <diskspace op=">" value="500" units="GB"/> </hostRequires> """, present=[two_disks], absent=[one_disk]) self.check_filter(""" <hostRequires> <diskspace op="<" value="50" units="GB"/> </hostRequires> """, present=[one_disk], absent=[two_disks]) self.check_filter(""" <hostRequires> <diskspace op="==" value="508" units="GB"/> </hostRequires> """, present=[two_disks], absent=[one_disk])
def test_role_fqdns_not_duplicated(self): with session.begin(): dt = data_setup.create_distro_tree() lc = data_setup.create_labcontroller() systems = [ data_setup.create_system(fqdn=u'server.bz951283', lab_controller=lc), data_setup.create_system(fqdn=u'client.bz951283', lab_controller=lc), ] job = data_setup.create_job_for_recipes([ data_setup.create_recipe(distro_tree=dt, role=u'SERVERS'), data_setup.create_recipe(distro_tree=dt, role=u'CLIENTS'), ]) # same roles on the tasks as on the recipes job.recipesets[0].recipes[0].tasks[0].role = u'SERVERS' job.recipesets[0].recipes[1].tasks[0].role = u'CLIENTS' for i in range(2): data_setup.mark_recipe_running(job.recipesets[0].recipes[i], system=systems[i]) self.server.auth.login_password(self.lc.user.user_name, u'logmein') expected = { 'SERVERS': ['server.bz951283'], 'CLIENTS': ['client.bz951283'], } for i in range(2): self.assertEquals(self.server.recipes.tasks.peer_roles( job.recipesets[0].recipes[i].tasks[0].id), expected)
def test_modify_active_access_policy(self): with session.begin(): user1 = data_setup.create_user() perm = SystemPermission.reserve system1 = data_setup.create_system(shared=False) system2 = data_setup.create_system(shared=False) system1.custom_access_policy.add_rule(perm, user=user1) system2.custom_access_policy.add_rule(perm, user=user1) pool = data_setup.create_system_pool(systems=[system1, system2]) user2 = data_setup.create_user() pool.access_policy.add_rule(perm, user=user2) # use pool policy run_client(['bkr', 'system-modify', '--pool-policy', pool.name, system1.fqdn, system2.fqdn]) with session.begin(): session.expire_all() for s in [system1, system2]: self.assertFalse(s.active_access_policy.grants(user1, perm)) self.assertTrue(s.active_access_policy.grants(user2, perm)) self.assertEquals(s.activity[-1].field_name, u'Active Access Policy') self.assertEquals(s.activity[-1].action, u'Changed') self.assertEquals(s.activity[-1].old_value, 'Custom Access Policy') self.assertEquals(s.activity[-1].new_value,'Pool policy: %s' % pool.name) # system not in a pool try: run_client(['bkr', 'system-modify', '--pool-policy', data_setup.create_system_pool().name, system1.fqdn]) except ClientError as e: self.assertIn('To use a pool policy, the system must be in the pool first', e.stderr_output) # Revert to custom policy run_client(['bkr', 'system-modify', '--use-custom-policy', system1.fqdn, system2.fqdn]) with session.begin(): session.expire_all() for s in [system1, system2]: self.assertTrue(s.active_access_policy.grants(user1, perm)) self.assertFalse(s.active_access_policy.grants(user2, perm)) # insufficient permission to change active policy with session.begin(): user1 = data_setup.create_user(password='******') try: run_client(['bkr', 'system-modify', '--use-custom-policy', '--user', user1.user_name, '--password', 'abc', system1.fqdn]) self.fail('Must raise') except ClientError as e: self.assertIn('Cannot edit system access policy', e.stderr_output)
def setUpClass(cls): cls.browser = cls.get_browser() login(cls.browser) cls.system_one_details = { 'fqdn' : u'a1', 'type' : u'Machine', 'arch' : u'i386', 'status' : u'Automated', 'owner' : data_setup.create_user(),} cls.system_one = data_setup.create_system(**cls.system_one_details) cls.system_one.loaned = data_setup.create_user() cls.system_one.numa = Numa(nodes=2) cls.system_one.key_values_string.append(Key_Value_String( Key.by_name(u'CPUMODEL'), 'foocodename')) cls.system_one.key_values_string.append(Key_Value_String( Key.by_name(u'HVM'), '1')) cls.system_one.cpu = Cpu(flags=['flag1', 'flag2']) cls.system_one.key_values_int.append(Key_Value_Int( Key.by_name(u'DISKSPACE'), '1024')) cls.system_one.key_values_int.append(Key_Value_Int( Key.by_name(u'MEMORY'), '4096')) cls.system_two_details = { 'fqdn' : u'a2', 'type' : u'Prototype', 'arch' : u'x86_64', 'status' : u'Manual', 'owner' : data_setup.create_user(),} cls.system_two = data_setup.create_system(**cls.system_two_details) cls.system_two.key_values_int.append(Key_Value_Int( Key.by_name(u'DISKSPACE'), '900')) cls.system_two.key_values_string.append(Key_Value_String( Key.by_name(u'HVM'), '1')) device_class = DeviceClass.lazy_create(device_class='class_type') device1 = Device.lazy_create(vendor_id = '0000', device_id = '0000', subsys_vendor_id = '2223', subsys_device_id = '2224', bus = '0000', driver = '0000', device_class_id = device_class.id, description = 'blah') cls.system_two.devices.append(device1) cls.system_three_details = { 'fqdn' : u'a3', 'type' : u'Laptop', 'arch' : u'ia64', 'status' : u'Removed', 'owner' : data_setup.create_user(),} cls.system_three = data_setup.create_system(**cls.system_three_details) cls.system_three.numa = Numa(nodes=1) device2 = Device.lazy_create(vendor_id = '0000', device_id = '0000', subsys_vendor_id = '1111', subsys_device_id = '1112', bus = '0000', driver = '0000', device_class_id = device_class.id, description = 'blah') cls.system_three.devices.append(device2)
def setUp(self): with session.begin(): self.user = data_setup.create_user(password=u'hypervisin') self.kvm = data_setup.create_system(loaned=self.user, hypervisor=u'KVM') self.xen = data_setup.create_system(loaned=self.user, hypervisor=u'Xen') self.phys = data_setup.create_system(loaned=self.user, hypervisor=None) self.browser = self.get_browser() login(self.browser, user=self.user.user_name, password=u'hypervisin')
def test_old_command_list_systems_still_works(self): with session.begin(): data_setup.create_system() # so that we have at least one system1 = data_setup.create_system(status=SystemStatus.removed) out = run_client(['bkr', 'list-systems']) self.assertNotIn(system1.fqdn, out.splitlines()) self.assertEqual(len(out.splitlines()), System.query.filter(System.status!=SystemStatus.removed).count())
def test_list_removed_systems(self): with session.begin(): system1 = data_setup.create_system() system2 = data_setup.create_system(status=SystemStatus.removed) out = run_client(['bkr', 'system-list', '--removed']) self.assertIn(system2.fqdn, out.splitlines()) self.assertEqual(len(out.splitlines()), System.query.filter(System.status==SystemStatus.removed).count())
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)
def test_system_status(self): excluded = data_setup.create_system(status=SystemStatus.manual) included = data_setup.create_system(status=SystemStatus.automated) self.check_filter(""" <hostRequires> <system><status op="==" value="Automated" /></system> </hostRequires> """, present=[included], absent=[excluded])
def test_memory(self): excluded = data_setup.create_system(memory=128) included = data_setup.create_system(memory=1024) self.check_filter(""" <hostRequires> <memory op=">=" value="256" /> </hostRequires> """, present=[included], absent=[excluded])
def test_system_model(self): excluded = data_setup.create_system(model=u'grover') included = data_setup.create_system(model=u'elmo') self.check_filter(""" <hostRequires> <system><model op="=" value="elmo" /></system> </hostRequires> """, present=[included], absent=[excluded])
def test_system_vendor(self): excluded = data_setup.create_system(vendor=u'apple') included = data_setup.create_system(vendor=u'mango') self.check_filter(""" <hostRequires> <system><vendor op="!=" value="apple" /></system> </hostRequires> """, present=[included], absent=[excluded])
def test_system_lender(self): excluded = data_setup.create_system(lender=u'my excluded lender') included = data_setup.create_system(lender=u'my included lender') self.check_filter(""" <hostRequires> <system><lender op="like" value="%included%" /></system> </hostRequires> """, present=[included], absent=[excluded])
def test_system_serial(self): excluded = data_setup.create_system(serial=u'0u812') included = data_setup.create_system(serial=u'2112') self.check_filter(""" <hostRequires> <system><serial op="=" value="2112" /></system> </hostRequires> """, present=[included], absent=[excluded])
def test_filter_by_group(self): # System groups became pools in Beaker 20.0 but we need to continue # supporting System/Group search (mapped to pools) for old clients. with session.begin(): pool = data_setup.create_system_pool() nopool = data_setup.create_system() inpool = data_setup.create_system() inpool.pools.append(pool) feed_url = urljoin( get_server_base(), '?' + urlencode({ 'tg_format': 'atom', 'systemsearch-0.table': 'System/Group', 'systemsearch-0.operation': 'is', 'systemsearch-0.value': pool.name })) feed = lxml.etree.parse(urlopen(feed_url)).getroot() self.assertFalse(self.feed_contains_system(feed, nopool.fqdn)) self.assertTrue(self.feed_contains_system(feed, inpool.fqdn))
def test_secret_system_visible_when_loaned(self): with session.begin(): secret_system = data_setup.create_system(shared=False, private=True) secret_system.loaned = self.user b = self.browser login(b, user=self.user.user_name, password=u'password') b.get(get_server_base()) search_for_system(b, secret_system) b.find_element_by_xpath('//table[@id="widget"]' '//tr/td[1][./a/text()="%s"]' % secret_system.fqdn)
def test_invalid_newowner_errors(self): """If an invalid username is passed as a new owner, we expect the command to error without changing the system.""" invalid_username = u'asdfasdfasdf' with session.begin(): user = data_setup.create_user() data_setup.create_system() self.assertFalse( session.query(User).filter_by( user_name=invalid_username).count()) try: run_client([ 'bkr', 'remove-account', '--new-owner=%s' % invalid_username, user.user_name ]) self.fail('Expected client to fail due to invalid new owner') except ClientError as e: self.assertIn('Invalid user name for owner', e.stderr_output)
def test_gets_logs(self): with session.begin(): system = data_setup.create_system(lab_controller=self.lc) recipe = data_setup.create_recipe() recipe.logs.append(LogRecipe(filename=u'test.log')) data_setup.create_job_for_recipes([recipe]) self.server.auth.login_password(self.lc.user.user_name, u'logmein') logs = self.server.recipes.files(recipe.id) self.assertEqual(len(logs), 1) self.assertEqual(logs[0]['filename'], u'test.log')
def test_hypervisor(self): baremetal = data_setup.create_system(hypervisor=None) kvm = data_setup.create_system(hypervisor=u'KVM') xen = data_setup.create_system(hypervisor=u'Xen') self.check_filter(""" <hostRequires> <system><hypervisor op="=" value="KVM" /></system> </hostRequires> """, present=[kvm], absent=[baremetal, xen]) self.check_filter(""" <hostRequires> <and> <hypervisor op="=" value="KVM" /> </and> </hostRequires> """, present=[kvm], absent=[baremetal, xen]) self.check_filter(""" <hostRequires> <system><hypervisor op="=" value="" /></system> </hostRequires> """, present=[baremetal], absent=[kvm, xen]) self.check_filter(""" <hostRequires> <and> <hypervisor op="=" value="" /> </and> </hostRequires> """, present=[baremetal], absent=[kvm, xen]) self.check_filter(""" <hostRequires/> """, present=[baremetal, kvm, xen]) # https://bugzilla.redhat.com/show_bug.cgi?id=886816 self.check_filter(""" <hostRequires> <hypervisor op="!=" value="KVM" /> </hostRequires> """, present=[baremetal, xen], absent=[kvm])
def test_can_release_system(self): with session.begin(): system = data_setup.create_system(status=SystemStatus.manual) user = data_setup.create_user() system.reserve_manually('TESTING', user=user) self.assertEqual(system.user, user) run_client(['bkr', 'system-release', system.fqdn]) with session.begin(): session.refresh(system) self.assertEqual(system.user, None)
def test_by_reserved_since(self): with session.begin(): s1 = data_setup.create_system() data_setup.create_manual_reservation(s1, start=datetime.datetime(2003, 1, 21, 11, 30, 0)) s2 = data_setup.create_system(fqdn='aaadvark.testdata') data_setup.create_manual_reservation(s2, start=datetime.datetime(2005, 1, 21, 11, 30, 0)) b = self.browser perform_search(b, [('System/Reserved', 'is', '2003-01-21')]) check_system_search_results(b, present=[s1], absent=[s2]) perform_search(b, [('System/Reserved', 'before', '2005-1-21')]) check_system_search_results(b, present=[s1], absent=[s2]) perform_search(b, [('System/Reserved', 'after', '2005-1-21')]) check_system_search_results(b, absent=[s1, s2]) perform_search(b, [('System/Reserved', 'after', '2005-1-1')]) check_system_search_results(b, present=[s2], absent=[s1])
def test_shows_current_loan(self): b = self.browser login(b) with session.begin(): system = data_setup.create_system() system.loaned = data_setup.create_user() self.go_to_system_view(system) usage = b.find_element_by_class_name('system-quick-usage') usage.find_element_by_xpath('.//span[contains(@class, "label") and text()="Loaned"]') usage.find_element_by_xpath('.//a[text()="%s"]' % system.loaned.user_name)
def test_secret_system_not_visible(self): with session.begin(): secret_system = data_setup.create_system(shared=False, private=True) b = self.browser login(b, user=self.user.user_name, password=u'password') b.get(get_server_base()) search_for_system(b, secret_system) # results grid should be empty b.find_element_by_xpath('//table[@id="widget" and not(.//td)]')
def setUp(self): with session.begin(): self.system = data_setup.create_system() user = data_setup.create_user() self.activity = CommandActivity(user, 'Just', 'testing', status=CommandStatus.queued) self.system.command_queue.append(self.activity) self.browser = self.get_browser()
def setUp(self): with session.begin(): self.system = data_setup.create_system(lab_controller=self.get_lc()) self.recipe = data_setup.create_recipe() job = data_setup.create_job_for_recipes([self.recipe]) self.addCleanup(self.cleanup_job, job) data_setup.mark_recipe_installing(self.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')
def test_get_system_returns_correct_id(self): # The bug was that Power.id was overwriting System.id. with session.begin(): # The bug is not observable if the system and power rows both # happen to have the same id, which is likely in the test suite # since we always create system and power rows together. Create # a throwaway system row without power, to ensure the autoincrement # ids are not in sync. data_setup.create_system(with_power=False) system = data_setup.create_system(owner=self.owner) self.assertNotEqual(system.id, system.power.id) # The bug is only observable to users with access to view power settings. self.assertTrue(system.can_view_power(self.owner)) s = requests.Session() requests_login(s, user=self.owner.user_name, password=u'theowner') response = s.get(get_server_base() + '/systems/%s/' % system.fqdn, headers={'Accept': 'application/json'}) response.raise_for_status() self.assertEqual(response.json()['id'], system.id)
def setUp(self): with session.begin(): self.lc = data_setup.create_labcontroller() self.system = data_setup.create_system(arch=u'i386', shared=True) # The distro tree is only on this lab controller, so when we are # picking systems we won't be shown any others left in the db. self.distro_tree = data_setup.create_distro_tree( arch=u'i386', lab_controllers=[self.lc]) self.system.lab_controller = self.lc self.browser = self.get_browser()
def test_cannot_power_without_permission(self): with session.begin(): user = data_setup.create_user(password=u'password') system = data_setup.create_system(shared=False) self.server.auth.login_password(user.user_name, 'password') try: self.server.systems.power('on', system.fqdn) self.fail('should raise') except xmlrpclib.Fault, e: self.assertIn('does not have permission to power system', e.faultString)
def test_no_arches(self): with session.begin(): system = data_setup.create_system(lab_controller=self.lc) system.arch[:] = [] login(self.browser) provision = self.go_to_provision_tab(system) provision.find_element_by_xpath( './/p[text()="System must have ' 'at least one supported architecture defined ' 'in order to provision."]')
def test_cannot_reserve_when_not_logged_in(self): with session.begin(): system = data_setup.create_system() server = self.get_server() try: server.systems.reserve(system.fqdn) self.fail('should raise') except Exception, e: self.assert_('Anonymous access denied' in e.faultString, e.faultString)
def test_xml_filter(self): with session.begin(): module_key = Key.by_name(u'MODULE') with_module = data_setup.create_system() with_module.key_values_string.extend([ Key_Value_String(module_key, u'cciss'), Key_Value_String(module_key, u'kvm') ]) without_module = data_setup.create_system() feed_url = urljoin( get_server_base(), '?' + urlencode({ 'tg_format': 'atom', 'list_tgp_order': '-date_modified', 'xmlsearch': '<key_value key="MODULE" />' })) feed = lxml.etree.parse(urlopen(feed_url)).getroot() self.assert_(self.feed_contains_system(feed, with_module.fqdn)) self.assert_(not self.feed_contains_system(feed, without_module.fqdn))
def test_cannot_provision_automated_system(self): with session.begin(): system = data_setup.create_system( owner=User.by_user_name(data_setup.ADMIN_USER), status=u'Automated', shared=True) user = data_setup.create_user(password=u'password') self.server.auth.login_password(user.user_name, 'password') try: self.server.systems.provision(system.fqdn, 'distro') except xmlrpclib.Fault, e: self.assertIn('Reserve a system before provisioning', e.faultString)
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_change_condition(self): with session.begin(): system = data_setup.create_system( lab_controller=data_setup.create_labcontroller(), status=SystemStatus.automated) run_client(['bkr', 'system-modify', '--condition=Manual', system.fqdn]) with session.begin(): session.expire_all() self.assertEquals(system.status, SystemStatus.manual) self.assertEquals(system.activity[0].field_name, u'Status') self.assertEquals(system.activity[0].new_value, u'Manual')
def test_cannot_reserve_automated_system(self): with session.begin(): user = data_setup.create_user(password=u'password') system = data_setup.create_system(owner=user, status=u'Automated', shared=True) server = self.get_server() server.auth.login_password(user.user_name, 'password') try: server.systems.reserve(system.fqdn) self.fail('should raise') except xmlrpclib.Fault, e: self.assertIn('Cannot manually reserve automated system', e.faultString)
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)
def test_shared_system(self): with session.begin(): system = data_setup.create_system(status=SystemStatus.automated, shared=True, lab_controller=self.lc) user = data_setup.create_user(password=u'testing') b = self.browser login(b, user=user.user_name, password='******') self.check_system_is_available(system) self.check_system_is_free(system) self.check_cannot_take(system)
def test_clear_running_commands(self): with session.begin(): system = data_setup.create_system(lab_controller=self.lc) command = CommandActivity(user=None, service=u'testdata', action=u'on', status=CommandStatus.running) system.command_queue.append(command) other_system = data_setup.create_system() other_command = CommandActivity(user=None, service=u'testdata', action=u'on', status=CommandStatus.running) other_system.command_queue.append(other_command) self.server.auth.login_password(self.lc.user.user_name, u'logmein') self.server.labcontrollers.clear_running_commands(u'Staleness') with session.begin(): session.refresh(command) self.assertEquals(command.status, CommandStatus.aborted) self.assertEquals(other_command.status, CommandStatus.running)
def test_system_activity_entry_is_correctly_truncated(self): with session.begin(): system = data_setup.create_system() b = self.browser b.get(get_server_base() + 'view/%s' % system.fqdn) b.find_element_by_xpath('//button[text()="Report problem"]').click() b.find_element_by_name('message').send_keys(u'a' + u'\u044f' * 100) b.find_element_by_xpath('//button[text()="Report"]').click() # Wait for our success box b.find_element_by_xpath('//div[contains(@class, "alert-success")]' '/h4[text()="Report sent"]')
def test_device_with_no_class(self): with session.begin(): system1 = data_setup.create_system() system2 = data_setup.create_system() device_data = { 'Devices': [{ 'type': None, 'bus': u'pci', 'driver': u'noclass', 'description': u'Oh so very tacky', 'vendorID': None, 'deviceID': None, 'subsysVendorID': None, 'subsysDeviceID': None, }] } self.server.push(system1.fqdn, device_data) # DeviceClass('NONE') already exists now, so do it again # and check that nothing blows up self.server.push(system2.fqdn, device_data)
def setUp(self): with session.begin(): self.system = data_setup.create_system(shared=False) self.system_public = data_setup.create_system(shared=False) self.user1 = data_setup.create_user() self.user2 = data_setup.create_user() self.group = data_setup.create_group() self.system.custom_access_policy.add_rule( permission=SystemPermission.edit_system, user=self.user1) self.system.custom_access_policy.add_rule( permission=SystemPermission.control_system, user=self.user2) self.system.custom_access_policy.add_rule( permission=SystemPermission.control_system, group=self.group) self.system_public.custom_access_policy.add_rule( permission=SystemPermission.control_system, everybody=True) self.pool = data_setup.create_system_pool(systems=[self.system]) self.user3 = data_setup.create_user() self.pool.access_policy.add_rule( permission=SystemPermission.edit_system, user=self.user3)
def test_export_install_options(self): with session.begin(): system = data_setup.create_system(arch=u'i386') distro_tree = data_setup.create_distro_tree(arch=u'i386') system.provisions[distro_tree.arch] = Provision( arch=distro_tree.arch, ks_meta=u'some_ks_meta_var=1', kernel_options=u'some_kernel_option=1', kernel_options_post=u'some_kernel_option=2') system.provisions[distro_tree.arch]\ .provision_families[distro_tree.distro.osversion.osmajor] = \ ProvisionFamily(osmajor=distro_tree.distro.osversion.osmajor, ks_meta=u'some_ks_meta_var=2', kernel_options=u'some_kernel_option=3', kernel_options_post=u'some_kernel_option=4') system.provisions[distro_tree.arch]\ .provision_families[distro_tree.distro.osversion.osmajor]\ .provision_family_updates[distro_tree.distro.osversion] = \ ProvisionFamilyUpdate(osversion=distro_tree.distro.osversion, ks_meta=u'some_ks_meta_var=3', kernel_options=u'some_kernel_option=5', kernel_options_post=u'some_kernel_option=6') login(self.browser) csv_request = self.get_csv('install') csv_rows = [ row for row in csv.DictReader(csv_request) if row['fqdn'] == system.fqdn ] self.assertEquals(csv_rows[0]['arch'], 'i386') self.assertEquals(csv_rows[0]['family'], '') self.assertEquals(csv_rows[0]['update'], '') self.assertEquals(csv_rows[0]['ks_meta'], 'some_ks_meta_var=1') self.assertEquals(csv_rows[0]['kernel_options'], 'some_kernel_option=1') self.assertEquals(csv_rows[0]['kernel_options_post'], 'some_kernel_option=2') self.assertEquals(csv_rows[1]['arch'], 'i386') self.assertEquals(csv_rows[1]['family'], unicode(distro_tree.distro.osversion.osmajor)) self.assertEquals(csv_rows[1]['update'], '') self.assertEquals(csv_rows[1]['ks_meta'], 'some_ks_meta_var=2') self.assertEquals(csv_rows[1]['kernel_options'], 'some_kernel_option=3') self.assertEquals(csv_rows[1]['kernel_options_post'], 'some_kernel_option=4') self.assertEquals(csv_rows[2]['arch'], 'i386') self.assertEquals(csv_rows[2]['family'], unicode(distro_tree.distro.osversion.osmajor)) self.assertEquals(csv_rows[2]['update'], unicode(distro_tree.distro.osversion.osminor)) self.assertEquals(csv_rows[2]['ks_meta'], 'some_ks_meta_var=3') self.assertEquals(csv_rows[2]['kernel_options'], 'some_kernel_option=5') self.assertEquals(csv_rows[2]['kernel_options_post'], 'some_kernel_option=6')
def test_ignore_system_status(self): with session.begin(): lc = data_setup.create_labcontroller() system = data_setup.create_system(lab_controller=lc, status=SystemStatus.broken) out = run_client([ 'bkr', 'workflow-simple', '--distro', self.distro.name, '--machine', system.fqdn, '--ignore-system-status', '--task', self.task.name, '--dry-run', '--pretty-xml' ]) self.assertIn('<hostRequires force="%s"/>' % system.fqdn, out)
def test_no_action(self): with session.begin(): lc = data_setup.create_labcontroller() system = data_setup.create_system(lab_controller=lc) run_client([ 'bkr', 'system-power', '--action', 'none', '--clear-netboot', system.fqdn ]) self.assertEqual(len(system.command_queue), 1) self.assertEqual(system.command_queue[0].action, 'clear_netboot')