Пример #1
0
    def create_encryption_type(self, volume_type, specs):
        """Create encryption type for a volume type. Default: admin only.

        :param volume_type: the volume type on which to add an encryption type
        :param specs: the encryption type specifications to add
        :return: an instance of :class: VolumeEncryptionType
        """
        aname = "cinder_v%s.create_encryption_type" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().volume_encryption_types.create(
                volume_type, specs)
Пример #2
0
    def run(self, actions_num=5, sleep_min=0, sleep_max=0):
        """Sleep random time in dummy actions.

        :param actions_num: int number of actions to generate
        :param sleep_min: minimal time to sleep, numeric seconds
        :param sleep_max: maximum time to sleep, numeric seconds
        """
        for idx in range(actions_num):
            duration = random.uniform(sleep_min, sleep_max)
            with atomic.ActionTimer(self, "action_%d" % idx):
                utils.interruptable_sleep(duration)
Пример #3
0
 def create(self):
     with atomic.ActionTimer(self.scenario, "heat.create"):
         self.stack = self.scenario.clients("heat").stacks.create(
             stack_name=self.scenario.generate_random_name(),
             template=self.template,
             files=self.files,
             parameters=self.parameters)
         self.stack_id = self.stack["stack"]["id"]
         self.stack = self.scenario.clients("heat").stacks.get(
             self.stack_id)
         self._wait(["CREATE_COMPLETE"], ["CREATE_FAILED"])
Пример #4
0
    def transfer_create(self, volume_id, name=None):
        """Create a volume transfer.

        :param name: The name of created transfer
        :param volume_id: The ID of the volume to transfer
        :rtype: VolumeTransfer
        """
        name = name or self.generate_random_name()
        aname = "cinder_v%s.transfer_create" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().transfers.create(volume_id, name=name)
Пример #5
0
    def boot_and_delete_server_with_secgroups(self, image, flavor,
                                              security_group_count,
                                              rules_per_security_group,
                                              **kwargs):
        """Boot and delete server with security groups attached.

        Plan of this scenario:
         - create N security groups with M rules per group
           vm with security groups)
         - boot a VM with created security groups
         - get list of attached security groups to server
         - delete server
         - delete all security groups
         - check that all groups were attached to server

        :param image: ID of the image to be used for server creation
        :param flavor: ID of the flavor to be used for server creation
        :param security_group_count: Number of security groups
        :param rules_per_security_group: Number of rules per security group
        :param **kwargs: Optional arguments for booting the instance
        """

        security_groups = self._create_security_groups(
            security_group_count)
        self._create_rules_for_security_group(security_groups,
                                              rules_per_security_group)

        secgroups_names = [sg.name for sg in security_groups]
        server = self._boot_server(image, flavor,
                                   security_groups=secgroups_names,
                                   **kwargs)

        action_name = "nova.get_attached_security_groups"
        with atomic.ActionTimer(self, action_name):
            attached_security_groups = server.list_security_group()

        self._delete_server(server)
        try:
            self._delete_security_groups(security_groups)
        except Exception as e:
            if hasattr(e, "http_status") and e.http_status == 400:
                raise NovaSecurityGroupException(six.text_type(e))
            raise

        error_message = ("Expected number of attached security groups to "
                         " server %(server)s is '%(all)s', but actual number "
                         "is '%(attached)s'." % {
                             "attached": len(attached_security_groups),
                             "all": len(security_groups),
                             "server": server})

        self.assertEqual(sorted([sg.id for sg in security_groups]),
                         sorted([sg.id for sg in attached_security_groups]),
                         error_message)
Пример #6
0
    def list_transfers(self, detailed=True, search_opts=None):
        """Get a list of all volume transfers.

        :param detailed: If True, detailed information about transfer
                         should be listed
        :param search_opts: Search options to filter out volume transfers
        :returns: list of :class:`VolumeTransfer`
        """
        aname = "cinder_v%s.list_transfers" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().transfers.list(detailed, search_opts)
Пример #7
0
    def list_objects_in_containers(self):
        """List objects in all containers."""
        containers = self._list_containers()[1]

        key_suffix = "container"
        if len(containers) > 1:
            key_suffix = "%i_containers" % len(containers)

        with atomic.ActionTimer(self, "swift.list_objects_in_%s" % key_suffix):
            for container in containers:
                self._list_objects(container["name"], atomic_action=False)
Пример #8
0
    def delete_volume_type(self, volume_type):
        """delete a volume type.

        :param volume_type: Name or Id of the volume type
        :returns: base on client response return True if the request
                  has been accepted or not
        """
        aname = "cinder_v%s.delete_volume_type" % self.version
        with atomic.ActionTimer(self, aname):
            tuple_res = self._get_client().volume_types.delete(volume_type)
            return (tuple_res[0].status_code == 202)
Пример #9
0
    def restore_backup(self, backup_id, volume_id=None):
        """Restore the given backup.

        :param backup_id: The ID of the backup to restore.
        :param volume_id: The ID of the volume to restore the backup to.
        """
        aname = "cinder_v%s.restore_backup" % self.version
        with atomic.ActionTimer(self, aname):
            restore = self._get_client().restores.restore(backup_id, volume_id)
            restored_volume = self._get_client().volumes.get(restore.volume_id)
            return self._wait_available_volume(restored_volume)
Пример #10
0
    def create_qos(self, specs):
        """Create a qos specs.

        :param specs: A dict of key/value pairs to be set
        :rtype: :class:'QoSSpecs'
        """
        aname = "cinder_v%s.create_qos" % self.version
        name = self.generate_random_name()

        with atomic.ActionTimer(self, aname):
            return self._get_client().qos_specs.create(name, specs)
Пример #11
0
    def _create_security_groups(self, security_group_count):
        security_groups = []
        with atomic.ActionTimer(
                self, "nova.create_%s_security_groups" % security_group_count):
            for i in range(security_group_count):
                sg_name = self.generate_random_name()
                sg = self.clients("nova").security_groups.create(
                    sg_name, sg_name)
                security_groups.append(sg)

        return security_groups
Пример #12
0
    def download_image(self, image_id, do_checksum=True):
        """Retrieve data of an image.

        :param image_id: ID of the image to download.
        :param do_checksum: Enable/disable checksum validation.
        :returns: An iterable body or None
        """
        aname = "glance_v%s.download_image" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().images.data(image_id,
                                                  do_checksum=do_checksum)
Пример #13
0
    def validate_cinder(self, repetitions):
        """Check Cinder Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        cinder_client = self.clients("cinder")
        for i in range(repetitions):
            with atomic.ActionTimer(self, "authenticate.validate_cinder"):
                cinder_client.volume_types.list()
Пример #14
0
    def validate_nova(self, repetitions):
        """Check Nova Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        nova_client = self.clients("nova")
        for i in range(repetitions):
            with atomic.ActionTimer(self, "authenticate.validate_nova"):
                nova_client.flavors.list()
Пример #15
0
    def validate_monasca(self, repetitions):
        """Check Monasca Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        monasca_client = self.clients("monasca")
        for i in range(repetitions):
            with atomic.ActionTimer(self, "authenticate.validate_monasca"):
                list(monasca_client.metrics.list(limit=0))
Пример #16
0
    def validate_heat(self, repetitions):
        """Check Heat Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        heat_client = self.clients("heat")
        for i in range(repetitions):
            with atomic.ActionTimer(self, "authenticate.validate_heat"):
                list(heat_client.stacks.list(limit=0))
Пример #17
0
    def run(self, repetitions):
        """Check Octavia Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        octavia_client = self.clients("octavia")
        with atomic.ActionTimer(self, "authenticate.validate_octavia"):
            for i in range(repetitions):
                octavia_client.load_balancer_list()
Пример #18
0
    def set_qos(self, qos_id, set_specs_args):
        """Add/Update keys in qos specs.

        :param qos_id: The ID of the :class:`QoSSpecs` to get
        :param set_specs_args: A dict of key/value pairs to be set
        :rtype: class 'cinderclient.apiclient.base.DictWithMeta'
                {"qos_specs": set_specs_args}
        """
        aname = "cinder_v%s.set_qos" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().qos_specs.set_keys(
                qos_id, set_specs_args)
Пример #19
0
    def _list_samples(self, query=None, limit=None):
        """List all Samples.

        :param query: optional param that specify query
        :param limit: optional param for maximum number of samples returned
        :returns: list of samples
        """
        key = self._make_profiler_key("ceilometer.list_samples", query,
                                      limit)
        with atomic.ActionTimer(self, key):
            return self.clients("ceilometer").new_samples.list(q=query,
                                                               limit=limit)
Пример #20
0
    def update_readonly_flag(self, volume, read_only):
        """Update the read-only access mode flag of the specified volume.

        :param volume: The UUID of the volume to update.
        :param read_only: The value to indicate whether to update volume to
            read-only access mode.
        :returns: A tuple of http Response and body
        """
        aname = "cinder_v%s.update_readonly_flag" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().volumes.update_readonly_flag(
                volume, read_only)
Пример #21
0
    def validate_neutron(self, repetitions):
        """Check Neutron Client to ensure validation of token.

        Creation of the client does not ensure validation of the token.
        We have to do some minimal operation to make sure token gets validated.

        :param repetitions: number of times to validate
        """
        neutron_client = self.clients("neutron")
        for i in range(repetitions):
            with atomic.ActionTimer(self, "authenticate.validate_neutron"):
                neutron_client.list_networks()
Пример #22
0
    def run(self, exception_probability=0.5):
        """Dummy.dummy_random_fail_in_atomic in dummy actions.

        Can be used to test atomic actions
        failures processing.

        :param exception_probability: Probability with which atomic actions
                                      fail in this dummy scenario (0 <= p <= 1)
        """
        # divide probability on the number of possible places to fail
        if exception_probability != 1:
            exception_probability = exception_probability / 4.0
        with atomic.ActionTimer(self, "dummy_fail_test"):
            self._play_roulette(exception_probability)
            with atomic.ActionTimer(self, "dummy_fail_inner_test"):
                self._play_roulette(exception_probability)

        with atomic.ActionTimer(self, "dummy_fail_test"):
            self._play_roulette(exception_probability)
            with atomic.ActionTimer(self, "dummy_fail_inner_test"):
                self._play_roulette(exception_probability)
Пример #23
0
    def _messages_post(self, queue, messages, min_msg_count, max_msg_count):
        """Post a list of messages to a given Zaqar queue.

        :param queue: post the messages to queue
        :param messages: messages to post
        :param min_msg_count: minimum number of messages
        :param max_msg_count: maximum number of messages
        """
        with atomic.ActionTimer(
                self, "zaqar.post_between_%s_and_%s_messages" %
            (min_msg_count, max_msg_count)):
            queue.post(messages)
Пример #24
0
    def update_encryption_type(self, volume_type, specs):
        """Update the encryption type information for the specified volume type.

        :param volume_type: the volume type whose encryption type information
                            must be updated
        :param specs: the encryption type specifications to update
        :return: an instance of :class: VolumeEncryptionType
        """
        aname = "cinder_v%s.update_encryption_type" % self.version
        with atomic.ActionTimer(self, aname):
            return self._get_client().volume_encryption_types.update(
                volume_type, specs)
Пример #25
0
    def _attach_floating_ip(self, server, floating_network):
        internal_network = list(server.networks)[0]
        fixed_ip = server.addresses[internal_network][0]["addr"]

        with atomic.ActionTimer(self, "neutron.create_floating_ip"):
            fip = network_wrapper.wrap(self.clients, self).create_floating_ip(
                ext_network=floating_network,
                tenant_id=server.tenant_id, fixed_ip=fixed_ip)

        self._associate_floating_ip(server, fip["ip"], fixed_address=fixed_ip)

        return fip
Пример #26
0
    def delete_encryption_type(self, volume_type):
        """Delete the encryption type information for the specified volume type.

        :param volume_type: the volume type whose encryption type information
                            must be deleted
        """
        aname = "cinder_v%s.delete_encryption_type" % self.version
        with atomic.ActionTimer(self, aname):
            resp = self._get_client().volume_encryption_types.delete(
                volume_type)
            if (resp[0].status_code != 202):
                raise exceptions.EncryptionTypeDeleteException()
Пример #27
0
    def get_image(self, image):
        """Get specified image.

        :param image: ID or object with ID of image to obtain.
        """
        image_id = getattr(image, "id", image)
        try:
            aname = "glance_v%s.get_image" % self.version
            with atomic.ActionTimer(self, aname):
                return self._get_client().images.get(image_id)
        except glance_exc.HTTPNotFound:
            raise exceptions.GetResourceNotFound(resource=image)
Пример #28
0
    def _update_security_groups(self, security_groups):
        """Update a list of security groups

        :param security_groups: list, security_groups that are to be updated
        """
        with atomic.ActionTimer(
                self, "nova.update_%s_security_groups" % len(security_groups)):
            for sec_group in security_groups:
                sg_new_name = self.generate_random_name()
                sg_new_desc = self.generate_random_name()
                self.clients("nova").security_groups.update(
                    sec_group.id, sg_new_name, sg_new_desc)
Пример #29
0
    def _list_meters(self, query=None, limit=None):
        """Get list of user's meters.

        :param query: query list for Ceilometer api
        :param limit: count of returned meters
        :returns: list of all meters
        """

        key = self._make_profiler_key("ceilometer.list_meters", query,
                                      limit)
        with atomic.ActionTimer(self, key):
            return self.clients("ceilometer").meters.list(q=query,
                                                          limit=limit)
Пример #30
0
    def _list_resources(self, query=None, limit=None):
        """List all resources.

        :param query: query list for Ceilometer api
        :param limit: count of returned resources
        :returns: list of all resources
        """

        key = self._make_profiler_key("ceilometer.list_resources", query,
                                      limit)
        with atomic.ActionTimer(self, key):
            return self.clients("ceilometer").resources.list(q=query,
                                                             limit=limit)