Example #1
0
def cinder_unit_tests(token, test_config):
    """
    Run through the unit tests for cinder
    """
    print("[CINDER UNIT TESTS]")

    servers = nova.get_servers(token)
    for server in servers['servers']:
        nova.delete_server(token, server['id'])

    while servers['servers']:
        servers = nova.get_servers(token)
        time.sleep(0.5)

    volumes = cinder.get_volumes(token)
    print("List of volumes: %s" % volumes)

    for volume in volumes['volumes']:
        print("Deleting volume: %s" % volume)
        cinder.delete_volume(token, volume['id'])

    volume = cinder.create_volume(token, "volume-test", "", 1)
    print("Created volume: %s" % volume)

    volume = cinder.get_volume(token, volume['volume']['id'])
    print("Fetched volume: %s" % volume)
Example #2
0
def process_do_teardown(setup_data):
    """
    Test - Process Do Teardown
    """
    from nfv_plugins.nfvi_plugins.openstack import cinder
    from nfv_plugins.nfvi_plugins.openstack import glance
    from nfv_plugins.nfvi_plugins.openstack import neutron
    from nfv_plugins.nfvi_plugins.openstack import nova
    from nfv_plugins.nfvi_plugins.openstack import openstack

    directory = openstack.get_directory(config,
                                        openstack.SERVICE_CATEGORY.OPENSTACK)
    token = openstack.get_token(directory)

    result = nova.get_flavors(token)
    flavors = result.result_data.get('flavors', list())

    result = glance.get_images(token)
    images = result.result_data.get('images', list())

    result = cinder.get_volumes(token)
    volumes = result.result_data.get('volumes', list())

    result = neutron.get_networks(token)
    networks = result.result_data.get('networks', list())

    result = neutron.get_subnets(token)
    subnets = result.result_data.get('subnets', list())

    result = nova.get_servers(token)
    servers = result.result_data.get('servers', list())

    for resource in setup_data['resources']:
        if 'instance' == resource['type']:
            process_progress_marker_start("Delete instance %s " %
                                          resource['name'])
            server = next(
                (x for x in servers if x['name'] == resource['name']), None)
            if server is not None:
                nova.delete_server(token, server['id'])

                for _ in range(10):
                    time.sleep(5)
                    servers = nova.get_servers(token).result_data
                    if servers is not None:
                        servers = servers.get('servers', list())
                        server = next((x for x in servers
                                       if x['name'] == resource['name']), None)
                        if server is None:
                            break
                else:
                    process_progress_marker_end("[FAILED]")
                    print("Server %s not deleted." % resource['name'])
                    return False
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'subnet' == resource['type']:
            process_progress_marker_start("Delete subnet %s " %
                                          resource['name'])
            subnet = next(
                (x for x in subnets if x['name'] == resource['name']), None)
            if subnet is not None:
                neutron.delete_subnet(token, subnet['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'network' == resource['type']:
            process_progress_marker_start("Delete network %s " %
                                          resource['name'])
            network = next(
                (x for x in networks if x['name'] == resource['name']), None)
            if network is not None:
                neutron.delete_network(token, network['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'volume' == resource['type']:
            process_progress_marker_start("Delete volume %s " %
                                          resource['name'])
            volume = next(
                (x for x in volumes if x['name'] == resource['name']), None)
            if volume is not None:
                cinder.delete_volume(token, volume['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'image' == resource['type']:
            process_progress_marker_start("Delete image %s " %
                                          resource['name'])
            image = next((x for x in images if x['name'] == resource['name']),
                         None)
            if image is not None:
                glance.delete_image(token, image['id'])
            process_progress_marker_end("[OKAY]")

    for resource in setup_data['resources']:
        if 'flavor' == resource['type']:
            process_progress_marker_start("Delete flavor %s " %
                                          resource['name'])
            flavor = next(
                (x for x in flavors if x['name'] == resource['name']), None)
            if flavor is not None:
                nova.delete_flavor(token, flavor['id'])
            process_progress_marker_end("[OKAY]")

    return True
Example #3
0
def nova_unit_tests(token, test_config):
    """
    Run through the unit tests for nova
    """
    print("[NOVA UNIT TESTS]")

    response = nova.create_host_services(token, test_config['host_name'])
    print("Host-Services create response: %s" % response)

    response = nova.disable_host_services(token, test_config['host_name'])
    print("Host-Services disable response: %s" % response)

    response = nova.enable_host_services(token, test_config['host_name'])
    print("Host-Services enable response: %s" % response)

    response = nova.disable_host_services(token, test_config['host_name'])
    print("Host-Services disable response: %s" % response)

    # NOTE: if you do a delete of the host-services, the hypervisors are
    # deleted and will not be populated again until nova-compute is
    # restarted even if you re-create and enable the host-services.
    # response = nova.delete_host_services(token, test_config['host_name'])
    # print "Host-Services delete response: %s" % response

    response = nova.create_host_services(token, test_config['host_name'])
    print("Host-Services create response: %s" % response)

    response = nova.enable_host_services(token, test_config['host_name'])
    print("Host-Services enable response: %s" % response)

    hypervisors = nova.get_hypervisors(token)
    print("List of hypervisors: %s" % hypervisors)

    for hypervisor in hypervisors['hypervisors']:
        visor = nova.get_hypervisor(token, hypervisor['id'])
        print("Fetched hypervisor: %s" % visor)

    flavors = nova.get_flavors(token)
    print("List of flavors: %s" % flavors)

    for flavor in flavors['flavors']:
        print("Deleting flavor: %s" % flavor)
        nova.delete_flavor(token, flavor['id'])

    flavor = nova.create_flavor(token, 1, "flavor-test", 1, 512, 1)
    print("Created flavor: %s" % flavor)

    servers = nova.get_servers(token)
    print("List of servers: %s" % servers)

    deleted_servers = servers.copy()
    for server in servers['servers']:
        print("Deleting server: %s" % server)
        nova.delete_server(token, server['id'])

    while servers['servers']:
        servers = nova.get_servers(token)
        time.sleep(0.5)
    print("Servers deleted: %s" % deleted_servers['servers'])

    images = glance.get_images(token)
    image = next(image for image in images['images']
                 if image['name'] == 'image-test')

    networks = neutron.get_networks(token)
    network = next(network for network in networks['networks']
                   if network['name'] == 'network-test')

    networks = list()
    networks.append({'uuid': network['id']})

    server = nova.create_server(token, "server-test-with-glance",
                                flavor['flavor']['id'], image['id'],
                                networks=networks)
    print("Created server: %s" % server)

    server = nova.get_server(token, server['server']['id'])
    print("Fetched server: %s" % server)

    volumes = cinder.get_volumes(token)
    volume = next(volume for volume in volumes['volumes']
                  if volume['name'] == 'volume-test')

    block_devices = list()
    block_devices.append({'uuid': volume['id'],
                          'device_name': '/dev/sda1',
                          'source_type': 'volume',
                          'destination_type': 'volume',
                          'boot_index': '0'})

    server = nova.create_server(token, "server-test-with-cinder",
                                flavor['flavor']['id'], image['id'],
                                block_devices=block_devices,
                                networks=networks)
    status = None
    while 'ACTIVE' != status:
        server = nova.get_server(token, server['server']['id'])
        status = server['server']['status']
        time.sleep(0.5)
    print("Created server: %s" % server)

    server = nova.get_server(token, server['server']['id'])
    print("Fetched server: %s" % server)

    nova.reboot_server(token, server['server']['id'], nova.VM_REBOOT_TYPE.HARD)
    status = None
    while 'ACTIVE' != status:
        server = nova.get_server(token, server['server']['id'])
        status = server['server']['status']
        time.sleep(0.5)
    print("Hard rebooted server: %s" % server['server']['name'])

    status = None
    nova.rebuild_server(token, server['server']['id'], server['server']['name'],
                        image['id'])
    while 'ACTIVE' != status:
        server = nova.get_server(token, server['server']['id'])
        status = server['server']['status']
        time.sleep(0.5)
    print("Rebuilt server: %s" % server['server']['name'])

    servers = nova.get_servers(token)
    print("List of servers: %s" % servers)

    for server in servers['servers']:
        nova.delete_server(token, server['id'])

    while servers['servers']:
        servers = nova.get_servers(token)
        time.sleep(0.5)
    print("Servers deleted")
Example #4
0
def neutron_unit_tests(token, test_config):
    """
    Run through the unit tests for neutron
    """
    print("[NEUTRON UNIT TESTS]")

    response = neutron.create_host_services(token, test_config['host_name'],
                                            test_config['host_uuid'])
    print("Host-Services create response: %s" % response)

    response = neutron.disable_host_services(token, test_config['host_uuid'])
    print("Host-Services disable response: %s" % response)

    response = neutron.enable_host_services(token, test_config['host_uuid'])
    print("Host-Services enable response: %s" % response)

    response = neutron.disable_host_services(token, test_config['host_uuid'])
    print("Host-Services disable response: %s" % response)

    response = neutron.delete_host_services(token, test_config['host_uuid'])
    print("Host-Services delete response: %s" % response)

    response = neutron.create_host_services(token, test_config['host_name'],
                                            test_config['host_uuid'])
    print("Host-Services create response: %s" % response)

    response = neutron.enable_host_services(token, test_config['host_uuid'])
    print("Host-Services enable response: %s" % response)

    servers = nova.get_servers(token)
    for server in servers['servers']:
        nova.delete_server(token, server['id'])

    while servers['servers']:
        servers = nova.get_servers(token)
        time.sleep(0.5)

    networks = neutron.get_networks(token)
    print("List of networks: %s" % networks)

    for network in networks['networks']:
        print("Deleting network: %s" % network)
        neutron.delete_network(token, network['id'])

    network = neutron.create_network(token, 'network-test', 'vlan', 450,
                                     'physnet0', False)
    print("Created network: %s" % network)

    network = neutron.update_network(token, network['network']['id'],
                                     neutron.NETWORK_ADMIN_STATE.DOWN, True)
    print("Updated network: %s" % network)

    subnets = neutron.get_subnets(token)
    print("List of subnets: %s" % subnets)

    for subnet in subnets['subnets']:
        print("Deleting subnet: %s" % subnet)
        neutron.delete_subnet(token, subnet['id'])

    subnet = neutron.create_subnet(token, network['network']['id'],
                                   'subnet-test', 4, '192.168.101.0/24',
                                   '192.168.101.1', True)
    print("Created subnet: %s" % subnet)

    subnet = neutron.update_subnet(token, subnet['subnet']['id'],
                                   delete_gateway=True, dhcp_enabled=False)
    print("Updated subnet: %s" % subnet)

    subnet = neutron.get_subnet(token, subnet['subnet']['id'])
    print("Fetched subnet: %s" % subnet)