示例#1
0
    def test_system_pool_activity(self):
        with session.begin():
            pool1 = data_setup.create_system_pool()
            act1 = pool1.record_activity(service=u'testdata',
                    user=User.by_user_name(data_setup.ADMIN_USER),
                    action=u'Nothing', field=u'Nonsense',
                    old=u'asdf', new=u'omgwtfbbq')
            pool2 = data_setup.create_system_pool()
            act2 = pool2.record_activity(service=u'testdata',
                    user=User.by_user_name(data_setup.ADMIN_USER),
                    action=u'Nothing', field=u'Nonsense',
                    old=u'asdf', new=u'lollercopter')
        b = self.browser
        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys(
            'pool.name:%s' % pool1.name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act1], absent=[act2])

        # search by pool owner
        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys(
            'pool.owner.user_name:%s' % pool2.owner.user_name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act2], absent=[act1])

        with session.begin():
            pool1.owning_user = None
            pool1.owning_group = data_setup.create_group()

        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys(
            'pool.owner.group_name:%s' % pool1.owner.group_name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act1], absent=[act2])
示例#2
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])
示例#3
0
    def test_system_pools_import(self):
        with session.begin():
            system = data_setup.create_system()
            pool1 = data_setup.create_system_pool()
            pool2 = data_setup.create_system_pool()

        login(self.browser)
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,%s,False\n'
                         u'system_pool,%s,%s,False'%(system.fqdn, pool1.name,
                                                     system.fqdn, pool2.name)) \
                        .encode('utf8'))
        self.failUnless(is_text_present(self.browser, 'No Errors'))
        with session.begin():
            session.refresh(system)
            self.assertEquals([pool1.name, pool2.name],
                              [pool.name for pool in system.pools])
        # test deletion
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,%s,True' % (system.fqdn, pool2.name)) \
                         .encode('utf8'))
        self.failUnless(is_text_present(self.browser, 'No Errors'))
        with session.begin():
            session.refresh(system)
            self.assertNotIn(pool2.name, [pool.name for pool in system.pools])

        # Attempting to add a system to a Non existent pool should throw an error
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,poolpool,True' % system.fqdn) \
                         .encode('utf8'))
        self.assertTrue(
            is_text_present(self.browser, 'poolpool: pool does not exist'))
示例#4
0
    def test_system_pools_import(self):
        with session.begin():
            system = data_setup.create_system()
            pool1 = data_setup.create_system_pool()
            pool2 = data_setup.create_system_pool()

        login(self.browser)
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,%s,False\n'
                         u'system_pool,%s,%s,False'%(system.fqdn, pool1.name,
                                                     system.fqdn, pool2.name)) \
                        .encode('utf8'))
        self.failUnless(is_text_present(self.browser, 'No Errors'))
        with session.begin():
            session.refresh(system)
            self.assertEquals([pool1.name, pool2.name],
                              [pool.name for pool in system.pools])
        # test deletion
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,%s,True' % (system.fqdn, pool2.name)) \
                         .encode('utf8'))
        self.failUnless(is_text_present(self.browser, 'No Errors'))
        with session.begin():
            session.refresh(system)
            self.assertNotIn(pool2.name, [pool.name for pool in system.pools])

        # Attempting to add a system to a Non existent pool should throw an error
        self.import_csv((u'csv_type,fqdn,pool,deleted\n'
                         u'system_pool,%s,poolpool,True' % system.fqdn) \
                         .encode('utf8'))
        self.assertTrue(is_text_present(self.browser, 'poolpool: pool does not exist'))
示例#5
0
    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)
示例#6
0
 def test_list_pools(self):
     with session.begin():
         pool1 = data_setup.create_system_pool()
         pool2 = data_setup.create_system_pool()
     out = run_client(['bkr', 'pool-list'])
     self.assertIn(pool1.name, out)
     self.assertIn(pool2.name, out)
示例#7
0
 def test_list_pools_by_owner(self):
     with session.begin():
         user1 = data_setup.create_user()
         user2 = data_setup.create_user()
         pool1 = data_setup.create_system_pool(owning_user=user1)
         pool2 = data_setup.create_system_pool(owning_user=user2)
     out = run_client(['bkr', 'pool-list', '--owner', str(user1.user_name)])
     self.assertIn(pool1.name, out)
     self.assertNotIn(pool2.name, out)
示例#8
0
    def test_active_access_policy_selection(self):
        with session.begin():
            user = data_setup.create_user()
            owner = data_setup.create_user(password='******')
            system = data_setup.create_system(owner=owner)
            data_setup.create_system_pool(systems=[system])
            pool2 = data_setup.create_system_pool(systems=[system])
            pool2.access_policy.add_rule(user=user,
                                         permission=SystemPermission.edit_system)
        b = self.browser
        login(b, owner.user_name, password='******')
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        pane = b.find_element_by_id('access-policy')
        # Currently the system is using its custom access policy
        self.assertTrue(pane.find_element_by_xpath(
            '//label[contains(string(.), "Use custom access policy")]'
            '/input[@type="radio"]').is_selected())

        # change to pool policy
        pane.find_element_by_xpath(
                           '//label[contains(string(.), "Use policy from pool:")]'
                           '/input[@type="radio"]').click()
        Select(pane.find_element_by_name('pool_name')).select_by_visible_text(pool2.name)
        pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
        # wait for the request to complete
        pane.find_element_by_xpath('.//span[@class="sync-status" and not(node())]')
        # check if the policy change has persisted
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertTrue(b.find_element_by_xpath(
                                        '//label[contains(string(.), "Use policy from pool:")]'
                                        '/input[@type="radio"]').is_selected())
        selected_options = Select(b.find_element_by_name('pool_name')).\
                           all_selected_options
        self.assertTrue(len(selected_options), 1)
        self.assertEquals(selected_options[0].text, pool2.name)
        self.assertFalse(b.find_element_by_xpath(
                                         '//label[contains(string(.), "Use custom access policy")]'
                                         '/input[@type="radio"]').is_selected())
        with session.begin():
            session.expire_all()
            self.assertTrue(system.active_access_policy.grants(user,
                                                   SystemPermission.edit_system))
        logout(b)
        # no change allowed when not logged in/no right privileges
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertFalse(b.find_element_by_xpath(
                                         '//label[contains(string(.), "Use policy from pool:")]'
                                         '/input[@type="radio"]').is_enabled())
        selected_options = Select(b.find_element_by_name('pool_name')). \
                           all_selected_options
        self.assertEquals(selected_options[0].text, pool2.name)
        self.assertFalse(b.find_element_by_xpath(
            '//label[contains(string(.), "Use custom access policy")]'
            '/input[@type="radio"]').is_enabled())
示例#9
0
 def test_list_pools_limit(self):
     with session.begin():
         data_setup.create_system_pool()
         data_setup.create_system_pool()
     out1 = run_client(['bkr', 'pool-list'])
     pools1 = out1.split()
     out2 = run_client(['bkr', 'pool-list', '--limit=1'])
     pools2 = out2.split()
     self.assertEquals(len(pools2), 1)
     self.assertEquals(pools1[0], pools2[0])
示例#10
0
 def test_searching_by_name(self):
     with session.begin():
         pool = data_setup.create_system_pool()
         other_pool = data_setup.create_system_pool()
     b = self.browser
     b.get(get_server_base() + 'pools/')
     b.find_element_by_class_name('search-query').send_keys('name:"%s"' %
                                                            pool.name)
     b.find_element_by_class_name('grid-filter').submit()
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#11
0
 def test_searching_by_name(self):
     with session.begin():
         pool = data_setup.create_system_pool()
         other_pool = data_setup.create_system_pool()
     b = self.browser
     b.get(get_server_base() + 'pools/')
     b.find_element_by_class_name('search-query').send_keys(
             'name:"%s"' % pool.name)
     b.find_element_by_class_name('grid-filter').submit()
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#12
0
 def test_mine_pools(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         pool = data_setup.create_system_pool(owning_user=user)
         other_pool = data_setup.create_system_pool()
     b = self.browser
     login(b, user=user.user_name, password='******')
     b.get(get_server_base() + 'pools/')
     click_menu_item(b, 'Hello, %s' % user.user_name, 'My System Pools')
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#13
0
 def test_mine_pools(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         pool = data_setup.create_system_pool(owning_user=user)
         other_pool = data_setup.create_system_pool()
     b = self.browser
     login(b, user=user.user_name, password='******')
     b.get(get_server_base() + 'pools/')
     click_menu_item(b, 'Hello, %s' % user.user_name, 'My System Pools')
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#14
0
 def test_list_pools_by_ownergroup(self):
     with session.begin():
         group1 = data_setup.create_group()
         pool1 = data_setup.create_system_pool(owning_group=group1)
         group2 = data_setup.create_group()
         pool2 = data_setup.create_system_pool(owning_group=group2)
     out = run_client(
         ['bkr', 'pool-list', '--owning-group',
          str(group1.group_name)])
     self.assertIn(pool1.name, out)
     self.assertNotIn(pool2.name, out)
示例#15
0
    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))
示例#16
0
 def test_pool_with_closing_script_tag_in_description(self):
     # Actually this bug affects many other things besides just the pools
     # grid, but this is a convenient place to test for it.
     with session.begin():
         pool = data_setup.create_system_pool(
             description=u'I am haxxing you lolz. </script>HAX')
         other_pool = data_setup.create_system_pool()
     b = self.browser
     b.get(get_server_base() + 'pools/')
     b.find_element_by_class_name('search-query').send_keys('name:"%s"' %
                                                            pool.name)
     b.find_element_by_class_name('grid-filter').submit()
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#17
0
 def test_pool_with_closing_script_tag_in_description(self):
     # Actually this bug affects many other things besides just the pools 
     # grid, but this is a convenient place to test for it.
     with session.begin():
         pool = data_setup.create_system_pool(
                 description=u'I am haxxing you lolz. </script>HAX')
         other_pool = data_setup.create_system_pool()
     b = self.browser
     b.get(get_server_base() + 'pools/')
     b.find_element_by_class_name('search-query').send_keys(
             'name:"%s"' % pool.name)
     b.find_element_by_class_name('grid-filter').submit()
     check_pool_search_results(b, present=[pool], absent=[other_pool])
示例#18
0
    def test_set_active_policy_from_pool(self):
        with session.begin():
            user = data_setup.create_user()
            pool = data_setup.create_system_pool()
            pool.systems.append(self.system)
            pool.access_policy.add_rule(
                permission=SystemPermission.edit_system, user=user)

        with session.begin():
            self.assertFalse(
                self.system.active_access_policy.grants(
                    user, SystemPermission.edit_system))

        s = requests.Session()
        s.post(get_server_base() + 'login',
               data={
                   'user_name': self.owner.user_name,
                   'password': '******'
               }).raise_for_status()
        response = patch_json(
            get_server_base() + 'systems/%s/' % self.system.fqdn,
            session=s,
            data={'active_access_policy': {
                'pool_name': pool.name
            }},
        )
        response.raise_for_status()
        with session.begin():
            session.expire_all()
            self.assertTrue(
                self.system.active_access_policy.grants(
                    user, SystemPermission.edit_system))

        # attempt to set active policy to a pool policy when the system
        # is not in the pool
        with session.begin():
            pool = data_setup.create_system_pool()
            session.expire_all()
        response = patch_json(
            get_server_base() + 'systems/%s/' % self.system.fqdn,
            session=s,
            data={'active_access_policy': {
                'pool_name': pool.name
            }},
        )
        self.assertEquals(response.status_code, 400)
        self.assertEquals(
            response.text,
            'To use a pool policy, the system must be in the pool first')
示例#19
0
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user()
         self.pool.access_policy.add_rule(
             user=self.user, permission=SystemPermission.edit_system)
示例#20
0
 def test_group_remove_should_not_remove_system_pool(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         group = data_setup.create_group(owner=user)
         pool = data_setup.create_system_pool(owning_group=group)
     b = self.browser
     login(b, user=user.user_name, password='******')
     b.get(get_server_base() + 'groups/')
     b.find_element_by_xpath("//input[@name='group.text']").clear()
     b.find_element_by_xpath("//input[@name='group.text']").send_keys(group.group_name)
     b.find_element_by_id('Search').submit()
     delete_and_confirm(b, "//tr[td/a[normalize-space(text())='%s']]" %
                        group.group_name, delete_text='Delete Group')
     self.assertEqual(
         b.find_element_by_class_name('flash').text,
         '%s deleted' % group.display_name)
     with session.begin():
         session.refresh(pool)
         self.assertFalse(pool.owning_group)
         self.assertEquals(pool.owning_user, user)
         self.assertEquals(pool.activity[-1].action, u'Changed')
         self.assertEquals(pool.activity[-1].field_name, u'Owner')
         self.assertEquals(pool.activity[-1].old_value, 'Group %s' % group.group_name)
         self.assertEquals(pool.activity[-1].new_value, user.user_name)
         self.assertEquals(pool.activity[-1].service, u'WEBUI')
示例#21
0
 def test_pool_column(self):
     with session.begin():
         pool = data_setup.create_system_pool()
         system_in_pool = data_setup.create_system()
         system_in_pool.pools.append(pool)
         system_outside_pool = 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/Pools')
     Select(b.find_element_by_name('systemsearch-0.operation'))\
         .select_by_visible_text('is')
     b.find_element_by_name('systemsearch-0.value').send_keys(pool.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/Pools').click()
     b.find_element_by_id('searchform').submit()
     check_system_search_results(b, present=[system_in_pool],
                                 absent=[system_outside_pool])
     b.find_element_by_xpath('//table[@id="widget"]'
                             '//td[2][normalize-space(text())="%s"]' % pool.name)
示例#22
0
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user()
         self.pool.access_policy.add_rule(user=self.user,
                                          permission=SystemPermission.edit_system)
示例#23
0
    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))
示例#24
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)
示例#25
0
    def test_add_systems_pool_privileges(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        with session.begin():
            system_owner = data_setup.create_user(password=u'password')
            pool_owner = data_setup.create_user(password=u'password')
            s1 = data_setup.create_system(owner=system_owner)
            pool = data_setup.create_system_pool(name=pool_name,
                                                 owning_user=pool_owner)
        try:
            run_client(['bkr', 'pool-add', '--pool', pool_name,
                        '--system', s1.fqdn],
                       config=create_client_config(
                           username=system_owner.user_name,
                           password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn('You do not have permission to'
                          ' add systems to pool %s' % pool_name,
                          e.stderr_output)

        try:
            run_client(['bkr', 'pool-add', '--pool', pool_name,
                        '--system', s1.fqdn],
                       config=create_client_config(
                           username=pool_owner.user_name,
                           password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn('You do not have permission to'
                          ' modify system %s' % s1.fqdn,
                          e.stderr_output)
示例#26
0
    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))
示例#27
0
 def setUp(self):
     with session.begin():
         self.user = data_setup.create_user()
         self.pool = data_setup.create_system_pool(
             owning_user=self.user,
             description=u'Systems for *doing* things.\n\nhttp://pool.com')
     self.browser = self.get_browser()
示例#28
0
 def test_give_away_permission(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         owner = data_setup.create_user(password='******')
         system = data_setup.create_system(owner=owner)
         pool = data_setup.create_system_pool(systems=[system])
         pool.access_policy.add_rule(user=user,
                                     permission=SystemPermission.edit_policy)
         system.active_access_policy = pool.access_policy
     b = self.browser
     login(b, user=user.user_name, password='******')
     b.get(get_server_base() + 'view/%s/' % system.fqdn)
     b.find_element_by_link_text('Access Policy').click()
     pane = b.find_element_by_id('access-policy')
     # Currently the system is using a pool access policy
     self.assertTrue(pane.find_element_by_xpath(
         '//label[contains(string(.), "Use policy from pool:")]'
         '/input[@type="radio"]').is_selected())
     # change to custom access policy
     pane.find_element_by_xpath(
                        '//label[contains(string(.), "Use custom access policy")]'
                        '/input[@type="radio"]').click()
     pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
     pane.find_element_by_xpath('//div[@id="access-policy" and not (.//div[@class="form-actions"])]')
     self.assertTrue(pane.find_element_by_xpath(
         '//label[contains(string(.), "Use custom access policy")]'
         '/input[@type="radio"]').is_selected())
     # The radio buttons should be read only
     self.assertFalse(b.find_element_by_xpath(
         '//label[contains(string(.), "Use policy from pool:")]'
         '/input[@type="radio"]').is_enabled())
     self.assertFalse(b.find_element_by_xpath(
         '//label[contains(string(.), "Use custom access policy")]'
         '/input[@type="radio"]').is_enabled())
示例#29
0
    def test_set_active_policy_to_custom_policy(self):
        with session.begin():
            user1 = data_setup.create_user()
            user2 = data_setup.create_user()
            self.system.custom_access_policy.add_rule(
                permission=SystemPermission.edit_system, user=user1)
            pool = data_setup.create_system_pool()
            pool.access_policy.add_rule(
                permission=SystemPermission.edit_system, user=user2)
            self.system.active_access_policy = pool.access_policy

        self.assertFalse(self.system.active_access_policy.grants 
                        (user1, SystemPermission.edit_system))
        self.assertTrue(self.system.active_access_policy.grants
                         (user2, SystemPermission.edit_system))

        s = requests.Session()
        s.post(get_server_base() + 'login', data={'user_name': self.owner.user_name,
                'password': '******'}).raise_for_status()
        response = patch_json(get_server_base() +
                              'systems/%s/' % self.system.fqdn, session=s,
                              data={'active_access_policy': {'custom': True}},
                         )
        response.raise_for_status()
        with session.begin():
            session.expire_all()
            self.assertTrue(self.system.active_access_policy.grants \
                            (user1, SystemPermission.edit_system))
示例#30
0
    def test_remove_systems_from_pool(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        with session.begin():
            s1 = data_setup.create_system()
            s2 = data_setup.create_system()
            s3 = data_setup.create_system()
            s4 = data_setup.create_system()
            pool = data_setup.create_system_pool(name=pool_name,
                                                 systems=[s1, s2, s3])
        run_client([
            'bkr', 'pool-remove', '--pool', pool_name, '--system', s1.fqdn,
            '--system', s2.fqdn
        ])
        with session.begin():
            session.refresh(pool)
            self.assertIn(s3, pool.systems)

        # remove system from a pool of which it is not a member of
        try:
            run_client([
                'bkr', 'pool-remove', '--pool', pool_name, '--system', s4.fqdn
            ])
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn('System %s is not in pool %s' % (s4.fqdn, pool_name),
                          e.stderr_output)
示例#31
0
 def test_pool_column(self):
     with session.begin():
         pool = data_setup.create_system_pool()
         system_in_pool = data_setup.create_system()
         system_in_pool.pools.append(pool)
         system_outside_pool = 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/Pools')
     Select(b.find_element_by_name('systemsearch-0.operation'))\
         .select_by_visible_text('is')
     b.find_element_by_name('systemsearch-0.value').send_keys(pool.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/Pools').click()
     b.find_element_by_id('searchform').submit()
     check_system_search_results(b,
                                 present=[system_in_pool],
                                 absent=[system_outside_pool])
     b.find_element_by_xpath('//table[@id="widget"]'
                             '//td[2][normalize-space(text())="%s"]' %
                             pool.name)
示例#32
0
    def test_add_systems_pool_privileges(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        with session.begin():
            system_owner = data_setup.create_user(password=u'password')
            pool_owner = data_setup.create_user(password=u'password')
            s1 = data_setup.create_system(owner=system_owner)
            pool = data_setup.create_system_pool(name=pool_name,
                                                 owning_user=pool_owner)
        try:
            run_client(
                ['bkr', 'pool-add', '--pool', pool_name, '--system', s1.fqdn],
                config=create_client_config(username=system_owner.user_name,
                                            password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn(
                'You do not have permission to'
                ' add systems to pool %s' % pool_name, e.stderr_output)

        try:
            run_client(
                ['bkr', 'pool-add', '--pool', pool_name, '--system', s1.fqdn],
                config=create_client_config(username=pool_owner.user_name,
                                            password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn(
                'You do not have permission to'
                ' modify system %s' % s1.fqdn, e.stderr_output)
示例#33
0
    def test_pool_change_name(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            pool1 = data_setup.create_system_pool()
        new_name = data_setup.unique_name(u'newpool%s')
        run_client(['bkr', 'pool-modify', '--name', new_name, pool.name])
        with session.begin():
            session.refresh(pool)
            self.assertEquals(pool.name, new_name)

        # rename to an existing pool will error out
        try:
            run_client(['bkr', 'pool-modify', '--name', pool1.name, pool.name])
            self.fail('Must error out')
        except ClientError as e:
            self.assertIn('System pool %s already exists' % pool1.name,
                          e.stderr_output)
示例#34
0
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.system = data_setup.create_system(owner=self.owner, shared=False)
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user(password='******')
         self.group = data_setup.create_group()
         self.pool.systems[:] = [self.system]
示例#35
0
 def test_pool_change_description(self):
     with session.begin():
         pool = data_setup.create_system_pool()
     run_client(
         ['bkr', 'pool-modify', '--description', 'Oh my pool', pool.name])
     with session.begin():
         session.refresh(pool)
         self.assertEquals(pool.description, 'Oh my pool')
示例#36
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)
示例#37
0
    def test_grant_policy_pool(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            user = data_setup.create_user()
            group = data_setup.create_group()
            group.add_member(user)
            user1 = data_setup.create_user()

        # group
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                    '--permission', 'edit_system', '--group', group.group_name])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                user, SystemPermission.edit_system))
        # non-existent group
        try:
            run_client(['bkr', 'policy-grant', '--pool', pool.name,
                        '--permission', 'edit_system', '--group', 'idontexist'])
            self.fail('Must fail or die')
        except ClientError as e:
            self.assertIn("Group 'idontexist' does not exist", e.stderr_output)

        # Everybody edit_system
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                '--permission', 'edit_system', '--everybody'])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                    user1, SystemPermission.edit_system))

        # test_multiple_permissions_and_targets
        with session.begin():
            user = data_setup.create_user()
            group = data_setup.create_group()
            user1 = data_setup.create_user()
            group.add_member(user1)
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                    '--permission=reserve', '--permission=view_power', \
                    '--user', user.user_name, '--group', group.group_name])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                    user, SystemPermission.view_power))
            self.assertTrue(pool.access_policy.grants(
                    user, SystemPermission.reserve))
            self.assertTrue(pool.access_policy.grants(
                user1, SystemPermission.view_power))
            self.assertTrue(pool.access_policy.grants(
                    user1, SystemPermission.reserve))
        # non-existent pool
        try:
            run_client(['bkr', 'policy-grant', '--pool', 'idontexist',
                        '--permission=reserve', '--permission=view_power', \
                        '--user', user.user_name, '--group', group.group_name])
        except ClientError as e:
            self.assertIn("System pool idontexist does not exist", e.stderr_output)
示例#38
0
 def test_pool_change_owner_to_another_user(self):
     with session.begin():
         user = data_setup.create_user()
         new_owner = user.user_name
         pool = data_setup.create_system_pool()
     run_client(['bkr', 'pool-modify', '--owner', new_owner, pool.name])
     with session.begin():
         session.refresh(pool)
         self.assertTrue(pool.owning_user, user)
示例#39
0
    def test_delete_pool(self):
        with session.begin():
            pool_name = data_setup.unique_name('mypool%s')
            data_setup.create_system_pool(name=pool_name)
        run_client(['bkr', 'pool-delete', pool_name])

        with session.begin():
            session.expire_all()
            with self.assertRaises(NoResultFound):
                SystemPool.by_name(pool_name)

        # attempt to delete non-existent pool
        try:
            run_client(['bkr', 'pool-delete', pool_name])
            self.fail()
        except ClientError as e:
            self.assertIn('System pool %s does not exist' % pool_name,
                          e.stderr_output)
示例#40
0
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.system = data_setup.create_system(owner=self.owner,
                                                shared=False)
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user(password='******')
         self.group = data_setup.create_group()
         self.pool.systems[:] = [self.system]
示例#41
0
    def test_list_systems_in_a_pool_with_format_list(self):
        with session.begin():
            system1 = data_setup.create_system()
            system2 = data_setup.create_system()
            pool = data_setup.create_system_pool(systems=[system1, system2])

        out = run_client(['bkr', 'pool-systems', pool.name])
        self.assertIn(system1.fqdn, out)
        self.assertIn(system2.fqdn, out)
示例#42
0
    def test_list_systems_in_a_pool_with_format_list(self):
        with session.begin():
            system1 = data_setup.create_system()
            system2 = data_setup.create_system()
            pool = data_setup.create_system_pool(systems=[system1, system2])

        out = run_client(['bkr', 'pool-systems', pool.name])
        self.assertIn(system1.fqdn, out)
        self.assertIn(system2.fqdn, out)
示例#43
0
 def test_pool_change_description(self):
     with session.begin():
         pool = data_setup.create_system_pool()
     run_client(['bkr', 'pool-modify',
                 '--description', 'Oh my pool',
                 pool.name])
     with session.begin():
         session.refresh(pool)
         self.assertEquals(pool.description, 'Oh my pool')
示例#44
0
    def test_delete_pool(self):
        with session.begin():
            pool_name = data_setup.unique_name(u'mypool%s')
            data_setup.create_system_pool(name=pool_name)
        run_client(['bkr', 'pool-delete', pool_name])

        with session.begin():
            session.expire_all()
            with self.assertRaises(NoResultFound):
                SystemPool.by_name(pool_name)

        # attempt to delete non-existent pool
        try:
            run_client(['bkr', 'pool-delete', pool_name])
            self.fail()
        except ClientError as e:
            self.assertIn('System pool %s does not exist' % pool_name,
                          e.stderr_output)
示例#45
0
 def test_records_activity_on_changing_access_policy(self):
     with session.begin():
         system = data_setup.create_system()
         pool = data_setup.create_system_pool()
         pool.systems.append(system)
     # change the system active access policy to pool access policy
     s = requests.Session()
     s.post(get_server_base() + 'login',
            data={
                'user_name': data_setup.ADMIN_USER,
                'password': data_setup.ADMIN_PASSWORD
            }).raise_for_status()
     response = patch_json(
         get_server_base() + 'systems/%s/' % system.fqdn,
         session=s,
         data={'active_access_policy': {
             'pool_name': pool.name
         }},
     )
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertTrue(system.active_access_policy, pool.access_policy)
         self.assertEquals(system.activity[-1].field_name,
                           'Active Access Policy')
         self.assertEquals(system.activity[-1].action, 'Changed')
         self.assertEquals(system.activity[-1].old_value,
                           'Custom access policy')
         self.assertEquals(system.activity[-1].new_value,
                           'Pool policy: %s' % unicode(pool))
     # change the system active access policy back to custom access policy
     s = requests.Session()
     s.post(get_server_base() + 'login',
            data={
                'user_name': data_setup.ADMIN_USER,
                'password': data_setup.ADMIN_PASSWORD
            }).raise_for_status()
     response = patch_json(
         get_server_base() + 'systems/%s/' % system.fqdn,
         session=s,
         data={'active_access_policy': {
             'custom': True
         }},
     )
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertTrue(system.active_access_policy,
                         system.custom_access_policy)
         self.assertEquals(system.activity[-2].field_name,
                           'Active Access Policy')
         self.assertEquals(system.activity[-2].action, 'Changed')
         self.assertEquals(system.activity[-2].old_value,
                           'Pool policy: %s' % unicode(pool))
         self.assertEquals(system.activity[-2].new_value,
                           'Custom access policy')
示例#46
0
 def test_pool_change_owner_to_another_user(self):
     with session.begin():
         user = data_setup.create_user()
         new_owner = user.user_name
         pool = data_setup.create_system_pool()
     run_client(['bkr', 'pool-modify',
                 '--owner', new_owner,
                 pool.name])
     with session.begin():
         session.refresh(pool)
         self.assertTrue(pool.owning_user, user)
示例#47
0
    def test_system_pool_activity(self):
        with session.begin():
            pool1 = data_setup.create_system_pool()
            act1 = pool1.record_activity(service=u'testdata',
                                         user=User.by_user_name(
                                             data_setup.ADMIN_USER),
                                         action=u'Nothing',
                                         field=u'Nonsense',
                                         old=u'asdf',
                                         new=u'omgwtfbbq')
            pool2 = data_setup.create_system_pool()
            act2 = pool2.record_activity(service=u'testdata',
                                         user=User.by_user_name(
                                             data_setup.ADMIN_USER),
                                         action=u'Nothing',
                                         field=u'Nonsense',
                                         old=u'asdf',
                                         new=u'lollercopter')
        b = self.browser
        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys('pool.name:%s' %
                                                               pool1.name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act1], absent=[act2])

        # search by pool owner
        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys(
            'pool.owner.user_name:%s' % pool2.owner.user_name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act2], absent=[act1])

        with session.begin():
            pool1.owning_user = None
            pool1.owning_group = data_setup.create_group()

        b.get(get_server_base() + 'activity/pool')
        b.find_element_by_class_name('search-query').send_keys(
            'pool.owner.group_name:%s' % pool1.owner.group_name)
        b.find_element_by_class_name('grid-filter').submit()
        check_activity_search_results(b, present=[act1], absent=[act2])
示例#48
0
    def test_filter_by_pool(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            inpool = data_setup.create_system()
            pool.systems.append(inpool)
            nopool = data_setup.create_system()
        out = run_client(['bkr', 'system-list', '--pool', pool.name])
        self.assertEquals([inpool.fqdn], out.splitlines())

        # --group is a hidden compatibility alias for --pool
        out = run_client(['bkr', 'system-list', '--group', pool.name])
        self.assertEquals([inpool.fqdn], out.splitlines())
示例#49
0
 def test_add_nonexistent_system_to_pool(self):
     system_fqdn = data_setup.unique_name(u'mysystem%s')
     pool_name = data_setup.unique_name(u'mypool%s')
     with session.begin():
         pool = data_setup.create_system_pool(name=pool_name)
     try:
         run_client(['bkr', 'pool-add', '--pool', pool_name,
                     '--system', system_fqdn])
         self.fail('Must fail')
     except ClientError as e:
         self.assertIn('System \'%s\' does not exist' %system_fqdn,
                       e.stderr_output)
示例#50
0
 def test_add_systems_to_pool(self):
     pool_name = data_setup.unique_name(u'mypool%s')
     with session.begin():
         pool = data_setup.create_system_pool(name=pool_name)
         s1 = data_setup.create_system()
         s2 = data_setup.create_system()
     run_client(['bkr', 'pool-add', '--pool', pool_name,
                 '--system', s1.fqdn,
                 '--system', s2.fqdn])
     with session.begin():
         session.refresh(pool)
         self.assertItemsEqual([s1, s2], pool.systems)
示例#51
0
    def test_revoke_policy_pool(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            user = data_setup.create_user()
            user1 = data_setup.create_user()
            group = data_setup.create_group()
            group.users.append(user1)

            pol = pool.access_policy
            pol.add_rule(SystemPermission.reserve, user=user)
            pol.add_rule(SystemPermission.view_power, user=user)
            pol.add_rule(SystemPermission.reserve, group=group)
            pol.add_rule(SystemPermission.view_power, group=group)

        # revoke edit_system from group
        run_client([
            'bkr', 'policy-revoke', '--pool', pool.name, '--permission',
            'view_power', '--group', group.group_name
        ])
        with session.begin():
            session.refresh(pool)
            self.assertFalse(
                pool.access_policy.grants(user1, SystemPermission.edit_system))

        # test_multiple_permissions_and_targets
        run_client(['bkr', 'policy-revoke', '--pool', pool.name,
                    '--permission=reserve', '--permission=view_power', \
                    '--user', user.user_name, '--group', group.group_name])
        with session.begin():
            session.refresh(pool)
            self.assertFalse(
                pool.access_policy.grants(user, SystemPermission.view_power))
            self.assertFalse(
                pool.access_policy.grants(user, SystemPermission.reserve))
            self.assertFalse(
                pool.access_policy.grants(user1, SystemPermission.view_power))
            self.assertFalse(
                pool.access_policy.grants(user1, SystemPermission.reserve))

        # this should still exist
        with session.begin():
            session.refresh(pool)
            self.assertTrue(
                pool.access_policy.grants(user, SystemPermission.view))

        # non-existent pool
        try:
            run_client(['bkr', 'policy-revoke', '--pool', 'idontexist',
                        '--permission=reserve', '--permission=view_power', \
                        '--user', user.user_name, '--group', group.group_name])
        except ClientError as e:
            self.assertIn("System pool idontexist does not exist",
                          e.stderr_output)
示例#52
0
    def test_pool_change_name(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            pool1 = data_setup.create_system_pool()
        new_name = data_setup.unique_name(u'newpool%s')
        run_client(['bkr', 'pool-modify',
                    '--name', new_name,
                    pool.name])
        with session.begin():
            session.refresh(pool)
            self.assertEquals(pool.name, new_name)

        # rename to an existing pool will error out
        try:
            run_client(['bkr', 'pool-modify',
                        '--name', pool1.name,
                        pool.name])
            self.fail('Must error out')
        except ClientError as e:
            self.assertIn('System pool %s already exists' % pool1.name,
                          e.stderr_output)
示例#53
0
    def test_delete_system_pool(self):
        with session.begin():
            system = data_setup.create_system()
            random_user = data_setup.create_user(password='******')
            pool_owner = data_setup.create_user(password='******')
            pool_name = data_setup.unique_name('mypool%s')
            pool = data_setup.create_system_pool(name=pool_name,
                                                 owning_user=pool_owner,
                                                 systems=[system])
            pool.access_policy.add_rule(user=self.user,
                                        permission=SystemPermission.edit_system)
            system.active_access_policy = pool.access_policy

        unicode_pool = unicode(pool)
        self.assertIn(pool, system.pools)
        self.assertTrue(system.active_access_policy.grants
                        (self.user, SystemPermission.edit_system))
        # first as a random user
        s = requests.Session()
        s.post(get_server_base() + 'login', data={'user_name': random_user.user_name,
                                                  'password': '******'}).raise_for_status()
        response = s.delete(get_server_base() + 'pools/%s/' % pool_name)
        self.assertEquals(response.status_code, 403)

        # now as the pool owner
        s = requests.Session()
        s.post(get_server_base() + 'login', data={'user_name': pool_owner.user_name,
                                                  'password': '******'}).raise_for_status()
        response = s.delete(get_server_base() + 'pools/%s/' % pool_name)
        response.raise_for_status()
        with session.begin():
            session.expire_all()
            with self.assertRaises(NoResultFound):
                SystemPool.by_name(pool_name)

            self.assertNotIn(pool, system.pools)
            self.assertFalse(system.active_access_policy.grants
                             (self.user, SystemPermission.edit_system))

            self.assertEquals(system.activity[-1].field_name, 'Pool')
            self.assertEquals(system.activity[-1].action, 'Removed')
            self.assertEquals(system.activity[-1].old_value, unicode_pool)

            self.assertEquals(system.activity[-2].field_name, 'Active Access Policy')
            self.assertEquals(system.activity[-2].old_value, 'Pool policy: %s' % pool_name)
            self.assertEquals(system.activity[-2].new_value, 'Custom access policy')

            self.assertEquals(1, Activity.query
                              .filter(Activity.field_name == u'Pool')
                              .filter(Activity.action == u'Deleted')
                              .filter(Activity.old_value == pool_name).count(),
                              'Expected to find activity record for pool deletion')
示例#54
0
 def test_filter_by_pool(self):
     with session.begin():
         data_setup.create_system(fqdn=u'nopool.system')
         pool = data_setup.create_system_pool()
         data_setup.create_system(fqdn=u'inpool.system').pools.append(pool)
     feed_url = urljoin(get_server_base(), '?' + urlencode({
             'tg_format': 'atom', 'list_tgp_order': '-date_modified',
             'systemsearch-0.table': 'System/Pools',
             '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.system'))
     self.assertTrue(self.feed_contains_system(feed, 'inpool.system'))
示例#55
0
 def test_pool_change_owner_to_group(self):
     with session.begin():
         group = data_setup.create_group()
         group_name = group.group_name
         pool_name = data_setup.unique_name(u'pool%s')
         pool = data_setup.create_system_pool(name=pool_name)
     run_client(['bkr', 'pool-modify',
                 '--owning-group', group_name,
                 pool_name])
     with session.begin():
         session.refresh(pool)
         self.assertTrue(pool.owning_group, group)
         self.assertFalse(pool.owning_user)