diff options
author | jose.lausuch <jose.lausuch@ericsson.com> | 2015-05-12 12:26:31 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2015-05-12 12:26:31 +0000 |
commit | 522e7a093b0c52f2ddca5f5334489bc1773a2ec3 (patch) | |
tree | 4627b71b398048779b7dc7bec490f4f741cd0cfe /testcases | |
parent | eb66536e331c047f3633a20a4e2d6bd4241e1c90 (diff) | |
parent | 2fd26619377c18b691627d918fa29b10f1e6ec89 (diff) |
Merge "config_functest.py: 1) Added create public network. 2) functest.yaml is now copied instead of downloaded. JIRA: FUNCTEST-10"
Diffstat (limited to 'testcases')
-rw-r--r-- | testcases/config_functest.py | 147 | ||||
-rw-r--r-- | testcases/functest.yaml | 20 | ||||
-rw-r--r-- | testcases/vPing/CI/libraries/vPing.py | 2 |
3 files changed, 107 insertions, 62 deletions
diff --git a/testcases/config_functest.py b/testcases/config_functest.py index 05376be29..76020046e 100644 --- a/testcases/config_functest.py +++ b/testcases/config_functest.py @@ -62,6 +62,7 @@ f.close() """ global variables """ +# Directories HOME = os.environ['HOME']+"/" FUNCTEST_BASE_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_functest") RALLY_REPO_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_repo") @@ -70,26 +71,39 @@ RALLY_INSTALLATION_DIR = HOME + functest_yaml.get("general").get("directories"). BENCH_TESTS_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_rally_scn") VPING_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_vping") ODL_DIR = HOME + functest_yaml.get("general").get("directories").get("dir_odl") -NEUTRON_PUBLIC_NAME = functest_yaml.get("general").get("openstack").get("neutron_public_net_name") -NEUTRON_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_net_name") -NEUTRON_SUBNET_NAME = functest_yaml.get("general").get("openstack").get("neutron_subnet_name") -NEUTRON_RANGE = functest_yaml.get("general").get("openstack").get("neutron_subnet_range") + +# NEUTRON Public Network parameters +NEUTRON_PUBLIC_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_public_net_name") +NEUTRON_PUBLIC_SUBNET_NAME = functest_yaml.get("general").get("openstack").get("neutron_public_subnet_name") +NEUTRON_PUBLIC_SUBNET_CIDR = functest_yaml.get("general").get("openstack").get("neutron_public_subnet_cidr") +NEUTRON_PUBLIC_SUBNET_START = functest_yaml.get("general").get("openstack").get("neutron_public_subnet_start") +NEUTRON_PUBLIC_SUBNET_END = functest_yaml.get("general").get("openstack").get("neutron_public_subnet_end") + +# NEUTRON Private Network parameters +NEUTRON_PRIVATE_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_private_net_name") +NEUTRON_PRIVATE_SUBNET_NAME = functest_yaml.get("general").get("openstack").get("neutron_private_subnet_name") +NEUTRON_PRIVATE_SUBNET_CIDR = functest_yaml.get("general").get("openstack").get("neutron_private_subnet_cidr") ROUTER_NAME = functest_yaml.get("general").get("openstack").get("neutron_router_name") +#GLANCE image parameters IMAGE_URL = functest_yaml.get("general").get("openstack").get("image_url") IMAGE_DISK_FORMAT = functest_yaml.get("general").get("openstack").get("image_disk_format") IMAGE_NAME = functest_yaml.get("general").get("openstack").get("image_name") IMAGE_FILE_NAME = IMAGE_URL.rsplit('/')[-1] IMAGE_DOWNLOAD_PATH = FUNCTEST_BASE_DIR + IMAGE_FILE_NAME +credentials = None +neutron_client = None def config_functest_start(): """ Start the functest environment installation """ - #if config_functest_check(): - # logger.info("Functest environment already installed in %s. Nothing to do." %FUNCTEST_BASE_DIR) - # exit(0) + + if config_functest_check(): + logger.info("Functest environment already installed in %s. Nothing to do." %FUNCTEST_BASE_DIR) + exit(0) + if not check_internet_connectivity(): logger.error("There is no Internet connectivity. Please check the network configuration.") exit(-1) @@ -97,14 +111,10 @@ def config_functest_start(): logger.error("Please source the openrc credentials and run the script again.") #TODO: source the credentials in this script exit(-1) - elif not check_neutron_net(NEUTRON_PUBLIC_NAME): - #The public network is normally created by default, no need to create a new one - logger.debug("Public network '%s' not found." % NEUTRON_PUBLIC_NAME) - logger.error("A public Neutron network is needed for the environment. Please create one.") - #TODO: source the credentials in this script - exit(-1) + else: # Clean in case there are left overs + config_functest_clean() logger.info("Starting installationg of functest environment in %s" % FUNCTEST_BASE_DIR) @@ -131,15 +141,29 @@ def config_functest_start(): config_functest_clean() exit(-1) - logger.info("Creating a private Neutron network...") - logger.debug("Checking if private network '%s' exists..." % NEUTRON_NET_NAME) - #Now: if exists we don't create it again (the clean command does not clean the neutron network) - #TODO: this check will not be needed when cleaning the neutron is implemented - if check_neutron_net(NEUTRON_NET_NAME): - logger.info("Private network '%s' found. No need to create another one." % NEUTRON_NET_NAME) + credentials = get_credentials() + neutron_client = client.Client(**credentials) + + logger.info("Configuring Neutron...") + logger.info("Checking if public network '%s' exists..." % NEUTRON_PUBLIC_NET_NAME) + #Now: if exists we don't create it again (the clean command does not clean the neutron networks yet) + if check_neutron_net(neutron_client, NEUTRON_PUBLIC_NET_NAME): + logger.info("Public network '%s' found. No need to create another one." % NEUTRON_PUBLIC_NET_NAME) else: - logger.info("Private network '%s' not found. Creating..." % NEUTRON_NET_NAME) - if not create_neutron_net(): + logger.info("Public network '%s' not found. Creating..." % NEUTRON_PUBLIC_NET_NAME) + if not create_public_neutron_net(neutron_client): + logger.error("There has been a problem while creating the Neutron network.") + #config_functest_clean() + exit(-1) + + + logger.info("Checking if private network '%s' exists..." % NEUTRON_PRIVATE_NET_NAME) + #Now: if exists we don't create it again (the clean command does not clean the neutron networks yet) + if check_neutron_net(neutron_client, NEUTRON_PRIVATE_NET_NAME): + logger.info("Private network '%s' found. No need to create another one." % NEUTRON_PRIVATE_NET_NAME) + else: + logger.info("Private network '%s' not found. Creating..." % NEUTRON_PRIVATE_NET_NAME) + if not create_private_neutron_net(neutron_client): logger.error("There has been a problem while creating the Neutron network.") #config_functest_clean() exit(-1) @@ -168,7 +192,8 @@ def config_functest_check(): errors_all = False logger.info("Checking current functest configuration...") - + credentials = get_credentials() + neutron_client = client.Client(**credentials) logger.debug("Checking directories...") errors = False @@ -197,19 +222,19 @@ def config_functest_check(): logger.debug("Checking Neutron...") errors = False - if not check_neutron_net(NEUTRON_NET_NAME): - logger.debug(" Private network '%s' NOT found." % NEUTRON_NET_NAME) + if not check_neutron_net(neutron_client, NEUTRON_PRIVATE_NET_NAME): + logger.debug(" Private network '%s' NOT found." % NEUTRON_PRIVATE_NET_NAME) errors = True errors_all = True else: - logger.debug(" Private network '%s' found." % NEUTRON_NET_NAME) + logger.debug(" Private network '%s' found." % NEUTRON_PRIVATE_NET_NAME) - if not check_neutron_net(NEUTRON_PUBLIC_NAME): - logger.debug(" Public network '%s' NOT found." % NEUTRON_PUBLIC_NAME) + if not check_neutron_net(neutron_client, NEUTRON_PUBLIC_NET_NAME): + logger.debug(" Public network '%s' NOT found." % NEUTRON_PUBLIC_NET_NAME) errors = True errors_all = True else: - logger.debug(" Public network '%s' found." % NEUTRON_PUBLIC_NAME) + logger.debug(" Public network '%s' found." % NEUTRON_PUBLIC_NET_NAME) if not errors: logger.debug("...OK") @@ -267,7 +292,7 @@ def config_functest_clean(): cmd = "sudo rm -rf " + FUNCTEST_BASE_DIR #need to be sudo, not possible with rmtree execute_command(cmd) - #logger.debug("Deleting Neutron network %s" % NEUTRON_NET_NAME) + #logger.debug("Deleting Neutron network %s" % NEUTRON_PRIVATE_NET_NAME) #if not delete_neutron_net() : # logger.error("Error deleting the network. Remove it manually.") @@ -402,10 +427,11 @@ def download_tests(): os.makedirs(ODL_DIR) os.makedirs(BENCH_TESTS_DIR) - logger.info("Downloading functest.yaml...") - yaml_url = 'https://git.opnfv.org/cgit/functest/plain/testcases/functest.yaml' - if not download_url(yaml_url,FUNCTEST_BASE_DIR): - logger.error("Unable to download the configuration file functest.yaml") + logger.info("Copying functest.yaml to functest environment...") + try: + shutil.copy("./functest.yaml", FUNCTEST_BASE_DIR+"functest.yaml") + except: + print "Error copying the file:", sys.exc_info()[0] return False logger.info("Downloading vPing test...") @@ -438,14 +464,33 @@ def download_tests(): return True +def create_public_neutron_net(neutron): + try: + neutron.format = 'json' + logger.debug('Creating Neutron network %s...' % NEUTRON_PUBLIC_NET_NAME) + json_body = {'network': {'name': NEUTRON_PUBLIC_NET_NAME, 'admin_state_up': True, 'router:external': True}} + netw = neutron.create_network(body=json_body) + net_dict = netw['network'] + network_id = net_dict['id'] + logger.debug("Network '%s' created successfully" % network_id) + + logger.debug('Creating Subnet....') + json_body = {'subnets': [{'cidr': NEUTRON_PUBLIC_SUBNET_CIDR, + 'ip_version': 4, 'network_id': network_id}]} + subnet = neutron.create_subnet(body=json_body) + logger.debug("Subnet '%s' created successfully" % subnet) + except: + print "Error:", sys.exc_info()[0] + return False -def create_neutron_net(): - credentials = get_credentials() - neutron = client.Client(**credentials) + logger.info("Public Neutron network created successfully.") + return True + +def create_private_neutron_net(neutron): try: neutron.format = 'json' - logger.debug('Creating Neutron network %s...' % NEUTRON_NET_NAME) - json_body = {'network': {'name': NEUTRON_NET_NAME, + logger.debug('Creating Neutron network %s...' % NEUTRON_PRIVATE_NET_NAME) + json_body = {'network': {'name': NEUTRON_PRIVATE_NET_NAME, 'admin_state_up': True}} netw = neutron.create_network(body=json_body) net_dict = netw['network'] @@ -453,7 +498,7 @@ def create_neutron_net(): logger.debug("Network '%s' created successfully" % network_id) logger.debug('Creating Subnet....') - json_body = {'subnets': [{'cidr': NEUTRON_RANGE, + json_body = {'subnets': [{'cidr': NEUTRON_PRIVATE_SUBNET_CIDR, 'ip_version': 4, 'network_id': network_id}]} subnet = neutron.create_subnet(body=json_body) logger.debug("Subnet '%s' created successfully" % subnet) @@ -475,21 +520,19 @@ def create_neutron_net(): logger.debug("Port created successfully.") logger.debug('Setting up gateway...') - public_network_id = get_network_id(neutron,NEUTRON_PUBLIC_NAME) + public_network_id = get_network_id(neutron,NEUTRON_PUBLIC_NET_NAME) json_body = {'network_id': public_network_id, 'enable_snat' : True} gateway = neutron.add_gateway_router(router_id,body=json_body) logger.debug("Gateway '%s' added successfully" % gateway) except: - logger.error("There has been a problem when creating the Neutron network.") + print "Error:", sys.exc_info()[0] return False - finally: - logger.info("Neutron network created successfully.") - return True - return False + logger.info("Private Neutron network created successfully.") + return True -def get_network_id(neutron_client, network_name): - networks = neutron_client.list_networks()['networks'] +def get_network_id(neutron, network_name): + networks = neutron.list_networks()['networks'] id = '' for n in networks: if n['name'] == network_name: @@ -497,23 +540,19 @@ def get_network_id(neutron_client, network_name): break return id -def check_neutron_net(net_name): - credentials = get_credentials() - neutron = client.Client(**credentials) +def check_neutron_net(neutron, net_name): for network in neutron.list_networks()['networks']: if network['name'] == net_name : for subnet in network['subnets']: return True return False -def delete_neutron_net(): +def delete_neutron_net(neutron): #TODO: remove router, ports - credentials = get_credentials() - neutron = client.Client(**credentials) try: #https://github.com/isginf/openstack_tools/blob/master/openstack_remove_tenant.py for network in neutron.list_networks()['networks']: - if network['name'] == NEUTRON_NET_NAME : + if network['name'] == NEUTRON_PRIVATE_NET_NAME : for subnet in network['subnets']: print "Deleting subnet " + subnet neutron.delete_subnet(subnet) diff --git a/testcases/functest.yaml b/testcases/functest.yaml index 2f3494997..cee07fcad 100644 --- a/testcases/functest.yaml +++ b/testcases/functest.yaml @@ -13,15 +13,21 @@ general: image_name: Ubuntu14.04 image_url: https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img image_disk_format: raw - #Public network. Must exist already. + #Public network. Will be created by config_functest.py + #It must be reachable from where the tests are ran + #For Fuel deployment, it exists already and its called net04_ext neutron_public_net_name: net04_ext + neutron_public_subnet_name: net04_ext__subnet + neutron_public_subnet_cidr: 172.16.9.0/24 + neutron_public_subnet_start: 172.16.9.130 + neutron_public_subnet_end: 172.16.9.254 #Private network for functest. Will be created by config_functest.py - neutron_net_name: functest-net - neutron_subnet_name: functest-subnet - neutron_subnet_range: 192.168.120.0/24 - neutron_subnet_start: 192.168.120.2 - neutron_subnet_end: 192.168.120.254 - neutron_subnet_gateway: 192.168.120.254 + neutron_private_net_name: functest-net + neutron_private_subnet_name: functest-subnet + neutron_private_subnet_cidr: 192.168.120.0/24 + neutron_private_subnet_start: 192.168.120.2 + neutron_private_subnet_end: 192.168.120.254 + neutron_private_subnet_gateway: 192.168.120.254 neutron_router_name: functest-router vping: ping_timeout: 200 diff --git a/testcases/vPing/CI/libraries/vPing.py b/testcases/vPing/CI/libraries/vPing.py index b81ebb881..45624de1f 100644 --- a/testcases/vPing/CI/libraries/vPing.py +++ b/testcases/vPing/CI/libraries/vPing.py @@ -31,7 +31,7 @@ PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout") NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1") NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2") GLANCE_IMAGE_NAME = functest_yaml.get("general").get("openstack").get("image_name") -NEUTRON_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_net_name") +NEUTRON_PRIVATE_NET_NAME = functest_yaml.get("general").get("openstack").get("neutron_private_net_name") FLAVOR = functest_yaml.get("vping").get("vm_flavor") |