Beispiel #1
0
    def delete(self, cancel=False, from_details=True, wait=True):
        if self.appliance.version < '5.7':
            raise OptionNotAvailable(
                'Cannot delete cloud tenants in CFME < 5.7')
        if from_details:
            if cancel:
                raise OptionNotAvailable(
                    'Cannot cancel cloud tenant delete from details page')
            # Generates no alert or confirmation
            try:
                navigate_to(self, 'Details')
            except Exception as ex:
                # Catch general navigation exceptions and raise
                raise TenantNotFound(
                    'Exception while navigating to Tenant details: {}'.format(
                        ex))
            cfg_btn('Delete Cloud Tenant')
        else:
            # Have to select the row in the list
            navigate_to(self, 'All')
            # double check we're in List View
            tb.select('List View')
            found = False
            for page in paginator.pages():
                try:
                    listview_checktable.select_row_by_cells({
                        'Name':
                        self.name,
                        'Cloud Provider':
                        self.provider.name
                    })
                    found = True
                except NoSuchElementException:
                    continue
                else:
                    break
            if not found:
                raise TenantNotFound(
                    'Could not locate tenant for delete by selection')
            cfg_btn('Delete Cloud Tenants', invokes_alert=True)
            sel.handle_alert(cancel=cancel)

        if cancel:
            return self.exists()
        else:
            # Flash message is the same whether deleted from details or by selection
            result = flash.assert_success_message(
                'Delete initiated for 1 Cloud Tenant.')
            if wait:
                self.provider.refresh_provider_relationships()
                result = self.wait_for_disappear(600)
                return result
Beispiel #2
0
    def power_control_from_cfme(self, *args, **kwargs):
        """Power controls a VM from within CFME using instance details screen

        Raises:
            OptionNotAvailable: option param is not visible or enabled
        """
        # TODO push this to common.vm when infra and cloud have navmazing destinations

        if kwargs.get('from_details', True):
            navigate_to(self, 'Details')
        else:
            navigate_to(self, 'AllForProvider')
            self.find_quadicon(mark=True)
        if not kwargs.get('option'):
            raise ValueError(
                'Need to provide option for power_control_from_cfme, no default.'
            )
        try:
            if not pwr_btn(kwargs.get('option'), invokes_alert=True):
                raise ToolbarOptionGreyedOrUnavailable(
                    'Failed to click power button')
        except NoSuchElementException:
            raise OptionNotAvailable(
                kwargs.get('option') + " is not visible or enabled")

        sel.handle_alert(cancel=kwargs.get('cancel', False))
Beispiel #3
0
def create_resource(rest_api,
                    col_name,
                    col_data,
                    col_action='create',
                    substr_search=False):
    """Creates new resource in collection."""
    collection = getattr(rest_api.collections, col_name)
    try:
        action = getattr(collection.action, col_action)
    except AttributeError:
        raise OptionNotAvailable(
            "Action `{}` for {} is not implemented in this version".format(
                col_action, col_name))

    entities = action(*col_data)
    action_response = rest_api.response
    search_str = '%{}%' if substr_search else '{}'
    for entity in col_data:
        if entity.get('name'):
            wait_for(lambda: collection.find_by(name=search_str.format(
                entity.get('name'))) or False,
                     num_sec=180,
                     delay=10)
        elif entity.get('description'):
            wait_for(lambda: collection.find_by(description=search_str.format(
                entity.get('description'))) or False,
                     num_sec=180,
                     delay=10)
        else:
            raise NotImplementedError

    # make sure action response is preserved
    rest_api.response = action_response
    return entities
Beispiel #4
0
def _creating_skeleton(request, rest_api, col_name, col_data):
    collection = getattr(rest_api.collections, col_name)
    if "create" not in collection.action.all:
        raise OptionNotAvailable(
            "Create action for {} is not implemented in this version".format(
                col_name))
    entities = collection.action.create(*col_data)
    for entity in col_data:
        if entity.get('name', None):
            wait_for(lambda: collection.find_by(name=entity.get('name')),
                     num_sec=180,
                     delay=10)
        elif entity.get('description', None):
            wait_for(lambda: collection.find_by(description=entity.get(
                'description')),
                     num_sec=180,
                     delay=10)
        else:
            raise NotImplementedError

    @request.addfinalizer
    def _finished():
        collection.reload()
        ids = [e.id for e in entities]
        delete_entities = [e for e in collection if e.id in ids]
        if len(delete_entities) != 0:
            collection.action.delete(*delete_entities)

    return entities
def _creating_skeleton(request, rest_api, col_name, col_data, col_action='create',
        substr_search=False):
    collection = getattr(rest_api.collections, col_name)
    try:
        action = getattr(collection.action, col_action)
    except AttributeError:
        raise OptionNotAvailable(
            "Action `{}` for {} is not implemented in this version".format(col_action, col_name))

    entities = action(*col_data)
    action_status = rest_api.response.status_code
    search_str = '%{}%' if substr_search else '{}'
    for entity in col_data:
        if entity.get('name'):
            wait_for(lambda: collection.find_by(
                name=search_str.format(entity.get('name'))) or False, num_sec=180, delay=10)
        elif entity.get('description'):
            wait_for(lambda: collection.find_by(
                description=search_str.format(entity.get('description'))) or False,
                num_sec=180, delay=10)
        else:
            raise NotImplementedError

    @request.addfinalizer
    def _finished():
        collection.reload()
        ids = [e.id for e in entities]
        delete_entities = [e for e in collection if e.id in ids]
        if len(delete_entities) != 0:
            collection.action.delete(*delete_entities)

    # make sure action status code is preserved
    rest_api.response.status_code = action_status
    return entities
    def power_control_from_provider(self, option):
        """Power control the instance from the provider

        Args:
            option: power control action to take against instance

        Raises:
            OptionNotAvailable: option param must have proper value
        """
        if option == OpenStackInstance.START:
            self.provider.mgmt.start_vm(self.name)
        elif option == OpenStackInstance.STOP:
            self.provider.mgmt.stop_vm(self.name)
        elif option == OpenStackInstance.SUSPEND:
            self.provider.mgmt.suspend_vm(self.name)
        elif option == OpenStackInstance.PAUSE:
            self.provider.mgmt.pause_vm(self.name)
        elif option == OpenStackInstance.SHELVE:
            # TODO: rewrite it once mgmtsystem will get shelve
            # and shelve_offload methods
            self.provider.mgmt._find_instance_by_name(self.name).shelve()
        elif option == OpenStackInstance.SHELVE_OFFLOAD:
            self.provider.mgmt._find_instance_by_name(self.name).shelve_offload()
        elif option == OpenStackInstance.RESTART:
            self.provider.mgmt.restart_vm(self.name)
        elif option == OpenStackInstance.TERMINATE:
            self.provider.mgmt.delete_vm(self.name)
        else:
            raise OptionNotAvailable(option + " is not a supported action")
Beispiel #7
0
    def power_control_from_cfme(self, option, cancel=True, from_details=False):
        """Power controls a VM from within CFME

        Args:
            option: corresponds to option values under the power button
            cancel: Whether or not to cancel the power operation on confirmation
            from_details: Whether or not to perform action from instance details page

        Raises:
            OptionNotAvailable: option param is not visible or enabled
        """
        if from_details:
            view = navigate_to(self, 'Details', use_resetter=False)
        else:
            view = navigate_to(self.parent, 'All')

        if self.is_pwr_option_available_in_cfme(option=option,
                                                from_details=from_details):

            view.toolbar.power.item_select(option, handle_alert=not cancel)
            logger.info(
                "Power control action of VM/instance %s, option %s, cancel %s executed",
                self.name, option, str(cancel))
        else:
            raise OptionNotAvailable(option + " is not visible or enabled")
Beispiel #8
0
def _test_vm_power_on():
    """Ensures power button is shown for a VM"""
    logger.info("Checking for power button")
    vm_name = vms.Vm.get_first_vm_title()
    logger.debug("VM " + vm_name + " selected")
    if not vms.is_pwr_option_visible(vm_name, option=vms.Vm.POWER_ON):
        raise OptionNotAvailable("Power button does not exist")
Beispiel #9
0
    def power_control_from_provider(self, option):
        """Power control the instance from the provider

        Args:
            option: power control action to take against instance

        Raises:
            OptionNotAvailable: option param must have proper value
        """
        if option == OpenStackInstance.START:
            self.provider.mgmt.start_vm(self.name)
        elif option == OpenStackInstance.STOP:
            self.provider.mgmt.stop_vm(self.name)
        elif option == OpenStackInstance.SUSPEND:
            self.provider.mgmt.suspend_vm(self.name)
        elif option == OpenStackInstance.RESUME:
            self.provider.mgmt.resume_vm(self.name)
        elif option == OpenStackInstance.PAUSE:
            self.provider.mgmt.pause_vm(self.name)
        elif option == OpenStackInstance.UNPAUSE:
            self.provider.mgmt.unpause_vm(self.name)
        elif option == OpenStackInstance.RESTART:
            self.provider.mgmt.restart_vm(self.name)
        elif option == OpenStackInstance.TERMINATE:
            self.provider.mgmt.delete_vm(self.name)
        else:
            raise OptionNotAvailable(option + " is not a supported action")
Beispiel #10
0
def test_object_attribute_type_in_automate_schedule(appliance):
    """
    Polarion:
        assignee: ghubale
        casecomponent: Automate
        initialEstimate: 1/15h
        startsin: 5.9
        tags: automate
        testSteps:
            1. Go to Configuration > settings > schedules
            2. Select 'Add a new schedule' from configuration drop down
            3. selecting 'Automation Tasks' under Action.
            4. Select a value from the drop down list of Object Attribute Type.
            5. Undo the selection by selecting "<Choose>" from the drop down.
        expectedResults:
            1.
            2.
            3.
            4. No pop-up window with Internal Server Error.
            5. No pop-up window with Internal Server Error.

    Bugzilla:
         1479570, 1686762
    """
    view = navigate_to(appliance.collections.system_schedules, 'Add')
    view.form.action_type.select_by_visible_text('Automation Tasks')
    all_options = view.form.object_type.all_options
    if len(all_options) < 2:
        # There should be more than one options available because <choose> is default option
        raise OptionNotAvailable("Options not available")
    for options in all_options:
        view.form.object_type.select_by_visible_text(options.text)
        view.flash.assert_no_error()
        view.form.object_type.select_by_visible_text('<Choose>')
        view.flash.assert_no_error()
Beispiel #11
0
 def step(self, *args, **kwargs):
     if isinstance(self.obj, Tenant):
         add_selector = 'Add child Tenant to this Tenant'
     elif isinstance(self.obj, Project):
         add_selector = 'Add Project to this Tenant'
     else:
         raise OptionNotAvailable('Object type unsupported for Tenant Add: {}'
                                  .format(type(self.obj).__name__))
     tb.select('Configuration', add_selector)
Beispiel #12
0
 def step(self):
     self.prerequisite_view.accordions.accesscontrol.tree.click_path(
         self.obj.appliance.server_region_string(), 'Tenants', *self.obj.parent_path)
     if isinstance(self.obj, Tenant):
         add_selector = 'Add child Tenant to this Tenant'
     elif isinstance(self.obj, Project):
         add_selector = 'Add Project to this Tenant'
     else:
         raise OptionNotAvailable('Object type unsupported for Tenant Add: {}'
                                  .format(type(self.obj).__name__))
     self.prerequisite_view.configuration.item_select(add_selector)
Beispiel #13
0
    def delete(self, cancel=False, from_details=True, wait=True):
        """Delete the tenant"""
        if self.appliance.version < '5.7':
            raise OptionNotAvailable('Cannot delete cloud tenants in CFME < 5.7')
        if from_details:
            if cancel:
                raise OptionNotAvailable('Cannot cancel cloud tenant delete from details page')
            # Generates no alert or confirmation
            try:
                view = navigate_to(self, 'Details')
            except Exception as ex:
                # Catch general navigation exceptions and raise
                raise TenantNotFound('Exception while navigating to Tenant details: {}'.format(ex))
            view.toolbar.configuration.item_select('Delete Cloud Tenant')
        else:
            # Have to select the row in the list
            view = navigate_to(self, 'All')
            # double check we're in List View
            view.toolbar.view_selector.select('List View')
            try:
                row = view.paginator.find_row_on_pages(view.entities.table, name=self.name)
                row[0].check()
                view.toolbar.configuration.item_select('Delete Cloud Tenants',
                                                       handle_alert=not cancel)
            except NoSuchElementException:
                raise TenantNotFound('Tenant {} not found'.format(self.name))

        if cancel:
            return self.exists
        else:
            # Flash message is the same whether deleted from details or by selection
            result = view.entities.flash.assert_success_message(
                'Delete initiated for 1 Cloud Tenant.')
            if wait:
                self.provider.refresh_provider_relationships()
                result = self.wait_for_disappear(600)
                return result
Beispiel #14
0
    def delete(self, cancel=False):
        """Delete generic object button group

            Args: cancel(bool): By default group will be deleted, pass True to cancel deletion
        """
        view = navigate_to(self, 'Details')

        if not view.configuration.item_enabled(self.REMOVE_TEXT):
            raise OptionNotAvailable(
                "Remove this Button Group is not enabled, there are buttons assigned to this group"
            )
        else:
            view.configuration.item_select(self.REMOVE_TEXT,
                                           handle_alert=not cancel)
        view = self.create_view(GenericObjectDefinitionAllView, wait=10)
        view.flash.assert_no_error()
Beispiel #15
0
    def create(self,
               name,
               description,
               profile_type,
               files=None,
               events=None,
               categories=None,
               registry=None,
               cancel=False):
        """Add Analysis Profile to appliance"""
        # The tab form values have to be dictionaries with the root key matching the tab widget name
        form_values = self.form_fill_args({
            'name': name,
            'description': description,
            'categories': categories,
            'files': files,
            'registry': registry,
            'events': events
        })

        if profile_type.lower() == 'vm':
            view = navigate_to(self, 'AddVmProfile')
        elif profile_type.lower() == 'host':
            view = navigate_to(self, 'AddHostProfile')
        else:
            raise OptionNotAvailable('Not such profile available')

        view.form.fill(form_values)

        if cancel:
            view.cancel.click()
        else:
            view.add.click()

        view.flush_widget_cache()
        view = self.create_view(AnalysisProfileAllView)

        assert view.is_displayed

        return self.instantiate(name=name,
                                description=description,
                                profile_type=profile_type,
                                files=files,
                                events=events,
                                categories=categories,
                                registry=registry)
Beispiel #16
0
def is_pwr_option_enabled(vm_names, option, provider_crud=None):
    """Returns whether a particular power option is enabled

    Args:
        vm_names: List of instances to interact with
        provider_crud: provider object where vm resides on (optional)
        option: Power option param; for available power option, see
                :py:class:`EC2Instance` and :py:class:`OpenStackInstance`

    Raises:
        OptionNotAvailable: When unable to find the power option passed
    """
    _method_setup(vm_names, provider_crud)
    try:
        return not toolbar.is_greyed('Power', option)
    except sel.NoSuchElementException:
        raise OptionNotAvailable("No such power option (" + str(option) + ") is available")
Beispiel #17
0
def is_pwr_option_enabled(vm_names, option, provider_crud=None):
    """Returns whether a particular power option is enabled.

    Args:
        vm_names: List of VMs to interact with
        provider_crud: provider object where vm resides on (optional)
        option: Power option param.

    Raises:
        NoOptionAvailable:
            When unable to find the power option passed
    """
    _method_setup(vm_names, provider_crud)
    try:
        return not toolbar.is_greyed('Power', option)
    except NoSuchElementException:
        raise OptionNotAvailable("No such power option (" + str(option) + ") is available")
Beispiel #18
0
    def power_control_from_cfme(self, option, cancel=True, from_details=False):
        """Power controls a VM from within CFME

        Args:
            option: corresponds to option values under the power button
            cancel: Whether or not to cancel the power operation on confirmation
            from_details: Whether or not to perform action from instance details page

        Raises:
            OptionNotAvailable: option param is not visible or enabled
        """
        if (self.is_pwr_option_available_in_cfme(option=option, from_details=from_details)):
                pwr_btn(option, invokes_alert=True)
                sel.handle_alert(cancel=cancel, check_present=True)
                logger.info(
                    "Power control action of VM/instance %s, option %s, cancel %s executed",
                    self.name, option, str(cancel))
        else:
            raise OptionNotAvailable(option + " is not visible or enabled")
    def power_control_from_provider(self, option):
        """Power control a vm from the provider

        Args:
            option: power control action to take against vm

        Raises:
            OptionNotAvailable: option parm must have proper value
        """
        if option == Vm.POWER_ON:
            self.provider.mgmt.start_vm(self.name)
        elif option == Vm.POWER_OFF:
            self.provider.mgmt.stop_vm(self.name)
        elif option == Vm.SUSPEND:
            self.provider.mgmt.suspend_vm(self.name)
        # elif reset:
        # elif shutdown:
        else:
            raise OptionNotAvailable(option + " is not a supported action")
Beispiel #20
0
    def power_control_from_provider(self, option):
        """Power control the instance from the provider

        Args:
            option: power control action to take against instance

        Raises:
            OptionNotAvailable: option param must have proper value
        """
        if option == EC2Instance.START:
            self.provider_crud.get_mgmt_system().start_vm(self.name)
        elif option == EC2Instance.STOP:
            self.provider_crud.get_mgmt_system().stop_vm(self.name)
        elif option == EC2Instance.RESTART:
            self.provider_crud.get_mgmt_system().restart_vm(self.name)
        elif option == EC2Instance.TERMINATE:
            self.provider_crud.get_mgmt_system().delete_vm(self.name)
        else:
            raise OptionNotAvailable(option + " is not a supported action")