def ec2_provider_with_sts_creds(appliance):
    collection = appliance.collections.cloud_providers
    prov = collection.instantiate(prov_class=EC2Provider,
                                  name=fauxfactory.gen_alphanumeric(5),
                                  key='ec2west')
    assume_role_creds = prov.data.sts_assume_role.credentials
    creds = Credential(principal=credentials[assume_role_creds]['username'],
                       secret=credentials[assume_role_creds]['password'])
    endpoint = EC2Endpoint(assume_role_arn=prov.data.sts_assume_role.role_arn,
                           credentials=creds)

    prov.endpoints = prepare_endpoints(endpoint)
    prov.region_name = prov.data.region_name

    yield prov
    prov.delete()
    def update(self, updates, cancel=False, validate_credentials=True):
        """
        Updates a provider in the UI.  Better to use utils.update.update context
        manager than call this directly.

        Args:
           updates (dict): fields that are changing.
           cancel (boolean): whether to cancel out of the update.
           validate_credentials (boolean): whether credentials have to be validated
        """
        edit_view = navigate_to(self, 'Edit')

        # filling main part of dialog
        endpoints = updates.pop('endpoints', None)
        if updates:
            edit_view.fill(updates)

        # filling endpoints
        if endpoints:
            endpoints = prepare_endpoints(endpoints)

            for endpoint in endpoints.values():
                # every endpoint class has name like 'default', 'events', etc.
                # endpoints view can have multiple tabs, the code below tries
                # to find right tab by passing endpoint name to endpoints view
                try:
                    endp_view = getattr(self.endpoints_form(parent=edit_view), endpoint.name)
                except AttributeError:
                    # tabs are absent in UI when there is only single (default) endpoint
                    endp_view = self.endpoints_form(parent=edit_view)
                endp_view.fill(endpoint.view_value_mapping)

                # filling credentials
                # the code below looks for existing endpoint equal to passed one and
                # compares their credentials. it fills passed credentials
                # if credentials are different
                cur_endpoint = self.endpoints[endpoint.name]
                if hasattr(endpoint, 'credentials'):
                    if not hasattr(cur_endpoint, 'credentials') or \
                            endpoint.credentials != cur_endpoint.credentials:
                        if hasattr(endp_view, 'change_password'):
                            endp_view.change_password.click()
                        elif hasattr(endp_view, 'change_key'):
                            endp_view.change_key.click()
                        else:
                            NotImplementedError(
                                "Such endpoint doesn't have change password/key button")

                        endp_view.fill(endpoint.credentials.view_value_mapping)
                if (validate_credentials and hasattr(endp_view, 'validate') and
                        endp_view.validate.is_displayed):
                    endp_view.validate.click()
                    self._post_validate_checks(edit_view)

        if cancel:
            edit_view.cancel.click()
            self._post_cancel_edit_checks()
        else:
            edit_view.save.click()
            if endpoints:
                for endp_name, endp in endpoints.items():
                    self.endpoints[endp_name] = endp
            if updates:
                self.name = updates.get('name', self.name)

            self._post_update_checks(edit_view)
Exemple #3
0
    def update(self, updates, cancel=False, validate_credentials=True):
        """
        Updates a provider in the UI.  Better to use utils.update.update context
        manager than call this directly.

        Args:
           updates (dict): fields that are changing.
           cancel (boolean): whether to cancel out of the update.
           validate_credentials (boolean): whether credentials have to be validated
        """
        edit_view = navigate_to(self, 'Edit')

        # filling main part of dialog
        endpoints = updates.pop('endpoints', None)
        if updates:
            edit_view.fill(updates)

        # filling endpoints
        if endpoints:
            endpoints = prepare_endpoints(endpoints)

            for endpoint in endpoints.values():
                # every endpoint class has name like 'default', 'events', etc.
                # endpoints view can have multiple tabs, the code below tries
                # to find right tab by passing endpoint name to endpoints view
                try:
                    endp_view = getattr(self.endpoints_form(parent=edit_view),
                                        endpoint.name)
                except AttributeError:
                    # tabs are absent in UI when there is only single (default) endpoint
                    endp_view = self.endpoints_form(parent=edit_view)
                endp_view.fill(endpoint.view_value_mapping)

                # filling credentials
                # the code below looks for existing endpoint equal to passed one and
                # compares their credentials. it fills passed credentials
                # if credentials are different
                cur_endpoint = self.endpoints[endpoint.name]
                if hasattr(endpoint, 'credentials'):
                    if not hasattr(cur_endpoint, 'credentials') or \
                            endpoint.credentials != cur_endpoint.credentials:
                        if hasattr(endp_view, 'change_password'):
                            endp_view.change_password.click()
                        elif hasattr(endp_view, 'change_key'):
                            endp_view.change_key.click()
                        else:
                            NotImplementedError(
                                "Such endpoint doesn't have change password/key button"
                            )

                        endp_view.fill(endpoint.credentials.view_value_mapping)
                if (validate_credentials and hasattr(endp_view, 'validate')
                        and endp_view.validate.is_displayed):
                    endp_view.validate.click()
                    self._post_validate_checks(edit_view)

        if cancel:
            edit_view.cancel.click()
            self._post_cancel_edit_checks()
        else:
            edit_view.save.click()
            if endpoints:
                for endp_name, endp in endpoints.items():
                    self.endpoints[endp_name] = endp
            if updates:
                self.name = updates.get('name', self.name)

            self._post_update_checks(edit_view)