def setupClass(cls):
        data_setup.create_labcontroller()
        cls.distro_one_name = data_setup.unique_name(u'nametest%s')
        cls.distro_one_osmajor = u'osmajortest1'
        cls.distro_one_osminor = u'1'
        cls.distro_one_variant = u'myvariant'
        cls.distro_one_tag = [u'MYTAG']

        cls.distro_one = data_setup.create_distro(name=cls.distro_one_name,
            osmajor=cls.distro_one_osmajor, osminor = cls.distro_one_osminor,
            tags =cls.distro_one_tag)
        cls.distro_tree_one = data_setup.create_distro_tree(distro=cls.distro_one,
            variant=cls.distro_one_variant)
        # Two days in the future
        cls.distro_two_name = data_setup.unique_name(u'nametest%s')
        cls.distro_two_osmajor = u'osmajortest2'
        cls.distro_two_osminor = u'2'

        cls.distro_two = data_setup.create_distro(name=cls.distro_two_name,
            osmajor=cls.distro_two_osmajor, osminor = cls.distro_two_osminor,)
        cls.distro_tree_two = data_setup.create_distro_tree(distro=cls.distro_two)
        cls.distro_tree_two.date_created = datetime.utcnow() + timedelta(days=2)

        cls.distro_three_name = data_setup.unique_name(u'nametest%s')
        cls.distro_three_osmajor = u'osmajortest3'
        cls.distro_three_osminor = u'3'

        cls.distro_three = data_setup.create_distro(name=cls.distro_three_name,
            osmajor=cls.distro_three_osmajor, osminor = cls.distro_three_osminor,)
        cls.distro_tree_three = data_setup.create_distro_tree(distro=cls.distro_three)
Example #2
0
    def setupClass(cls):
        data_setup.create_labcontroller()
        cls.distro_one_name = data_setup.unique_name(u"nametest%s")
        cls.distro_one_osmajor = u"osmajortest1"
        cls.distro_one_osminor = u"1"
        cls.distro_one_variant = u"myvariant"
        cls.distro_one_tag = [u"MYTAG"]

        cls.distro_one = data_setup.create_distro(
            name=cls.distro_one_name,
            osmajor=cls.distro_one_osmajor,
            osminor=cls.distro_one_osminor,
            tags=cls.distro_one_tag,
        )
        cls.distro_tree_one = data_setup.create_distro_tree(distro=cls.distro_one, variant=cls.distro_one_variant)
        # Two days in the future
        cls.distro_two_name = data_setup.unique_name(u"nametest%s")
        cls.distro_two_osmajor = u"osmajortest2"
        cls.distro_two_osminor = u"2"

        cls.distro_two = data_setup.create_distro(
            name=cls.distro_two_name, osmajor=cls.distro_two_osmajor, osminor=cls.distro_two_osminor
        )
        cls.distro_tree_two = data_setup.create_distro_tree(distro=cls.distro_two)
        cls.distro_tree_two.date_created = datetime.utcnow() + timedelta(days=2)

        cls.distro_three_name = data_setup.unique_name(u"nametest%s")
        cls.distro_three_osmajor = u"osmajortest3"
        cls.distro_three_osminor = u"3"

        cls.distro_three = data_setup.create_distro(
            name=cls.distro_three_name, osmajor=cls.distro_three_osmajor, osminor=cls.distro_three_osminor
        )
        cls.distro_tree_three = data_setup.create_distro_tree(distro=cls.distro_three)
Example #3
0
    def setUpClass(cls):
        # Each distro needs to have a tree in some lab controller, otherwise it 
        # won't show up in search results.
        data_setup.create_labcontroller()

        cls.distro_one_name = data_setup.unique_name(u'nametest%s')
        cls.distro_one_osmajor = u'osmajortest1'
        cls.distro_one_osminor = u'1'
        cls.distro_one_tags = None

        cls.distro_one = data_setup.create_distro(name=cls.distro_one_name,
            osmajor=cls.distro_one_osmajor, osminor = cls.distro_one_osminor,
            tags =cls.distro_one_tags)
        data_setup.create_distro_tree(distro=cls.distro_one)
        # Two days in the future
        cls.distro_one.date_created = datetime.utcnow() + timedelta(days=2)
        cls.distro_two_name = data_setup.unique_name(u'nametest%s')
        cls.distro_two_osmajor = u'osmajortest2'
        cls.distro_two_osminor = u'2'
        cls.distro_two_tags = None

        cls.distro_two = data_setup.create_distro(name=cls.distro_two_name,
            osmajor=cls.distro_two_osmajor, osminor = cls.distro_two_osminor,
            tags =cls.distro_two_tags)
        data_setup.create_distro_tree(distro=cls.distro_two)

        cls.distro_three_name = data_setup.unique_name(u'nametest%s')
        cls.distro_three_osmajor = u'osmajortest3'
        cls.distro_three_osminor = u'3'
        cls.distro_three_tags = None

        cls.distro_three = data_setup.create_distro(name=cls.distro_three_name,
            osmajor=cls.distro_three_osmajor, osminor = cls.distro_three_osminor,
            tags =cls.distro_three_tags)
        data_setup.create_distro_tree(distro=cls.distro_three)
    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)
Example #5
0
    def test_lab_controller_add(self):
        b = self.browser
        lc_name = data_setup.unique_name('lc%s.com')
        lc_email = data_setup.unique_name('me@my%s.com')
        self._add_lc(b, lc_name, lc_email, data_setup.ADMIN_USER)
        self.assert_('%s saved' % lc_name in
            b.find_element_by_css_selector('.flash').text)

        # Search in activity
        b.get(get_server_base() + 'activity/labcontroller')
        b.find_element_by_id('advancedsearch').click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_table']/"
            "option[@value='LabController/Name']").click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_operation']/"
            "option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='activitysearch_0_value']"). \
            send_keys(lc_name)
        b.find_element_by_xpath("//input[@name='Search']").click()

        self.assert_(is_activity_row_present(b,
            object_='LabController: %s' % lc_name, via='WEBUI',
            property_='FQDN', action='Changed', new_value=lc_name))
        self.assert_(is_activity_row_present(b,
            object_='LabController: %s' % lc_name, via='WEBUI',
            property_='User', action='Changed',
            new_value=data_setup.ADMIN_USER))
        self.assert_(is_activity_row_present(b,
            object_='LabController: %s' % lc_name, via='WEBUI',
            property_='Disabled', action='Changed', new_value='False'))
Example #6
0
    def test_add_invalid_details_existing_user(self):
        with session.begin():
            existing_name = data_setup.unique_name("user%s")
            existing_email = data_setup.unique_name("*****@*****.**")
            data_setup.create_user(user_name=existing_name, email_address=existing_email)

            existing_name2 = data_setup.unique_name("user%s")
            existing_email2 = data_setup.unique_name("*****@*****.**")
            data_setup.create_user(user_name=existing_name2, email_address=existing_email2)

        b = self.browser
        b.get(get_server_base() + "users")
        # Test with duplicate name
        b.find_element_by_name("user.text").send_keys(existing_name)
        b.find_element_by_xpath("//form[@id='Search']").submit()
        b.find_element_by_link_text(existing_name).click()
        b.find_element_by_name("user_name").clear()
        b.find_element_by_name("user_name").send_keys(existing_name2)
        b.find_element_by_xpath("//form[@id='User']").submit()
        self.assert_(
            b.find_element_by_xpath(
                "//form[@id='User'] \
            //input[@name='user_name']/following-sibling::span"
            ).text
            == "Login name is not unique"
        )
        # Reset back to current name
        b.find_element_by_name("user_name").clear()
        b.find_element_by_name("user_name").send_keys(existing_name)

        # Verify our exiting details submit ok
        b.find_element_by_name("email_address").clear()
        b.find_element_by_name("email_address").send_keys(existing_email)
        b.find_element_by_xpath("//form[@id='User']").submit()
        is_text_present(b, "%s saved" % existing_name)
    def test_create_pool_set_owner(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        owner = data_setup.create_user()
        run_client(['bkr', 'pool-create',
                    '--owner', owner.user_name,
                    pool_name])
        with session.begin():
            p = SystemPool.by_name(pool_name)
            self.assertFalse(p.owning_group)
            self.assertTrue(p.owning_user.user_name,
                            owner.user_name)

        pool_name = data_setup.unique_name(u'mypool%s')

        owning_group = data_setup.create_group()
        run_client(['bkr', 'pool-create',
                    '--owning-group', owning_group.group_name,
                    pool_name])
        with session.begin():
            p = SystemPool.by_name(pool_name)
            self.assertTrue(p.owning_group, owning_group)
            self.assertFalse(p.owning_user)

        # specifying both should error out
        try:
            run_client(['bkr', 'pool-create',
                        '--owner', owner.user_name,
                        '--owning-group', owning_group.group_name,
                    pool_name])
            self.fail('Must error out')
        except ClientError as e:
            self.assertIn('Only one of owner or owning-group must be specified',
                          e.stderr_output)
Example #8
0
    def setUp(self):
        self.job_whiteboard = data_setup.unique_name(u'foobarhi %s')
        self.recipe_whiteboard = data_setup.unique_name(u'sdfjkljk%s')
        self.passed_job = data_setup.create_completed_job(
                whiteboard=self.job_whiteboard, result=TaskResult.pass_,
                recipe_whiteboard=self.recipe_whiteboard)

        self.browser = self.get_browser()
Example #9
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)
Example #10
0
 def test_adduser(self):
     user_1_name = data_setup.unique_name('anonymous%s')
     user_1_email = data_setup.unique_name('*****@*****.**')
     b = self.browser
     login(b)
     b.get(get_server_base() + 'users/')
     b.find_element_by_xpath('//button[normalize-space(string(.))="Create"]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_name('user_name').send_keys(user_1_name)
     modal.find_element_by_name('display_name').send_keys(user_1_name)
     modal.find_element_by_name('email_address').send_keys(user_1_email)
     modal.find_element_by_tag_name('form').submit()
     b.find_element_by_xpath('//title[text()="%s"]' % user_1_name)
Example #11
0
 def test_can_search_normal_groups_by_member_username(self):
     with session.begin():
         group = data_setup.create_group(
                 group_name=data_setup.unique_name(u'aardvark%s'))
         member = data_setup.create_user()
         group.add_member(member)
         other_group = data_setup.create_group(
                 group_name=data_setup.unique_name(u'aardvark%s'))
     b = self.browser
     b.get(get_server_base() + 'groups/')
     b.find_element_by_class_name('search-query').send_keys(
             'member.user_name:%s' % member.user_name)
     b.find_element_by_class_name('grid-filter').submit()
     check_group_search_results(b, present=[group], absent=[other_group])
Example #12
0
    def test_single_job(self):
        with session.begin():
            unique_whiteboard = data_setup.unique_name('whiteboard%s')
            non_unique_whiteboard = data_setup.unique_name('whiteboard%s')
            non_unique_rwhiteboard = data_setup.unique_name('rwhiteboard%s')
            distro_tree = data_setup.create_distro_tree(arch=u'i386')
            for i in range(0,9):
                data_setup.create_completed_job(
                        whiteboard=non_unique_whiteboard, result=TaskResult.pass_,
                        recipe_whiteboard=non_unique_rwhiteboard,
                        distro_tree=distro_tree)

            single_job = data_setup.create_completed_job(
                    whiteboard=unique_whiteboard, result=TaskResult.pass_,
                    recipe_whiteboard=data_setup.unique_name('rwhiteboard%s'),
                    distro_tree=distro_tree)

        b = self.browser
        b.get(get_server_base() + 'matrix')
        # No need to filter the whiteboard, we just created the jobs so they 
        # will be at the top of the list of whiteboards.
        b.find_element_by_xpath("//select/option[@value='%s']" % unique_whiteboard).click()
        b.find_element_by_xpath('//input[@value="Generate"]').click()
        b.find_element_by_link_text('Pass: 1').click()
        task_id = b.find_element_by_xpath('//table[position()=2]//tr[position()=2]/td').text
        self.assertEqual(task_id,
            single_job.recipesets[0].recipes[0].tasks[0].t_id)

        # Test by job id
        # See https://bugzilla.redhat.com/show_bug.cgi?id=803713
        with session.begin():
            single_job_2 = data_setup.create_completed_job(
                    whiteboard=non_unique_whiteboard, result=TaskResult.pass_,
                    recipe_whiteboard=non_unique_rwhiteboard,
                    distro_tree=distro_tree)
        b = self.browser
        b.get(get_server_base() + 'matrix')
        b.find_element_by_id('remote_form_job_ids').send_keys(str(single_job_2.id))
        b.find_element_by_xpath('//input[@value="Generate"]').click()
        b.find_element_by_link_text('Pass: 1').click()

        # This tests that we are indeed only looking at one recipe task.
        task_spec_columns = b.find_elements_by_xpath('//table[2]//tr/td[1]')
        failed = True
        for col in task_spec_columns:
            if col and col.text.strip():
                self.assertEqual(col.text, single_job_2.recipesets[0].recipes[0].tasks[0].t_id)
                failed=False
        self.assert_(not failed)
Example #13
0
    def test_single_job(self):
        with session.begin():
            unique_whiteboard = data_setup.unique_name('whiteboard%s')
            non_unique_whiteboard = data_setup.unique_name('whiteboard%s')
            non_unique_rwhiteboard = data_setup.unique_name('rwhiteboard%s')
            distro_tree = data_setup.create_distro_tree(arch=u'i386')
            for i in range(0,9):
                data_setup.create_completed_job(
                        whiteboard=non_unique_whiteboard, result=TaskResult.pass_,
                        recipe_whiteboard=non_unique_rwhiteboard,
                        distro_tree=distro_tree)

            single_job = data_setup.create_completed_job(
                    whiteboard=unique_whiteboard, result=TaskResult.pass_,
                    recipe_whiteboard=data_setup.unique_name('rwhiteboard%s'),
                    distro_tree=distro_tree)

        b = self.browser
        b.get(get_server_base() + 'matrix')
        # No need to filter the whiteboard, we just created the jobs so they 
        # will be at the top of the list of whiteboards.
        b.find_element_by_xpath("//select/option[@value='%s']" % unique_whiteboard).click()
        b.find_element_by_xpath('//button[@type="submit" and text()="Generate"]').click()
        b.find_element_by_link_text('Pass: 1').click()
        # Should take us to Executed Tasks filtered by whiteboard.
        # There should only be one task in the results.
        tasks_table = b.find_element_by_css_selector('table.tasks')
        task_ids = [e.text for e in tasks_table.find_elements_by_xpath(
                'tbody/tr/td[1][@class="task"]')]
        self.assertEquals(task_ids, [single_job.recipesets[0].recipes[0].tasks[0].t_id])

        # Test by job id
        # See https://bugzilla.redhat.com/show_bug.cgi?id=803713
        with session.begin():
            single_job_2 = data_setup.create_completed_job(
                    whiteboard=non_unique_whiteboard, result=TaskResult.pass_,
                    recipe_whiteboard=non_unique_rwhiteboard,
                    distro_tree=distro_tree)
        b = self.browser
        b.get(get_server_base() + 'matrix')
        b.find_element_by_id('remote_form_job_ids').send_keys(str(single_job_2.id))
        b.find_element_by_xpath('//button[@type="submit" and text()="Generate"]').click()
        b.find_element_by_link_text('Pass: 1').click()
        # Should take us to Executed Tasks filtered by whiteboard and job ID.
        # There should only be one task in the results.
        tasks_table = b.find_element_by_css_selector('table.tasks')
        task_ids = [e.text for e in tasks_table.find_elements_by_xpath(
                'tbody/tr/td[1][@class="task"]')]
        self.assertEquals(task_ids, [single_job_2.recipesets[0].recipes[0].tasks[0].t_id])
Example #14
0
 def test_can_search_inverted_groups_by_member_username(self):
     with session.begin():
         member = data_setup.create_user()
         group = data_setup.create_group(
                 group_name=data_setup.unique_name(u'aardvark%s'))
         inverted_group = data_setup.create_group(
            group_name=data_setup.unique_name(u'aardvark%s'),
            membership_type=GroupMembershipType.inverted)
     b = self.browser
     b.get(get_server_base() + 'groups/')
     b.find_element_by_class_name('search-query').send_keys(
             'member.user_name:%s' % member.user_name)
     b.find_element_by_class_name('grid-filter').submit()
     check_group_search_results(b, present=[inverted_group],
             absent=[group])
Example #15
0
    def test_remove_user_from_owning_group(self):
        with session.begin():
            user = data_setup.create_user(password='******')

        group_name = data_setup.unique_name('AAAAAA%s')
        display_name = data_setup.unique_name('Group Display Name %s')

        b = self.browser
        login(b, user=self.user.user_name, password='******')
        b.get(get_server_base() + 'groups/mine')
        b.find_element_by_link_text('Add').click()
        b.find_element_by_xpath('//input[@id="Group_display_name"]').send_keys(display_name)
        b.find_element_by_xpath('//input[@id="Group_group_name"]').send_keys(group_name)
        b.find_element_by_id('Group').submit()
        b.find_element_by_xpath('//title[text()="My Groups"]')
        b.find_element_by_link_text(group_name).click()

        # add an user
        b.find_element_by_xpath('//input[@id="GroupUser_user_text"]').send_keys(user.user_name)
        b.find_element_by_id('GroupUser').submit()

        self.mail_capture.captured_mails[:] = []

        group_id = Group.by_name(group_name).group_id
        username = user.user_name
        user_id = user.user_id

        b.find_element_by_xpath('//td[preceding-sibling::td[2]/text()="%s"]' % username)\
                .find_element_by_link_text('Remove').click()
        self.assertEquals(b.find_element_by_class_name('flash').text,
                          '%s Removed' % username)
        with session.begin():
            group = Group.by_name(group_name)
        self.check_notification(user, group, action='Removed')

        # remove self when I am the only owner of the group
        b.find_element_by_xpath('//td[preceding-sibling::td[2]/text()="%s"]' % self.user.user_name)\
                .find_element_by_link_text('Remove').click()
        self.assert_('Cannot remove member' in b.find_element_by_class_name('flash').text)

        # admin should be able to remove an owner, even if only one
        logout(b)
        #login back as admin
        login(b)
        b.get(get_server_base() + 'groups/edit?group_id=%s' % group_id)
        b.find_element_by_xpath('//td[preceding-sibling::td[2]/text()="%s"]' % self.user.user_name)\
                .find_element_by_link_text('Remove').click()
        self.assert_('%s Removed' % self.user.user_name in b.find_element_by_class_name('flash').text)
Example #16
0
    def test_remove_user_job_cancel(self):
        with session.begin():
            user = data_setup.create_user(user_name =
                                          data_setup.unique_name('aaaaa%s'))
            job = data_setup.create_job(owner=user)
            data_setup.mark_job_running(job)

        b = self.browser
        login(b)
        b.get(get_server_base() + 'users')
        b.find_element_by_xpath('//a[@href="remove?id=%d"]' %user.user_id).click()
        # XXX: not necessary, but doing it here to buy time, since sometimes the
        # job cancellation seems to take a while
        logout(b)

        # reflect the change in recipe task status when
        # update_dirty_jobs() is called
        session.expunge_all()
        beakerd.update_dirty_jobs()

        with session.begin():
            job = Job.by_id(job.id)
            self.assertEquals(job.status, TaskStatus.cancelled)
            self.assertIn('User %s removed' % user.user_name,
                          job.recipesets[0].recipes[0].tasks[0].results[0].log)
Example #17
0
 def test_creating_a_system_with_hardware_details(self):
     s = requests.Session()
     s.post(get_server_base() + 'login', data={'user_name': self.user.user_name,
                                               'password': u'password'}).raise_for_status()
     fqdn = data_setup.unique_name(u'newsystem%s')
     data = {
         'fqdn': fqdn,
         'hypervisor': u'KVM',
         'vendor': u'dummyvendor',
         'location': u'dummylocation',
         'model': u'dummymodel',
         'serial_number': u'dummynumber',
         'mac_address': u'dummymacaddress',
         'memory': 111111,
         'numa_nodes': 5,
     }
     response = post_json(get_server_base() + 'systems/', session=s, data=data)
     with session.begin():
         system = System.by_fqdn(fqdn, self.user)
         self.assertEquals(system.fqdn, fqdn)
         self.assertEquals(system.hypervisor, Hypervisor.by_name(u'KVM'))
         self.assertEquals(system.location, u'dummylocation')
         self.assertEquals(system.serial, u'dummynumber')
         self.assertEquals(system.mac_address, u'dummymacaddress')
         self.assertEquals(system.memory, 111111)
         self.assertEquals(system.numa.nodes, 5)
Example #18
0
 def test_creating_a_system_with_power_settings(self):
     s = requests.Session()
     s.post(get_server_base() + 'login', data={'user_name': self.user.user_name,
                                               'password': u'password'}).raise_for_status()
     fqdn = data_setup.unique_name(u'newsystem%s')
     data = {
         'fqdn': fqdn,
         'lab_controller_id': self.lc.id,
         'power_type': u'apc_snmp_then_etherwake',
         'power_address': u'dummyaddress',
         'power_user': u'dummyuser',
         'power_password': u'dummypassword',
         'power_id': u'dummyvm',
         'power_quiescent_period': 5,
         'release_action': u'LeaveOn',
         'reprovision_distro_tree': {'id': self.distro_tree.id},
     }
     response = post_json(get_server_base() + 'systems/', session=s, data=data)
     with session.begin():
         system = System.by_fqdn(fqdn, self.user)
         self.assertEquals(system.power.power_type, PowerType.by_name(u'apc_snmp_then_etherwake'))
         self.assertEquals(system.power.power_address, u'dummyaddress')
         self.assertEquals(system.power.power_user, u'dummyuser')
         self.assertEquals(system.power.power_passwd, u'dummypassword')
         self.assertEquals(system.power.power_id, u'dummyvm')
         self.assertEquals(system.power.power_quiescent_period, 5)
         self.assertEquals(system.release_action, ReleaseAction.leave_on)
         self.assertEquals(system.reprovision_distro_tree, self.distro_tree)
Example #19
0
    def test_modifying_email(self):
        current_user_email = self.user.email_address
        b = self.browser

        # Try and use the same email as an existing user
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys(self.user2.email_address)
        b.find_element_by_id("UserPrefs").submit()
        self.assert_(is_text_present(b, "Email address is not unique"))

        # Check invalid email
        self.browser.get(get_server_base() + "prefs")
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys("InvalidEmailAddress")
        b.find_element_by_id("UserPrefs").submit()
        self.assert_(is_text_present(b, "An email address must contain a single @"))

        # Check new unused  and valid email
        self.browser.get(get_server_base() + "prefs")
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys("*****@*****.**" % data_setup.unique_name("dude%s"))
        b.find_element_by_id("UserPrefs").submit()
        self.assert_(is_text_present(b, "Email address changed"))
Example #20
0
    def test_search_group(self):
        with session.begin():
            group = data_setup.create_group()
            whiteboard = data_setup.unique_name(u'whiteboard%s')
            job = data_setup.create_job(group=group, whiteboard=whiteboard)
            job2 = data_setup.create_job(whiteboard=whiteboard)

        b = self.browser
        # Ensures that both jobs are present
        b.get(get_server_base() + 'jobs')
        b.find_element_by_link_text('Show Search Options').click()
        wait_for_animation(b, '#searchform')
        b.find_element_by_xpath("//select[@id='jobsearch_0_table'] \
            /option[@value='Whiteboard']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='jobsearch_0_value']"). \
            send_keys(whiteboard)
        b.find_element_by_id('searchform').submit()
        check_job_search_results(b, present=[job, job2])

        # Now do the actual test
        b.find_element_by_xpath("//select[@id='jobsearch_0_table'] \
            /option[@value='Group']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='jobsearch_0_value']").clear()
        b.find_element_by_xpath("//input[@id='jobsearch_0_value']"). \
            send_keys(job.group.group_name)
        b.find_element_by_id('searchform').submit()
        check_job_search_results(b, present=[job], absent=[job2])
Example #21
0
    def test_modifying_email(self):
        current_user_email = self.user.email_address
        b = self.browser

        # Try and use the same email as an existing user
        # (This used to be forbidden, now it is allowed.)
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys(self.user2.email_address)
        b.find_element_by_id('UserPrefs').submit()
        self.assertEquals(b.find_element_by_class_name('flash').text,
                'Email address changed')

        # Check invalid email
        self.browser.get(get_server_base() + 'prefs')
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys('InvalidEmailAddress')
        b.find_element_by_id('UserPrefs').submit()
        error_msg = b.find_element_by_css_selector(
                '#UserPrefs .help-block.error').text
        self.assertEquals(error_msg, 'An email address must contain a single @')

        # Check new unused  and valid email
        self.browser.get(get_server_base() + 'prefs')
        e = b.find_element_by_name("email_address")
        e.clear()
        e.send_keys('*****@*****.**' % data_setup.unique_name('dude%s'))
        b.find_element_by_id('UserPrefs').submit()
        self.assertEquals(b.find_element_by_class_name('flash').text,
                'Email address changed')
Example #22
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)
 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)
Example #24
0
 def setUp(self):
     self.system = data_setup.create_system()
     self.lc = data_setup.create_labcontroller(
         fqdn=data_setup.unique_name(u'%d1111'))
     self.system.lab_controller = self.lc
     self.distro_tree = data_setup.create_distro_tree(lab_controllers=[self.lc])
     self.browser = self.get_browser()
     login(self.browser)
 def test_create_system_set_host_hypervisor(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     run_client(['bkr', 'system-create', fqdn,
                 '--host-hypervisor=KVM'])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertEquals(str(system.hypervisor), u'KVM')
         self.assertEquals(system.activity[0].new_value, u'KVM')
 def test_cannot_delete_nonexistent_system(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     try:
         run_client(['bkr', 'system-delete', fqdn])
         self.fail('should raise')
     except ClientError, e:
         self.assertEqual(e.status, 1)
         self.assertIn("System %s does not exist" % fqdn, e.stderr_output)
Example #27
0
    def test_lab_controller_remove(self):
        b = self.browser
        lc_name = data_setup.unique_name('lc%s.com')
        lc_email = data_setup.unique_name('me@my%s.com')
        self._add_lc(b, lc_name, lc_email, data_setup.ADMIN_USER)
        with session.begin():
            sys = data_setup.create_system()
            sys.lab_controller = LabController.by_name(lc_name)
        b.get(get_server_base() + 'labcontrollers')
        b.find_element_by_xpath("//table[@id='widget']/tbody/tr/"
            "td[preceding-sibling::td/a[normalize-space(text())='%s']]"
            "/a[normalize-space(text())='Remove (-)']" % lc_name).click()
        self.assert_('%s removed' % lc_name in
            b.find_element_by_css_selector('.flash').text)

        # Search in  LC activity
        b.get(get_server_base() + 'activity/labcontroller')
        b.find_element_by_id('advancedsearch').click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_table']/"
            "option[@value='LabController/Name']").click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_operation']/"
            "option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='activitysearch_0_value']"). \
            send_keys(lc_name)
        b.find_element_by_xpath("//input[@name='Search']").click()
        self.assert_(is_activity_row_present(b,
            object_='LabController: %s' % lc_name, via='WEBUI',
            property_='Disabled', action='Changed', new_value='True'))
        self.assert_(is_activity_row_present(b,
            object_='LabController: %s' % lc_name, via='WEBUI',
            property_='Removed', action='Changed', new_value='True'))

        # Ensure System Actvity has been updated to note removal of LC
        b.get(get_server_base() + 'activity/system')
        b.find_element_by_id('advancedsearch').click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_table']/"
            "option[@value='System/Name']").click()
        b.find_element_by_xpath("//select[@id='activitysearch_0_operation']/"
            "option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='activitysearch_0_value']"). \
            send_keys(sys.fqdn)
        b.find_element_by_xpath("//input[@name='Search']").click()
        self.assert_(is_activity_row_present(b,
            object_='System: %s' % sys.fqdn, via='WEBUI',
            property_='lab_controller', action='Changed', new_value=''))
Example #28
0
    def test_create_pool_set_description(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        run_client(['bkr', 'pool-create',
                    '--description', 'My Pool',
                    pool_name])

        with session.begin():
            pool = SystemPool.by_name(pool_name)
            self.assertEquals(pool.description, 'My Pool')
Example #29
0
 def add_note(self):
     b = self.browser
     b.get(get_server_base() + "view/%s" % self.system.fqdn)
     b.find_element_by_link_text("Notes").click()
     note = data_setup.unique_name("note%s")
     b.find_element_by_id("notes_note").send_keys(note)
     b.find_element_by_name("notes").submit()
     b.find_element_by_xpath('//*[@id="notes"]//tr/td[3]/p[text()="%s"]' % note)
     return note
 def test_create_system_set_labcontroller(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     lc = data_setup.create_labcontroller()
     run_client(['bkr', 'system-create',
                 '--lab-controller', str(lc.fqdn),
                 fqdn])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertTrue(system.lab_controller, lc)
Example #31
0
 def test_change_fqdn_being_used_by_another_lab_controller(self):
     with session.begin():
         lc = data_setup.create_labcontroller()
         another_lc = data_setup.create_labcontroller()
     new_fqdn = data_setup.unique_name(u'lab%s.testdata.invalid')
     try:
         run_client(['bkr', 'labcontroller-modify',
                     '--fqdn', another_lc.fqdn,
                     lc.fqdn])
         self.fail('Must error out')
     except ClientError as e:
         self.assertIn('FQDN %s already in use' % another_lc.fqdn,
                       e.stderr_output)
Example #32
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)
Example #33
0
 def test_grants_view_permission_to_everybody_by_default(self):
     fqdn = data_setup.unique_name(u'test-csv-import%s.example.invalid')
     b = self.browser
     login(b)
     self.import_csv((u'csv_type,fqdn\n'
             u'system,%s' % fqdn).encode('utf8'))
     self.assertEquals(self.browser.find_element_by_xpath(
             '//table[@id="csv-import-log"]//td').text,
             'No Errors')
     with session.begin():
         system = System.query.filter(System.fqdn == fqdn).one()
         self.assertTrue(system.custom_access_policy.grants_everybody(
                 SystemPermission.view))
Example #34
0
    def test_excluded_family_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            osmajor = OSMajor.lazy_create(osmajor=u'MyEnterpriseLinux')
        self.import_csv((u'csv_type,fqdn,arch,family,update,excluded\n'
                         u'exclude,%s,x86_64,MyEnterpriseLinux,,True' %
                         fqdn).encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            self.assertEquals(system.excluded_osmajor[0].osmajor_id,
                              osmajor.id)
Example #35
0
 def test_grants_view_permission_to_everybody_by_default(self):
     fqdn = data_setup.unique_name(u'test-add-system%s.example.invalid')
     b = self.browser
     b.get(get_server_base())
     b.find_element_by_link_text('Add').click()
     b.find_element_by_name('fqdn').send_keys(fqdn)
     b.find_element_by_xpath('//button[text()="Add"]').click()
     b.find_element_by_xpath('//h1[text()="%s"]' % fqdn)
     with session.begin():
         system = System.query.filter(System.fqdn == fqdn).one()
         self.assertTrue(
             system.custom_access_policy.grants_everybody(
                 SystemPermission.view))
Example #36
0
 def test_search_works_on_reserve_report(self):
     # Reserve Report is a specialisation of the regular systems grid, so we 
     # aren't testing it exhaustively, we just want to make sure that the 
     # search is wired up properly.
     with session.begin():
         included = data_setup.create_system()
         data_setup.create_manual_reservation(included)
         excluded = data_setup.create_system(fqdn=data_setup.unique_name(u'aardvark%s'))
         data_setup.create_manual_reservation(excluded)
     b = self.browser
     perform_search(b, [('System/Name', 'is', included.fqdn)],
             search_url='reports/')
     check_system_search_results(b, present=[included], absent=[excluded])
Example #37
0
    def test_groups_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            group = data_setup.create_group()
        self.import_csv((u'csv_type,fqdn,group,deleted\n'
                         u'system_group,%s,%s,False' % 
                         (fqdn, group.group_name))
                        .encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            self.assertIn(group.group_name, 
                          [g.group_name for g in system.groups])
Example #38
0
    def test_keyvalue_non_existent_system_valid(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        self.import_csv(
            (u'csv_type,fqdn,key,key_value,deleted\n'
             u'keyvalue,%s,COMMENT,acomment,False' % fqdn).encode('utf8'))

        self.assertEquals(
            self.browser.find_element_by_xpath(
                '//table[@id="csv-import-log"]//td').text, "No Errors")

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            assert_has_key_with_value(system, 'COMMENT', u'acomment')
Example #39
0
 def test_labinfo_non_existent_system(self):
     login(self.browser)
     fqdn = data_setup.unique_name('system%s.idonot.exist')
     self.import_csv((u'csv_type,fqdn,orig_cost,curr_cost,dimensions,weight,wattage,cooling\n'
                      u'labinfo,%s,10000,10000,3000,4000.0,5001.0,6000.0' % fqdn)
                     .encode('utf8'))
     with session.begin():
         system = System.query.filter(System.fqdn == fqdn).one()
         self.assertEqual(system.labinfo.orig_cost, Decimal('10000'))
         self.assertEqual(system.labinfo.curr_cost, Decimal('10000'))
         self.assertEqual(system.labinfo.dimensions, u'3000')
         self.assertEqual(system.labinfo.weight, 4000.0)
         self.assertEqual(system.labinfo.wattage, 5001.0)
         self.assertEqual(system.labinfo.cooling, 6000.0)
Example #40
0
    def test_group_modify_password(self):
        # Test successful hashed password change
        hashed_password = '******'
        run_client([
            'bkr', 'group-modify', '--root-password', hashed_password,
            self.group.group_name
        ],
                   config=self.client_config)
        session.expire(self.group)
        with session.begin():
            group = self.group
            self.assertEquals(group.root_password, hashed_password)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Root Password')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        # Test successful cleartext password change
        good_password = data_setup.unique_name('Borrow or %srob?')
        run_client([
            'bkr', 'group-modify', '--root-password', good_password,
            self.group.group_name
        ],
                   config=self.client_config)
        session.expire(self.group)
        with session.begin():
            group = self.group
            self.assertEquals(group.root_password, good_password)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Root Password')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        # Test unsuccessful cleartext password change
        short_password = '******'
        try:
            run_client([
                'bkr', 'group-modify', '--root-password', short_password,
                self.group.group_name
            ],
                       config=self.client_config)
            self.fail('Should fail with short password')
        except ClientError, e:
            self.assertTrue('password is too short' in str(e))
            session.expire(self.group)
            with session.begin():
                group = self.group
                self.assertEquals(group.root_password, good_password)
Example #41
0
    def test_group_duplicate(self):
        group_name = data_setup.unique_name(u'group%s')
        display_name = u'My Group'
        out = run_client([
            'bkr', 'group-create', '--display-name', display_name, group_name
        ])

        self.assert_('Group created' in out, out)

        try:
            out = run_client(['bkr', 'group-create', group_name])
            self.fail('Must fail or die')
        except ClientError, e:
            self.assert_('Group already exists' in e.stderr_output,
                         e.stderr_output)
Example #42
0
    def test_simple_search(self):
        with session.begin():
            group = data_setup.create_group()
            whiteboard = data_setup.unique_name(u'default_search%s')
            job = data_setup.create_job(whiteboard=whiteboard)

        b = self.browser
        b.get(get_server_base() + 'jobs')
        b.find_element_by_xpath("//form[@id='simpleform']/input").\
            send_keys("default_search")
        b.find_element_by_xpath(
            "//form[@id='simpleform']/button[text()='Search']").click()
        whiteboard_search = b.find_element_by_xpath(
            "//table[@id='widget']/tbody/tr[1]/td[2]").text
        self.assertEqual(whiteboard_search, whiteboard)
    def setUp(self):
        self.lc = data_setup.create_labcontroller()
        self.system = data_setup.create_system(arch=u'i386', shared=True)
        self.system2 = data_setup.create_system(arch=u'x86_64', shared=True)
        self.unique_distro_name = data_setup.unique_name('distro%s')
        self.distro = data_setup.create_distro(name=self.unique_distro_name)
        self.distro_tree_i386 = data_setup.create_distro_tree(
                variant=u'Server', arch=u'i386', distro=self.distro)
        self.distro_tree_x86_64= data_setup.create_distro_tree(
                variant=u'Server', arch=u'x86_64', distro=self.distro)

        self.system.lab_controller = self.lc
        self.system2.lab_controller = self.lc

        self.browser = self.get_browser()
 def setupClass(cls):
     with session.begin():
         cls.owner_email_address = data_setup.unique_name(
             u'*****@*****.**')
         cls.system_owner = data_setup.create_user(
             email_address=cls.owner_email_address)
         cls.system_fqdn = data_setup.unique_name('ncc1701d%s')
         cls.system = data_setup.create_system(fqdn=cls.system_fqdn,
                                               owner=cls.system_owner)
         cls.lc_name = data_setup.unique_name(u'testing_for_mail%s')
         lc = data_setup.create_labcontroller(cls.lc_name)
         cls.system.lab_controller = lc
         lender = u'amd'
         location = u'bne'
         vendor = u'intel'
         cls.system.lender = lender
         cls.system.location = location
         cls.system.vendor = vendor
         cls.reporter_email_address = data_setup.unique_name(
             u'*****@*****.**')
         cls.problem_reporter = data_setup.create_user(
             password=u'password',
             display_name=data_setup.unique_name('Crusher Lady%s'),
             email_address=cls.reporter_email_address)
Example #45
0
 def test_create_system_defaults(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     run_client(['bkr', 'system-create', fqdn])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertTrue(system.owner.user_name, data_setup.ADMIN_USER)
         self.assertTrue(system.custom_access_policy.grants_everybody(
                 SystemPermission.view))
     # duplicate
     try:
         run_client(['bkr', 'system-create', fqdn])
         self.fail('Must fail')
     except ClientError as e:
         self.assertIn("System with fqdn %r already exists" % fqdn,
                       e.stderr_output)
Example #46
0
    def test_add_invalid_details_new_user(self):
        with session.begin():
            existing_name = data_setup.unique_name('user%s')
            existing_email = data_setup.unique_name('*****@*****.**')
            data_setup.create_user(user_name=existing_name,
                                   password='******',
                                   email_address=existing_email)
        b = self.browser
        b.get(get_server_base() + 'users')
        b.find_element_by_link_text('Add').click()

        # Test with all blank fields
        b.find_element_by_xpath('//form[@id=\'User\']').submit()
        self.assert_(b.find_element_by_xpath('//form[@id=\'User\'] \
            //input[@name=\'user_name\']/following-sibling::span'                                                                 ).text == \
                'Please enter a value')
        self.assert_(b.find_element_by_xpath('//form[@id=\'User\'] \
            //input[@name=\'display_name\']/following-sibling::span'                                                                    ).text == \
                'Please enter a value')
        self.assert_(b.find_element_by_xpath('//form[@id=\'User\'] \
            //input[@name=\'email_address\']/following-sibling::span'                                                                     ).text == \
                'Please enter an email address')

        # Submit valid details to make sure it recovers
        valid_user_1 = data_setup.unique_name('user%s')
        b.find_element_by_name('user_name').send_keys(valid_user_1)
        b.find_element_by_name('display_name').send_keys(valid_user_1)
        b.find_element_by_name('email_address').send_keys(
            data_setup.unique_name('*****@*****.**'))
        b.find_element_by_xpath('//form[@id=\'User\']').submit()
        is_text_present(b, '%s saved' % valid_user_1)

        # Enter duplicate user name
        b.get(get_server_base() + 'users')
        b.find_element_by_link_text('Add').click()
        b.find_element_by_name('user_name').send_keys(existing_name)
        b.find_element_by_name('display_name').send_keys(
            data_setup.unique_name('display%s'))
        b.find_element_by_name('email_address').send_keys(
            data_setup.unique_name('*****@*****.**'))

        # Check our custom user name validator
        b.find_element_by_xpath('//form[@id=\'User\']').submit()
        self.assert_(b.find_element_by_xpath('//form[@id=\'User\'] \
            //input[@name=\'user_name\']/following-sibling::span'                                                                 ).text == \
                'Login name is not unique')

        valid_user_2 = data_setup.unique_name('user%s')
        b.find_element_by_name('user_name').send_keys(valid_user_2)
        b.find_element_by_id('User').submit()
        is_text_present(b, '%s saved' % valid_user_2)
Example #47
0
 def test_create_new_group_sans_password(self):
     b = self.browser
     group_name = data_setup.unique_name('group%s')
     login(b, user=self.user.user_name, password='******')
     b.get(get_server_base() + 'groups/mine')
     b.find_element_by_link_text('Add').click()
     b.find_element_by_xpath('//input[@id="Group_display_name"]'). \
         send_keys(group_name)
     b.find_element_by_xpath('//input[@id="Group_group_name"]'). \
         send_keys(group_name)
     b.find_element_by_id('Group').submit()
     b.find_element_by_xpath('//title[text()="My Groups"]')
     b.find_element_by_link_text(group_name).click()
     b.find_element_by_xpath(
         '//input[@name="root_password" and '
         'not(following-sibling::span[contains(@class, "error")])]')
Example #48
0
    def test_search_product(self):
        with session.begin():
            my_job = data_setup.create_job()
            new_product = Product(name=data_setup.unique_name('myproduct%s'))
            my_job.product = new_product
        b = self.browser

        # Test with product.
        b.get(get_server_base() + 'jobs')
        b.find_element_by_link_text('Show Search Options').click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_table'] \
            /option[@value='Product']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_value']/"
                                "option[normalize-space(text())='%s']" %
                                new_product.name).click()
        b.find_element_by_id('searchform').submit()
        job_search_result = \
            b.find_element_by_xpath('//table[@id="widget"]').text
        self.assert_('J:%s' % my_job.id in job_search_result)

        with session.begin():
            my_job.product = None

        # Test without product
        b.find_element_by_xpath("//select[@id='jobsearch_0_table'] \
            /option[@value='Product']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath(
            "//select[@id='jobsearch_0_value']/"
            "option[normalize-space(text())='None']").click()

        b.find_element_by_link_text('Add').click()

        b.find_element_by_xpath("//select[@id='jobsearch_1_table'] \
            /option[@value='Id']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_1_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath("//input[@id='jobsearch_1_value']"). \
            send_keys(str(my_job.id))
        b.find_element_by_id('searchform').submit()
        job_search_result = \
            b.find_element_by_xpath('//table[@id="widget"]').text

        self.assert_('J:%s' % my_job.id in job_search_result)
Example #49
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)
Example #50
0
 def test_can_search_by_owner_username(self):
     with session.begin():
         group = data_setup.create_group()
         owner = data_setup.create_user()
         group.add_member(owner, is_owner=True)
         # User is a member but *not* an owner of the other group. This is
         # to prove we really are filtering by ownership, not just
         # membership.
         other_group = data_setup.create_group(
             group_name=data_setup.unique_name(u'aardvark%s'))
         other_group.add_member(owner, is_owner=False)
     b = self.browser
     b.get(get_server_base() + 'groups/')
     b.find_element_by_class_name('search-query').send_keys(
         'owner.user_name:%s' % owner.user_name)
     b.find_element_by_class_name('grid-filter').submit()
     check_group_search_results(b, present=[group], absent=[other_group])
Example #51
0
    def test_install_options_non_existent_system(self):
        login(self.browser)
        fqdn = data_setup.unique_name('system%s.idonot.exist')
        with session.begin():
            distro_tree = data_setup.create_distro_tree(
                osmajor='MyEnterpriseLinux', arch=u'x86_64')
        self.import_csv((
            u'csv_type,fqdn,arch,family,update,ks_meta,kernel_options,kernel_options_post\n'
            u'install,%s,x86_64,MyEnterpriseLinux,,mode=cmdline,,console=ttyS0'
            % fqdn).encode('utf8'))

        with session.begin():
            system = System.query.filter(System.fqdn == fqdn).one()
            arch = Arch.by_name(u'x86_64')
            osmajor = OSMajor.by_name(u'MyEnterpriseLinux')
            p = system.provisions[arch].provision_families[osmajor]
            self.assertEquals(p.ks_meta, u'mode=cmdline')
            self.assertEquals(p.kernel_options_post, u'console=ttyS0')
Example #52
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)
Example #53
0
    def test_group_modify_password(self):
        # Test successful hashed password change
        hashed_password = '******'
        run_client(['bkr', 'group-modify', '--root-password', hashed_password,
            self.group.group_name], config=self.client_config)
        session.expire(self.group)
        with session.begin():
            group = self.group
            self.assertEquals(group.root_password, hashed_password)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Root Password')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        # Test successful cleartext password change
        good_password = data_setup.unique_name('Borrow or %srob?')
        run_client(['bkr', 'group-modify', '--root-password', good_password,
            self.group.group_name], config=self.client_config)
        session.expire(self.group)
        with session.begin():
            group = self.group
            self.assertEquals(group.root_password, good_password)
            self.assertEquals(group.activity[-1].action, u'Changed')
            self.assertEquals(group.activity[-1].field_name, u'Root Password')
            self.assertEquals(group.activity[-1].user.user_id,
                              self.user.user_id)
            self.assertEquals(group.activity[-1].service, u'HTTP')

        # Test unsuccessful cleartext password change
        short_password = '******'
        try:
            run_client(['bkr', 'group-modify', '--root-password', short_password,
                self.group.group_name], config=self.client_config)
            self.fail('Should fail with short password')
        except ClientError as e:
            # Number of req chars was changed in RPM, however RHEL is using older one
            # RHEL requires 7, Fedora requires 8 at this moment
            self.assertTrue(
                re.search('The group root password is shorter than . characters', str(e)))
            session.expire(self.group)
            with session.begin():
                group = self.group
                self.assertEquals(group.root_password, good_password)
Example #54
0
    def test_create_pool_defaults(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        run_client(['bkr', 'pool-create', pool_name])

        with session.begin():
            pool = SystemPool.by_name(pool_name)
            self.assertFalse(pool.description)
            self.assertFalse(pool.owning_group)
            self.assertTrue(pool.owning_user.user_name, "admin")
            self.assertEquals(pool.activity[-1].field_name, u'Pool')
            self.assertEquals(pool.activity[-1].action, u'Created')
            self.assertEquals(pool.activity[-1].new_value, pool_name)
        # duplicate
        try:
            run_client(['bkr', 'pool-create', pool_name])
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn("System pool with name u'%s' already exists" % pool_name,
                          e.stderr_output)
Example #55
0
 def test_reporter_and_system_cc_list_are_cced(self):
     with session.begin():
         interested_party_email = data_setup.unique_name(u'*****@*****.**')
         system = data_setup.create_system()
         system.cc = [interested_party_email]
     b = self.browser
     b.get(get_server_base() + 'view/%s' % system.fqdn)
     b.find_element_by_xpath('//button[text()="Report problem"]').click()
     b.find_element_by_name('message').send_keys('I broke it')
     b.find_element_by_xpath('//button[text()="Report"]').click()
     b.find_element_by_xpath('//div[contains(@class, "alert-success")]'
             '/h4[text()="Report sent"]')
     self.assertEqual(len(self.mail_capture.captured_mails), 1)
     sender, rcpts, raw_msg = self.mail_capture.captured_mails[0]
     self.assertEqual(rcpts, [system.owner.email_address,
             self.problem_reporter.email_address, interested_party_email])
     msg = email.message_from_string(raw_msg)
     self.assertEqual(msg['Cc'], '%s, %s' % (self.problem_reporter.email_address,
             interested_party_email))
Example #56
0
    def test_remove_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')
            random_user = data_setup.create_user(password=u'password')
            s1 = data_setup.create_system(owner=system_owner)
            s2 = data_setup.create_system(owner=system_owner)
            s3 = data_setup.create_system(owner=system_owner)
            pool = data_setup.create_system_pool(name=pool_name,
                                                 owning_user=pool_owner,
                                                 systems=[s1, s2, s3])
        run_client(
            ['bkr', 'pool-remove', '--pool', pool_name, '--system', s1.fqdn],
            config=create_client_config(username=system_owner.user_name,
                                        password='******'))
        with session.begin():
            session.refresh(pool)
            self.assertNotIn(s1, pool.systems)

        run_client(
            ['bkr', 'pool-remove', '--pool', pool_name, '--system', s2.fqdn],
            config=create_client_config(username=pool_owner.user_name,
                                        password='******'))
        with session.begin():
            session.refresh(pool)
            self.assertNotIn(s2, pool.systems)

        try:
            run_client([
                'bkr', 'pool-remove', '--pool', pool_name, '--system', s3.fqdn
            ],
                       config=create_client_config(
                           username=random_user.user_name,
                           password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn(
                'You do not have permission to modify system %s'
                'or remove systems from pool %s' % (s3.fqdn, pool_name),
                e.stderr_output)
Example #57
0
    def test_search_tag(self):
        with session.begin():
            my_job = data_setup.create_job()
            new_tag = RetentionTag(tag=data_setup.unique_name('mytag%s'))
            my_job.retention_tag = new_tag
        b = self.browser

        # Test with tag.
        b.get(get_server_base() + 'jobs')
        b.find_element_by_link_text('Show Search Options').click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_table'] \
            /option[@value='Tag']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_operation'] \
            /option[@value='is']").click()
        b.find_element_by_xpath("//select[@id='jobsearch_0_value']/"
                                "option[normalize-space(text())='%s']" %
                                new_tag.tag).click()
        b.find_element_by_id('searchform').submit()
        job_search_result = \
            b.find_element_by_xpath('//table[@id="widget"]').text
        self.assert_('J:%s' % my_job.id in job_search_result)
Example #58
0
 def test_creating_a_system_with_scheduler_settings(self):
     s = requests.Session()
     s.post(get_server_base() + 'login',
            data={
                'user_name': self.user.user_name,
                'password': u'password'
            }).raise_for_status()
     fqdn = data_setup.unique_name(u'newsystem%s')
     data = {
         'fqdn': fqdn,
         'status': u'Broken',
         'status_reason': u'Currently is broken',
         'type': u'Laptop',
     }
     response = post_json(get_server_base() + 'systems/',
                          session=s,
                          data=data)
     with session.begin():
         system = System.by_fqdn(fqdn, self.user)
         self.assertEquals(system.status, SystemStatus.broken)
         self.assertEquals(system.status_reason, u'Currently is broken')
         self.assertEquals(system.type, SystemType.laptop)
Example #59
0
 def test_create_system_set_power_settings(self):
     fqdn = data_setup.unique_name(u'mysystem%s')
     distro_tree = data_setup.create_distro_tree()
     run_client([
         'bkr', 'system-create', '--power-type', u'apc_snmp_then_etherwake',
         '--power-address', u'dummyaddress', '--power-user', u'dummyuser',
         '--power-password', u'dummypassword', '--power-id', u'dummyvm',
         '--power-quiescent-period', u'5', '--release-action', u'LeaveOn',
         '--reprovision-distro-tree',
         str(distro_tree.id), fqdn
     ])
     with session.begin():
         system = System.by_fqdn(fqdn, User.by_user_name(u'admin'))
         self.assertEquals(system.power.power_type,
                           PowerType.by_name(u'apc_snmp_then_etherwake'))
         self.assertEquals(system.power.power_address, u'dummyaddress')
         self.assertEquals(system.power.power_user, u'dummyuser')
         self.assertEquals(system.power.power_passwd, u'dummypassword')
         self.assertEquals(system.power.power_id, u'dummyvm')
         self.assertEquals(system.power.power_quiescent_period, 5)
         self.assertEquals(system.release_action, ReleaseAction.leave_on)
         self.assertEquals(system.reprovision_distro_tree, distro_tree)
Example #60
0
 def test_lab_controller_create(self):
     fqdn = data_setup.unique_name(u'mylab%s')
     run_client([
         'bkr', 'labcontroller-create', '--fqdn', fqdn, '--user',
         'host/%s' % fqdn, '--email',
         'lab1@%s.com' % fqdn
     ])
     with session.begin():
         lc = LabController.by_name(fqdn)
         self.assertEqual(lc.user.user_name, 'host/%s' % fqdn)
         self.assertEqual(lc.user.email_address, 'lab1@%s.com' % fqdn)
         self.assertIn(Group.by_name(u'lab_controller'), lc.user.groups)
     # cann't create duplicate lab controller
     try:
         run_client([
             'bkr', 'labcontroller-create', '--fqdn', fqdn, '--user',
             'host/%s' % fqdn, '--email',
             'lab1@%s.com' % fqdn
         ])
         self.fail('Must fail')
     except ClientError as e:
         self.assertIn("Lab Controller %s already exists" % fqdn,
                       e.stderr_output)