Exemplo n.º 1
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 test_user_reenable(username):
    """ test enable a user who was disabled """

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if (user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id + '/enabled'

    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    body = {
        'user': {
            'enabled': True,
        },
    }

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

    if (response['status'] != '200'):
        print "Reenable user failed!"
        return 1

    return 0
def test_disable_user(username):
    """ test administrator to disable a ueser by giving user name """

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if (user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id + '/enabled'

    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    body = {
        'user': {
            'enabled': False,
        },
    }

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

    if (response['status'] != '200'):
        return 1

    return 0
Exemplo n.º 4
0
def test_create_tenant_by_name(name):
    """ test administrator to create a tenant whose name is the giving name """
    bt = BaseTest()
    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants'
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }

    body = {
        "tenant": {
            "name": name,
            "description": "test create tenant",
            "enabled": "true",
        },
    }

    response, content = bt.post(endpoint,
                                headers=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_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
Exemplo n.º 7
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_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_disable_user(username):
    """ test administrator to disable a ueser by giving user name """

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if(user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id + '/enabled'

    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
    body = {
            'user': {
                'enabled': False,
            },
        }

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

    if(response['status'] != '200'):
        return 1

    return 0
def upload_glance_remote_image(file_path, disk_format='raw', container_format='bare', image_name='jeos_remote', timeout=60):
    """ Upload remote glance image file """

    baseTest = BaseTest()
    token = baseTest.token
    endpoint = baseTest.get_service_endpoint('glance')
    endpoint = endpoint.rsplit('/', 1)[0]

    glance = Client('1', endpoint, token)

    meta = {
        'name': image_name,
        'is_public': True,
        'disk_format': disk_format,
        'container_format': container_format,
        'copy_from': file_path,
    }

    start = int(time.time())
    results = glance.images.create(**meta)

    image_id = results.id
   
    ret = baseTest._wait_for_image_status(image_id, 'ACTIVE', timeout)

    image_file = "/var/lib/glance/images/" + image_id
    # Ensure the image has been realy stroed in the glance location
    if ret == 0 and os.path.isfile(image_file):
        # clean the created image
        baseTest.clean_images(image_name)
        return 0
    return 1
def change_user_password(username, password, tenant_name, newpassword):
    """ Change a user can change its password """

    bt = BaseTest()
    user = bt.get_user_by_name(username)
    if user == None:
        return 3

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

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user['id']

    bt_user = BaseTest(username, password, tenant_name)
    
    post_body = {
                'user': {
                    'id': user['id'],
                    'password': newpassword,
                }
            }

    response, content = bt_user.put(endpoint, headers=headers, body=json.dumps(post_body))

    if(response['status'] != '200'):
        return 1
    return 0
def test_user_reenable(username):
    """ test enable a user who was disabled """

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if(user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id + '/enabled'

    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
    body = {
            'user': {
                'enabled': True,
            },
        }

    response, content = bt.put(endpoint, headers=headers, body=json.dumps(body));
    
    if(response['status'] != '200'):
        print "Reenable user failed!"
        return 1

    return 0
def upload_glance_image(file, disk_format='raw', container_format='bare', image_name='jeos1', timeout=60):
    """ Upload glance image file """

    baseTest = BaseTest()
    token = baseTest.token
    endpoint = baseTest.get_service_endpoint('glance')
    endpoint = endpoint.rsplit('/', 1)[0]

    glance = Client('1', endpoint, token)

    start = int(time.time())
    image = glance.images.create(name=image_name, disk_format=disk_format, container_format=container_format, is_public=True)

    image.update(data=open(file, 'rb'))
   
    return baseTest._wait_for_image_status(image.id, 'ACTIVE', 60) 
def test_create_tenant_by_name(name):
    """ test administrator to create a tenant whose name is the giving name """
    bt = BaseTest()
    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/tenants'
    headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}

    body = {
                "tenant": {
                    "name": name,
                    "description": "test create tenant",
                    "enabled": "true",
                },
    }
    
    response, content = bt.post(endpoint, headers=headers, body=json.dumps(body))

    if(response['status'] == '200'):
        return 0
    return 1
def test_delete_user(username):
    """ test administrator to delete a user whose name is the giving name"""

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if(user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id

    response, content = bt.delete(endpoint)    

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

    return 1
def test_delete_user(username):
    """ test administrator to delete a user whose name is the giving name"""

    bt = BaseTest()
    user = bt.get_user_by_name(username)

    if (user == None):
        return 3

    user_id = user['id']

    endpoint = bt.get_service_endpoint('keystone')
    endpoint = endpoint + '/users/' + user_id

    response, content = bt.delete(endpoint)

    if (response['status'] == '200'):
        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 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_user_chpasswd_login(username, password, tenant_name, newpassword):
    """ test change a users password and the user can login with new password """

    ret = change_user_password(username, password, tenant_name, newpassword)

    if(ret != 0):
        return ret

    bt = BaseTest()
    endpoint = bt.get_service_endpoint('nova')
    endpoint = endpoint + '/servers'

    bt_user = BaseTest(username, newpassword, tenant_name)
    response, content = bt_user.get(endpoint)

    # restore the user's password
    change_user_password(username, newpassword, tenant_name, password)

    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
Exemplo n.º 21
0
def upload_glance_remote_image(file_path,
                               disk_format='raw',
                               container_format='bare',
                               image_name='jeos_remote',
                               timeout=60):
    """ Upload remote glance image file """

    baseTest = BaseTest()
    token = baseTest.token
    endpoint = baseTest.get_service_endpoint('glance')
    endpoint = endpoint.rsplit('/', 1)[0]

    glance = Client('1', endpoint, token)

    meta = {
        'name': image_name,
        'is_public': True,
        'disk_format': disk_format,
        'container_format': container_format,
        'copy_from': file_path,
    }

    start = int(time.time())
    results = glance.images.create(**meta)

    image_id = results.id

    ret = baseTest._wait_for_image_status(image_id, 'ACTIVE', timeout)

    image_file = "/var/lib/glance/images/" + image_id
    # Ensure the image has been realy stroed in the glance location
    if ret == 0 and os.path.isfile(image_file):
        # clean the created image
        baseTest.clean_images(image_name)
        return 0
    return 1