Esempio n. 1
0
 def test_cannot_specify_finished_and_unfinished_at_the_same_time (self):
     try:
         run_client(['bkr', 'job-list', '--finished', '--unfinished'])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 2)
         self.assertIn("Only one of --finished or --unfinished may be specified", e.stderr_output)
Esempio n. 2
0
 def test_user_edit_email(self):
     try:
         run_client(['bkr', 'update-prefs', '[email protected]'],
                    config=self.client_config1)
         fail('should raise')
     except ClientError, e:
         self.assert_('is same as before' in e.stderr_output)
Esempio n. 3
0
    def test_ldap_group(self):
        if not config.get("identity.ldap.enabled", False):
            raise SkipTest('Server is not configured for LDAP')

        group_name = u'wyfp'
        display_name = u'My LDAP Group'
        out = run_client(['bkr', 'group-create', '--ldap',
                          '--display-name', display_name,
                          group_name])

        group = Group.by_name(group_name)
        self.assertEquals(group.membership_type, GroupMembershipType.ldap)
        self.assertEquals(group.users, [User.by_user_name(u'asaha')])

        with session.begin():
            rand_user = data_setup.create_user(password = '******')

        rand_client_config = create_client_config(username=rand_user.user_name,
                                                  password='******')

        group_name = u'alp'
        display_name = u'ALP'
        try:
            out = run_client(['bkr', 'group-create', '--ldap',
                          '--display-name', display_name,
                              group_name],
                             config = rand_client_config)
            self.fail('Must fail or die')
        except ClientError, e:
            self.assert_('Only admins can create LDAP groups' in
                         e.stderr_output)
Esempio n. 4
0
    def test_machine_test(self):
        out = run_client(
            [
                "bkr",
                "machine-test",
                "--inventory",
                "--machine",
                self.system.fqdn,
                "--arch",
                "i386",
                "--family",
                self.distro.osversion.osmajor.osmajor,
            ]
        )
        self.assert_(out.startswith("Submitted:"), out)

        with session.begin():
            new_job = Job.query.order_by(Job.id.desc()).first()
            self.assertEqual(new_job.whiteboard, u"Test " + self.system.fqdn)
            tasks = new_job.recipesets[0].recipes[0].tasks
            self.assertEqual(len(tasks), 2)
            self.assertEqual(tasks[0].name, u"/distribution/install")
            self.assertEqual(tasks[1].name, u"/distribution/inventory")

        # https://bugzilla.redhat.com/show_bug.cgi?id=893878
        try:
            out = run_client(["bkr", "machine-test", "--machine", self.system.fqdn, "--tag", "aTAG"])
        except Exception as ex:
            self.assertEqual(
                ex.stderr_output.rstrip("\n"), "Could not find an appropriate distro to provision system with."
            )
Esempio n. 5
0
 def test_empty_comment_is_rejected(self):
     try:
         run_client(['bkr', 'job-comment', self.job.recipesets[0].t_id,
                     '--message', ''])
         self.fail('should raise')
     except ClientError, e:
         self.assertIn('Comment text cannot be empty', e.stderr_output)
Esempio n. 6
0
 def test_doesnt_barf_on_xml_encoding_declaration(self):
     out = run_client(['bkr', 'job-submit', '-'],
             input=self.job_xml_with_encoding('UTF-8', u'яяя'))
     self.assert_(out.startswith('Submitted:'), out)
     out = run_client(['bkr', 'job-submit', '-'],
             input=self.job_xml_with_encoding('ISO-8859-1', u'äóß'))
     self.assert_(out.startswith('Submitted:'), out)
Esempio n. 7
0
 def test_grant_existing_permission(self):
     with session.begin():
         self.system.custom_access_policy.add_rule(
                 permission=SystemPermission.edit_system, everybody=True)
     # should silently have no effect
     run_client(['bkr', 'policy-grant', '--system', self.system.fqdn,
             '--permission', 'edit_system', '--everybody'])
Esempio n. 8
0
 def test_exits_with_error_if_none_match(self):
     try:
         run_client(['bkr', 'distro-trees-list', '--name', 'NOTEXIST'])
         fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 1)
         self.assertEqual(e.stderr_output, 'Nothing Matches\n')
Esempio n. 9
0
    def test_group_modify_group_name(self):
        group_name = 'mynewgroup'
        out = run_client(['bkr', 'group-modify',
                          '--group-name', group_name,
                          self.group.group_name],
                         config = self.client_config)

        with session.begin():
            session.refresh(self.group)
            group = Group.by_name(group_name)
            self.assertEquals(group.group_name, group_name)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Name')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].new_value, group_name)
            self.assertEquals(group.activity[-1].service, u'XMLRPC')

        try:
            out = run_client(['bkr', 'group-modify',
                              '--group-name', 'areallylonggroupname'*20,
                              self.group.group_name],
                             config = self.client_config)
            self.fail('Must fail or die')
        except ClientError,e:
            max_length = Group.group_name.property.columns[0].type.length
            self.assertRegexpMatches(e.stderr_output,
                                     'Enter a value (less|not more) than %r characters long' % max_length)
Esempio n. 10
0
    def test_group_modify_add_member(self):
        with session.begin():
            user = data_setup.create_user()


        out = run_client(['bkr', 'group-modify',
                          '--add-member', user.user_name,
                          self.group.group_name],
                         config = self.client_config)

        with session.begin():
            session.refresh(self.group)
            group = Group.by_name(self.group.group_name)
            self.assert_(user.user_name in
                         [u.user_name for u in group.users])


        self.check_notification(user, group, action='Added')

        try:
            out = run_client(['bkr', 'group-modify',
                              '--add-member', 'idontexist',
                              self.group.group_name],
                             config = self.client_config)
            self.fail('Must fail or die')
        except ClientError, e:
            self.assert_('User does not exist' in
                         e.stderr_output, e.stderr_output)
Esempio n. 11
0
 def test_tag_distro(self):
     with session.begin():
         self.distro = data_setup.create_distro()
     run_client(["bkr", "distros-tag", "--name", self.distro.name, "LOL"])
     with session.begin():
         session.refresh(self.distro)
         self.assert_(u"LOL" in self.distro.tags)
Esempio n. 12
0
 def test_cannot_add_empty_tag(self):
     try:
         run_client(['bkr', 'distros-tag'])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 2)
         self.assertIn('Please specify a tag', e.stderr_output)
Esempio n. 13
0
 def test_tag_distro(self):
     with session.begin():
         self.distro = data_setup.create_distro()
     run_client(['bkr', 'distros-tag', '--name', self.distro.name, 'LOL'])
     with session.begin():
         session.refresh(self.distro)
         self.assert_(u'LOL' in self.distro.tags)
Esempio n. 14
0
 def test_releasing_a_nonexistent_system_fails(self):
     try:
         run_client(['bkr', 'system-release', 'test.invalid.nonexistent.com'])
         self.fail('Should raise')
     except ClientError, e:
         self.assertEqual(e.status, 1)
         self.assertIn('System not found', e.stderr_output)
Esempio n. 15
0
 def test_cannot_add_nonexistent_task(self):
     try:
         run_client(['bkr', 'task-add', '/non/exist/task.rpm'])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 1)
         self.assertIn("No such file or directory:", e.stderr_output)
Esempio n. 16
0
 def test_cannot_add_tag_without_distro_name(self):
     try:
         run_client(['bkr', 'distros-tag', 'asdf'])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 2)
         self.assertIn('If you really want to tag every distro in Beaker, use --name=%', e.stderr_output)
Esempio n. 17
0
    def test_ldap_group(self):

        group_name = 'wyfp'
        display_name = 'My LDAP Group'
        out = run_client(['bkr', 'group-create', '--ldap',
                          '--display-name', display_name,
                          group_name])

        group = Group.by_name(group_name)
        self.assertEquals(group.ldap, True)
        self.assertEquals(group.users, [User.by_user_name(u'asaha')])

        with session.begin():
            rand_user = data_setup.create_user(password = '******')

        rand_client_config = create_client_config(username=rand_user.user_name,
                                                  password='******')

        group_name = 'alp'
        display_name = 'ALP'
        try:
            out = run_client(['bkr', 'group-create', '--ldap',
                          '--display-name', display_name,
                              group_name],
                             config = rand_client_config)
            self.fail('Must fail or die')
        except ClientError, e:
            self.assert_('Only admins can create LDAP groups' in
                         e.stderr_output)
Esempio n. 18
0
 def test_untag_distro(self):
     with session.begin():
         self.distro = data_setup.create_distro(tags=[u'RELEASED', u'STABLE'])
     run_client(['bkr', 'distros-untag', '--name', self.distro.name, 'RELEASED'])
     with session.begin():
         session.refresh(self.distro)
         self.assertEquals(self.distro.tags, [u'STABLE'])
Esempio n. 19
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)
Esempio n. 20
0
    def test_group_modify_group_name(self):
        group_name = u'mynewgroup'
        out = run_client(['bkr', 'group-modify',
                          '--group-name', group_name,
                          self.group.group_name],
                         config = self.client_config)

        with session.begin():
            session.refresh(self.group)
            group = Group.by_name(group_name)
            self.assertEquals(group.group_name, group_name)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Name')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].new_value, group_name)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        try:
            out = run_client(['bkr', 'group-modify',
                              '--group-name', 'areallylonggroupname'*20,
                              self.group.group_name],
                             config = self.client_config)
            self.fail('Must fail or die')
        except ClientError,e:
            self.assertIn(
                    'Group name must be not more than 255 characters long',
                    e.stderr_output)
Esempio n. 21
0
 def test_revoke_nonexistent_permission(self):
     with session.begin():
         self.assertFalse(self.system.custom_access_policy.grants_everybody(
                 SystemPermission.edit_system))
     # should silently have no effect
     run_client(['bkr', 'policy-revoke', '--system', self.system.fqdn,
             '--permission', 'edit_system', '--everybody'])
Esempio n. 22
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))
Esempio n. 23
0
 def test_invalid_system(self):
     try:
         run_client(['bkr', 'system-modify', '--owner=somebody',
                     'ireallydontexistblah.test.fqdn'])
         self.fail('Must raise')
     except ClientError as e:
         self.assertIn('System not found', e.stderr_output)
Esempio n. 24
0
    def test_job_group(self):
        with session.begin():
            user_in_group = data_setup.create_user(password='******')
            group = data_setup.create_group()
            user_in_group.groups.append(group)
            user_not_in_group = data_setup.create_user(password='******')

        # Test submitting on behalf of user's group
        config1 = create_client_config(username=user_in_group.user_name,
            password='******')
        out = run_client(['bkr', 'workflow-simple', '--random',
                '--arch', self.distro_tree.arch.arch,
                '--family', self.distro.osversion.osmajor.osmajor,
                '--job-group', group.group_name,
                '--task', self.task.name], config=config1)
        self.assertTrue(out.startswith('Submitted:'), out)
        m = re.search('J:(\d+)', out)
        job_id = m.group(1)
        with session.begin():
            job = Job.by_id(job_id)
        self.assertEqual(group, job.group)

        # Test submitting on behalf of group user does not belong to
        config2 = create_client_config(username=user_not_in_group.user_name,
            password='******')
        try:
            out2 = run_client(['bkr', 'workflow-simple', '--random',
                    '--arch', self.distro_tree.arch.arch,
                    '--family', self.distro.osversion.osmajor.osmajor,
                    '--job-group', group.group_name,
                    '--task', self.task.name], config=config2)
            fail('should raise')
        except ClientError, e:
            self.assertTrue('You are not a member of the %s group' % \
                group.group_name in e.stderr_output, e)
Esempio n. 25
0
 def test_cant_delete_group_mates_job(self):
     # XXX This whole test can go away with BZ#1000861
     try:
         stop_process('gunicorn')
     except ValueError:
         # It seems gunicorn is not a running process
         raise SkipTest('Can only run this test against gunicorn')
     try:
         tmp_config = edit_file(CONFIG_FILE, 'beaker.deprecated_job_group_permissions.on = True',
             'beaker.deprecated_job_group_permissions.on = False')
         start_process('gunicorn', env={'BEAKER_CONFIG_FILE': tmp_config.name})
         with session.begin():
             group = data_setup.create_group()
             mate = data_setup.create_user(password=u'asdf')
             test_job = data_setup.create_completed_job(owner=mate)
             data_setup.add_user_to_group(self.user, group)
             data_setup.add_user_to_group(mate, group)
         try:
             run_client(['bkr', 'job-delete', test_job.t_id],
                 config=self.client_config)
             self.fail('We should not have permission to delete %s' % \
                 test_job.t_id)
         except ClientError, e:
             self.assertIn("You don't have permission to delete job %s" %
             test_job.t_id, e.stderr_output)
     finally:
         stop_process('gunicorn')
         start_process('gunicorn')
Esempio n. 26
0
 def test_user_edit_email(self):
     try:
         run_client(['bkr', 'update-prefs', '--email=%s' % self.user1.email_address],
                    config=self.client_config1)
         self.fail('should raise')
     except ClientError, e:
         self.assertIn('is same as before', e.stderr_output)
Esempio n. 27
0
    def test_user_with_borrow_permissions_only(self):
        # Grant everyone borrow permissions on the system
        with session.begin():
            self.system.custom_access_policy.add_rule(
                    permission=SystemPermission.loan_self, everybody=True)

        # user2 should now be able to borrow and return the system
        out = run_client(['bkr', 'loan-grant', self.system.fqdn],
                config=self.client_config2)
        self.assertRegexpMatches('^Borrowed %s' % self.system.fqdn, out)
        self.assertLoanedTo(self.user2)

        out = run_client(['bkr', 'loan-return', self.system.fqdn],
                config=self.client_config2)
        self.assertRegexpMatches('^Returned loan for %s' % self.system.fqdn,
                                out)
        self.assertNotLoaned()
        # user2 should still not be able to lend the system to anyone else
        details = "%s cannot lend this system" % self.user2.user_name
        with self.assertTriggersPermissionsError(details):
            run_client(['bkr', 'loan-grant',
                        '--recipient', self.user.user_name,
                        self.system.fqdn],
                       config=self.client_config2)
        self.assertNotLoaned()
Esempio n. 28
0
 def test_user_cannot_borrow_system(self):
     # user2 should not be able to lend the system to themselves
     details = "%s cannot borrow this system" % self.user2.user_name
     with self.assertTriggersPermissionsError(details):
         run_client(['bkr', 'loan-grant', self.system.fqdn],
                    config=self.client_config2)
     self.assertNotLoaned()
Esempio n. 29
0
    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)
Esempio n. 30
0
 def test_unknown_fqdn(self):
     try:
         run_client(['bkr', 'system-status',
             data_setup.unique_name('invalid.example%s.com')])
         self.fail('Should raise 404 from the server')
     except ClientError as e:
         self.assertIn('System not found', e.stderr_output)
Esempio n. 31
0
 def test_details_include_owner_and_priority(self):
     with session.begin():
         owner = data_setup.create_user()
         task = data_setup.create_task(owner=owner, priority=u'Low')
     out = run_client(['bkr', 'task-details', task.name])
     details = eval(out[len(task.name) + 1:])  # XXX dodgy
     self.assertEquals(details['owner'], owner.user_name)
     self.assertEquals(details['priority'], u'Low')
Esempio n. 32
0
 def test_details_without_uploader(self):
     # We now always record Uploader, but older tasks may lack it
     with session.begin():
         task = data_setup.create_task()
         task.uploader = None
     out = run_client(['bkr', 'task-details', task.name])
     details = eval(out[len(task.name) + 1:])  # XXX dodgy
     self.assertEquals(details['uploader'], None)
Esempio n. 33
0
    def test_group_modify_revoke_owner(self):
        with session.begin():
            user1 = data_setup.create_user()
            self.group.add_member(user1)
            user2 = data_setup.create_user()
            self.group.add_member(user2)
            user3 = data_setup.create_user()

        out = run_client([
            'bkr', 'group-modify', '--grant-owner', user1.user_name,
            '--grant-owner', user2.user_name, self.group.group_name
        ],
                         config=self.client_config)

        out = run_client([
            'bkr', 'group-modify', '--revoke-owner', user1.user_name,
            '--revoke-owner', user2.user_name, self.group.group_name
        ],
                         config=self.client_config)

        with session.begin():
            session.refresh(self.group)
            group = Group.by_name(self.group.group_name)
            self.assert_(
                user1.user_id not in [u.user_id for u in group.owners()])
            self.assert_(
                user2.user_id not in [u.user_id for u in group.owners()])
            self.assertEquals(
                Activity.query.filter_by(service=u'HTTP',
                                         field_name=u'Owner',
                                         action=u'Removed',
                                         old_value=user2.user_name).count(), 1)
            self.assertEquals(group.activity[-1].action, u'Removed')
            self.assertEquals(group.activity[-1].field_name, u'Owner')
            self.assertEquals(group.activity[-1].old_value, user2.user_name)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        try:
            out = run_client([
                'bkr', 'group-modify', '--revoke-owner', user3.user_name,
                self.group.group_name
            ],
                             config=self.client_config)
            self.fail('Must fail or die')
        except ClientError, e:
            self.assert_('User is not a member of group' in e.stderr_output)
Esempio n. 34
0
 def test_reserve(self):
     out = run_client([
         'bkr', 'workflow-simple', '--dry-run', '--pretty-xml', '--arch',
         self.distro_tree.arch.arch, '--family',
         self.distro.osversion.osmajor.osmajor, '--task', self.task.name,
         '--reserve', '--reserve-duration', '3600'
     ])
     self.assertIn('<reservesys duration="3600"/>', out)
Esempio n. 35
0
 def test_hostrequire_raw_xml(self):
     out = run_client([
         'bkr', 'workflow-simple', '--dryrun', '--prettyxml',
         '--hostrequire', '<device vendor_id="8086"/>', '--arch',
         self.distro_tree.arch.arch, '--family',
         self.distro.osversion.osmajor.osmajor, '--task', self.task.name
     ])
     self.assertIn('<device vendor_id="8086"/>', out)
Esempio n. 36
0
 def test_successful_add_tag_for_all_distros(self):
     with session.begin():
         self.distro = data_setup.create_distro()
     out = run_client(['bkr', 'distros-tag', '--name=%', 'addAll'])
     with session.begin():
         session.expire_all()
         for distro in Distro.query:
             self.assertIn(u'addAll', distro.tags)
Esempio n. 37
0
    def test_cannot_cancel_other_peoples_job(self):
        with session.begin():
            user1 = data_setup.create_user(password='******')
            job_owner = data_setup.create_user()
            job = data_setup.create_job(owner=job_owner)

        try:
            run_client([
                'bkr', 'job-cancel', '--username', user1.user_name,
                '--password', 'abc', job.t_id
            ])
            self.fail('should raise')
        except ClientError, e:
            self.assertEquals(e.status, 1)
            self.assert_(
                'You don\'t have permission to cancel' in e.stderr_output,
                e.stderr_output)
Esempio n. 38
0
 def test_details_without_owner(self):
     # We no longer permit empty Owner but older tasks may still lack it
     with session.begin():
         task = data_setup.create_task()
         task.owner = None
     out = run_client(['bkr', 'task-details', task.name])
     details = eval(out[len(task.name) + 1:])  # XXX dodgy
     self.assertEquals(details['owner'], None)
Esempio n. 39
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)
Esempio n. 40
0
 def test_multiple_permissions_and_targets(self):
     with session.begin():
         user = data_setup.create_user()
         group = data_setup.create_group()
         pol = self.system.custom_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)
         # there is always the rule granting everybody view
         self.assertEquals(len(self.system.custom_access_policy.rules), 5)
     run_client(['bkr', 'policy-revoke', '--system', self.system.fqdn,
             '--permission=reserve', '--permission=view_power',
             '--user', user.user_name, '--group', group.group_name])
     with session.begin():
         session.expire_all()
         self.assertEquals(len(self.system.custom_access_policy.rules), 1)
Esempio n. 41
0
 def test_remove_invalid_submission_delegate(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         notadelegate = data_setup.create_user()
     client_config = create_client_config(username=user.user_name,
                                          password='******')
     try:
         run_client([
             'bkr', 'user-modify', '--remove-submission-delegate',
             notadelegate.user_name
         ],
                    config=client_config)
         self.fail('Does not throw error when removing non delegate')
     except ClientError as e:
         self.assertTrue('%s is not a submission delegate of %s' % \
             (notadelegate.user_name, user) in e.stderr_output,
             e.stderr_output)
Esempio n. 42
0
 def test_record_retention_tag(self):
     with session.begin():
         rt = data_setup.create_retention_tag()
     out = run_client(['bkr', 'job-modify', self.job.t_id,  '--retention-tag', '%s' % rt.tag])
     self.assertEquals(self.job.activity[0].action, u'Changed')
     self.assertEquals(self.job.activity[0].field_name, 'Retention Tag')
     self.assertEquals(self.job.activity[0].old_value, self.job.retention_tag.tag)
     self.assertEquals(self.job.activity[0].new_value, rt.tag)
Esempio n. 43
0
 def test_by_task(self):
     out = run_client(['bkr', 'job-logs',
             self.job.recipesets[0].recipes[0].tasks[0].t_id])
     logs = out.splitlines()
     self.assertEquals(logs[0], get_server_base() + u'recipes/%s/tasks/%s/logs/T/dummy.txt'
             % (self.recipe.id, self.recipe.tasks[0].id))
     self.assertEquals(logs[1], get_server_base() + u'recipes/%s/tasks/%s/results/%s/logs/TR/dummy.txt'
             % (self.recipe.id, self.recipe.tasks[0].id, self.recipe.tasks[0].results[0].id))
Esempio n. 44
0
 def test_list_distro(self):
     output = run_client([
         'bkr', 'distros-list', '--format=json', '--name', self.distro.name
     ])
     distros = json.loads(output)
     self.assertEquals(len(distros), 1)
     self.assertEquals(distros[0]['distro_id'], self.distro.id)
     self.assertEquals(distros[0]['distro_name'], self.distro.name)
Esempio n. 45
0
    def test_hostfilter_preset(self):
        out = run_client([
            'bkr', 'workflow-simple', '--dryrun', '--prettyxml',
            '--host-filter', "INTEL__FAM15_CELERON", '--arch',
            self.distro_tree.arch.arch, '--family',
            self.distro.osversion.osmajor.osmajor, '--task', self.task.name
        ])
        self.assertIn('<model_name op="like" value="%Celeron%"/>', out)

        # with other host requires
        out = run_client([
            'bkr', 'workflow-simple', '--dryrun', '--prettyxml',
            '--host-filter', "INTEL__FAM15_CELERON", '--hostrequire',
            'hostlabcontroller=lab.example.com', '--arch',
            self.distro_tree.arch.arch, '--family',
            self.distro.osversion.osmajor.osmajor, '--task', self.task.name
        ])
        self.assertIn('<model_name op="like" value="%Celeron%"/>', out)
        self.assertIn('<hostlabcontroller op="=" value="lab.example.com"/>',
                      out)

        # Override $HOME and check if the updated defintion is read
        test_home = pkg_resources.resource_filename \
                    ('bkr.inttest.client', '.')
        out = run_client([
            'bkr', 'workflow-simple', '--dryrun', '--prettyxml',
            '--host-filter', "INTEL__FAM15_CELERON", '--arch',
            self.distro_tree.arch.arch, '--family',
            self.distro.osversion.osmajor.osmajor, '--task', self.task.name
        ],
                         extra_env={'HOME': test_home})
        self.assertIn('<model_name op="like" value="%MyCeleron%"/>', out)

        # Non-existent filter
        try:
            run_client([
                'bkr', 'workflow-simple', '--dryrun', '--prettyxml',
                '--host-filter', "awesomefilter", '--arch',
                self.distro_tree.arch.arch, '--family',
                self.distro.osversion.osmajor.osmajor, '--task', self.task.name
            ])
            self.fail('Must fail or die')
        except ClientError as e:
            self.assertIn(
                'Pre-defined host-filter does not exist: awesomefilter',
                e.stderr_output)
Esempio n. 46
0
 def test_set_recipe_whiteboard(self):
     recipe = self.job.recipesets[0].recipes[0]
     out = run_client(['bkr', 'job-modify', recipe.t_id,
             '--whiteboard', 'found himself transformed'])
     self.assertIn('Successfully modified jobs %s' % recipe.t_id, out)
     with session.begin():
         session.expire_all()
         self.assertEquals(recipe.whiteboard, u'found himself transformed')
Esempio n. 47
0
 def test_clean_defaults(self):
     out = run_client([
         'bkr', 'workflow-simple', '--dryrun', '--prettyxml', '--arch',
         self.distro_tree.arch.arch, '--family',
         self.distro.osversion.osmajor.osmajor, '--task', self.task.name
     ])
     # Try to minimise noise in the default output
     self.assertNotIn('ks_appends', out)
Esempio n. 48
0
 def test_list_systems_nonexistent_pool(self):
     pool_name = data_setup.unique_name(u'mypool%s')
     try:
         out = run_client(['bkr', 'pool-systems', pool_name])
         self.fail('Must fail or die')
     except ClientError as e:
         self.assertIn('System pool %s does not exist' % pool_name,
                       e.stderr_output)
Esempio n. 49
0
 def test_xml_filter(self):
     output = run_client(['bkr', 'distro-trees-list', '--format=json',
             '--xml-filter',
             '<distro_name value="%s" />' % self.distro_tree.distro.name])
     trees = json.loads(output)
     self.assertEquals(len(trees), 1)
     self.assertEquals(trees[0]['distro_tree_id'], self.distro_tree.id)
     self.assertEquals(trees[0]['distro_name'], self.distro_tree.distro.name)
 def test_verify_distro(self):
     output = run_client([
         'bkr', 'distro-trees-verify', '--name',
         self.distro_tree.distro.name
     ])
     lines = output.splitlines()
     self.assert_(self.distro_tree.distro.name in lines[0])
     self.assertEquals(lines[1],
                       "missing from labs ['dodgylc.example.invalid']")
Esempio n. 51
0
    def test_loan_comment(self):
        # Set a comment while granting the loan
        out = run_client([
            'bkr', 'loan-grant', '--comment', 'Mine! All mine!',
            self.system.fqdn
        ],
                         config=self.client_config)
        self.assertRegexpMatches('^Borrowed %s' % self.system.fqdn, out)
        self.assertLoanedTo(self.user, "Mine! All mine!")

        out = run_client(['bkr', 'loan-return', self.system.fqdn],
                         config=self.client_config)
        self.assertRegexpMatches('^Returned loan for %s' % self.system.fqdn,
                                 out)
        with session.begin():
            session.refresh(self.system)
            self.assertIsNone(self.system.loaned)
            self.assertIsNone(self.system.loan_comment)
Esempio n. 52
0
 def test_add_new_task_successfully(self):
     test_rpm = pkg_resources.resource_filename(
         'bkr.inttest.server',
         'task-rpms/tmp-test-add-new-task-successfully.noarch.rpm')
     new_rpm = path.join(config.get('basepath.rpms'),
                         'tmp-test-add-new-task-successfully.noarch.rpm')
     out = run_client(['bkr', 'task-add', test_rpm])
     self.assertIn(u'Success', out)
     self.assertTrue(path.exists(new_rpm))
Esempio n. 53
0
 def test_cannot_add_task_with_same_version(self):
     new_rpm = pkg_resources.resource_filename(
         'bkr.inttest.server',
         'task-rpms/tmp-test-cannot-add-same-version-tasks-1.1.2-0.noarch.rpm'
     )
     same_version_rpm = pkg_resources.resource_filename(
         'bkr.inttest.server',
         'task-rpms/tmp-test-cannot-add-same-version-1-tasks-1.1.2-0.noarch.rpm'
     )
     run_client(['bkr', 'task-add', new_rpm])
     try:
         run_client(['bkr', 'task-add', same_version_rpm])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 1)
         self.assertIn(
             'Failed to import,  1.1.2-0 is the same version we already have',
             e.stderr_output)
Esempio n. 54
0
 def test_size_handles_http_errors(self):
     with session.begin():
         # /error/500 is treated specially by http_server.py, returns 500
         self.job.recipesets[0].recipes[0].logs[0].path = u'error'
         self.job.recipesets[0].recipes[0].logs[0].filename = u'500'
     out = run_client(['bkr', 'job-logs', '--size', self.job.t_id])
     lines = out.splitlines()
     self.assertEquals(lines[0],
                       '<error:500> %serror/500' % self.log_server_url)
Esempio n. 55
0
 def test_change_power_type(self):
     with session.begin():
         system = data_setup.create_system(hypervisor=None)
     # set to 'apc_snmp_then_etherwake'
     run_client([
         'bkr', 'system-modify', '--power-type=apc_snmp_then_etherwake',
         system.fqdn
     ])
     with session.begin():
         session.refresh(system)
         self.assertEquals(system.power.power_type,
                           PowerType.by_name(u'apc_snmp_then_etherwake'))
     # set back to ilo
     run_client(['bkr', 'system-modify', '--power-type=ilo', system.fqdn])
     with session.begin():
         session.refresh(system)
         self.assertEquals(system.power.power_type,
                           PowerType.by_name(u'ilo'))
Esempio n. 56
0
 def test_prints_sizes(self):
     out = run_client(['bkr', 'job-logs', '--size', self.job.t_id])
     lines = out.splitlines()
     self.assertEquals(lines[0],
                       '     7 %sR/dummy.txt' % self.log_server_url)
     self.assertEquals(lines[1],
                       '     5 %sT/dummy.txt' % self.log_server_url)
     self.assertEquals(lines[2],
                       '     7 %sTR/dummy.txt' % self.log_server_url)
Esempio n. 57
0
 def test_size_handles_404(self):
     with session.begin():
         self.job.recipesets[0].recipes[0].logs[
             0].filename = u'idontexist.txt'
     out = run_client(['bkr', 'job-logs', '--size', self.job.t_id])
     lines = out.splitlines()
     self.assertEquals(
         lines[0], '<missing> %srecipes/%s/logs/R/idontexist.txt' %
         (get_server_base(), self.recipe.id))
Esempio n. 58
0
    def test_delete_job_with_admin(self):
        with session.begin():
            other_user = data_setup.create_user(password=u'asdf')
            tag = data_setup.create_retention_tag(name=u'myblahtag')
            job1 = data_setup.create_completed_job(owner=other_user)
            job2 = data_setup.create_completed_job(owner=other_user, \
                                                   retention_tag=tag)

        # As the default admin user
        # Admin can delete other's job with job ID
        out = run_client(['bkr', 'job-delete', job1.t_id])
        self.assert_(out.startswith('Jobs deleted:'), out)
        self.assert_(job1.t_id in out, out)

        # Admin can not delete other's job with tags
        out = run_client(['bkr', 'job-delete', '-t%s' % tag.tag])
        self.assert_(out.startswith('Jobs deleted:'), out)
        self.assert_(job2.t_id not in out, out)
Esempio n. 59
0
 def test_accepts_machine_and_systype(self):
     out = run_client([
         'bkr', 'workflow-simple', '--dryrun', '--prettyxml', '--machine',
         'system.example.com', '--systype', 'Prototype', '--arch',
         self.distro_tree.arch.arch, '--family',
         self.distro.osversion.osmajor.osmajor, '--task', self.task.name
     ])
     self.assertIn('<hostname op="=" value="system.example.com"/>', out)
     self.assertIn('<system_type op="=" value="Prototype"/>', out)
Esempio n. 60
0
    def test_unpopulated_status(self):
        with session.begin():
            system = data_setup.create_system(status=SystemStatus.automated)
        json_out = run_client(
            ['bkr', 'system-status', system.fqdn, '--format', 'json'])
        json_out = loads(json_out)
        self.assertEqual(json_out.get('current_reservation'), None)
        self.assertEqual(json_out.get('current_loan'), None)
        self.assertEqual(json_out.get('condition'), unicode(system.status))

        # Human friendly output
        human_out = run_client(['bkr', 'system-status', system.fqdn])
        expected_out = textwrap.dedent('''\
            Condition: %s
            Current reservation: None
            Current loan: None''' % (system.status))
        human_out = human_out.rstrip('\n')
        self.assertEqual(human_out, expected_out, human_out)