Exemplo n.º 1
0
 def test_arbitrary_string(self):
     actual = data_utils.arbitrary_string()
     self.assertEqual(actual, "test")
     actual = data_utils.arbitrary_string(size=30, base_text="abc")
     self.assertEqual(actual, "abc" * int(30 / len("abc")))
     actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf")
     self.assertEqual(actual, "deadb")
Exemplo n.º 2
0
 def test_identity_update_user(self):
     user_create = self.user()
     # create user in other domain
     user_create['domain_id'] = self.other_domain['id']
     user = self.admin_users_client.create_user(**user_create)['user']
     self.addCleanup(self.admin_users_client.delete_user, user['id'])
     user_update = {
         'user_id': user['id'],
         'description': data_utils.arbitrary_string()
     }
     self.do_request('update_user',
                     expected_status=exceptions.Forbidden,
                     **user_update)
     # create user in own domain
     user_create['domain_id'] = self.persona.credentials.domain_id
     user = self.admin_users_client.create_user(**user_create)['user']
     self.addCleanup(self.admin_users_client.delete_user, user['id'])
     user_update = {
         'user_id': user['id'],
         'description': data_utils.arbitrary_string()
     }
     self.do_request('update_user',
                     expected_status=exceptions.Forbidden,
                     **user_update)
     # user gets a 403 for nonexistent user
     user_update = {
         'user_id': 'fakeuser',
         'description': data_utils.arbitrary_string()
     }
     self.do_request('update_user',
                     expected_status=exceptions.Forbidden,
                     **user_update)
Exemplo n.º 3
0
 def test_arbitrary_string(self):
     actual = data_utils.arbitrary_string()
     self.assertEqual(actual, "test")
     actual = data_utils.arbitrary_string(size=30, base_text="abc")
     self.assertEqual(actual, "abc" * int(30 / len("abc")))
     actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf")
     self.assertEqual(actual, "deadb")
Exemplo n.º 4
0
 def test_create_subscriptions_with_invalid_body(self):
     # Missing subscriber parameter in body
     message_ttl = data_utils.\
         rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     rbody = {'options': option_body, 'ttl': message_ttl}
     self.assertRaises(lib_exc.BadRequest,
                       self.create_subscription, self.queue_name, rbody)
 def test_create_subscriptions_with_invalid_body(self):
     # Missing subscriber parameter in body
     message_ttl = data_utils.\
         rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     rbody = {'options': option_body, 'ttl': message_ttl}
     self.assertRaises(lib_exc.BadRequest, self.create_subscription,
                       self.queue_name, rbody)
Exemplo n.º 6
0
    def generate_message_body(cls, repeat=1):
        """Wrapper utility that sets the metadata of a queue."""
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
        return rbody
Exemplo n.º 7
0
 def test_identity_update_project(self):
     project_id = self.admin_projects_client.create_project(
         name=data_utils.rand_name())['project']['id']
     self.addCleanup(self.admin_projects_client.delete_project, project_id)
     self.do_request('update_project',
                     project_id=project_id,
                     description=data_utils.arbitrary_string())
     # user gets a 404 for nonexistent domain
     self.do_request('update_project',
                     expected_status=exceptions.NotFound,
                     project_id=data_utils.rand_uuid_hex(),
                     description=data_utils.arbitrary_string())
Exemplo n.º 8
0
    def generate_message_body(cls, repeat=1):
        """Wrapper utility that sets the metadata of a queue."""
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
        return rbody
Exemplo n.º 9
0
    def test_create_namespace(self):
        # Check non-admin role of 'project' not allowed to create namespace
        self.do_request('create_namespace',
                        expected_status=exceptions.Forbidden,
                        client=self.namespace_client,
                        namespace=data_utils.arbitrary_string())

        # Check non-admin role of 'alt_project' not allowed to create namespace
        self.do_request('create_namespace',
                        expected_status=exceptions.Forbidden,
                        client=self.alt_namespace_client,
                        namespace=data_utils.arbitrary_string())
Exemplo n.º 10
0
 def test_identity_update_role(self):
     # user can update role
     role = self.admin_roles_client.create_role(**self.role())['role']
     self.addCleanup(self.admin_roles_client.delete_role, role['id'])
     self.do_request('update_role',
                     role_id=role['id'],
                     description=data_utils.arbitrary_string())
     # user gets a 404 for nonexistent role
     self.do_request('update_role',
                     expected_status=exceptions.NotFound,
                     role_id=data_utils.rand_uuid_hex(),
                     description=data_utils.arbitrary_string())
Exemplo n.º 11
0
    def generate_subscription_body(cls):
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        option_body = {key: value}
        subscribers = ['http://*****:*****@123.com']
        rbody = [{'options': option_body, 'ttl': message_ttl,
                  'subscriber': subscriber} for subscriber in subscribers]
        return rbody
Exemplo n.º 12
0
 def test_create_subscriptions_with_non_integer_value_for_ttl(self):
     # The subscriber type of subscription must be supported in the list
     # ['http', 'https', 'mailto']
     message_ttl = "123"
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     subscriber = 'http://fake:8080'
     rbody = {'options': option_body, 'ttl': message_ttl,
              'subscriber': subscriber}
     self.assertRaises(lib_exc.BadRequest,
                       self.create_subscription, self.queue_name, rbody)
Exemplo n.º 13
0
 def test_create_subscriptions_with_non_integer_value_for_ttl(self):
     # The subscriber type of subscription must be supported in the list
     # ['http', 'https', 'mailto']
     message_ttl = "123"
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     subscriber = 'http://fake:8080'
     rbody = {'options': option_body, 'ttl': message_ttl,
              'subscriber': subscriber}
     self.assertRaises(lib_exc.BadRequest,
                       self.create_subscription, self.queue_name, rbody)
 def test_identity_update_service_provider(self):
     sp_id = self.admin_sp_client.create_service_provider(
         sp_id=data_utils.rand_name(),
         auth_url=data_utils.rand_url(),
         sp_url=data_utils.rand_url())['service_provider']['id']
     self.addCleanup(self.admin_sp_client.delete_service_provider, sp_id)
     self.do_request('update_service_provider',
                     sp_id=sp_id,
                     description=data_utils.arbitrary_string())
     # user gets a 404 for nonexistent sp
     self.do_request('update_service_provider',
                     expected_status=exceptions.NotFound,
                     sp_id=data_utils.rand_uuid_hex(),
                     description=data_utils.arbitrary_string())
Exemplo n.º 15
0
    def test_post_messages_without_TTL(self):
        # TTL for a message may not exceed 1209600 seconds, and
        # must be at least 60 seconds long.
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body}] * 1)

        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
Exemplo n.º 16
0
 def test_create_subscriptions_with_invalid_subscriber(self):
     # The subscriber type of subscription must be supported in the list
     # ['http', 'https', 'mailto']
     message_ttl = data_utils.\
         rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     subscriber = 'fake'
     rbody = {'options': option_body, 'ttl': message_ttl,
              'subscriber': subscriber}
     self.assertRaises(lib_exc.BadRequest,
                       self.create_subscription, self.queue_name, rbody)
Exemplo n.º 17
0
    def test_post_messages_without_TTL(self):
        # TTL for a message may not exceed 1209600 seconds, and
        # must be at least 60 seconds long.
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body}] * 1)

        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
Exemplo n.º 18
0
 def test_create_subscriptions_with_unsupported_subscriber(self):
     # The subscriber type of subscription must be supported in the list
     # ['http', 'https', 'mailto']
     message_ttl = data_utils.\
         rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
     key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
     value = data_utils.arbitrary_string(size=20,
                                         base_text='MessagingValue')
     option_body = {key: value}
     subscriber = 'email://fake'
     rbody = {'options': option_body, 'ttl': message_ttl,
              'subscriber': subscriber}
     self.assertRaises(lib_exc.BadRequest,
                       self.create_subscription, self.queue_name, rbody)
Exemplo n.º 19
0
    def test_post_messages_with_invalid_body_size(self):
        # Maximum number of queue message per page
        # while posting messages is 20
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        message_body = {key: value}
        rbody = ([{'body': message_body, 'ttl': message_ttl}] * 21)
        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
Exemplo n.º 20
0
    def test_post_messages_with_invalid_body_size(self):
        # Maximum number of queue message per page
        # while posting messages is 20
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        message_body = {key: value}
        rbody = ([{'body': message_body, 'ttl': message_ttl}] * 21)
        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
 def test_identity_update_endpoint_group(self):
     eg = self.admin_eg_client.create_endpoint_group(
         **self.endpoint_group())['endpoint_group']['id']
     self.addCleanup(self.admin_eg_client.delete_endpoint_group, eg)
     # user can update an endpoint group
     self.do_request('update_endpoint_group',
                     client=self.eg_client,
                     endpoint_group_id=eg,
                     description=data_utils.arbitrary_string())
     # nonexistent endpoint group gives a 404
     self.do_request('update_endpoint_group',
                     client=self.eg_client,
                     expected_status=exceptions.NotFound,
                     endpoint_group_id=data_utils.rand_uuid_hex(),
                     description=data_utils.arbitrary_string())
Exemplo n.º 22
0
 def test_update_node_resource_class_old_api(self):
     """Try to update a node with resource class using older api version."""
     resource_class = data_utils.arbitrary_string()
     self.assertRaises(lib_exc.UnexpectedResponseCode,
                       self.client.update_node,
                       self.node['uuid'],
                       resource_class=resource_class)
Exemplo n.º 23
0
 def test_update_node_resource_class_too_long(self):
     """Try to update a node with too long resource class name."""
     resource_class = data_utils.arbitrary_string(81)
     self.assertRaises(lib_exc.BadRequest,
                       self.client.update_node,
                       self.node['uuid'],
                       resource_class=resource_class)
Exemplo n.º 24
0
    def test_upload_valid_object(self):
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        self.assertHeaders(resp, 'Object', 'PUT')
Exemplo n.º 25
0
 def test_identity_update_user(self):
     user = self.admin_users_client.create_user(**self.user())['user']
     self.addCleanup(self.admin_users_client.delete_user, user['id'])
     user_update = {
         'user_id': user['id'],
         'description': data_utils.arbitrary_string()
     }
     self.do_request('update_user', **user_update)
     # user gets a 404 for nonexistent user
     user_update = {
         'user_id': 'fakeuser',
         'description': data_utils.arbitrary_string()
     }
     self.do_request('update_user',
                     expected_status=exceptions.NotFound,
                     **user_update)
Exemplo n.º 26
0
 def test_create_node_resource_class_long(self):
     """Create new node with specified longest name of resource class."""
     res_class_long_name = data_utils.arbitrary_string(80)
     _, body = self.create_node(
         self.chassis['uuid'],
         resource_class=res_class_long_name)
     self.assertEqual(res_class_long_name, body['resource_class'])
Exemplo n.º 27
0
 def test_identity_update_limit(self):
     reg_limit_id = self.admin_limits_client.create_limits(
         payload=self.limits())['limits'][0]['id']
     self.addCleanup(self.admin_limits_client.delete_limit,
                     limit_id=reg_limit_id)
     updated = {'description': data_utils.arbitrary_string()}
     self.do_request('update_limit', limit_id=reg_limit_id, limit=updated)
Exemplo n.º 28
0
    def verify_metadata(self):
        if self.run_ssh and CONF.compute_feature_enabled.metadata_service:
            # Verify metadata service
            md_url = 'http://169.254.169.254/latest/meta-data/public-ipv4'

            def exec_cmd_and_verify_output():
                cmd = 'curl ' + md_url
                result = self.ssh_client.exec_command(cmd)
                if result:
                    msg = ('Failed while verifying metadata on server. Result '
                           'of command "%s" is NOT "%s".' % (cmd, self.fip))
                    self.assertEqual(self.fip, result, msg)
                    return 'Verification is successful!'

            if not test_utils.call_until_true(exec_cmd_and_verify_output,
                                              CONF.compute.build_timeout,
                                              CONF.compute.build_interval):
                raise exceptions.TimeoutException('Timed out while waiting to '
                                                  'verify metadata on server. '
                                                  '%s is empty.' % md_url)

            # Also, test a POST
            md_url = 'http://169.254.169.254/openstack/2013-10-17/password'
            data = data_utils.arbitrary_string(100)
            cmd = 'curl -X POST -d ' + data + ' ' + md_url
            self.ssh_client.exec_command(cmd)
            result = self.servers_client.show_password(self.instance['id'])
            self.assertEqual(data, result['password'])
Exemplo n.º 29
0
    def test_upload_valid_object(self):
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        self.assertHeaders(resp, 'Object', 'PUT')
Exemplo n.º 30
0
    def verify_metadata(self):
        if self.run_ssh and CONF.compute_feature_enabled.metadata_service:
            # Verify metadata service
            md_url = 'http://169.254.169.254/latest/meta-data/public-ipv4'

            def exec_cmd_and_verify_output():
                cmd = 'curl ' + md_url
                result = self.ssh_client.exec_command(cmd)
                if result:
                    msg = ('Failed while verifying metadata on server. Result '
                           'of command "%s" is NOT "%s".' % (cmd, self.fip))
                    self.assertEqual(self.fip, result, msg)
                    return 'Verification is successful!'

            if not test_utils.call_until_true(exec_cmd_and_verify_output,
                                              CONF.compute.build_timeout,
                                              CONF.compute.build_interval):
                raise exceptions.TimeoutException('Timed out while waiting to '
                                                  'verify metadata on server. '
                                                  '%s is empty.' % md_url)

            # Also, test a POST
            md_url = 'http://169.254.169.254/openstack/2013-10-17/password'
            data = data_utils.arbitrary_string(100)
            cmd = 'curl -X POST -d ' + data + ' ' + md_url
            self.ssh_client.exec_command(cmd)
            result = self.servers_client.show_password(self.instance['id'])
            self.assertEqual(data, result['password'])
Exemplo n.º 31
0
 def test_create_node_resource_class_long(self):
     """Create new node with specified longest name of resource class."""
     res_class_long_name = data_utils.arbitrary_string(80)
     _, body = self.create_node(
         self.chassis['uuid'],
         resource_class=res_class_long_name)
     self.assertEqual(res_class_long_name, body['resource_class'])
Exemplo n.º 32
0
    def test_web_error(self):
        """Test web error"""
        headers = {'web-listings': 'true',
                   'web-error': self.object_name}

        self.container_client.create_update_or_delete_container_metadata(
            self.container_name, create_update_metadata=headers)

        # Create object to return when requested object not found
        object_name_404 = "404" + self.object_name
        object_data_404 = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name,
                                         object_name_404,
                                         object_data_404)

        # Do not set auth in HTTP headers for next request
        self.object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )

        # Request non-existing object
        self.assertRaises(
            lib_exc.NotFound, self.object_client.get_object,
            self.container_name, "notexisting")
Exemplo n.º 33
0
    def test_add_node_trait_long(self):
        """Add a node trait of the largest possible length."""
        trait_long_name = 'CUSTOM_' + data_utils.arbitrary_string(248).upper()
        self.client.add_node_trait(self.node['uuid'], trait_long_name)

        _, body = self.client.list_node_traits(self.node['uuid'])
        self.assertEqual([trait_long_name], body['traits'])
Exemplo n.º 34
0
 def test_identity_update_consumer(self):
     consumer = self.admin_client.create_consumer(
         **self.consumer())['consumer']
     self.addCleanup(self.admin_client.delete_consumer, consumer['id'])
     self.do_request('update_consumer',
                     expected_status=exceptions.Forbidden,
                     consumer_id=consumer['id'],
                     description=data_utils.arbitrary_string())
 def upload_object_to_container(self, container_name):
     obj_name = data_utils.rand_name('swift-scenario-object')
     obj_data = data_utils.arbitrary_string()
     self.object_client.create_object(container_name, obj_name, obj_data)
     self.addCleanup(self.object_client.delete_object,
                     container_name,
                     obj_name)
     return obj_name
 def test_create_persistent_object(self):
     object_name = data_utils.rand_name(name='TestObject')
     data = data_utils.arbitrary_string(15)
     resp, _ = self.object_client.create_object(self.containers[0],
                                                object_name, data)
     self.assertHeaders(resp, 'Object', 'PUT')
     self.objects.append(object_name)
     self.object_data.append(data)
 def registered_limits(self):
     return [{
         "service_id": self.service_id,
         "region_id": self.region_id,
         "resource_name": data_utils.rand_name(),
         "default_limit": 5,
         "description": data_utils.arbitrary_string()
     }]
Exemplo n.º 38
0
    def generate_subscription_body(cls):
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        option_body = {key: value}
        subscribers = [
            'http://*****:*****@123.com'
        ]
        rbody = [{
            'options': option_body,
            'ttl': message_ttl,
            'subscriber': subscriber
        } for subscriber in subscribers]
        return rbody
Exemplo n.º 39
0
    def test_post_messages_with_TTL_less_than_60(self):
        # TTL for a message may not exceed 1209600 seconds,
        # and must be at least 60 seconds long.
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        message_ttl = data_utils.\
            rand_int_id(start=0, end=60)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1)

        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
Exemplo n.º 40
0
    def test_post_messages_with_TTL_less_than_60(self):
        # TTL for a message may not exceed 1209600 seconds,
        # and must be at least 60 seconds long.
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        message_ttl = data_utils.\
            rand_int_id(start=0, end=60)

        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1)

        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
Exemplo n.º 41
0
    def test_add_node_trait_too_long(self):
        """Try to add a node trait longer than the largest possible length."""
        trait_long_name = 'CUSTOM_' + data_utils.arbitrary_string(249).upper()
        self.assertRaises(lib_exc.BadRequest, self.client.add_node_trait,
                          self.node['uuid'], trait_long_name)

        _, body = self.client.list_node_traits(self.node['uuid'])
        self.assertEqual([], body['traits'])
Exemplo n.º 42
0
 def test_list_nodes_by_resource_class_old_api(self):
     """Try to list nodes with resource class using older api version."""
     resource_class = data_utils.arbitrary_string()
     self.assertRaises(
         lib_exc.UnexpectedResponseCode,
         self.client.list_nodes, resource_class=resource_class)
     self.assertRaises(
         lib_exc.UnexpectedResponseCode,
         self.client.list_nodes_detail, resource_class=resource_class)
 def test_identity_update_identity_provider(self):
     idp = self.admin_idp_client.create_identity_provider(
         idp_id=data_utils.rand_name())['identity_provider']
     self.addCleanup(self.admin_client.domains_client.delete_domain,
                     idp['domain_id'])
     self.addCleanup(self.admin_client.domains_client.update_domain,
                     idp['domain_id'],
                     enabled=False)
     self.addCleanup(self.admin_idp_client.delete_identity_provider,
                     idp['id'])
     self.do_request('update_identity_provider',
                     idp_id=idp['id'],
                     description=data_utils.arbitrary_string())
     # user gets a 404 for nonexistent idp
     self.do_request('update_identity_provider',
                     expected_status=exceptions.NotFound,
                     idp_id=data_utils.rand_uuid_hex(),
                     description=data_utils.arbitrary_string())
Exemplo n.º 44
0
    def test_create_a_subscription_without_a_token(self):
        # X-Auth-Token is not provided
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = data_utils.arbitrary_string(size=20,
                                            base_text='MessagingValue')
        option_body = {key: value}
        subscriber = 'http://fake:8080'
        rbody = {'options': option_body, 'ttl': message_ttl,
                 'subscriber': subscriber}

        self.client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )
        self.assertRaises(lib_exc.Unauthorized,
                          self.create_subscription, self.queue_name, rbody)
    def _create_object(self, container_name, object_name=None):
        # setup object
        if object_name is None:
            object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        self.object_client.create_object(container_name,
                                         object_name,
                                         data)

        return object_name
 def test_create_container_name_exceeds_max_length(self):
     # Attempts to create a container name that is longer than max
     max_length = self.constraints['max_container_name_length']
     # create a container with long name
     container_name = data_utils.arbitrary_string(size=max_length + 1)
     ex = self.assertRaises(exceptions.BadRequest,
                            self.container_client.create_container,
                            container_name)
     self.assertIn('Container name length of ' + str(max_length + 1) +
                   ' longer than ' + str(max_length), str(ex))
 def test_create_container_metadata_value_exceeds_max_length(self):
     # Attempts to create container with metadata value
     # that is longer than max.
     max_length = self.constraints['max_meta_value_length']
     container_name = data_utils.rand_name(name='TestContainer')
     metadata_value = data_utils.arbitrary_string(size=max_length + 1)
     metadata = {'animal': metadata_value}
     ex = self.assertRaises(exceptions.BadRequest,
                            self.container_client.create_container,
                            container_name, metadata=metadata)
     self.assertIn('Metadata value longer than ' + str(max_length), str(ex))
Exemplo n.º 48
0
    def _upload_segments(self):
        # create object
        object_name = data_utils.rand_name(name='LObject')
        data = data_utils.arbitrary_string()
        segments = 10
        data_segments = [data + str(i) for i in range(segments)]
        # uploading segments
        for i in range(segments):
            self.object_client.create_object_segments(
                self.container_name, object_name, i, data_segments[i])

        return object_name, data_segments
Exemplo n.º 49
0
    def test_upload_valid_object(self):
        """Attempts to uploads an object smaller than the bytes quota."""
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string(QUOTA_BYTES)

        nbefore = self._get_bytes_used()

        resp, _ = self.object_client.create_object(
            self.container_name, object_name, data)
        self.assertHeaders(resp, 'Object', 'PUT')

        nafter = self._get_bytes_used()
        self.assertEqual(nbefore + len(data), nafter)
 def test_create_container_metadata_name_exceeds_max_length(self):
     # Attempts to create container with metadata name
     # that is longer than max.
     max_length = self.constraints['max_meta_name_length']
     container_name = data_utils.rand_name(name='TestContainer')
     metadata_name = 'X-Container-Meta-' + data_utils.arbitrary_string(
         size=max_length + 1)
     metadata = {metadata_name: 'penguin'}
     ex = self.assertRaises(
         exceptions.BadRequest,
         self.container_client.update_container,
         container_name, **metadata)
     self.assertIn('Metadata name too long', str(ex))
Exemplo n.º 51
0
    def test_upload_large_object(self):
        """Attempts to upload an object larger than the bytes quota."""
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string(QUOTA_BYTES + 1)

        nbefore = self._get_bytes_used()

        self.assertRaises(lib_exc.OverLimit,
                          self.object_client.create_object,
                          self.container_name, object_name, data)

        nafter = self._get_bytes_used()
        self.assertEqual(nbefore, nafter)
Exemplo n.º 52
0
    def create_object(cls, container_name, object_name=None,
                      data=None, metadata=None):
        # wrapper that returns a test object
        if object_name is None:
            object_name = data_utils.rand_name(name='TestObject')
        if data is None:
            data = data_utils.arbitrary_string()
        cls.object_client.create_object(container_name,
                                        object_name,
                                        data,
                                        metadata=metadata)

        return object_name, data
Exemplo n.º 53
0
    def test_post_messages_exceeding_message_post_size(self):
        # Post messages with greater message size
        queue_name = self.queues[data_utils.rand_int_id(0,
                                                        len(self.queues) - 1)]
        key = data_utils.arbitrary_string(size=20, base_text='MessagingKey')
        value = 'a' * 1024
        message_ttl = data_utils.\
            rand_int_id(start=60, end=CONF.messaging.max_message_ttl)

        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * 1)

        self.assertRaises(lib_exc.BadRequest,
                          self.client.post_messages, queue_name, rbody)
    def setUp(self):
        super(ObjectTempUrlNegativeTest, self).setUp()
        # make sure the metadata has been set
        self.assertIn('x-account-meta-temp-url-key',
                      self.account_client_metadata)

        self.assertEqual(
            self.account_client_metadata['x-account-meta-temp-url-key'],
            self.key)

        # create object
        self.object_name = data_utils.rand_name(name='ObjectTemp')
        content = data_utils.arbitrary_string(size=len(self.object_name),
                                              base_text=self.object_name)
        self.object_client.create_object(self.container_name,
                                         self.object_name, content)
Exemplo n.º 55
0
    def test_object_upload_in_segments(self):
        # create object
        object_name = data_utils.rand_name(name='LObject')
        data = data_utils.arbitrary_string()
        segments = 10
        data_segments = [data + str(i) for i in range(segments)]
        # uploading segments
        for i in range(segments):
            obj_name = "%s/%s" % (object_name, i)
            resp, _ = self.object_client.create_object(
                self.container_name, obj_name, data_segments[i])
        # creating a manifest file
        metadata = {'X-Object-Manifest': '%s/%s/'
                    % (self.container_name, object_name)}
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data='')
        self.assertHeaders(resp, 'Object', 'PUT')

        resp, _ = self.object_client.create_or_update_object_metadata(
            self.container_name, object_name, headers=metadata)
        self.assertHeaders(resp, 'Object', 'POST')

        resp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)

        # Etag value of a large object is enclosed in double-quotations.
        # After etag quotes are checked they are removed and the response is
        # checked if all common headers are present and well formatted
        self.assertTrue(resp['etag'].startswith('\"'))
        self.assertTrue(resp['etag'].endswith('\"'))
        resp['etag'] = resp['etag'].strip('"')
        self.assertHeaders(resp, 'Object', 'HEAD')

        self.assertIn('x-object-manifest', resp)
        self.assertEqual(resp['x-object-manifest'],
                         '%s/%s/' % (self.container_name, object_name))

        # downloading the object
        resp, body = self.object_client.get_object(
            self.container_name, object_name)
        self.assertEqual(''.join(data_segments), body.decode())
Exemplo n.º 56
0
    def test_update_object_metadata_with_x_remove_object_metakey(self):
        # update object metadata with a blank value of remove metadata
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        create_metadata = {'X-Object-Meta-test-meta': 'Meta'}
        self.object_client.create_object(self.container_name,
                                         object_name,
                                         data,
                                         metadata=create_metadata)

        update_metadata = {'X-Remove-Object-Meta-test-meta': ''}
        resp, _ = self.object_client.create_or_update_object_metadata(
            self.container_name,
            object_name,
            headers=update_metadata)
        self.assertHeaders(resp, 'Object', 'POST')

        resp, _ = self.object_client.list_object_metadata(
            self.container_name,
            object_name)
        self.assertNotIn('x-object-meta-test-meta', resp)
Exemplo n.º 57
0
    def test_web_error(self):
        headers = {'web-listings': 'true',
                   'web-error': self.object_name}

        self.container_client.update_container_metadata(
            self.container_name, metadata=headers)

        # Create object to return when requested object not found
        object_name_404 = "404" + self.object_name
        object_data_404 = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name,
                                         object_name_404,
                                         object_data_404)

        # Do not set auth in HTTP headers for next request
        self.object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )

        # Request non-existing object
        self.assertRaises(
            lib_exc.NotFound, self.object_client.get_object,
            self.container_name, "notexisting")
Exemplo n.º 58
0
 def test_update_node_resource_class_too_long(self):
     """Try to update a node with too long resource class name."""
     resource_class = data_utils.arbitrary_string(81)
     self.assertRaises(lib_exc.BadRequest, self.client.update_node,
                       self.node['uuid'], resource_class=resource_class)
Exemplo n.º 59
0
 def test_update_node_resource_class_old_api(self):
     """Try to update a node with resource class using older api version."""
     resource_class = data_utils.arbitrary_string()
     self.assertRaises(lib_exc.UnexpectedResponseCode,
                       self.client.update_node,
                       self.node['uuid'], resource_class=resource_class)