Exemplo n.º 1
0
    def test_create_update_delete_domain(self):
        d_name = data_utils.rand_name('domain')
        d_desc = data_utils.rand_name('domain-desc')
        domain = self.client.create_domain(
            d_name, description=d_desc)
        self.addCleanup(self._delete_domain, domain['id'])
        self.assertIn('id', domain)
        self.assertIn('description', domain)
        self.assertIn('name', domain)
        self.assertIn('enabled', domain)
        self.assertIn('links', domain)
        self.assertIsNotNone(domain['id'])
        self.assertEqual(d_name, domain['name'])
        self.assertEqual(d_desc, domain['description'])
        self.assertEqual(True, domain['enabled'])
        new_desc = data_utils.rand_name('new-desc')
        new_name = data_utils.rand_name('new-name')

        updated_domain = self.client.update_domain(
            domain['id'], name=new_name, description=new_desc)
        self.assertIn('id', updated_domain)
        self.assertIn('description', updated_domain)
        self.assertIn('name', updated_domain)
        self.assertIn('enabled', updated_domain)
        self.assertIn('links', updated_domain)
        self.assertIsNotNone(updated_domain['id'])
        self.assertEqual(new_name, updated_domain['name'])
        self.assertEqual(new_desc, updated_domain['description'])
        self.assertEqual('true', str(updated_domain['enabled']).lower())

        fetched_domain = self.client.get_domain(domain['id'])
        self.assertEqual(new_name, fetched_domain['name'])
        self.assertEqual(new_desc, fetched_domain['description'])
        self.assertEqual('true', str(fetched_domain['enabled']).lower())
Exemplo n.º 2
0
    def test_create_update_delete_ike_policy(self):
        # Creates a IKE policy
        name = data_utils.rand_name('ike-policy')
        body = (self.client.create_ikepolicy(
                name=name,
                ike_version="v1",
                encryption_algorithm="aes-128",
                auth_algorithm="sha1"))
        ikepolicy = body['ikepolicy']
        self.assertIsNotNone(ikepolicy['id'])
        self.addCleanup(self._delete_ike_policy, ikepolicy['id'])

        # Update IKE Policy
        new_ike = {'name': data_utils.rand_name("New-IKE"),
                   'description': "Updated ike policy",
                   'encryption_algorithm': "aes-256",
                   'ike_version': "v2",
                   'pfs': "group14",
                   'lifetime': {'units': "seconds", 'value': 2000}}
        self.client.update_ikepolicy(ikepolicy['id'], **new_ike)
        # Confirm that update was successful by verifying using 'show'
        body = self.client.show_ikepolicy(ikepolicy['id'])
        ike_policy = body['ikepolicy']
        for key, value in new_ike.iteritems():
            self.assertIn(key, ike_policy)
            self.assertEqual(value, ike_policy[key])

        # Verification of ike policy delete
        self.client.delete_ikepolicy(ikepolicy['id'])
        body = self.client.list_ikepolicies()
        ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
        self.assertNotIn(ike_policy['id'], ikepolicies)
Exemplo n.º 3
0
    def resource_setup(cls):
        super(AuthorizationTestJSON, cls).resource_setup()
        server = cls.create_test_server(wait_until='ACTIVE')
        cls.server = cls.client.get_server(server['id'])

        name = data_utils.rand_name('image')
        body = cls.glance_client.create_image(name=name,
                                              container_format='bare',
                                              disk_format='raw',
                                              is_public=False)
        image_id = body['id']
        image_file = StringIO.StringIO(('*' * 1024))
        body = cls.glance_client.update_image(image_id, data=image_file)
        cls.glance_client.wait_for_image_status(image_id, 'active')
        cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = data_utils.rand_name('keypair')
        cls.keypairs_client.create_keypair(cls.keypairname)

        name = data_utils.rand_name('security')
        description = data_utils.rand_name('description')
        cls.security_group = cls.security_client.create_security_group(
            name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port)
Exemplo n.º 4
0
    def test_create_object_with_x_fresh_metadata(self):
        # create object with x_fresh_metadata
        object_name_base = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        metadata_1 = {'X-Object-Meta-test-meta': 'Meta'}
        self.object_client.create_object(self.container_name,
                                         object_name_base,
                                         data,
                                         metadata=metadata_1)
        object_name = data_utils.rand_name(name='TestObject')
        metadata_2 = {'X-Copy-From': '%s/%s' % (self.container_name,
                                                object_name_base),
                      'X-Fresh-Metadata': 'true'}
        resp, _ = self.object_client.create_object(
            self.container_name,
            object_name,
            '',
            metadata=metadata_2)
        self.assertHeaders(resp, 'Object', 'PUT')

        resp, body = self.object_client.get_object(self.container_name,
                                                   object_name)
        #Bug = 1417489
        #self.assertNotIn('x-object-meta-test-meta', resp)
        self.assertEqual(data, body)
 def resource_setup(cls):
     super(LoadBalancerTestJSON, cls).resource_setup()
     _params = cls.manager.default_params_with_timeout_values.copy()
     for p in _params.keys():
         if p in ['service', 'region', 'endpoint_type']:
             _params.pop(p)
     cls.lbv1_client = LBV1C.get_client(cls.manager)
     cls.network = cls.create_network()
     cls.name = cls.network['name']
     cls.subnet = cls.create_subnet(cls.network)
     cls.ext_net_id = CONF.network.public_network_id
     cls.router = cls.create_router(data_utils.rand_name('router-'),
                                    admin_state_up=True,
                                    external_network_id=cls.ext_net_id,
                                    router_type='exclusive')
     cls.create_router_interface(cls.router['id'], cls.subnet['id'])
     pool_name = data_utils.rand_name('pool-')
     vip_name = data_utils.rand_name('vip-')
     cls.pool = cls.lbv1_client.create_pool(
         pool_name, "ROUND_ROBIN", "HTTP", cls.subnet['id'])['pool']
     cls.vip = cls.lbv1_client.create_vip(cls.pool['id'],
                                          subnet_id=cls.subnet['id'],
                                          name=vip_name,
                                          protocol="HTTP",
                                          protocol_port=80)['vip']
     cls.member = cls.lbv1_client.create_member(
         80, cls.pool['id'], cls._ip_version)['member']
     cls.member_address = ("10.0.9.47" if cls._ip_version == 4
                           else "2015::beef")
     cls.health_monitor = cls.lbv1_client.create_health_monitor(
         delay=4, max_retries=3, type="TCP", timeout=1)['health_monitor']
Exemplo n.º 6
0
    def test_security_groups_rules_exceed_limit(self):
        # Negative test: Creation of Security Group Rules should FAIL
        # when we reach limit maxSecurityGroupRules

        quota_set = self.adm_client.get_quota_set(self.demo_tenant_id)
        default_sg_rules_quota = quota_set['security_group_rules']
        sg_rules_quota = 0  # Set the quota to zero to conserve resources

        quota_set =\
            self.adm_client.update_quota_set(
                self.demo_tenant_id,
                force=True,
                security_group_rules=sg_rules_quota)

        self.addCleanup(self.adm_client.update_quota_set,
                        self.demo_tenant_id,
                        security_group_rules=default_sg_rules_quota)

        s_name = data_utils.rand_name('securitygroup')
        s_description = data_utils.rand_name('description')
        securitygroup =\
            self.sg_client.create_security_group(s_name, s_description)
        self.addCleanup(self.sg_client.delete_security_group,
                        securitygroup['id'])

        secgroup_id = securitygroup['id']
        ip_protocol = 'tcp'

        # Check we cannot create SG rule anymore
        # A 403 Forbidden or 413 Overlimit (old behaviour) exception
        # will be raised when out of quota
        self.assertRaises((lib_exc.OverLimit, lib_exc.Forbidden),
                          self.sg_client.create_security_group_rule,
                          secgroup_id, ip_protocol, 1025, 1025)
Exemplo n.º 7
0
    def test_create_list_update_show_delete_security_group(self):
        group_create_body, name = self._create_security_group()

        # List security groups and verify if created group is there in response
        list_body = self.client.list_security_groups()
        secgroup_list = list()
        for secgroup in list_body['security_groups']:
            secgroup_list.append(secgroup['id'])
        self.assertIn(group_create_body['security_group']['id'], secgroup_list)
        # Update the security group
        new_name = data_utils.rand_name('security-')
        new_description = data_utils.rand_name('security-description')
        update_body = self.client.update_security_group(
            group_create_body['security_group']['id'],
            name=new_name,
            description=new_description)
        # Verify if security group is updated
        self.assertEqual(update_body['security_group']['name'], new_name)
        self.assertEqual(update_body['security_group']['description'],
                         new_description)
        # Show details of the updated security group
        show_body = self.client.show_security_group(
            group_create_body['security_group']['id'])
        self.assertEqual(show_body['security_group']['name'], new_name)
        self.assertEqual(show_body['security_group']['description'],
                         new_description)
Exemplo n.º 8
0
    def test_get_share_with_share_type(self):

        # Data
        share_name = data_utils.rand_name("share")
        shr_type_name = data_utils.rand_name("share-type")
        extra_specs = self.add_required_extra_specs_to_dict({
            "storage_protocol": CONF.share.capability_storage_protocol,
        })

        # Create share type
        st_create = self.create_share_type(
            shr_type_name, extra_specs=extra_specs)

        # Create share with share type
        share = self.create_share(
            name=share_name, share_type_id=st_create["share_type"]["id"])
        self.assertEqual(share["name"], share_name)
        self.shares_client.wait_for_share_status(share["id"], "available")

        # Verify share info
        get = self.shares_v2_client.get_share(share["id"], version="2.5")
        self.assertEqual(share_name, get["name"])
        self.assertEqual(share["id"], get["id"])
        self.assertEqual(shr_type_name, get["share_type"])

        get = self.shares_v2_client.get_share(share["id"], version="2.6")
        self.assertEqual(st_create["share_type"]["id"], get["share_type"])
        self.assertEqual(shr_type_name, get["share_type_name"])
Exemplo n.º 9
0
    def create_standard_security_group(self):
        name = data_utils.rand_name('sgName')
        desc = data_utils.rand_name('sgDesc')
        kwargs = {'GroupName': name, 'Description': desc}
        resp, data = self.vpc_client.CreateSecurityGroup(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.addResourceCleanUp(self.vpc_client.DeleteSecurityGroup,
                                GroupName=name)
        time.sleep(2)

        kwargs = {
            'GroupName': name,
            'IpPermissions': [{
                'IpProtocol': 'icmp',
                'FromPort': -1,
                'ToPort': -1,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }, {
                'IpProtocol': 'tcp',
                'FromPort': 22,
                'ToPort': 22,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }]
        }
        resp, data = self.vpc_client.AuthorizeSecurityGroupIngress(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        return name
    def setUpClass(cls):
        if hasattr(super(IdentityTests, cls), 'setUpClass'):
            super(IdentityTests, cls).setUpClass()

        # prepare v3 env
        auth_url = os.environ.get('OS_AUTH_URL')
        auth_url = auth_url.replace('v2.0', 'v3')
        os.environ['OS_AUTH_URL'] = auth_url
        os.environ['OS_IDENTITY_API_VERSION'] = '3'
        os.environ['OS_AUTH_TYPE'] = 'v3password'

        # create dummy domain
        cls.domain_name = data_utils.rand_name('TestDomain')
        cls.domain_description = data_utils.rand_name('description')
        cls.openstack(
            'domain create '
            '--description %(description)s '
            '--enable '
            '%(name)s' % {'description': cls.domain_description,
                          'name': cls.domain_name})

        # create dummy project
        cls.project_name = data_utils.rand_name('TestProject')
        cls.project_description = data_utils.rand_name('description')
        cls.openstack(
            'project create '
            '--domain %(domain)s '
            '--description %(description)s '
            '--enable '
            '%(name)s' % {'domain': cls.domain_name,
                          'description': cls.project_description,
                          'name': cls.project_name})
 def _create_dummy_user(self, add_clean_up=True):
     username = data_utils.rand_name('TestUser')
     password = data_utils.rand_name('password')
     email = data_utils.rand_name() + '@example.com'
     description = data_utils.rand_name('description')
     raw_output = self.openstack(
         'user create '
         '--domain %(domain)s '
         '--project %(project)s '
         '--project-domain %(project_domain)s '
         '--password %(password)s '
         '--email %(email)s '
         '--description %(description)s '
         '--enable '
         '%(name)s' % {'domain': self.domain_name,
                       'project': self.project_name,
                       'project_domain': self.domain_name,
                       'email': email,
                       'password': password,
                       'description': description,
                       'name': username})
     if add_clean_up:
         self.addCleanup(
             self.openstack,
             'user delete %s' % self.parse_show_as_object(raw_output)['id'])
     items = self.parse_show(raw_output)
     self.assert_show_fields(items, self.USER_FIELDS)
     return username
Exemplo n.º 12
0
    def create_standard_security_group(self):
        name = data_utils.rand_name('sgName')
        desc = data_utils.rand_name('sgDesc')
        kwargs = {'GroupName': name, 'Description': desc}
        self.client.create_security_group(*[], **kwargs)
        self.addResourceCleanUp(self.client.delete_security_group,
                                GroupName=name)
        time.sleep(2)

        kwargs = {
            'GroupName': name,
            'IpPermissions': [{
                'IpProtocol': 'icmp',
                'FromPort': -1,
                'ToPort': -1,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }, {
                'IpProtocol': 'tcp',
                'FromPort': 22,
                'ToPort': 22,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }]
        }
        self.client.authorize_security_group_ingress(*[], **kwargs)

        return name
Exemplo n.º 13
0
    def test_check_simple_image_attributes(self):
        name = data_utils.rand_name('image')
        desc = data_utils.rand_name('desc for image')
        image_id, image_clean = self._create_image(name, desc)

        data = self.client.describe_image_attribute(
            ImageId=image_id, Attribute='kernel')
        self.assertIn('KernelId', data)

        data = self.client.describe_image_attribute(
            ImageId=image_id, Attribute='ramdisk')
        self.assertIn('RamdiskId', data)

        # description
        data = self.client.describe_image_attribute(
            ImageId=image_id, Attribute='description')
        self.assertIn('Description', data)
        self.assertIn('Value', data['Description'])
        self.assertEqual(desc, data['Description']['Value'])

        def _modify_description(**kwargs):
            self.client.modify_image_attribute(ImageId=image_id, **kwargs)
            data = self.client.describe_image_attribute(
                ImageId=image_id, Attribute='description')
            self.assertEqual(new_desc, data['Description']['Value'])

        new_desc = data_utils.rand_name('new desc')
        _modify_description(Attribute='description', Value=new_desc)
        _modify_description(Description={'Value': new_desc})

        data = self.client.deregister_image(ImageId=image_id)
        self.cancelResourceCleanUp(image_clean)
Exemplo n.º 14
0
    def test_list_users_for_tenant(self):
        # Return a list of all users for a tenant
        self.data.setup_test_tenant()
        user_ids = list()
        fetched_user_ids = list()
        alt_tenant_user1 = data_utils.rand_name('tenant_user1')
        user1 = self.client.create_user(alt_tenant_user1, 'password1',
                                        self.data.tenant['id'],
                                        'user1@123')
        user_ids.append(user1['id'])
        self.data.users.append(user1)

        alt_tenant_user2 = data_utils.rand_name('tenant_user2')
        user2 = self.client.create_user(alt_tenant_user2, 'password2',
                                        self.data.tenant['id'],
                                        'user2@123')
        user_ids.append(user2['id'])
        self.data.users.append(user2)
        # List of users for the respective tenant ID
        body = self.client.list_users_for_tenant(self.data.tenant['id'])
        for i in body:
            fetched_user_ids.append(i['id'])
        # verifying the user Id in the list
        missing_users =\
            [user for user in user_ids if user not in fetched_user_ids]
        self.assertEqual(0, len(missing_users),
                         "Failed to find user %s in fetched list" %
                         ', '.join(m_user for m_user in missing_users))
Exemplo n.º 15
0
 def test_create_update_delete_policy(self):
     # Test to update policy
     blob = data_utils.rand_name('BlobName')
     policy_type = data_utils.rand_name('PolicyType')
     policy = self.policy_client.create_policy(blob, policy_type)
     self.addCleanup(self._delete_policy, policy['id'])
     self.assertIn('id', policy)
     self.assertIn('type', policy)
     self.assertIn('blob', policy)
     self.assertIsNotNone(policy['id'])
     self.assertEqual(blob, policy['blob'])
     self.assertEqual(policy_type, policy['type'])
     # Update policy
     update_type = data_utils.rand_name('UpdatedPolicyType')
     data = self.policy_client.update_policy(
         policy['id'], type=update_type)
     self.assertIn('type', data)
     # Assertion for updated value with fetched value
     fetched_policy = self.policy_client.get_policy(policy['id'])
     self.assertIn('id', fetched_policy)
     self.assertIn('blob', fetched_policy)
     self.assertIn('type', fetched_policy)
     self.assertEqual(fetched_policy['id'], policy['id'])
     self.assertEqual(fetched_policy['blob'], policy['blob'])
     self.assertEqual(update_type, fetched_policy['type'])
Exemplo n.º 16
0
 def test_update_endpoint(self):
     # Creating an endpoint so as to check update endpoint
     # with new values
     region1 = data_utils.rand_name('region')
     url1 = data_utils.rand_url()
     interface1 = 'public'
     endpoint_for_update =\
         self.client.create_endpoint(self.service_id, interface1,
                                     url1, region=region1,
                                     enabled=True)
     self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id'])
     # Creating service so as update endpoint with new service ID
     s_name = data_utils.rand_name('service')
     s_type = data_utils.rand_name('type')
     s_description = data_utils.rand_name('description')
     service2 =\
         self.service_client.create_service(s_name, s_type,
                                            description=s_description)
     self.service_ids.append(service2['id'])
     # Updating endpoint with new values
     region2 = data_utils.rand_name('region')
     url2 = data_utils.rand_url()
     interface2 = 'internal'
     endpoint = \
         self.client.update_endpoint(endpoint_for_update['id'],
                                     service_id=service2['id'],
                                     interface=interface2, url=url2,
                                     region=region2, enabled=False)
     # Asserting if the attributes of endpoint are updated
     self.assertEqual(service2['id'], endpoint['service_id'])
     self.assertEqual(interface2, endpoint['interface'])
     self.assertEqual(url2, endpoint['url'])
     self.assertEqual(region2, endpoint['region'])
     self.assertEqual(False, endpoint['enabled'])
Exemplo n.º 17
0
def baymodel_data(**kwargs):
    """Generates random baymodel data

    Keypair and image id cannot be random for the baymodel to be valid due to
    validations for the presence of keypair and image id prior to baymodel
    creation.

    :param keypair_id: keypair name
    :param image_id: image id or name
    :returns: BayModelEntity with generated data
    """

    data = {
        "name": data_utils.rand_name('bay'),
        "coe": "swarm",
        "tls_disabled": False,
        "network_driver": None,
        "volume_driver": None,
        "docker_volume_size": 3,
        "labels": {},
        "fixed_network": "192.168.0.0/24",
        "dns_nameserver": "8.8.8.8",
        "flavor_id": data_utils.rand_name('bay'),
        "master_flavor_id": data_utils.rand_name('bay'),
        "external_network_id": str(data_utils.rand_uuid()),
        "keypair_id": data_utils.rand_name('bay'),
        "image_id": data_utils.rand_name('bay')
    }

    data.update(kwargs)
    model = baymodel_model.BayModelEntity.from_dict(data)

    return model
Exemplo n.º 18
0
    def test_get_updated_quotas(self):
        # Verify that GET shows the updated quota set of tenant
        tenant_name = data_utils.rand_name('cpu_quota_tenant')
        tenant_desc = tenant_name + '-desc'
        identity_client = self.os_adm.identity_client
        tenant = identity_client.create_tenant(name=tenant_name,
                                               description=tenant_desc)
        tenant_id = tenant['id']
        self.addCleanup(identity_client.delete_tenant, tenant_id)

        self.adm_client.update_quota_set(tenant_id, ram='5120')
        quota_set = self.adm_client.show_quota_set(tenant_id)
        self.assertEqual(5120, quota_set['ram'])

        # Verify that GET shows the updated quota set of user
        user_name = data_utils.rand_name('cpu_quota_user')
        password = data_utils.rand_name('password')
        email = user_name + '@testmail.tm'
        user = identity_client.create_user(name=user_name,
                                           password=password,
                                           tenant_id=tenant_id,
                                           email=email)
        user_id = user['id']
        self.addCleanup(identity_client.delete_user, user_id)

        self.adm_client.update_quota_set(tenant_id,
                                         user_id=user_id,
                                         ram='2048')
        quota_set = self.adm_client.show_quota_set(tenant_id,
                                                   user_id=user_id)
        self.assertEqual(2048, quota_set['ram'])
Exemplo n.º 19
0
 def create_share(self, share_protocol=None, size=1,
                  name=None, snapshot_id=None, description=None,
                  metadata=None, share_network_id=None,
                  share_type_id=None, is_public=False):
     metadata = metadata or {}
     if name is None:
         name = data_utils.rand_name("tempest-created-share")
     if description is None:
         description = data_utils.rand_name("tempest-created-share-desc")
     if share_protocol is None:
         share_protocol = self.share_protocol
     if share_protocol is None:
         raise share_exceptions.ShareProtocolNotSpecified()
     post_body = {
         "share": {
             "share_proto": share_protocol,
             "description": description,
             "snapshot_id": snapshot_id,
             "name": name,
             "size": size,
             "metadata": metadata,
             "is_public": is_public,
         }
     }
     if share_network_id:
         post_body["share"]["share_network_id"] = share_network_id
     if share_type_id:
         post_body["share"]["share_type"] = share_type_id
     body = json.dumps(post_body)
     resp, body = self.post("shares", body)
     self.expected_success(200, resp.status)
     return self._parse_resp(body)
 def test_VMs_when_hosted_on_different_network(self):
     network_name1 = data_utils.rand_name('first-network-')
     post_body = {'name': network_name1}
     body = self.admin_client.create_network(**post_body)
     network1 = body['network']
     subnet1 = self.create_subnet(network1, client=self.admin_client)
     group_create_body1 = self.admin_client.create_security_group()
     network_name2 = data_utils.rand_name('second-network-')
     post_body = {'name': network_name2}
     body = self.admin_client.create_network(**post_body)
     network2 = body['network']
     sub_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr).next()
     subnet2 = self.create_subnet(network2, client=self.admin_client,
                                  cidr=sub_cidr)
     group_create_body2 = self.admin_client.create_security_group()
     name = data_utils.rand_name('router-')
     router = self.admin_client.create_router(
         name, external_gateway_info={
             "network_id": CONF.network.public_network_id},
         admin_state_up=True)
     self.addCleanup(self.admin_client.delete_router,
                     router['router']['id'])
     floating_ip_admin1, server_ip1 = \
         self._attach_subnet_to_router_fip(network1, subnet1,
                                           group_create_body1, router)
     floating_ip_admin2, server_ip2 = \
         self._attach_subnet_to_router_fip(network2, subnet2,
                                           group_create_body2, router)
     self.assertTrue(self._check_remote_connectivity(floating_ip_admin1,
                                                     server_ip2))
     self.assertTrue(self._check_remote_connectivity(floating_ip_admin2,
                                                     server_ip1))
Exemplo n.º 21
0
    def test_credentials_create_get_update_delete(self):
        keys = [data_utils.rand_name('Access'),
                data_utils.rand_name('Secret')]
        cred = self.creds_client.create_credential(
            keys[0], keys[1], self.user_body['id'],
            self.projects[0])
        self.addCleanup(self._delete_credential, cred['id'])
        for value1 in self.creds_list[0]:
            self.assertIn(value1, cred)
        for value2 in self.creds_list[1]:
            self.assertIn(value2, cred['blob'])

        new_keys = [data_utils.rand_name('NewAccess'),
                    data_utils.rand_name('NewSecret')]
        update_body = self.creds_client.update_credential(
            cred['id'], access_key=new_keys[0], secret_key=new_keys[1],
            project_id=self.projects[1])
        self.assertEqual(cred['id'], update_body['id'])
        self.assertEqual(self.projects[1], update_body['project_id'])
        self.assertEqual(self.user_body['id'], update_body['user_id'])
        self.assertEqual(update_body['blob']['access'], new_keys[0])
        self.assertEqual(update_body['blob']['secret'], new_keys[1])

        get_body = self.creds_client.get_credential(cred['id'])
        for value1 in self.creds_list[0]:
            self.assertEqual(update_body[value1],
                             get_body[value1])
        for value2 in self.creds_list[1]:
            self.assertEqual(update_body['blob'][value2],
                             get_body['blob'][value2])
Exemplo n.º 22
0
    def test_tenant_update_desc(self):
        # Update description attribute of a tenant
        t_name = data_utils.rand_name(name='tenant')
        t_desc = data_utils.rand_name(name='desc')
        body = self.client.create_tenant(t_name, description=t_desc)
        tenant = body
        self.data.tenants.append(tenant)

        t_id = body['id']
        resp1_desc = body['description']

        t_desc2 = data_utils.rand_name(name='desc2')
        body = self.client.update_tenant(t_id, description=t_desc2)
        resp2_desc = body['description']
        self.assertNotEqual(resp1_desc, resp2_desc)

        body = self.client.get_tenant(t_id)
        resp3_desc = body['description']

        self.assertNotEqual(resp1_desc, resp3_desc)
        self.assertEqual(t_desc, resp1_desc)
        self.assertEqual(resp2_desc, resp3_desc)

        self.client.delete_tenant(t_id)
        self.data.tenants.remove(tenant)
Exemplo n.º 23
0
    def test_associate_user_to_project(self):
        # Associate a user to a project
        # Create a Project
        p_name = data_utils.rand_name('project')
        project = self.client.create_project(p_name)
        self.data.projects.append(project)

        # Create a User
        u_name = data_utils.rand_name('user')
        u_desc = u_name + 'description'
        u_email = u_name + '@testmail.tm'
        u_password = data_utils.rand_name('pass')
        user = self.client.create_user(
            u_name, description=u_desc, password=u_password,
            email=u_email, project_id=project['id'])
        # Delete the User at the end of this method
        self.addCleanup(self.client.delete_user, user['id'])

        # Get User To validate the user details
        new_user_get = self.client.get_user(user['id'])
        # Assert response body of GET
        self.assertEqual(u_name, new_user_get['name'])
        self.assertEqual(u_desc, new_user_get['description'])
        self.assertEqual(project['id'],
                         new_user_get['project_id'])
        self.assertEqual(u_email, new_user_get['email'])
 def test_create_show_list_delete_l2gateway_connection(self):
     # Create a network
     name = data_utils.rand_name('network')
     net_body = self.admin_client.create_network(name=name)
     net_id = net_body['network']['id']
     self.addCleanup(self.admin_client.delete_network, net_id)
     # Create an L2Gateway
     gw_name = data_utils.rand_name('l2gw')
     devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
     l2_gw_body = self.admin_client.create_l2_gateway(
         name=gw_name, devices=devices)
     l2_gw_id = l2_gw_body['l2_gateway']['id']
     self.addCleanup(self.admin_client.delete_l2_gateway, l2_gw_id)
     # Create an L2Gateway Connection
     l2_gw_conn_body = self.admin_client.create_l2_gateway_connection(
         l2_gateway_id=l2_gw_id, network_id=net_id)
     l2_gw_conn_id = l2_gw_conn_body['l2_gateway_connection']['id']
     self.addCleanup(self.admin_client.delete_l2_gateway_connection,
                     l2_gw_conn_id)
     # Show details of created L2 Gateway connection
     show_body = self.admin_client.show_l2_gateway_connection(l2_gw_conn_id)
     l2_gw_conn = show_body['l2_gateway_connection']
     self.assertEqual(net_id, l2_gw_conn['network_id'])
     self.assertEqual(l2_gw_id, l2_gw_conn['l2_gateway_id'])
     # List L2Gateway Connections
     self.admin_client.list_l2_gateway_connections()
Exemplo n.º 25
0
    def _check_create_cluster_template(self):
        ng_template_name = data_utils.rand_name('sahara-ng-template')
        ng_template = self.create_node_group_template(ng_template_name,
                                                      **self.worker_template)

        full_cluster_template = self.cluster_template.copy()
        full_cluster_template['node_groups'] = [
            {
                'name': 'master-node',
                'flavor_id': TEMPEST_CONF.compute.flavor_ref,
                'node_processes': ['namenode'],
                'count': 1
            },
            {
                'name': 'worker-node',
                'node_group_template_id': ng_template.id,
                'count': 3
            }
        ]

        template_name = data_utils.rand_name('sahara-cluster-template')

        # create cluster template
        resp_body = self.create_cluster_template(template_name,
                                                 **full_cluster_template)

        # check that template created successfully
        self.assertEqual(template_name, resp_body.name)
        self.assertDictContainsSubset(self.cluster_template,
                                      resp_body.__dict__)

        return resp_body.id, template_name
    def _create_creds(self, suffix="", admin=False, roles=None):
        """Create random credentials under the following schema.

        If the name contains a '.' is the full class path of something, and
        we don't really care. If it isn't, it's probably a meaningful name,
        so use it.

        For logging purposes, -user and -tenant are long and redundant,
        don't use them. The user# will be sufficient to figure it out.
        """
        if '.' in self.name:
            root = ""
        else:
            root = self.name

        tenant_name = data_utils.rand_name(root) + suffix
        tenant_desc = tenant_name + "-desc"
        tenant = self._create_tenant(name=tenant_name,
                                     description=tenant_desc)

        username = data_utils.rand_name(root) + suffix
        email = data_utils.rand_name(root) + suffix + "@example.com"
        user = self._create_user(username, self.password,
                                 tenant, email)
        if admin:
            self._assign_user_role(tenant, user, CONF.identity.admin_role)
        # Add roles specified in config file
        for conf_role in CONF.auth.tempest_roles:
            self._assign_user_role(tenant, user, conf_role)
        # Add roles requested by caller
        if roles:
            for role in roles:
                self._assign_user_role(tenant, user, role)
        return self._get_credentials(user, tenant)
 def test_create_l2gw_conn_with_segid_when_l2gw_created_without_segid(self):
     # Create an L2Gateway
     gw_name = data_utils.rand_name('l2gw')
     devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
     if devices[0]['interfaces'][0]['segmentation_id']:
         seg_id = devices[0]['interfaces'][0]['segmentation_id'][0]
         devices[0]['interfaces'][0].pop('segmentation_id')
     body = self.admin_client.create_l2_gateway(
         name=gw_name, devices=devices)
     l2_gateway = body['l2_gateway']
     l2_gw_id = l2_gateway['id']
     self.addCleanup(self.admin_client.delete_l2_gateway, l2_gw_id)
     # Create a network
     name = data_utils.rand_name('network')
     net_body = self.admin_client.create_network(name=name)
     net_id = net_body['network']['id']
     self.addCleanup(self.admin_client.delete_network, net_id)
     # Create an L2Gateway Connection
     l2_gw_conn_body = self.admin_client.create_l2_gateway_connection(
         l2_gateway_id=l2_gw_id, network_id=net_id,
         segmentation_id=seg_id)
     l2_gw_conn_id = l2_gw_conn_body['l2_gateway_connection']['id']
     l2_gw_seg_id = l2_gw_conn_body['l2_gateway_connection'][
         'segmentation_id']
     self.addCleanup(self.admin_client.delete_l2_gateway_connection,
                     l2_gw_conn_id)
     # Show details of created L2 Gateway connection
     show_body = self.admin_client.show_l2_gateway_connection(
         l2_gw_conn_id)
     l2_gw_conn = show_body['l2_gateway_connection']
     self.assertEqual(net_id, l2_gw_conn['network_id'])
     self.assertEqual(l2_gw_id, l2_gw_conn['l2_gateway_id'])
     self.assertEqual(str(l2_gw_seg_id),
                      str(l2_gw_conn['segmentation_id']))
Exemplo n.º 28
0
    def test_update_image(self):
        # Updates an image by image_id

        # Create image
        image_name = data_utils.rand_name('image')
        body = self.client.create_image(name=image_name,
                                        container_format='bare',
                                        disk_format='iso',
                                        visibility='private')
        self.addCleanup(self.client.delete_image, body['id'])
        self.assertEqual('queued', body['status'])
        image_id = body['id']

        # Now try uploading an image file
        image_file = moves.cStringIO(data_utils.random_bytes())
        self.client.store_image(image_id, image_file)

        # Update Image
        new_image_name = data_utils.rand_name('new-image')
        body = self.client.update_image(image_id, [
            dict(replace='/name', value=new_image_name)])

        # Verifying updating

        body = self.client.get_image(image_id)
        self.assertEqual(image_id, body['id'])
        self.assertEqual(new_image_name, body['name'])
Exemplo n.º 29
0
    def test_copy_object_2d_way(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.arbitrary_string(size=len(src_object_name) * 2,
                                               base_text=src_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name, src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.arbitrary_string(size=len(dst_object_name) * 3,
                                               base_text=dst_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name, dst_data)
        # copy source object to destination
        resp, _ = self.object_client.copy_object_2d_way(self.container_name,
                                                        src_object_name,
                                                        dst_object_name)
        self.assertHeaders(resp, 'Object', 'COPY')
        #Bug 1417469
        #self.assertEqual(
        #    resp['x-copied-from'],
        #    self.container_name + "/" + src_object_name)

        # check data
        self._check_copied_obj(dst_object_name, src_data)
Exemplo n.º 30
0
 def test_create_get_delete_token(self):
     # get a token by username and password
     user_name = data_utils.rand_name(name='user')
     user_password = data_utils.rand_name(name='pass')
     # first:create a tenant
     tenant_name = data_utils.rand_name(name='tenant')
     tenant = self.client.create_tenant(tenant_name)
     self.data.tenants.append(tenant)
     # second:create a user
     user = self.client.create_user(user_name, user_password,
                                    tenant['id'], '')
     self.data.users.append(user)
     # then get a token for the user
     body = self.token_client.auth(user_name,
                                   user_password,
                                   tenant['name'])
     self.assertEqual(body['token']['tenant']['name'],
                      tenant['name'])
     # Perform GET Token
     token_id = body['token']['id']
     token_details = self.client.get_token(token_id)
     self.assertEqual(token_id, token_details['token']['id'])
     self.assertEqual(user['id'], token_details['user']['id'])
     self.assertEqual(user_name, token_details['user']['name'])
     self.assertEqual(tenant['name'],
                      token_details['token']['tenant']['name'])
     # then delete the token
     self.client.delete_token(token_id)
Exemplo n.º 31
0
 def _create_volume_from_snapshot(self, snap_id):
     vol_name = data_utils.rand_name('volume')
     return self.create_volume(name=vol_name, snapshot_id=snap_id)
Exemplo n.º 32
0
 def test_create_tenant_by_unauthorized_user(self):
     # Non-administrator user should not be authorized to create a tenant
     tenant_name = data_utils.rand_name(name='tenant')
     self.assertRaises(lib_exc.Forbidden,
                       self.non_admin_client.create_tenant, tenant_name)
Exemplo n.º 33
0
 def setUp(self):
     super(ObjectExpiryTest, self).setUp()
     # create object
     self.object_name = data_utils.rand_name(name='TestObject')
     resp, _ = self.object_client.create_object(self.container_name,
                                                self.object_name, '')
Exemplo n.º 34
0
 def resource_setup(cls):
     super(ObjectExpiryTest, cls).resource_setup()
     cls.container_name = data_utils.rand_name(name='TestContainer')
     cls.container_client.create_container(cls.container_name)
Exemplo n.º 35
0
    def test_create_backup(self):
        # Positive test:create backup successfully and rotate backups correctly
        # create the first and the second backup
        backup1 = data_utils.rand_name('backup-1')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup1).response
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                try:
                    self.os.image_client.delete_image(oldest_backup)
                except lib_exc.NotFound:
                    pass
                else:
                    LOG.warning("Deletion of oldest backup %s should not have "
                                "been successful as it should have been "
                                "deleted during rotation." % oldest_backup)

        image1_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.os.image_client.wait_for_image_status(image1_id, 'active')

        backup2 = data_utils.rand_name('backup-2')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup2).response
        image2_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image2_id)
        self.os.image_client.wait_for_image_status(image2_id, 'active')

        # verify they have been created
        properties = {
            'image_type': 'backup',
            'backup_type': "daily",
            'instance_uuid': self.server_id,
        }
        image_list = self.os.image_client.list_images(detail=True,
                                                      properties=properties,
                                                      status='active',
                                                      sort_key='created_at',
                                                      sort_dir='asc')
        self.assertEqual(2, len(image_list))
        self.assertEqual((backup1, backup2),
                         (image_list[0]['name'], image_list[1]['name']))

        # create the third one, due to the rotation is 2,
        # the first one will be deleted
        backup3 = data_utils.rand_name('backup-3')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup3).response
        image3_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image3_id)
        # the first back up should be deleted
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        self.os.image_client.wait_for_resource_deletion(image1_id)
        oldest_backup_exist = False
        image_list = self.os.image_client.list_images(detail=True,
                                                      properties=properties,
                                                      status='active',
                                                      sort_key='created_at',
                                                      sort_dir='asc')
        self.assertEqual(
            2, len(image_list), 'Unexpected number of images for '
            'v2:test_create_backup; was the oldest backup not '
            'yet deleted? Image list: %s' %
            [image['name'] for image in image_list])
        self.assertEqual((backup2, backup3),
                         (image_list[0]['name'], image_list[1]['name']))
Exemplo n.º 36
0
 def setUp(self):
     super(ObjectTestACLs, self).setUp()
     self.container_name = data_utils.rand_name(name='TestContainer')
     self.container_client.create_container(self.container_name)
Exemplo n.º 37
0
 def test_create_project_by_unauthorized_user(self):
     # Non-admin user should not be authorized to create a project
     project_name = data_utils.rand_name('project')
     self.assertRaises(
         lib_exc.Forbidden, self.non_admin_client.create_project,
         project_name)
Exemplo n.º 38
0
    def _write_text(self, ssh_client):
        text = data_utils.rand_name('text')
        ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text))

        return self._get_content(ssh_client)
Exemplo n.º 39
0
def random_user_name(tag, prefix):
    if tag:
        return data_utils.rand_name('-'.join((tag, prefix)))
    else:
        return data_utils.rand_name(prefix)
Exemplo n.º 40
0
 def _create_volume_from_image(self):
     img_uuid = CONF.compute.image_ref
     vol_name = data_utils.rand_name('volume-origin')
     return self.create_volume(name=vol_name, imageRef=img_uuid)
Exemplo n.º 41
0
 def test_list_shares_with_detail_filter_by_fake_name(self):
     # list shares by fake name, no shares are expected
     params = {"name": data_utils.rand_name("fake-nonexistent-name")}
     shares = self.shares_client.list_shares_with_detail(params)
     self.assertEqual(0, len(shares))
Exemplo n.º 42
0
 def test_create_distributed_router(self):
     name = data_utils.rand_name('router')
     create_body = self.admin_client.create_router(name, distributed=True)
     self.addCleanup(self._delete_router, create_body['router']['id'],
                     self.admin_client)
     self.assertTrue(create_body['router']['distributed'])
Exemplo n.º 43
0
 def test_list_share_servers_with_fake_project(self):
     search_opts = {"project_id": data_utils.rand_name("fake_project_id")}
     servers = self.shares_client.list_share_servers(search_opts)
     self.assertEqual(len(servers), 0)
 def _create_address_scope(self, is_admin=False, **kwargs):
     name = data_utils.rand_name(ADDRESS_SCOPE_NAME)
     return self.create_address_scope(name=name,
                                      is_admin=is_admin,
                                      **kwargs)
Exemplo n.º 45
0
 def test_update_user_for_non_existent_user(self):
     # Attempt to update a user non-existent user should fail
     user_name = data_utils.rand_name('user')
     non_existent_id = str(uuid.uuid4())
     self.assertRaises(lib_exc.NotFound, self.client.update_user,
                       non_existent_id, name=user_name)
Exemplo n.º 46
0
 def test_list_share_servers_with_fake_share_network(self):
     search_opts = {
         "share_network": data_utils.rand_name("fake_share_network"),
     }
     servers = self.shares_client.list_share_servers(search_opts)
     self.assertEqual(len(servers), 0)
Exemplo n.º 47
0
 def test_rand_name_with_prefix(self):
     actual = data_utils.rand_name(prefix='prefix-str')
     self.assertIsInstance(actual, str)
     self.assertRegexpMatches(actual, "^prefix-str-")
     actual2 = data_utils.rand_name(prefix='prefix-str')
     self.assertNotEqual(actual, actual2)
Exemplo n.º 48
0
 def resource_setup(cls):
     super(UsersNegativeTestJSON, cls).resource_setup()
     cls.alt_user = data_utils.rand_name('test_user')
     cls.alt_password = data_utils.rand_name('pass')
     cls.alt_email = cls.alt_user + '@testmail.tm'
Exemplo n.º 49
0
 def test_update_non_existent_network(self):
     non_exist_id = data_utils.rand_name('network')
     self.assertRaises(lib_exc.NotFound,
                       self.client.update_network,
                       non_exist_id,
                       name="new_name")
Exemplo n.º 50
0
 def test_create_container(self):
     container_name = data_utils.rand_name(name='TestContainer')
     resp, body = self.container_client.create_container(container_name)
     self.containers.append(container_name)
     self.assertHeaders(resp, 'Container', 'PUT')
Exemplo n.º 51
0
    def test_rescope_token(self):
        """Rescope a token.

        An unscoped token can be requested, that token can be used to request a
        scoped token. The scoped token can be revoked, and the original token
        used to get a token in a different project.

        """

        # Create a user.
        user_name = data_utils.rand_name(name='user')
        user_password = data_utils.rand_name(name='pass')
        user = self.client.create_user(user_name, password=user_password)
        self.addCleanup(self.client.delete_user, user['id'])

        # Create a couple projects
        project1_name = data_utils.rand_name(name='project')
        project1 = self.client.create_project(project1_name)
        self.addCleanup(self.client.delete_project, project1['id'])

        project2_name = data_utils.rand_name(name='project')
        project2 = self.client.create_project(project2_name)
        self.addCleanup(self.client.delete_project, project2['id'])

        # Create a role
        role_name = data_utils.rand_name(name='role')
        role = self.client.create_role(role_name)
        self.addCleanup(self.client.delete_role, role['id'])

        # Grant the user the role on both projects.
        self.client.assign_user_role(project1['id'], user['id'], role['id'])

        self.client.assign_user_role(project2['id'], user['id'], role['id'])

        # Get an unscoped token.
        token_auth = self.token.auth(user_id=user['id'],
                                     password=user_password)

        token_id = token_auth.response['x-subject-token']
        orig_expires_at = token_auth['token']['expires_at']
        orig_issued_at = token_auth['token']['issued_at']
        orig_user = token_auth['token']['user']

        self.assertIsInstance(token_auth['token']['expires_at'], unicode)
        self.assertIsInstance(token_auth['token']['issued_at'], unicode)
        self.assertEqual(['password'], token_auth['token']['methods'])
        self.assertEqual(user['id'], token_auth['token']['user']['id'])
        self.assertEqual(user['name'], token_auth['token']['user']['name'])
        self.assertEqual('default',
                         token_auth['token']['user']['domain']['id'])
        self.assertEqual('Default',
                         token_auth['token']['user']['domain']['name'])
        self.assertNotIn('catalog', token_auth['token'])
        self.assertNotIn('project', token_auth['token'])
        self.assertNotIn('roles', token_auth['token'])

        # Use the unscoped token to get a scoped token.
        token_auth = self.token.auth(token=token_id,
                                     project_name=project1_name,
                                     project_domain_name='Default')
        token1_id = token_auth.response['x-subject-token']

        self.assertEqual(orig_expires_at, token_auth['token']['expires_at'],
                         'Expiration time should match original token')
        self.assertIsInstance(token_auth['token']['issued_at'], unicode)
        self.assertNotEqual(orig_issued_at, token_auth['token']['issued_at'])
        self.assertEqual(set(['password', 'token']),
                         set(token_auth['token']['methods']))
        self.assertEqual(orig_user, token_auth['token']['user'],
                         'User should match original token')
        self.assertIsInstance(token_auth['token']['catalog'], list)
        self.assertEqual(project1['id'], token_auth['token']['project']['id'])
        self.assertEqual(project1['name'],
                         token_auth['token']['project']['name'])
        self.assertEqual('default',
                         token_auth['token']['project']['domain']['id'])
        self.assertEqual('Default',
                         token_auth['token']['project']['domain']['name'])
        self.assertEqual(1, len(token_auth['token']['roles']))
        self.assertEqual(role['id'], token_auth['token']['roles'][0]['id'])
        self.assertEqual(role['name'], token_auth['token']['roles'][0]['name'])

        # Revoke the unscoped token.
        self.client.delete_token(token1_id)

        # Now get another scoped token using the unscoped token.
        token_auth = self.token.auth(token=token_id,
                                     project_name=project2_name,
                                     project_domain_name='Default')

        self.assertEqual(project2['id'], token_auth['token']['project']['id'])
        self.assertEqual(project2['name'],
                         token_auth['token']['project']['name'])
Exemplo n.º 52
0
 def test_delete_non_existent_network(self):
     non_exist_id = data_utils.rand_name('network')
     self.assertRaises(lib_exc.NotFound, self.client.delete_network,
                       non_exist_id)
Exemplo n.º 53
0
 def test_delete_non_existent_subnetpool(self):
     non_exist_id = data_utils.rand_name('subnetpool')
     self.assertRaises(lib_exc.NotFound, self.client.delete_subnetpool,
                       non_exist_id)
Exemplo n.º 54
0
 def test_show_non_existent_port(self):
     non_exist_id = data_utils.rand_name('port')
     self.assertRaises(lib_exc.NotFound, self.client.show_port,
                       non_exist_id)
Exemplo n.º 55
0
 def _create_keypair(cls, name_start='keypair-heat-'):
     kp_name = data_utils.rand_name(name_start)
     body = cls.keypairs_client.create_keypair(kp_name)
     cls.keypairs.append(kp_name)
     return body
Exemplo n.º 56
0
 def test_update_non_existent_subnetpool(self):
     non_exist_id = data_utils.rand_name('subnetpool')
     self.assertRaises(lib_exc.NotFound,
                       self.client.update_subnetpool,
                       non_exist_id,
                       name='foo-name')
Exemplo n.º 57
0
    def _volume_create_get_update_delete(self, **kwargs):
        # Create a volume, Get it's details and Delete the volume
        volume = {}
        v_name = data_utils.rand_name('Volume')
        metadata = {'Type': 'Test'}
        # Create a volume
        kwargs[self.name_field] = v_name
        kwargs['metadata'] = metadata
        volume = self.client.create_volume(**kwargs)
        self.assertIn('id', volume)
        self.addCleanup(self._delete_volume, volume['id'])
        self.client.wait_for_volume_status(volume['id'], 'available')
        self.assertIn(self.name_field, volume)
        self.assertEqual(
            volume[self.name_field], v_name,
            "The created volume name is not equal "
            "to the requested name")
        self.assertTrue(volume['id'] is not None,
                        "Field volume id is empty or not found.")
        # Get Volume information
        fetched_volume = self.client.show_volume(volume['id'])
        self.assertEqual(
            v_name, fetched_volume[self.name_field],
            'The fetched Volume name is different '
            'from the created Volume')
        self.assertEqual(
            volume['id'], fetched_volume['id'],
            'The fetched Volume id is different '
            'from the created Volume')
        self.assertThat(
            fetched_volume['metadata'].items(),
            matchers.ContainsAll(metadata.items()),
            'The fetched Volume metadata misses data '
            'from the created Volume')

        if 'imageRef' in kwargs:
            self.assertEqual('true', fetched_volume['bootable'])
        if 'imageRef' not in kwargs:
            self.assertEqual('false', fetched_volume['bootable'])

        # Update Volume
        # Test volume update when display_name is same with original value
        params = {self.name_field: v_name}
        self.client.update_volume(volume['id'], **params)
        # Test volume update when display_name is new
        new_v_name = data_utils.rand_name('new-Volume')
        new_desc = 'This is the new description of volume'
        params = {self.name_field: new_v_name, self.descrip_field: new_desc}
        update_volume = self.client.update_volume(volume['id'], **params)
        # Assert response body for update_volume method
        self.assertEqual(new_v_name, update_volume[self.name_field])
        self.assertEqual(new_desc, update_volume[self.descrip_field])
        # Assert response body for show_volume method
        updated_volume = self.client.show_volume(volume['id'])
        self.assertEqual(volume['id'], updated_volume['id'])
        self.assertEqual(new_v_name, updated_volume[self.name_field])
        self.assertEqual(new_desc, updated_volume[self.descrip_field])
        self.assertThat(
            updated_volume['metadata'].items(),
            matchers.ContainsAll(metadata.items()),
            'The fetched Volume metadata misses data '
            'from the created Volume')
        # Test volume create when display_name is none and display_description
        # contains specific characters,
        # then test volume update if display_name is duplicated
        new_volume = {}
        new_v_desc = data_utils.rand_name('@#$%^* description')
        params = {
            self.descrip_field: new_v_desc,
            'availability_zone': volume['availability_zone']
        }
        new_volume = self.client.create_volume(**params)
        self.assertIn('id', new_volume)
        self.addCleanup(self._delete_volume, new_volume['id'])
        self.client.wait_for_volume_status(new_volume['id'], 'available')

        params = {
            self.name_field: volume[self.name_field],
            self.descrip_field: volume[self.descrip_field]
        }
        self.client.update_volume(new_volume['id'], **params)

        if 'imageRef' in kwargs:
            self.assertEqual('true', updated_volume['bootable'])
        if 'imageRef' not in kwargs:
            self.assertEqual('false', updated_volume['bootable'])
 def test_upload_large_object(self):
     object_name = data_utils.rand_name(name="TestObject")
     data = data_utils.arbitrary_string(30)
     self.assertRaises(lib_exc.OverLimit, self.object_client.create_object,
                       self.container_name, object_name, data)
Exemplo n.º 59
0
    def test_network_interface_attribute(self):
        desc = data_utils.rand_name('ni')
        kwargs = {'SubnetId': self.subnet_id, 'Description': desc}
        resp, data = self.client.CreateNetworkInterface(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        ni_id = data['NetworkInterface']['NetworkInterfaceId']
        res_clean = self.addResourceCleanUp(self.client.DeleteNetworkInterface,
                                            NetworkInterfaceId=ni_id)
        self.get_network_interface_waiter().wait_available(ni_id)

        resp, data = self.client.DescribeNetworkInterfaceAttribute(
            NetworkInterfaceId=ni_id, attribute='description')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(desc, data['Description']['Value'])

        new_desc = data_utils.rand_name('new-ni')
        kwargs = {
            'NetworkInterfaceId': ni_id,
            'Description': {
                'Value': new_desc
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DescribeNetworkInterfaceAttribute(
            NetworkInterfaceId=ni_id, attribute='description')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(new_desc, data['Description']['Value'])

        kwargs = {
            'NetworkInterfaceId': ni_id,
            'SourceDestCheck': {
                'Value': False
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DescribeNetworkInterfaceAttribute(
            NetworkInterfaceId=ni_id, attribute='sourceDestCheck')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(False, data['SourceDestCheck']['Value'])

        # NOTE(andrey-mp): ResetNetworkInterfaceAttribute has inadequate json
        # scheme in botocore.

        kwargs = {
            'NetworkInterfaceId': ni_id,
            'SourceDestCheck': {
                'Value': True
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DescribeNetworkInterfaceAttribute(
            NetworkInterfaceId=ni_id, attribute='sourceDestCheck')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(True, data['SourceDestCheck']['Value'])

        kwargs = {
            'NetworkInterfaceId': ni_id,
            'Attachment': {
                'AttachmentId': 'fake'
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(400, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual('MissingParameter', data['Error']['Code'])

        kwargs = {
            'NetworkInterfaceId': ni_id,
            'Attachment': {
                'AttachmentId': 'eni-attach-ffffffff',
                'DeleteOnTermination': True
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(400, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual('InvalidAttachmentID.NotFound', data['Error']['Code'])

        resp, data = self.client.DeleteNetworkInterface(
            NetworkInterfaceId=ni_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_network_interface_waiter().wait_delete(ni_id)
Exemplo n.º 60
0
 def test_flavor_unset_nonexistent_key(self):
     nonexistent_key = data_utils.rand_name('flavor_key')
     self.assertRaises(lib_exc.NotFound,
                       self.client.unset_flavor_extra_spec,
                       self.flavor['id'],
                       nonexistent_key)