Create a common network for functest for all the tests
authorjose.lausuch <jose.lausuch@ericsson.com>
Wed, 9 Dec 2015 11:07:40 +0000 (12:07 +0100)
committerjose.lausuch <jose.lausuch@ericsson.com>
Wed, 9 Dec 2015 13:07:44 +0000 (14:07 +0100)
Some installers provide a private network by default,
if that is the case, it will not create another one.
This is needed for Rally/Tempest to work.

Removed from vPing test case, since it will use that network as well.

Change-Id: Iaff8a9e18026fe5aba31e567a4a8d5faf4a0bb6b
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
testcases/config_functest.py
testcases/config_functest.yaml
testcases/functest_utils.py
testcases/vPing/CI/libraries/vPing.py

index e66240e..11b31c9 100755 (executable)
@@ -68,6 +68,18 @@ RALLY_COMMIT = functest_yaml.get("general").get("openstack").get("rally_stable_c
 IMAGE_FILE_NAME = functest_yaml.get("general").get("openstack").get("image_file_name")
 IMAGE_PATH = DATA_DIR + "/" + IMAGE_FILE_NAME
 
+# 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")
+NEUTRON_ROUTER_NAME = functest_yaml.get("general"). \
+    get("openstack").get("neutron_router_name")
+
+creds_neutron = functest_utils.get_credentials("neutron")
+neutron_client = neutronclient.Client(**creds_neutron)
 
 def action_start():
     """
@@ -85,8 +97,20 @@ def action_start():
         # Clean in case there are left overs
         logger.debug("Cleaning possible functest environment leftovers.")
         action_clean()
-
         logger.info("Starting installation of functest environment")
+
+        private_net = functest_utils.get_private_net(neutron_client)
+        if private_net is None:
+            # If there is no private network in the deployment we create one
+            if not create_private_neutron_net(neutron_client):
+                logger.error("There has been a problem while creating the functest network.")
+                action_clean()
+                exit(-1)
+        else:
+            logger.info("Private network '%s' already existing in the deployment."
+                 % private_net['name'])
+
+
         logger.info("Installing Rally...")
         if not install_rally():
             logger.error("There has been a problem while installing Rally.")
@@ -262,6 +286,46 @@ def check_rally():
         return False
 
 
+def create_private_neutron_net(neutron):
+    neutron.format = 'json'
+    logger.info('Creating neutron network %s...' % NEUTRON_PRIVATE_NET_NAME)
+    network_id = functest_utils. \
+        create_neutron_net(neutron, NEUTRON_PRIVATE_NET_NAME)
+
+    if not network_id:
+        return False
+    logger.debug("Network '%s' created successfully" % network_id)
+    logger.debug('Creating Subnet....')
+    subnet_id = functest_utils. \
+        create_neutron_subnet(neutron,
+                              NEUTRON_PRIVATE_SUBNET_NAME,
+                              NEUTRON_PRIVATE_SUBNET_CIDR,
+                              network_id)
+    if not subnet_id:
+        return False
+    logger.debug("Subnet '%s' created successfully" % subnet_id)
+    logger.debug('Creating Router...')
+    router_id = functest_utils. \
+        create_neutron_router(neutron, NEUTRON_ROUTER_NAME)
+
+    if not router_id:
+        return False
+
+    logger.debug("Router '%s' created successfully" % router_id)
+    logger.debug('Adding router to subnet...')
+
+    result = functest_utils.add_interface_router(neutron, router_id, subnet_id)
+
+    if not result:
+        return False
+
+    logger.debug("Interface added successfully.")
+    network_dic = {'net_id': network_id,
+                   'subnet_id': subnet_id,
+                   'router_id': router_id}
+    return True
+
+
 def main():
     if not (args.action in actions):
         logger.error('argument not valid')
@@ -273,6 +337,7 @@ def main():
         #TODO: source the credentials in this script
         exit(-1)
 
+
     if args.action == "start":
         action_start()
 
index 4603357..fc8b1c1 100644 (file)
@@ -38,7 +38,6 @@ general:
         image_file_name:  cirros-0.3.4-x86_64-disk.img
         image_disk_format:  qcow2
 
-
         #Public network. Optional
         neutron_public_net_name: net04_ext
         neutron_public_subnet_name: net04_ext__subnet
@@ -53,13 +52,18 @@ general:
         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
     vm_flavor: m1.small #adapt to your environment
     vm_name_1: opnfv-vping-1
     vm_name_2: opnfv-vping-2
-    ip_1: 192.168.120.30
-    ip_2: 192.168.120.40
+    vping_private_net_name: vping-net
+    vping_private_subnet_name: vping-subnet
+    vping_private_subnet_cidr: 192.168.130.0/24
+    vping_router_name: vping-router
+    ip_1: 192.168.130.30
+    ip_2: 192.168.130.40
 
 vIMS:
     general:
index d09ae83..7dce96d 100644 (file)
@@ -250,6 +250,17 @@ def update_sg_quota(neutron_client, tenant_id, sg_quota, sg_rule_quota):
         print "Error:", sys.exc_info()[0]
         return False
 
+
+def get_private_net(neutron_client):
+    # Checks if there is an existing private network
+    networks = neutron_client.list_networks()['networks']
+    if len(networks) == 0:
+        return None
+    for net in networks:
+        if net['router:external'] == False:
+            return net
+    return None
+
 # ################ GLANCE #################
 
 
index e9f8ad1..e85948b 100644 (file)
@@ -89,17 +89,17 @@ FLAVOR = functest_yaml.get("vping").get("vm_flavor")
 
 # NEUTRON Private Network parameters
 
-NEUTRON_PRIVATE_NET_NAME = functest_yaml.get("general"). \
-    get("openstack").get("neutron_private_net_name")
+NEUTRON_PRIVATE_NET_NAME = functest_yaml.get("vping"). \
+    get("vping_private_net_name")
 
-NEUTRON_PRIVATE_SUBNET_NAME = functest_yaml.get("general"). \
-    get("openstack").get("neutron_private_subnet_name")
+NEUTRON_PRIVATE_SUBNET_NAME = functest_yaml.get("vping"). \
+    get("vping_private_subnet_name")
 
-NEUTRON_PRIVATE_SUBNET_CIDR = functest_yaml.get("general"). \
-    get("openstack").get("neutron_private_subnet_cidr")
+NEUTRON_PRIVATE_SUBNET_CIDR = functest_yaml.get("vping"). \
+    get("vping_private_subnet_cidr")
 
-NEUTRON_ROUTER_NAME = functest_yaml.get("general"). \
-    get("openstack").get("neutron_router_name")
+NEUTRON_ROUTER_NAME = functest_yaml.get("vping"). \
+    get("vping_router_name")
 
 
 def pMsg(value):