예제 #1
0
파일: objects.py 프로젝트: yongfengdu/rally
    def create_container_and_object_then_download_object(
            self, objects_per_container=1, object_size=1024, **kwargs):
        """Create container and objects then download all objects.

        :param objects_per_container: int, number of objects to upload
        :param object_size: int, temporary local object size
        :param kwargs: dict, optional parameters to create container
        """
        key_suffix = "object"
        if objects_per_container > 1:
            key_suffix = "%i_objects" % objects_per_container

        container_name = None
        objects_list = []
        with tempfile.TemporaryFile() as dummy_file:
            # set dummy file to specified object size
            dummy_file.truncate(object_size)
            container_name = self._create_container(**kwargs)
            with base.AtomicAction(self, "swift.create_%s" % key_suffix):
                for i in range(objects_per_container):
                    dummy_file.seek(0)
                    object_name = self._upload_object(container_name,
                                                      dummy_file,
                                                      atomic_action=False)[1]
                    objects_list.append(object_name)

        with base.AtomicAction(self, "swift.download_%s" % key_suffix):
            for object_name in objects_list:
                self._download_object(container_name,
                                      object_name,
                                      atomic_action=False)
예제 #2
0
파일: utils.py 프로젝트: yongfengdu/rally
    def _upload_object(self, container_name, content, object_name=None,
                       atomic_action=True, **kwargs):
        """Upload content to a given container.

        :param container_name: str, name of the container to upload object to
        :param content: file stream, content to upload
        :param object_name: str, name of the object to upload
        :param atomic_action: bool, enable upload object to be tracked as an
                              atomic action
        :param kwargs: dict, other optional parameters to put_object

        :returns: tuple, (etag and object name)
        """
        if object_name is None:
            object_name = self._generate_random_name(prefix="rally_object_")

        if atomic_action:
            with base.AtomicAction(self, "swift.upload_object"):
                return (self.clients("swift").put_object(container_name,
                                                         object_name, content,
                                                         **kwargs),
                        object_name)

        return (self.clients("swift").put_object(container_name, object_name,
                                                 content, **kwargs),
                object_name)
예제 #3
0
파일: test_base.py 프로젝트: x-ion-de/rally
 def test__exit__(self, mock_time, mock__add_atomic_actions):
     fake_scenario_instance = fakes.FakeScenario()
     self.start = mock_time.time()
     with base.AtomicAction(fake_scenario_instance, "asdf"):
         pass
     duration = mock_time.time() - self.start
     mock__add_atomic_actions.assert_called_once_with("asdf", duration)
예제 #4
0
파일: utils.py 프로젝트: yongfengdu/rally
    def _create_container(self, container_name=None, public=False,
                          atomic_action=True, **kwargs):
        """Create a new container with given name.

        :param container_name: str, name of the container to create
        :param public: bool, set container as public
        :param atomic_action: bool, enable create container to be tracked as an
                              atomic action
        :param kwargs: dict, other optional parameters to put_container

        :returns: container name
        """
        if public:
            kwargs.setdefault("headers", {})
            kwargs["headers"].setdefault("X-Container-Read", ".r:*,.rlistings")

        if container_name is None:
            container_name = self._generate_random_name(
                prefix="rally_container_")

        if atomic_action:
            with base.AtomicAction(self, "swift.create_container"):
                self.clients("swift").put_container(container_name, **kwargs)
        else:
            self.clients("swift").put_container(container_name, **kwargs)
        return container_name
예제 #5
0
파일: utils.py 프로젝트: yongfengdu/rally
    def _delete_metadata(self, volume, keys, deletes=10, delete_size=3):
        """Delete volume metadata keys.

        Note that ``len(keys)`` must be greater than or equal to
        ``deletes * delete_size``.

        :param volume: The volume to delete metadata from
        :param deletes: how many operations to perform
        :param delete_size: number of metadata keys to delete in each operation
        :param keys: a list of keys to choose deletion candidates from
        """
        if len(keys) < deletes * delete_size:
            raise exceptions.InvalidArgumentsException(
                "Not enough metadata keys to delete: "
                "%(num_keys)s keys, but asked to delete %(num_deletes)s" % {
                    "num_keys": len(keys),
                    "num_deletes": deletes * delete_size
                })
        # make a shallow copy of the list of keys so that, when we pop
        # from it later, we don't modify the original list.
        keys = list(keys)
        random.shuffle(keys)
        action_name = "cinder.delete_%s_metadatas_%s_times" % (delete_size,
                                                               deletes)
        with base.AtomicAction(self, action_name):
            for i in range(deletes):
                to_del = keys[i * delete_size:(i + 1) * delete_size]
                self.clients("cinder").volumes.delete_metadata(volume, to_del)
예제 #6
0
파일: stacks.py 프로젝트: yongfengdu/rally
    def list_stacks_and_resources(self):
        """List all resources from tenant stacks."""

        stacks = self._list_stacks()
        with base.AtomicAction(
                self, "heat.list_resources_of_%s_stacks" % len(stacks)):
            for stack in stacks:
                self.clients("heat").resources.list(stack.id)
예제 #7
0
 def test__exit__(self, mock_time):
     fake_scenario_instance = mock.Mock()
     self.start = mock_time.time()
     with base.AtomicAction(fake_scenario_instance, "asdf"):
         pass
     duration = mock_time.time() - self.start
     fake_scenario_instance._add_atomic_actions.assert_called_once_with(
                                         'asdf', duration)
예제 #8
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 base.AtomicAction(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(e.message)
            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)
예제 #9
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 base.AtomicAction(self, "zaqar.post_between_%s_and_%s_messages" %
                               (min_msg_count, max_msg_count)):
            queue.post(messages)
예제 #10
0
 def test_validate_neutron(self, mock_admin_clients, mock_users_clients):
     fc = fakes.FakeClients()
     mock_admin_clients.clients.return_value = fc
     mock_users_clients.clients.return_value = fc
     scenario = authenticate.Authenticate(admin_clients=mock_admin_clients,
                                          clients=mock_users_clients)
     scenario._clients.neutron.get_auth_info = mock.MagicMock()
     with base.AtomicAction(scenario, "authenticate.validate_neutron"):
         scenario.validate_neutron(5)
     self.assertEqual(scenario._clients.neutron().get_auth_info.call_count,
                      5)
예제 #11
0
파일: utils.py 프로젝트: frobware/rally
    def _delete_all_servers(self, force=False):
        """Delete all servers in the current tenant.

        :param force: If True, force_delete will be used instead of delete.
        """
        atomic_name = ("nova.%sdelete_all_servers") % (force
                                                       and "force_" or "")
        with base.AtomicAction(self, atomic_name):
            servers = self.clients("nova").servers.list()
            for server in servers:
                self._delete_server(server, force)
예제 #12
0
파일: utils.py 프로젝트: frobware/rally
    def _create_security_groups(self, security_group_count):
        security_groups = []
        with base.AtomicAction(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
예제 #13
0
 def test_validate_nova(self, mock_admin_clients, mock_users_clients):
     flavors_list = [mock.Mock(), mock.Mock()]
     fc = fakes.FakeClients()
     mock_admin_clients.clients.return_value = fc
     mock_users_clients.clients.return_value = fc
     scenario = authenticate.Authenticate(admin_clients=mock_admin_clients,
                                          clients=mock_users_clients)
     scenario._clients.nova.flavors.list = mock.MagicMock(
         return_value=flavors_list)
     with base.AtomicAction(scenario, "authenticate.validate_nova"):
         scenario.validate_nova(5)
     self.assertEqual(scenario._clients.nova().flavors.list.call_count, 5)
예제 #14
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 base.AtomicAction(self, "authenticate.validate_neutron"):
                neutron_client.get_auth_info()
예제 #15
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 base.AtomicAction(self, "authenticate.validate_heat"):
                list(heat_client.stacks.list(limit=0))
예제 #16
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 base.AtomicAction(self, "authenticate.validate_nova"):
                nova_client.flavors.list()
예제 #17
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 base.AtomicAction(self, "authenticate.validate_cinder"):
                cinder_client.volume_types.list()
예제 #18
0
 def test_validate_heat(self, mock_admin_clients, mock_users_clients):
     stacks_list = [mock.Mock(), mock.Mock()]
     fc = fakes.FakeClients()
     mock_admin_clients.clients.return_value = fc
     mock_users_clients.clients.return_value = fc
     scenario = authenticate.Authenticate(admin_clients=mock_admin_clients,
                                          clients=mock_users_clients)
     scenario._clients.heat.stacks.list = mock.MagicMock(
         return_value=stacks_list)
     with base.AtomicAction(scenario, "authenticate.validate_heat"):
         scenario.validate_heat(5)
     scenario._clients.heat().stacks.list.assert_called_with(limit=0)
     self.assertEqual(scenario._clients.heat().stacks.list.call_count, 5)
예제 #19
0
    def _delete_record(self, domain_id, record_id, atomic_action=True):
        """Delete a record in a domain..

        :param domain_id: Domain ID
        :param record_id: Record ID
        """
        client = self.clients('designate')

        if atomic_action:
            with base.AtomicAction(self, 'designate.delete_record'):
                client.records.create(domain_id, record_id)

        client.records.delete(domain_id, record_id)
예제 #20
0
 def test_validate_cinder(self, mock_admin_clients, mock_users_clients):
     volume_types_list = [mock.Mock(), mock.Mock()]
     fc = fakes.FakeClients()
     mock_admin_clients.clients.return_value = fc
     mock_users_clients.clients.return_value = fc
     scenario = authenticate.Authenticate(admin_clients=mock_admin_clients,
                                          clients=mock_users_clients)
     scenario._clients.cinder.volume_types.list = mock.MagicMock(
         return_value=volume_types_list)
     with base.AtomicAction(scenario, "authenticate.validate_cinder"):
         scenario.validate_cinder(5)
     self.assertEqual(
         scenario._clients.cinder().volume_types.list.call_count, 5)
예제 #21
0
    def validate_glance(self, repetitions):
        """Check Glance 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.
        In following we are checking for non-existent image.

        :param repetitions: number of times to validate
        """
        glance_client = self.clients("glance")
        image_name = "__intentionally_non_existent_image___"
        for i in range(repetitions):
            with base.AtomicAction(self, "authenticate.validate_glance"):
                list(glance_client.images.list(name=image_name))
예제 #22
0
파일: basic.py 프로젝트: varunarya10/rally
    def create_and_delete_records(self, records_per_domain=5):
        """Add and then delete records.

        Measure the performance of creating and deleting records
        with different level of load.

        :param records_per_domain: Records to create pr domain.
        """
        domain = self._create_domain()

        records = []

        key = "designate.create_%s_records" % records_per_domain
        with base.AtomicAction(self, key):
            for i in range(records_per_domain):
                record = self._create_record(domain, atomic_action=False)
                records.append(record)

        key = "designate.delete_%s_records" % records_per_domain
        with base.AtomicAction(self, key):
            for record in records:
                self._delete_record(
                    domain["id"], record["id"], atomic_action=False)
예제 #23
0
파일: utils.py 프로젝트: frobware/rally
 def _create_rules_for_security_group(self, security_groups,
                                      rules_per_security_group,
                                      ip_protocol="tcp", cidr="0.0.0.0/0"):
     action_name = ("nova.create_%s_rules" % (rules_per_security_group *
                                              len(security_groups)))
     with base.AtomicAction(self, action_name):
         for i in range(len(security_groups)):
             for j in range(rules_per_security_group):
                     self.clients("nova").security_group_rules.create(
                         security_groups[i].id,
                         from_port=(i * rules_per_security_group + j + 1),
                         to_port=(i * rules_per_security_group + j + 1),
                         ip_protocol=ip_protocol,
                         cidr=cidr)
예제 #24
0
파일: utils.py 프로젝트: yongfengdu/rally
    def _delete_container(self, container_name, atomic_action=True, **kwargs):
        """Delete a container with given name.

        :param container_name: str, name of the container to delete
        :param atomic_action: bool, enable delete container to be tracked as an
                              atomic action
        :param kwargs: dict, other optional parameters to delete_container
        """
        if atomic_action:
            with base.AtomicAction(self, "swift.delete_container"):
                self.clients("swift").delete_container(container_name,
                                                       **kwargs)
        else:
            self.clients("swift").delete_container(container_name, **kwargs)
예제 #25
0
    def _delete_record(self, domain_id, record_id, atomic_action=True):
        """Delete a domain record.

        :param domain_id: domain ID
        :param record_id: record ID
        :param atomic_action: True if the record creation should be tracked
                              as an atomic action
        """
        client = self.clients("designate")

        if atomic_action:
            with base.AtomicAction(self, "designate.delete_record"):
                client.records.delete(domain_id, record_id)
        else:
            client.records.delete(domain_id, record_id)
예제 #26
0
 def test_validate_glance(self, mock_admin_clients, mock_users_clients):
     images_list = [mock.Mock(), mock.Mock()]
     fc = fakes.FakeClients()
     mock_admin_clients.Clients.return_value = fc
     mock_users_clients.Clients.return_value = fc
     scenario = authenticate.Authenticate(admin_clients=mock_admin_clients,
                                          clients=mock_users_clients)
     scenario._clients.glance.images.list = mock.MagicMock(
         return_value=images_list)
     image_name = "__intentionally_non_existent_image___"
     with base.AtomicAction(scenario, "authenticate.validate_glance"):
         scenario.validate_glance(5)
     scenario._clients.glance().images.list.assert_called_with(
         name=image_name)
     self.assertEqual(scenario._clients.glance().images.list.call_count, 5)
예제 #27
0
    def create_and_delete_records(self, records_per_domain=5):
        """Test adds and then deletes records.

        This is very useful to measure perfromance of creating and deleting
        records with different level of load.

        :param records_per_domain: Records to create pr domain.
        """
        domain = self._create_domain()

        records = []

        key = "designate.create_%s_records" % records_per_domain
        with base.AtomicAction(self, key):
            for i in range(records_per_domain):
                record = self._create_record(domain, atomic_action=False)
                records.append(record)

        key = "designate.delete_%s_records" % records_per_domain
        with base.AtomicAction(self, key):
            for record in records:
                self._delete_record(domain['id'],
                                    record['id'],
                                    atomic_action=False)
예제 #28
0
파일: utils.py 프로젝트: yongfengdu/rally
    def _delete_object(self, container_name, object_name, atomic_action=True,
                       **kwargs):
        """Delete object from container.

        :param container_name: str, name of the container to delete object from
        :param object_name: str, name of the object to delete
        :param atomic_action: bool, enable delete object to be tracked as an
                              atomic action
        :param kwargs: dict, other optional parameters to delete_object
        """
        if atomic_action:
            with base.AtomicAction(self, "swift.delete_object"):
                self.clients("swift").delete_object(container_name,
                                                    object_name, **kwargs)
        else:
            self.clients("swift").delete_object(container_name, object_name,
                                                **kwargs)
예제 #29
0
파일: basic.py 프로젝트: varunarya10/rally
    def create_and_list_records(self, records_per_domain=5):
        """Add and then list records.

        If you have only 1 user in your context, you will
        add 1 record on every iteration. So you will have more
        and more records and will be able to measure the
        performance of the "designate record-list" command depending on
        the number of domains/records owned by users.

        :param records_per_domain: Records to create pr domain.
        """
        domain = self._create_domain()

        key = "designate.create_%s_records" % records_per_domain
        with base.AtomicAction(self, key):
            for i in range(records_per_domain):
                self._create_record(domain, atomic_action=False)

        self._list_records(domain["id"])
예제 #30
0
    def create_and_deploy_environment(self, packages_per_env=1):
        """Create environment, session and deploy environment.

        Create environment, create session, add app to environment
        packages_per_env times, send environment to deploy.

        :param packages_per_env: number of packages per environment
        """
        environment = self._create_environment()
        session = self._create_session(environment.id)
        package = self.context["tenant"]["packages"][0]

        with base.AtomicAction(self, "murano.create_service"):
            for i in range(packages_per_env):
                self._create_service(environment,
                                     session,
                                     package.fully_qualified_name,
                                     atomic_action=False)

        self._deploy_environment(environment, session)