Пример #1
0
def test_nova_change_quota_by_tenantname(tenant_name, key, value):
    """ test to change quotas of a tenant with a key and value """

    support_keys = ('metadata_items', 'injected_file_content_bytes', 'injected_files', 'gigabytes', 'ram',
                    'floating_ips',   'security_group_rules',        'instances',      'volumes',   'cores',
                    'id',             'security_groups')

    if key not in support_keys:
        return 2

    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

    bt = BaseTest()
    endpoint = bt.get_service_endpoint('nova')
    tenant = bt.get_tenant_by_name(tenant_name)

    body = {
        'quota_set': {
            key: value
        }
    }

    endpoint = endpoint + '/os-quota-sets/' + tenant['id']
    #response, content = bt.get(endpoint)
    
    response, content = bt.put(endpoint, headers, body=json.dumps(body))

    if response['status'] == '200':
        return 0
    return 1
def test_tenant_disable(tenant_name):
    """ test disable a tenant by name given """
    
    bt = BaseTest()
    tenant = bt.get_tenant_by_name(tenant_name)

    if(tenant == None):
        return 3

    tenant_id = tenant['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants/' + tenant_id

    body = {
                "tenant": {
                    "enabled": False,
                },
    }

    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

    response, content = bt.post(endpoint, headers=headers, body=json.dumps(body))

    if(response['status'] == '200'):
        return 0
    return 1
def test_create_user_by_name(username, password, tenant_name):
    """ test administrator to create a user whose name is the giving name"""
    bt = BaseTest()
    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users'
    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

    tenant = bt.get_tenant_by_name(tenant_name)
    user = bt.get_user_by_name(username)

    if tenant == None or user != None:
        return 3

    body = {
            'user': {
                'name': username,
                'password': password,
                'tenantId': tenant['id'],
                'email': '*****@*****.**',
                'enabled': True
            }
        }

    response, content = bt.post(endpoint, headers=headers, body=json.dumps(body))

    if(response['status'] == '200'):
        return 0
    return 1
def test_tenant_reenable(tenant_name):
    """ test enable a disabled tenant """

    bt = BaseTest()
    tenant = bt.get_tenant_by_name(tenant_name)

    if (tenant == None):
        return 3

    tenant_id = tenant['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants/' + tenant_id

    body = {
        "tenant": {
            "enabled": True,
        },
    }

    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    response, content = bt.post(endpoint,
                                headers=headers,
                                body=json.dumps(body))

    if (response['status'] == '200'):
        return 0
    return 1
Пример #5
0
def test_create_user_by_name(username, password, tenant_name):
    """ test administrator to create a user whose name is the giving name"""
    bt = BaseTest()
    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users'
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    tenant = bt.get_tenant_by_name(tenant_name)
    user = bt.get_user_by_name(username)

    if tenant == None or user != None:
        return 3

    body = {
        'user': {
            'name': username,
            'password': password,
            'tenantId': tenant['id'],
            'email': '*****@*****.**',
            'enabled': True
        }
    }

    response, content = bt.post(endpoint,
                                headers=headers,
                                body=json.dumps(body))

    if (response['status'] == '200'):
        return 0
    return 1
def delete_tenant(name):
    """ test administrator to delete a tenant whose name is the giving name"""
    bt = BaseTest()

    tenant = bt.get_tenant_by_name(name)

    if(tenant == None):
        print 'the tenant named %s is not existed!, skipped' %name
        return 3

    tenant_id = tenant['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants/' + tenant_id

    response, content = bt.delete(endpoint)

    if(response['status'] == '204'):
        return 0

    return 1
def test_delete_tenant_by_name(name):
    """ test administrator to delete a tenant whose name is the giving name"""
    bt = BaseTest()

    tenant = bt.get_tenant_by_name(name)

    if (tenant == None):
        print 'the tenant named %s is not existed!, skipped' % name
        return 3

    tenant_id = tenant['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants/' + tenant_id

    response, content = bt.delete(endpoint)

    if (response['status'] == '204'):
        return 0

    return 1
def test_tenant_reenable(tenant_name):
    """ test enable a disabled tenant """

    bt = BaseTest()
    tenant = bt.get_tenant_by_name(tenant_name)

    if tenant == None:
        return 3

    tenant_id = tenant["id"]

    endpoint = bt.get_service_endpoint("keystone")
    endpoint = endpoint + "/tenants/" + tenant_id

    body = {"tenant": {"enabled": True}}

    headers = {"Content-Type": "application/json", "Accept": "application/json"}

    response, content = bt.post(endpoint, headers=headers, body=json.dumps(body))

    if response["status"] == "200":
        return 0
    return 1