def find_request(cells, partial_check=False):
    """Finds the request and returns the row element

    Args:
        cells: Search data for the requests table.
        partial_check: If to use the ``in`` operator rather than ``==`` in find_rows_by_cells().
    Returns: row
    """
    navigate_to(Request, 'All')
    for page in paginator.pages():
        results = fields.request_list.find_rows_by_cells(cells, partial_check)
        if len(results) == 0:
            # row not on this page, assume it has yet to appear
            # it might be nice to add an option to fail at this point
            continue
        elif len(results) > 1:
            raise RequestException(
                'Multiple requests with matching content found - be more specific!'
            )
        else:
            # found the row!
            row = results[0]
            logger.debug(' Request Message: %s', row.last_message.text)
            return row
    else:
        # Request not found at all, can't continue
        return False
Exemple #2
0
    def find_request(self, cells, partial_check=False):
        """Finds the request and returns the row element
        Args:
            cells: Search data for the requests table.
            partial_check: If to use the ``__contains`` operator
        Returns: row
        """
        contains = '' if not partial_check else '__contains'
        column_list = self.table.attributized_headers
        cells = copy(cells)
        for key in cells.keys():
            for column_name, column_text in column_list.items():
                if key == column_text:
                    cells['{}{}'.format(column_name,
                                        contains)] = cells.pop(key)
                    break

        for _ in self.paginator.pages():
            rows = list(self.table.rows(**cells))
            if len(rows) == 0:
                # row not on this page, assume it has yet to appear
                # it might be nice to add an option to fail at this point
                continue
            elif len(rows) > 1:
                raise RequestException(
                    'Multiple requests with matching content found - be more specific!'
                )
            else:
                # found the row!
                row = rows[0]
                logger.debug(' Request Message: %s', row.last_message.text)
                return row
        else:
            raise Exception("The requst specified by {} not found!".format(
                str(cells)))
def wait_for_request(cells):
    """helper function checks if a request is complete

    After finding the request's row using the ``cells`` argument, this will wait for a request to
    reach the 'Finished' state and return it. In the event of an 'Error' state, it will raise an
    AssertionError, for use with ``pytest.raises``, if desired.

    Args:
        cells: A dict of cells use to identify the request row to inspect in the
            :py:attr:`request_list` Table. See :py:meth:`cfme.web_ui.Table.find_rows_by_cells`
            for more.

    Usage:

        # Filter on the "Description" column
        description = 'Provision from [%s] to [%s]' % (template_name, vm_name)
        cells = {'Description': description}

        # Filter on the "Request ID" column
        # Text must match exactly, you can use "{:,}".format(request_id) to add commas if needed.
        request_id = '{:,}'.format(1000000000001)  # Becomes '1,000,000,000,001', as in the table
        cells = {'Request ID': request_id}

        # However you construct the cells dict, pass it to wait_for_request
        # Provisioning requests often take more than 5 minutes but less than 10.
        wait_for(wait_for_request, [cells], num_sec=600)

    Raises:
        AssertionError: if the matched request has status 'Error'
        RequestException: if multiple matching requests were found

    Returns:
         The matching :py:class:`cfme.web_ui.Table.Row` if found, ``False`` otherwise.
    """
    for page in paginator.pages():
        results = request_list.find_rows_by_cells(cells)
        if len(results) == 0:
            # row not on this page, assume it has yet to appear
            continue
        elif len(results) > 1:
            raise RequestException(
                'Multiple requests with matching content found - be more specific!'
            )
        else:
            # found the row!
            row = results[0]
            logger.debug(' Request Message: %s' % row.last_message.text)
            break
    else:
        # Request not found at all, can't continue
        return False

    assert row.status.text != 'Error'
    if row.request_state.text == 'Finished':
        return row
    else:
        return False
Exemple #4
0
def delete_request(cells, cancel=False):
    """Open the specified request and delete it.

    Args:
        cells: Search data for the requests table.
        cancel: Whether to cancel the deletion.

    Raises:
        RequestException: :py:class:`cfme.exceptions.RequestException` if the request was not found
    """
    if not go_to_request(cells):
        raise RequestException("Request with identification {} not found!".format(str(cells)))
    delete(cancel)
Exemple #5
0
def approve_request(cells, reason, cancel=False):
    """Open the specified request and approve it.

    Args:
        cells: Search data for the requests table.
        reason: Reason for approving the request.
        cancel: Whether to cancel the approval.

    Raises:
        RequestException: :py:class:`cfme.exceptions.RequestException` if the request was not found
    """
    if not go_to_request(cells):
        raise RequestException("Request with identification {} not found!".format(str(cells)))
    approve(reason, cancel)
Exemple #6
0
 def rest(self):
     if self.partial_check:
         matching_requests = self.appliance.rest_api.collections.requests.find_by(
             description='%{}%'.format(self.cells['Description']))
     else:
         matching_requests = self.appliance.rest_api.collections.requests.find_by(
             description=self.cells['Description'])
     if len(matching_requests) > 1:
         raise RequestException('Multiple requests with matching \"{}\" '
                                'found - be more specific!'.format(
                                    self.description))
     elif len(matching_requests) == 0:
         raise ItemNotFound(
             'Nothing matching "{}" with partial_check={} was found'.format(
                 self.cells['Description'], self.partial_check))
     else:
         self.description = matching_requests[0].description
         return matching_requests[0]
Exemple #7
0
    def rest(self):
        if self.partial_check:
            matching_requests = self.appliance.rest_api.collections.requests.find_by(
                description=f'%{self.cells["Description"]}%')
        else:
            matching_requests = self.appliance.rest_api.collections.requests.find_by(
                description=self.cells['Description'])

        if len(matching_requests) > 1:
            # TODO: This forces anything using requests to handle this exception
            # The class needs support for identifying a request by its ID
            # This ID might not be available on instantiation, but needs to be set somehow
            # Ideally before MIQ receives multiple orders for the same service, which have same desc
            raise RequestException(
                f'Multiple requests with matching "{self.description}" found - be more specific!'
            )
        elif len(matching_requests) == 0:
            raise ItemNotFound(
                f'Nothing matching "{self.cells["Description"]}" with '
                f'partial_check={self.partial_check} was found'
            )
        else:
            return matching_requests[0]
Exemple #8
0
def wait_for_request(cells, partial_check=False):
    """helper function checks if a request is complete

    After finding the request's row using the ``cells`` argument, this will wait for a request to
    reach the 'Finished' state and return it. In the event of an 'Error' state, it will raise an
    AssertionError, for use with ``pytest.raises``, if desired.

    Args:
        cells: A dict of cells use to identify the request row to inspect in the
            :py:attr:`request_list` Table. See :py:meth:`cfme.web_ui.Table.find_rows_by_cells`
            for more.
        partial_check: If to use the ``in`` operator rather than ``==`` in find_rows_by_cells().

    Usage:

        # Filter on the "Description" column
        description = 'Provision from [%s] to [%s]' % (template_name, vm_name)
        cells = {'Description': description}

        # Filter on the "Request ID" column
        # Text must match exactly, you can use "{:,}".format(request_id) to add commas if needed.
        request_id = '{:,}'.format(1000000000001)  # Becomes '1,000,000,000,001', as in the table
        cells = {'Request ID': request_id}

        # However you construct the cells dict, pass it to wait_for_request
        # Provisioning requests often take more than 5 minutes but less than 10.
        wait_for(wait_for_request, [cells], num_sec=600)

    Raises:
        RequestException: if multiple matching requests were found

    Returns:
         The matching :py:class:`cfme.web_ui.Table.Row` if found, ``False`` otherwise.
    """
    for page in paginator.pages():
        # We check only for the SplitTable. Can't think of better detection.
        if version.current_version() < "5.5.0.8"\
                and sel.elements(fields.request_list._header_loc) and\
                not sel.is_displayed(fields.request_list):
            # The table exists but it is hidden - no cells
            return False
        results = fields.request_list.find_rows_by_cells(cells, partial_check)
        if len(results) == 0:
            # row not on this page, assume it has yet to appear
            continue
        elif len(results) > 1:
            raise RequestException(
                'Multiple requests with matching content found - be more specific!'
            )
        else:
            # found the row!
            row = results[0]
            logger.debug(' Request Message: %s', row.last_message.text)
            break
    else:
        # Request not found at all, can't continue
        return False

    if row.request_state.text in REQUEST_FINISHED_STATES:
        return row
    else:
        return False