diff options
Diffstat (limited to 'test/vcpe/vcpe.py')
-rwxr-xr-x | test/vcpe/vcpe.py | 153 |
1 files changed, 100 insertions, 53 deletions
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py index c768aa84d..e6038e719 100755 --- a/test/vcpe/vcpe.py +++ b/test/vcpe/vcpe.py @@ -4,7 +4,7 @@ import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s') import sys -from vcpecommon import * +from vcpecommon import * # pylint: disable=W0614 import sdcutils import soutils from datetime import datetime @@ -13,7 +13,15 @@ import vcpe_custom_service import csar_parser import config_sdnc_so import json +import urllib3 +import argparse +from collections import OrderedDict +# disable InsecureRequestWarning warning in requests < 2.16.0 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +# disable InsecureRequestWarning warning in requests >= 2.16.0 +from requests.packages.urllib3.exceptions import InsecureRequestWarning +requests.packages.urllib3.disable_warnings(InsecureRequestWarning) def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid): logger = logging.getLogger(__name__) @@ -60,22 +68,30 @@ def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, s def deploy_brg_only(): - logger = logging.getLogger(__name__) + logger = logging.getLogger(__name__) # pylint: disable=W0612 - vcpecommon = VcpeCommon() + vcpecommon = VcpeCommon(cfg_file=args.config) preload_dict = vcpecommon.load_preload_data() # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1] name_suffix = datetime.now().strftime('%Y%m%d%H%M') # create multiple services based on the pre-determined order svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) - for keyword in ['brg']: + for keyword in ['brgemu']: + keyword_vnf=keyword + "_" + keyword_gra=keyword + "gra_" heatbridge = 'gmux' == keyword csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') - vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates') - vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0']) - svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, - name_suffix, heatbridge) + vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates') + gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates') + if vcpecommon.gra_api_flag: + vcpecommon.increase_ip_address_or_vni_in_template(gra_template_file, ['vbrgemu_private_ip_0']) + svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict, + name_suffix, heatbridge) + else: + vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0']) + svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, + name_suffix, heatbridge) if not svc_instance_uuid[keyword]: sys.exit(1) @@ -86,7 +102,7 @@ def deploy_brg_only(): def deploy_infra(): logger = logging.getLogger(__name__) - vcpecommon = VcpeCommon() + vcpecommon = VcpeCommon(cfg_file=args.config) # preload all VNF-API networks network_template = vcpecommon.find_file('network.', 'json', 'preload_templates') @@ -121,11 +137,11 @@ def deploy_infra(): vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates') gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates') if vcpecommon.gra_api_flag: - svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict, - name_suffix, heatbridge) + svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict, + name_suffix, heatbridge) else: - svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, - name_suffix, heatbridge) + svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, + name_suffix, heatbridge) if not svc_instance_uuid[keyword]: sys.exit(1) @@ -153,12 +169,12 @@ def deploy_infra(): def deploy_custom_service(): nodes = ['brg', 'mux'] - vcpecommon = VcpeCommon(nodes) + vcpecommon = VcpeCommon(nodes, cfg_file=args.config) custom_service = vcpe_custom_service.CustomService(vcpecommon) # clean up host_dic = {k: vcpecommon.hosts[k] for k in nodes} - if False: + if False: # pylint: disable=W0125 if not vcpecommon.delete_vxlan_interfaces(host_dic): sys.exit(1) custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword) @@ -176,7 +192,7 @@ def deploy_custom_service(): def closed_loop(lossrate=0): nodes = ['brg', 'mux'] logger = logging.getLogger('__name__') - vcpecommon = VcpeCommon(nodes) + vcpecommon = VcpeCommon(nodes, cfg_file=args.config) logger.info('Setting up closed loop policy') policy_template_file = vcpecommon.find_file('operational.vcpe', 'json', 'preload_templates') @@ -199,9 +215,9 @@ def closed_loop(lossrate=0): def init_so_sdnc(): - logger = logging.getLogger('__name__') - vcpecommon = VcpeCommon() - #config_sdnc_so.insert_sdnc_ip_pool(vcpecommon) + logger = logging.getLogger('__name__') # pylint: disable=W0612 + vcpecommon = VcpeCommon(cfg_file=args.config) + config_sdnc_so.insert_sdnc_ip_pool(vcpecommon) config_sdnc_so.insert_customer_service_to_so(vcpecommon) #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon) vgw_vfmod_name_index= 0 @@ -209,13 +225,16 @@ def init_so_sdnc(): def init(): - vcpecommon = VcpeCommon() + vcpecommon = VcpeCommon(cfg_file=args.config) init_sdc(vcpecommon) download_vcpe_service_templates(vcpecommon) + preloader = preload.Preload(vcpecommon) + template_aai_region_data = vcpecommon.find_file('aai_region_data', 'json', 'preload_templates') + preloader.preload_aai_data(template_aai_region_data) def init_sdc(vcpecommon): - sdc = sdcutils.SdcUtils(vcpecommon) + sdc = sdcutils.SdcUtils(vcpecommon) # pylint: disable=W0612 # default SDC creates BRG - remove this in frankfurt #sdc.create_allotted_resource_subcategory('BRG') @@ -226,54 +245,82 @@ def download_vcpe_service_templates(vcpecommon): def tmp_sniro(): - logger = logging.getLogger(__name__) + logger = logging.getLogger(__name__) # pylint: disable=W0612 - vcpecommon = VcpeCommon() + vcpecommon = VcpeCommon(cfg_file=args.config) svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) # Setting up SNIRO config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu']) -def test(): - vcpecommon = VcpeCommon() +def test(): + vcpecommon = VcpeCommon(cfg_file=args.config) print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04'))) -if __name__ == '__main__': - print('----------------------------------------------------------------------------------------------------') - print(' vcpe.py: Brief info about this program') -# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)') - print(' vcpe.py init: Add customer service data to SDNC and SO DBs.') - print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.') - print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).') - print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs') - print(' vcpe.py loop: Test closed loop control (packet loss set to 22)') - print(' vcpe.py noloss: Set vGMUX packet loss to 0') - print('----------------------------------------------------------------------------------------------------') +def get_arg_parser(modes): + """ + Parse cmd line options and return ArgumentParser object + :param modes: map of supported script modes + :return: ArgumentParser object + """ + # Build usage synopsis string + usage = "\n"*2 + for k,v in modes.items(): + usage += 'vcpe.py {0:12} {1}\n'.format(k + ':',v) - if len(sys.argv) != 2: - sys.exit() + parser = argparse.ArgumentParser(usage=usage, formatter_class= + argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('mode',metavar='MODE', + help='Script mode: {0}'.format('|'.join(modes.keys())), + choices=modes.keys()) + parser.add_argument('--config',help='Configuration file path',default=None) - if sys.argv[1] == 'sdc': - print('Under development') - elif sys.argv[1] == 'init': - init() - init_so_sdnc() - elif sys.argv[1] == 'infra': + return parser + +if __name__ == '__main__': + # Supported modes matrix + # OrderedDict object has to be used to preserve desired modes + # order in synopsis text + modes = OrderedDict() +# modes["sdc"] = "Onboard VNFs, design and distribute vCPE services (under development)" + modes["init"] = "Add customer service data to SDNC and SO DBs" + modes["infra"] = "Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG" + modes["brg"] = "Deploy brg only (for testing after infra succeeds)" + modes["customer"] = "Deploy customer service, including vGW and VxLANs" + modes["loop"] = "Test closed loop control (packet loss set to 22)" + modes["noloss"] = "Set vGMUX packet loss to 0" + modes["test"] = "" + modes["sniro"] = "Config SNIRO homing emulator" + + parser = get_arg_parser(modes) + + try: + assert len(sys.argv) != 1 + except AssertionError: + # No cmd line opts given, print help + parser.print_help() + sys.exit(1) + else: + args = parser.parse_args() + + if args.mode == 'init': + init() + init_so_sdnc() + elif args.mode == 'infra': #if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower(): - deploy_infra() - elif sys.argv[1] == 'customer': - if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower(): + deploy_infra() + elif args.mode == 'customer': + if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower(): # pylint: disable=E0602 deploy_custom_service() - elif sys.argv[1] == 'loop': + elif args.mode == 'loop': closed_loop(22) - elif sys.argv[1] == 'noloss': + elif args.mode == 'noloss': closed_loop(0) - elif sys.argv[1] == 'brg': + elif args.mode == 'brg': deploy_brg_only() - elif sys.argv[1] == 'sniro': + elif args.mode == 'sniro': tmp_sniro() - elif sys.argv[1] == 'test': + elif args.mode == 'test': test() - |