Example #1
0
 def setUp(self):
     with session.begin():
         self.system = data_setup.create_system()
         user = data_setup.create_user()
         self.activity = CommandActivity(user,
                                         'Just',
                                         'testing',
                                         status=CommandStatus.queued)
         self.system.command_queue.append(self.activity)
     self.browser = self.get_browser()
Example #2
0
 def add_completed_command(self, fqdn, action):
     # Reports completion of a command that was executed
     # synchronously by the lab controller
     user = identity.current.user
     system = System.by_fqdn(fqdn, user)
     cmd = CommandActivity(user=user,
                           service=u"XMLRPC",
                           action=action,
                           status=CommandStatus.completed)
     system.command_queue.append(cmd)
     session.flush() # Populates cmd.system (needed for next call)
     cmd.log_to_system_history()
     return True
Example #3
0
 def add_completed_command(self, fqdn, action):
     # Reports completion of a command that was executed
     # synchronously by the lab controller
     user = identity.current.user
     system = System.by_fqdn(fqdn, user)
     cmd = CommandActivity(user=user,
                           service=u"XMLRPC",
                           action=action,
                           status=CommandStatus.completed)
     system.command_queue.append(cmd)
     session.flush()  # Populates cmd.system (needed for next call)
     cmd.log_to_system_history()
     return True
Example #4
0
def _system_command_metrics_for_query_grouped(name, grouping, query):
    group_counts = CommandActivity.get_queue_stats_by_group(grouping, query)
    for group, counts in group_counts.iteritems():
        for status, count in counts.iteritems():
            metrics.measure(
                'gauges.system_commands_%s.%s.%s' %
                (status, name, group.replace('.', '_')), count)
Example #5
0
 def setUp(self):
     with session.begin():
         self.system = data_setup.create_system()
         user = data_setup.create_user()
         self.activity = CommandActivity(user, 'Just', 'testing',
             status=CommandStatus.queued)
         self.system.command_queue.append(self.activity)
     self.browser = self.get_browser()
Example #6
0
 def test_clear_running_commands(self):
     with session.begin():
         system = data_setup.create_system(lab_controller=self.lc)
         command = CommandActivity(
                 user=None, service=u'testdata', action=u'on',
                 status=CommandStatus.running)
         system.command_queue.append(command)
         other_system = data_setup.create_system()
         other_command = CommandActivity(
                 user=None, service=u'testdata', action=u'on',
                 status=CommandStatus.running)
         other_system.command_queue.append(other_command)
     self.server.auth.login_password(self.lc.user.user_name, u'logmein')
     self.server.labcontrollers.clear_running_commands(u'Staleness')
     with session.begin():
         session.refresh(command)
         self.assertEquals(command.status, CommandStatus.aborted)
         self.assertEquals(other_command.status, CommandStatus.running)
Example #7
0
 def _make_command(lc=None, creation_date=None):
     job = data_setup.create_job(distro_tree=distro_tree)
     recipe = job.recipesets[0].recipes[0]
     system = data_setup.create_system(lab_controller=lc)
     data_setup.mark_recipe_waiting(recipe, system=system)
     command = CommandActivity(
             user=None, service=u'testdata', action=u'on',
             status=CommandStatus.running,
             callback=u'bkr.server.model.auto_cmd_handler')
     if creation_date is not None:
         command.created = command.updated = creation_date
     system.command_queue.append(command)
     return recipe.tasks[0], command
Example #8
0
def _system_command_metrics_for_query_grouped(name, grouping, query):
    group_counts = CommandActivity.get_queue_stats_by_group(grouping, query)
    for group, counts in group_counts.iteritems():
        for status, count in counts.iteritems():
            metrics.measure('gauges.system_commands_%s.%s.%s'
                    % (status, name, group.replace('.', '_')), count)
Example #9
0
def _system_command_metrics_for_query(name, query):
    for status, count in CommandActivity.get_queue_stats(query).items():
        metrics.measure('gauges.system_commands_%s.%s' % (status, name), count)
Example #10
0
class GridTest(WebDriverTestCase):
    #    This test class assumes a couple of things:
    #
    #      2) The number of rows returned per page on the System activity tab is 50
    #      3) This number cannot be modified by using tg_paginate_limit

    def setUp(self):
        with session.begin():
            self.system = data_setup.create_system()
            user = data_setup.create_user()
            self.activity = CommandActivity(user, 'Just', 'testing',
                status=CommandStatus.queued)
            self.system.command_queue.append(self.activity)
        self.browser = self.get_browser()

    def _get_paginators(self):
        b = self.browser
        paginators = b.find_elements_by_class_name('pagination')
        if not paginators:
            raise AssertionError('Could not find pagination links')
        return paginators

    def create_activity_pages(self, number_of_pages):
        with session.begin():
            for i in range(50 * number_of_pages):
                self.activity.log_to_system_history()

    def check_paginate_links_not_there(self):
        b = self.browser
        paginators = self._get_paginators()
        for p in paginators:
            p.find_element_by_xpath('div[@class="pagination-beside" '
                'and not(..//ul)]')

    def check_page_text_is_shown(self, page_text, current=False):
        b = self.browser
        if current:
            page_xpath = u"ul/li/span[normalize-space(text())='%s']" % page_text
        else:
            page_xpath = u"ul/li/a[normalize-space(text())='%s']" % page_text

        paginators = self._get_paginators()
        for p in paginators:
            p.find_element_by_xpath(page_xpath)

    def click_page_number(self, page_text):
        b = self.browser
        b.find_element_by_xpath(u'//div[@class="pagination'
            ' pagination-right"]/ul/li/a[text()="%s"]' % page_text).click()

    def go_to_system_activity(self):
        b = self.browser
        b.get(get_server_base() + 'activity/system')
        b.find_element_by_link_text('Show Search Options').click()
        Select(b.find_element_by_id('activitysearch_0_table')). \
            select_by_visible_text('System/Name')
        Select(b.find_element_by_id('activitysearch_0_operation')). \
            select_by_visible_text('is')
        b.find_element_by_xpath("//input[@id='activitysearch_0_value']"). \
            send_keys(self.system.fqdn)
        b.find_element_by_id('searchform').submit()

    def test_no_pagination_with_single_page(self):
        self.create_activity_pages(1)
        self.go_to_system_activity()
        self.check_paginate_links_not_there()

    def test_pagination_links_exist_with_five_pages(self):
        self.create_activity_pages(5)
        self.go_to_system_activity()
        for number in range(1,6):
            self.check_page_text_is_shown(number, True if number is 1 else False)

    def test_no_ellipsis_with_six_pages(self):
        # We're expecting 1 2 3 4 5 6 and no ellipsis.
        b = self.browser
        self.create_activity_pages(6)
        self.go_to_system_activity()
        # Start clicking from page #2
        for number in range(2,7):
            self.click_page_number(number)
            one_is_current=False
            six_is_current=False
            if number is 1:
                one_is_current = True
            if number is 6:
                six_is_current = True
            self.check_page_text_is_shown(1, one_is_current)
            self.check_page_text_is_shown(6, six_is_current)

    def test_min_count_of_two_between_ends_of_ellipsis(self):
        # Checking for the following
        # _1 2 3 4 5...8
        # 1 2 3 _4 5...8
        # 1...3 4 _5 6 7 8
        self.create_activity_pages(8)
        self.go_to_system_activity()
        # We will be on page 1...
        self.check_page_text_is_shown(u'…8')

        self.click_page_number('4')
        self.check_page_text_is_shown(u'…8')
        self.check_page_text_is_shown('1')

        self.click_page_number('5')
        self.check_page_text_is_shown(u'1…')
        self.check_page_text_is_shown('8')
Example #11
0
def _system_command_metrics_for_query(name, query):
    for status, count in CommandActivity.get_queue_stats(query).items():
        metrics.measure('gauges.system_commands_%s.%s' % (status, name), count)
Example #12
0
class GridTest(WebDriverTestCase):
    #    This test class assumes a couple of things:
    #
    #      2) The number of rows returned per page on the System activity tab is 50
    #      3) This number cannot be modified by using tg_paginate_limit

    def setUp(self):
        with session.begin():
            self.system = data_setup.create_system()
            user = data_setup.create_user()
            self.activity = CommandActivity(user,
                                            'Just',
                                            'testing',
                                            status=CommandStatus.queued)
            self.system.command_queue.append(self.activity)
        self.browser = self.get_browser()

    def _get_paginators(self):
        b = self.browser
        paginators = b.find_elements_by_class_name('pagination')
        if not paginators:
            raise AssertionError('Could not find pagination links')
        return paginators

    def create_activity_pages(self, number_of_pages):
        with session.begin():
            for i in range(50 * number_of_pages):
                self.activity.log_to_system_history()

    def check_paginate_links_not_there(self):
        b = self.browser
        paginators = self._get_paginators()
        for p in paginators:
            p.find_element_by_xpath('div[@class="pagination-beside" '
                                    'and not(..//ul)]')

    def check_page_text_is_shown(self, page_text, current=False):
        b = self.browser
        if current:
            page_xpath = u"ul/li/span[normalize-space(text())='%s']" % page_text
        else:
            page_xpath = u"ul/li/a[normalize-space(text())='%s']" % page_text

        paginators = self._get_paginators()
        for p in paginators:
            p.find_element_by_xpath(page_xpath)

    def click_page_number(self, page_text):
        b = self.browser
        b.find_element_by_xpath(u'//div[@class="pagination'
                                ' pagination-right"]/ul/li/a[text()="%s"]' %
                                page_text).click()

    def go_to_system_activity(self):
        b = self.browser
        b.get(get_server_base() + 'activity/system')
        b.find_element_by_link_text('Show Search Options').click()
        Select(b.find_element_by_id('activitysearch_0_table')). \
            select_by_visible_text('System/Name')
        Select(b.find_element_by_id('activitysearch_0_operation')). \
            select_by_visible_text('is')
        b.find_element_by_xpath("//input[@id='activitysearch_0_value']"). \
            send_keys(self.system.fqdn)
        b.find_element_by_id('searchform').submit()

    def test_no_pagination_with_single_page(self):
        self.create_activity_pages(1)
        self.go_to_system_activity()
        self.check_paginate_links_not_there()

    def test_pagination_links_exist_with_five_pages(self):
        self.create_activity_pages(5)
        self.go_to_system_activity()
        for number in range(1, 6):
            self.check_page_text_is_shown(number,
                                          True if number is 1 else False)

    def test_no_ellipsis_with_six_pages(self):
        # We're expecting 1 2 3 4 5 6 and no ellipsis.
        b = self.browser
        self.create_activity_pages(6)
        self.go_to_system_activity()
        # Start clicking from page #2
        for number in range(2, 7):
            self.click_page_number(number)
            one_is_current = False
            six_is_current = False
            if number is 1:
                one_is_current = True
            if number is 6:
                six_is_current = True
            self.check_page_text_is_shown(1, one_is_current)
            self.check_page_text_is_shown(6, six_is_current)

    def test_min_count_of_two_between_ends_of_ellipsis(self):
        # Checking for the following
        # _1 2 3 4 5...8
        # 1 2 3 _4 5...8
        # 1...3 4 _5 6 7 8
        self.create_activity_pages(8)
        self.go_to_system_activity()
        # We will be on page 1...
        self.check_page_text_is_shown(u'…8')

        self.click_page_number('4')
        self.check_page_text_is_shown(u'…8')
        self.check_page_text_is_shown('1')

        self.click_page_number('5')
        self.check_page_text_is_shown(u'1…')
        self.check_page_text_is_shown('8')