SDNC SSL port, BRG category, DEBUG
[integration.git] / test / vcpe / vcpe.py
1 #! /usr/bin/python
2
3 import logging
4 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
5 #logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
6
7 import sys
8 from vcpecommon import *
9 import sdcutils
10 import soutils
11 from datetime import datetime
12 import preload
13 import vcpe_custom_service
14 import csar_parser
15 import config_sdnc_so
16 import json
17
18
19 def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
20     logger = logging.getLogger(__name__)
21
22     logger.info('\n----------------------------------------------------------------------------------')
23     logger.info('Start to config SNIRO homing emulator')
24
25     preloader = preload.Preload(vcpecommon)
26     template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
27     template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
28
29     vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar')
30     parser = csar_parser.CsarParser()
31     parser.parse_csar(vcperescust_csar)
32     tunnelxconn_ar_name = None
33     brg_ar_name = None
34     vgw_name = None
35     for model in parser.vnf_models:
36         logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
37         if 'tunnel' in model['modelCustomizationName'].lower():
38             logger.info('tunnel is in %s', model['modelCustomizationName'])
39             tunnelxconn_ar_name = model['modelCustomizationName']
40         elif 'brg' in model['modelCustomizationName'].lower():
41             logger.info('brg is in %s', model['modelCustomizationName'])
42             brg_ar_name = model['modelCustomizationName']
43         #elif 'vgw' in model['modelCustomizationName']:
44         else:
45             vgw_name = model['modelCustomizationName']
46
47     if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
48         logger.error('Cannot find all names from %s.', vcperescust_csar)
49         sys.exit()
50
51     preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
52                             vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)
53
54
55 def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
56     """
57     :return:  service instance UUID
58     """
59     so = soutils.SoUtils(vcpecommon, 'v4')
60     return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
61
62
63 def deploy_brg_only():
64     logger = logging.getLogger(__name__)
65
66     vcpecommon = VcpeCommon()
67     preload_dict = vcpecommon.load_preload_data()
68 #    name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
69     name_suffix = datetime.now().strftime('%Y%m%d%H%M')
70
71     # create multiple services based on the pre-determined order
72     svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
73     for keyword in ['brg']:
74         heatbridge = 'gmux' == keyword
75         csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
76         vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
77         vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
78         svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
79                                                         name_suffix, heatbridge)
80         if not svc_instance_uuid[keyword]:
81             sys.exit()
82
83     # Setting up SNIRO
84     config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
85
86
87 def deploy_infra():
88     logger = logging.getLogger(__name__)
89
90     vcpecommon = VcpeCommon()
91
92     # preload all networks
93     network_template = vcpecommon.find_file('network', 'json', 'preload_templates')
94     name_suffix = datetime.now().strftime('%Y%m%d%H%M')
95     preloader = preload.Preload(vcpecommon)
96     preload_dict = preloader.preload_all_networks(network_template, name_suffix)
97     logger.debug('Initial preload dictionary:')
98     logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
99     if not preload_dict:
100         logger.error("Failed to preload networks.")
101         sys.exit()
102     vcpecommon.save_preload_data(preload_dict)
103
104     # create multiple services based on the pre-determined order
105     svc_instance_uuid = {}
106     for keyword in ['infra', 'bng', 'gmux', 'brg']:
107         heatbridge = 'gmux' == keyword
108         csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
109         vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
110         svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
111                                                         name_suffix, heatbridge)
112         if not svc_instance_uuid[keyword]:
113             sys.exit()
114
115     vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
116     # Setting up SNIRO
117     config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
118
119     print('----------------------------------------------------------------------------------------------------')
120     print('Congratulations! The following have been completed correctly:')
121     print(' - Infrastructure Service Instantiation: ')
122     print('     * 4 VMs:      DHCP, AAA, DNS, Web Server')
123     print('     * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
124     print(' - vBNG Service Instantiation: ')
125     print('     * 1 VM:       vBNG')
126     print('     * 2 Networks: BRG_BNG, BNG_MUX')
127     print(' - vGMUX Service Instantiation: ')
128     print('     * 1 VM:       vGMUX')
129     print('     * 1 Network:  MUX_GW')
130     print(' - vBRG Service Instantiation: ')
131     print('     * 1 VM:       vBRG')
132     print(' - Adding vGMUX vServer information to AAI.')
133     print(' - SNIRO Homing Emulator configuration.')
134
135
136 def deploy_custom_service():
137     nodes = ['brg', 'mux']
138     vcpecommon = VcpeCommon(nodes)
139     custom_service = vcpe_custom_service.CustomService(vcpecommon)
140
141     # clean up
142     host_dic = {k: vcpecommon.hosts[k] for k in nodes}
143     if False:
144         if not vcpecommon.delete_vxlan_interfaces(host_dic):
145             sys.exit()
146         custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
147
148     #custom_service.clean_up_sdnc()
149
150     # create new service
151     csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
152     vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
153     vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
154     preload_dict = vcpecommon.load_preload_data()
155     custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
156
157
158 def closed_loop(lossrate=0):
159     nodes = ['brg', 'mux']
160     logger = logging.getLogger('__name__')
161     vcpecommon = VcpeCommon(nodes)
162     logger.info('Cleaning up vGMUX data reporting settings')
163     vcpecommon.del_vgmux_ves_mode()
164     time.sleep(2)
165     vcpecommon.del_vgmux_ves_collector()
166
167     logger.info('Starting vGMUX data reporting to DCAE')
168     time.sleep(2)
169     vcpecommon.set_vgmux_ves_collector()
170
171     logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
172     time.sleep(2)
173     vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
174     if lossrate > 0:
175         print('Now please observe vGMUX being restarted')
176
177
178 def init_so_sdnc():
179     logger = logging.getLogger('__name__')
180     vcpecommon = VcpeCommon()
181     config_sdnc_so.insert_customer_service_to_so(vcpecommon)
182     #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
183     vgw_vfmod_name_index=  0
184     vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
185
186
187 def init():
188     vcpecommon = VcpeCommon()
189     init_sdc(vcpecommon)
190     download_vcpe_service_templates(vcpecommon)
191
192
193 def init_sdc(vcpecommon):
194     sdc = sdcutils.SdcUtils(vcpecommon)
195     # default SDC creates BRG - remove this in frankfurt
196     #sdc.create_allotted_resource_subcategory('BRG')
197
198
199 def download_vcpe_service_templates(vcpecommon):
200     sdc = sdcutils.SdcUtils(vcpecommon)
201     sdc.download_vcpe_service_template()
202
203
204 def tmp_sniro():
205     logger = logging.getLogger(__name__)
206
207     vcpecommon = VcpeCommon()
208
209     svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
210     # Setting up SNIRO
211     config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
212
213
214 def test(): 
215     vcpecommon = VcpeCommon()
216     print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
217
218
219 if __name__ == '__main__':
220     print('----------------------------------------------------------------------------------------------------')
221     print(' vcpe.py:            Brief info about this program')
222 #    print(' vcpe.py sdc:        Onboard VNFs, design and distribute vCPE services (under development)')
223     print(' vcpe.py init:       Add customer service data to SDNC and SO DBs.')
224     print(' vcpe.py infra:      Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
225     print(' vcpe.py brg:        Deploy brg only (for testing after infra succeeds).')
226     print(' vcpe.py customer:   Deploy customer service, including vGW and VxLANs')
227     print(' vcpe.py loop:       Test closed loop control')
228     print('----------------------------------------------------------------------------------------------------')
229
230     if len(sys.argv) != 2:
231         sys.exit()
232
233     if sys.argv[1] == 'sdc':
234         print('Under development')
235     elif sys.argv[1] == 'init':
236             init()
237             init_so_sdnc()
238     elif sys.argv[1] == 'infra':
239         if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
240             deploy_infra()
241     elif sys.argv[1] == 'customer':
242         if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
243             deploy_custom_service()
244     elif sys.argv[1] == 'loop':
245         closed_loop(22)
246     elif sys.argv[1] == 'noloss':
247         closed_loop(0)
248     elif sys.argv[1] == 'brg':
249         deploy_brg_only()
250     elif sys.argv[1] == 'sniro':
251         tmp_sniro()
252     elif sys.argv[1] == 'test':
253         test()
254