#!/usr/bin/env python # # Copyright (c) 2017 All rights reserved # This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # # http://www.apache.org/licenses/LICENSE-2.0 # import logging import os import sys from random import randint from sdnvpn.lib import config as sdnvpn_config from sdnvpn.lib import openstack_utils as os_utils from sdnvpn.lib import utils as test_utils from sdnvpn.lib.results import Results logger = logging.getLogger(__name__) COMMON_CONFIG = sdnvpn_config.CommonConfig() TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig( 'sdnvpn.test.functest.testcase_13') def main(): conn = os_utils.get_os_connection() results = Results(COMMON_CONFIG.line_length, conn) results.add_to_summary(0, "=") results.add_to_summary(2, "STATUS", "SUBTEST") results.add_to_summary(0, "=") if not os.path.isfile(COMMON_CONFIG.ubuntu_image_path): logger.info("Downloading image") image_dest_path = '/'.join( COMMON_CONFIG.ubuntu_image_path.split('/')[:-1]) os_utils.download_url( "http://artifacts.opnfv.org/sdnvpn/" "ubuntu-16.04-server-cloudimg-amd64-disk1.img", image_dest_path) else: logger.info("Using old image") neutron_client = os_utils.get_neutron_client() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids, flavor_ids) = ([] for i in range(9)) try: image_id = os_utils.create_glance_image( conn, COMMON_CONFIG.ubuntu_image_name, COMMON_CONFIG.ubuntu_image_path, disk="qcow2", container="bare", public="public") image_ids.append(image_id) _, flavor_id = test_utils.create_custom_flavor() flavor_ids.append(flavor_id) network_1_id, subnet_1_id, router_1_id = test_utils.create_network( conn, TESTCASE_CONFIG.net_1_name, TESTCASE_CONFIG.subnet_1_name, TESTCASE_CONFIG.subnet_1_cidr, TESTCASE_CONFIG.router_1_name) interfaces.append(tuple((router_1_id, subnet_1_id))) network_ids.extend([network_1_id]) subnet_ids.extend([subnet_1_id]) router_ids.extend([router_1_id]) sg_id = os_utils.create_security_group_full( conn, TESTCASE_CONFIG.secgroup_name, TESTCASE_CONFIG.secgroup_descr) compute_nodes = test_utils.assert_and_get_compute_nodes(conn) av_zone_1 = "nova:" + compute_nodes[0] av_zone_2 = "nova:" + compute_nodes[1] u1 = test_utils.generate_userdata_interface_create( TESTCASE_CONFIG.interface_name, TESTCASE_CONFIG.interface_number, TESTCASE_CONFIG.extra_route_ip, TESTCASE_CONFIG.extra_route_subnet_mask) # boot INTANCES vm_1 = test_utils.create_instance( conn, TESTCASE_CONFIG.instance_1_name, image_id, network_1_id, sg_id, flavor=COMMON_CONFIG.custom_flavor_name, secgroup_name=TESTCASE_CONFIG.secgroup_name, compute_node=av_zone_1, userdata=u1) vm_1_ip = test_utils.get_instance_ip(conn, vm_1) vm1_port = test_utils.get_port(conn, vm_1.id) test_utils.update_port_allowed_address_pairs( conn, vm1_port.id, [test_utils.AllowedAddressPair( TESTCASE_CONFIG.extra_route_cidr, vm1_port.mac_address)]) vm_2 = test_utils.create_instance( conn, TESTCASE_CONFIG.instance_2_name, image_id, network_1_id, sg_id, flavor=COMMON_CONFIG.custom_flavor_name, secgroup_name=TESTCASE_CONFIG.secgroup_name, compute_node=av_zone_1, userdata=u1) vm_2_ip = test_utils.get_instance_ip(conn, vm_2) vm2_port = test_utils.get_port(conn, vm_2.id) test_utils.update_port_allowed_address_pairs( conn, vm2_port.id, [test_utils.AllowedAddressPair( TESTCASE_CONFIG.extra_route_cidr, vm2_port.mac_address)]) test_utils.async_Wait_for_instances([vm_1, vm_2]) image_2_id = os_utils.create_glance_image( conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_2_id) # Moved vm_3 creation before associating its network/router with # bgpvpn. If VM is created after its network is associated to bgpvpn # via router, then BGPVPN in ODL uses router's vrf id for newly create