def config_st(self, st_name, mgmt=None, left=None, right=None, st_version=2, service_mode='transparent', service_type='firewall'): ''' mgmt, left, right are VN fq name strings ''' if_details = {} if mgmt: if_details['management'] = {} if left: if_details['left'] = {} if right: if_details['right'] = {} st_fixture = self.useFixture( SvcTemplateFixture(connections=self.connections, st_name=st_name, service_type=service_type, if_details=if_details, service_mode=service_mode, version=st_version)) assert st_fixture.verify_on_setup() return st_fixture
def create_l3pnf(self, left_lr, right_lr, pnf_device, left_svc_vlan='1000', right_svc_vlan='2000', left_svc_asn_srx='65000', left_svc_asn_qfx='65100', right_svc_asn_qfx='65200'): virtualization_type = 'physical-device' device_dict = self.inputs.physical_routers_data[pnf_device.name] left_intf = device_dict['local_left_intf'] right_intf = device_dict['local_right_intf'] left_qfx = device_dict['left_qfx'] right_qfx = device_dict['right_qfx'] left_qfx_intf = device_dict['left_qfx_intf'] right_qfx_intf = device_dict['right_qfx_intf'] sas_id = self.vnc_h.create_service_appliance_set( virtualization_type=virtualization_type) self.addCleanup(self.vnc_h.delete_service_appliance_set, sas_id) st_name = get_random_name('pnf_st') if_details = {'left': dict(), 'right': dict()} st_fixture = self.useFixture( SvcTemplateFixture(self.connections, st_name, 'firewall', if_details, virtualization_type=virtualization_type, service_appliance_set=sas_id)) sa_id = self.vnc_h.create_service_appliance_pnf( sas_id, pnf_device.name, left_intf, right_intf, left_qfx, left_qfx_intf, right_qfx, right_qfx_intf, virtualization_type=virtualization_type) self.addCleanup(self.vnc_h.delete_service_appliance, sa_id) si_name = get_random_name('pnf_si') si_fixture = self.useFixture( SvcInstanceFixture(self.connections, si_name, st_fixture.st_obj, if_details, virtualization_type=virtualization_type, left_svc_vlan=left_svc_vlan, right_svc_vlan=right_svc_vlan, left_svc_asn_srx=left_svc_asn_srx, left_svc_asn_qfx=left_svc_asn_qfx, right_svc_asn_qfx=right_svc_asn_qfx)) si_id = si_fixture.si_obj.uuid pt_id = self.vnc_h.create_port_tuple_pnf(si_id, left_lr, right_lr) self.addCleanup(self.vnc_h.delete_port_tuple, pt_id) self.logger.info("waiting for the configs to be pushed") self.sleep(60)
def config_st_si_subInt(self): st_name = get_random_name("in_net_svc_template_1") svc_scaling = False max_inst = 1 svc_img_name = 'tiny_in_net' svc_type = 'firewall' static_route = [None, None, None] mgmt_props = ['management', False, False] left_scaling = False right_scaling = False if_list = [ mgmt_props, ['left', left_scaling, bool(static_route[1])], ['right', right_scaling, bool(static_route[2])], ] flavor = 'contrail_flavor_2cpu' st_version = 2 ordered_interfaces = True si_name = get_random_name("in_net_svc_instance") svc_mode = 'in-network' st_fixture = self.useFixture( SvcTemplateFixture(connections=self.connections, inputs=self.inputs, domain_name=self.inputs.domain_name, st_name=st_name, svc_img_name=svc_img_name, svc_type=svc_type, if_list=if_list, svc_mode=svc_mode, svc_scaling=svc_scaling, flavor=flavor, ordered_interfaces=ordered_interfaces, version=st_version)) si_fixture = self.useFixture( SvcInstanceFixture(connections=self.connections, inputs=self.inputs, domain_name=self.inputs.domain_name, project_name=self.inputs.project_name, si_name=si_name, svc_template=st_fixture.st_obj, if_list=if_list, mgmt_vn_name=self.mgmt_vn_fixture.vn_fq_name, left_vn_name=self.left_vn_fixture.vn_fq_name, right_vn_name=self.right_vn_fixture.vn_fq_name, do_verify=True, max_inst=max_inst, static_route=static_route)) return si_fixture
def config_st_si_subInt(self): st_name = get_random_name("in_net_svc_template_1") svc_scaling = False max_inst = 1 svc_img_name = 'tiny_in_net' svc_type = 'firewall' static_route = [None, None, None] left_scaling = False right_scaling = False if_details = { 'management': { 'shared_ip_enable': False, 'static_route_enable': False }, 'left': { 'shared_ip_enable': left_scaling, 'static_route_enable': False }, 'right': { 'shared_ip_enable': right_scaling, 'static_route_enable': False } } flavor = 'contrail_flavor_2cpu' st_version = 2 si_name = get_random_name("in_net_svc_instance") svc_mode = 'in-network' st_fixture = self.useFixture( SvcTemplateFixture(connections=self.connections, st_name=st_name, svc_type=svc_type, if_details=if_details, svc_mode=svc_mode, version=st_version)) si_fixture = self.useFixture( SvcInstanceFixture(connections=self.connections, si_name=si_name, svc_template=st_fixture.st_obj, if_details=if_details, mgmt_vn_name=self.mgmt_vn_fixture.vn_fq_name, left_vn_name=self.left_vn_fixture.vn_fq_name, right_vn_name=self.right_vn_fixture.vn_fq_name, do_verify=True, max_inst=max_inst)) return si_fixture
def createServiceTemplate(self): self.st_fixture = {} if not hasattr(self.topo, 'st_list'): return self for st_name in self.topo.st_list: self.st_fixture[st_name] = self.useFixture( SvcTemplateFixture( connections=self.project_connections, st_name=st_name, svc_img_name=self.topo.st_params[st_name]['svc_img_name'], service_type=self.topo.st_params[st_name]['service_type'], service_mode=self.topo.st_params[st_name]['service_mode'], svc_scaling=self.topo.st_params[st_name]['svc_scaling'], flavor=self.topo.st_params[st_name]['flavor'], if_details=self.topo.st_params[st_name]['if_details'], version=self.topo.st_params[st_name]['version'])) if self.skip_verify == 'no': assert self.st_fixture[st_name].verify_on_setup() return self
def config_st_si(self, st_name, si_name_prefix, si_count, svc_scaling=False, max_inst=1, domain='default-domain', project='admin', left_vn=None, right_vn=None, svc_type='firewall', svc_mode='transparent', flavor='contrail_flavor_2cpu', static_route=['None', 'None', 'None'], ordered_interfaces=True): if svc_scaling == True: if svc_mode == 'in-network-nat': if_list = [['management', False, False], ['left', True, False], ['right', False, False]] else: if_list = [['management', False, False], ['left', True, False], ['right', True, False]] else: if_list = [['management', False, False], ['left', False, False], ['right', False, False]] for entry in static_route: if entry != 'None': if_list[static_route.index(entry)][2] = True svc_img_name = "vsrx" if left_vn and right_vn: # In network/routed mode if svc_mode == 'in-network': svc_img_name = 'ubuntu-in-net' if svc_scaling == True: if_list = [['left', True, False], ['right', True, False]] else: if_list = [['left', False, False], ['right', False, False]] elif left_vn: # Analyzer mode svc_img_name = "analyzer" if_list = [['left', False, False]] if svc_mode == 'transparent': # No need to pass left vn for transparent mode. left_vn = None else: # Transperent/bridge mode svc_img_name = "vsrx-bridge" # create service template st_fixture = self.useFixture( SvcTemplateFixture(connections=self.connections, inputs=self.inputs, domain_name=domain, st_name=st_name, svc_img_name=svc_img_name, svc_type=svc_type, if_list=if_list, svc_mode=svc_mode, svc_scaling=svc_scaling, flavor=flavor, ordered_interfaces=ordered_interfaces)) assert st_fixture.verify_on_setup() # create service instances si_fixtures = [] for i in range(0, si_count): verify_vn_ri = True if i: verify_vn_ri = False si_name = si_name_prefix + str(i + 1) si_fixture = self.useFixture( SvcInstanceFixture(connections=self.connections, inputs=self.inputs, domain_name=domain, project_name=project, si_name=si_name, svc_template=st_fixture.st_obj, if_list=if_list, left_vn_name=left_vn, right_vn_name=right_vn, do_verify=verify_vn_ri, max_inst=max_inst, static_route=static_route)) si_fixtures.append(si_fixture) return (st_fixture, si_fixtures)
def config_st_si(self, st_name, si_name_prefix, si_count, svc_scaling=False, max_inst=1, domain='default-domain', project='admin', mgmt_vn=None, left_vn=None, right_vn=None, svc_type='firewall', svc_mode='transparent', flavor='contrail_flavor_2cpu', static_route=[None, None, None], ordered_interfaces=True, svc_img_name=None, st_version=1): svc_type_props = { 'firewall': {'in-network-nat': 'tiny_nat_fw', 'in-network': 'tiny_in_net', 'transparent': 'tiny_trans_fw', }, 'analyzer': {'analyzer': 'analyzer'} } svc_mode_props = { 'in-network-nat': {'left': {'shared': True}, 'right': {'shared': False}, }, 'in-network': {'left': {'shared': True}, 'right': {'shared': True} }, 'transparent': {'left': {'shared': True}, 'right': {'shared': True} } } mgmt_props = ['management', False, False] left_scaling = False right_scaling = False if svc_scaling: left_scaling = True right_scaling = svc_mode_props[svc_mode]['right']['shared'] svc_img_name = svc_img_name or svc_type_props[svc_type][svc_mode] images_info = parse_cfg_file('configs/images.cfg') flavor = flavor or images_info[svc_img_name]['flavor'] if_list = [mgmt_props, ['left', left_scaling, bool(static_route[1])], ['right', right_scaling, bool(static_route[2])], ] if svc_type == 'analyzer': left_scaling = svc_mode_props[svc_mode]['left']['shared'] if_list = [['left', left_scaling, bool(static_route[1])]] self.logger.debug('SI properties:'"\n" 'type: %s '"\n" 'mode: %s' "\n" 'image: %s' "\n" 'flavor: %s' "\n" 'intf_list: %s' % (svc_type, svc_mode, svc_img_name, flavor, if_list)) # create service template st_fixture = self.useFixture(SvcTemplateFixture( connections=self.connections, inputs=self.inputs, domain_name=domain, st_name=st_name, svc_img_name=svc_img_name, svc_type=svc_type, if_list=if_list, svc_mode=svc_mode, svc_scaling=svc_scaling, flavor=flavor, ordered_interfaces=ordered_interfaces, version=st_version)) assert st_fixture.verify_on_setup() # create service instances si_fixtures = [] for i in range(0, si_count): verify_vn_ri = True if i: verify_vn_ri = False si_name = si_name_prefix + str(i + 1) si_fixture = self.useFixture(SvcInstanceFixture( connections=self.connections, inputs=self.inputs, domain_name=domain, project_name=project, si_name=si_name, svc_template=st_fixture.st_obj, if_list=if_list, mgmt_vn_name=mgmt_vn, left_vn_name=left_vn, right_vn_name=right_vn, do_verify=verify_vn_ri, max_inst=max_inst, static_route=static_route)) if st_version == 2: self.logger.debug('Launching SVM') if svc_mode == 'transparent': self.trans_mgmt_vn_name = get_random_name('trans_mgmt_vn') self.trans_mgmt_vn_subnets = [ get_random_cidr(af=self.inputs.get_af())] self.trans_left_vn_name = get_random_name('trans_left_vn') self.trans_left_vn_subnets = [ get_random_cidr(af=self.inputs.get_af())] self.trans_right_vn_name = get_random_name( 'trans_right_vn') self.trans_right_vn_subnets = [ get_random_cidr(af=self.inputs.get_af())] self.trans_mgmt_vn_fixture = self.config_vn( self.trans_mgmt_vn_name, self.trans_mgmt_vn_subnets) self.trans_left_vn_fixture = self.config_vn( self.trans_left_vn_name, self.trans_left_vn_subnets) self.trans_right_vn_fixture = self.config_vn( self.trans_right_vn_name, self.trans_right_vn_subnets) for i in range(max_inst): svm_name = get_random_name("pt_svm" + str(i)) pt_name = get_random_name("port_tuple" + str(i)) if svc_mode == 'transparent': svm_fixture = self.config_and_verify_vm( svm_name, image_name=svc_img_name, vns=[self.trans_mgmt_vn_fixture, self.trans_left_vn_fixture, self.trans_right_vn_fixture], count=1, flavor='m1.large') else: svm_fixture = self.config_and_verify_vm( svm_name, image_name=svc_img_name, vns=[self.mgmt_vn_fixture, self.vn1_fixture, self.vn2_fixture], count=1, flavor='m1.large') si_fixture.add_port_tuple(svm_fixture, pt_name) si_fixture.verify_on_setup() si_fixtures.append(si_fixture) return (st_fixture, si_fixtures)
def setUpClass(cls): super(TestQosSVCBase, cls).setUpClass() if_list = [['left', False, False], ['right', False, False]] cls.st_fixture = SvcTemplateFixture(connections=cls.connections, inputs=cls.inputs, domain_name=cls.inputs.domain_name, st_name="service_template", svc_img_name='ubuntu-in-net', svc_type='firewall', if_list=if_list, svc_mode='in-network', svc_scaling=False, flavor='contrail_flavor_2cpu', ordered_interfaces=True, availability_zone_enable=True) cls.st_fixture.setUp() cls.si_fixture = SvcInstanceFixture( connections=cls.connections, inputs=cls.inputs, domain_name=cls.inputs.domain_name, project_name=cls.inputs.project_name, si_name="service_instance", svc_template=cls.st_fixture.st_obj, if_list=if_list, left_vn_name=cls.vn1_fixture.vn_fq_name, right_vn_name=cls.vn2_fixture.vn_fq_name, do_verify=True, max_inst=1, static_route=['None', 'None', 'None'], availability_zone="nova:" + cls.inputs.compute_names[0]) cls.si_fixture.setUp() cls.si_fixture.verify_on_setup() cls.action_list = [":".join(cls.si_fixture.si_fq_name)] rules = [{ 'direction': '<>', 'protocol': 'any', 'dest_network': cls.vn2_fixture.vn_name, 'source_network': cls.vn1_fixture.vn_name, 'dst_ports': 'any', 'simple_action': 'pass', 'src_ports': 'any', 'action_list': { 'apply_service': cls.action_list } }] cls.policy_fixture = PolicyFixture(policy_name='policyTestQos', rules_list=rules, inputs=cls.inputs, connections=cls.connections) cls.policy_fixture.setUp() cls.vn1_policy_fixture = VN_Policy_Fixture( connections=cls.connections, vn_name=cls.vn1_fixture.vn_name, policy_obj={cls.vn1_fixture.vn_name :\ [cls.policy_fixture.policy_obj]}, vn_obj={cls.vn1_fixture.vn_name : cls.vn1_fixture}, vn_policys=['policyTestQos'], project_name=cls.project.project_name) cls.vn1_policy_fixture.setUp() cls.vn2_policy_fixture = VN_Policy_Fixture( connections=cls.connections, vn_name=cls.vn2_fixture.vn_name, policy_obj={cls.vn2_fixture.vn_name : \ [cls.policy_fixture.policy_obj]}, vn_obj={cls.vn2_fixture.vn_name : cls.vn2_fixture}, vn_policys=['policyTestQos'], project_name=cls.project.project_name) cls.vn2_policy_fixture.setUp()
def launch_svc_vms(self,host, left_rt='2000',right_rt='3000'): # Create two virtual networks self.vn1_name='vn100-left' self.vn1_subnets=['12.0.0.0/8','2005::/64'] self.vn1_fq_name = "default-domain:" + self.inputs.project_name + ":" + self.vn1_name self.vn2_name = 'vn100-right' self.vn2_subnets = ['13.0.0.0/8','2006::/64'] self.vn2_fq_name = "default-domain:" + self.inputs.project_name + ":" + self.vn2_name self.vmlist = [] self.vm_fixture = [] self.version = '2' self.userdata = '/tmp/metadata_script.txt' self.inputs.set_af(self.perf_conf['family']) if self.perf_conf['family'] == 'v6': self.vn1_fixture= self.useFixture(VNFixture(project_name= self.inputs.project_name, connections= self.connections,vn_name=self.vn1_name, inputs= self.inputs,router_asn=self.inputs.router_asn, rt_number=self.inputs.mx_rt)) else: self.vn1_fixture= self.useFixture(VNFixture(project_name= self.inputs.project_name, connections= self.connections,vn_name=self.vn1_name, inputs= self.inputs, subnets= self.vn1_subnets,router_asn=self.inputs.router_asn, rt_number=left_rt)) self.vn2_fixture= self.useFixture(VNFixture(project_name= self.inputs.project_name, connections= self.connections,vn_name=self.vn2_name, inputs= self.inputs, subnets= self.vn2_subnets,router_asn=self.inputs.router_asn, rt_number=right_rt)) # Create service instance self.svc_tmp_name = 'perf_svc_template' self.svc_int_prefix = 'perf_vm_' self.svc_policy_name = 'perf_svc_policy' if self.perf_conf['si']> 1: self.dpdk_svc_scaling = True if self.version == '2': # create service template if_details = { 'left': {}, 'right': {} } self.perf_st_fixture = self.useFixture(SvcTemplateFixture( connections=self.connections, st_name=self.svc_tmp_name, svc_img_name=self.perf_conf['image'], service_type='firewall', if_details=if_details, service_mode='in-network', svc_scaling=self.dpdk_svc_scaling, flavor=self.nova_flavor[str(self.perf_conf['cores'])], version=2,availability_zone_enable=True)) if_details = { 'left' : {'vn_name' : self.vn1_fq_name}, 'right': {'vn_name' : self.vn2_fq_name} } for i in range(0, 1): si_name = self.svc_int_prefix + str(i + 1) self.perf_si_fixture = self.useFixture(SvcInstanceFixture( connections=self.connections, si_name=si_name, svc_template=self.perf_st_fixture.st_obj, if_details=if_details, max_inst=self.perf_conf['si'], availability_zone=self.perf_conf['zone'])) self.logger.debug('Launching SVM') for i in range(self.perf_conf['si']): svm_name = get_random_name("pt_svm" + str(i)) pt_name = get_random_name("port_tuple" + str(i)) svm_fixture = self.config_and_verify_vm( svm_name, image_name=self.perf_conf['image'], vns=[self.vn1_fixture, self.vn2_fixture], count=1, flavor=self.nova_flavor[str(self.perf_conf['cores'])], zone=self.perf_conf['zone'],node_name=host) port_tuples_props = [] svm_pt_props = {} svm_pt_props['left'] = svm_fixture.vmi_ids[self.vn1_fq_name] svm_pt_props['right'] = svm_fixture.vmi_ids[self.vn2_fq_name] svm_pt_props['name'] = get_random_name("port_tuple") port_tuples_props.append(svm_pt_props) self.perf_si_fixture.add_port_tuple(svm_pt_props) #self.perf_si_fixture.verify_on_setup() self.perf_si_fixtures.append(self.perf_si_fixture) # action_list = self.chain_si(self.vm_num,self.svc_int_prefix,self.inputs.project_name) action_list = [] for i in range(1): si_name = self.svc_int_prefix + str(i + 1) # chain services by appending to action list si_fq_name = 'default-domain' + ':' + self.inputs.project_name + ':' + si_name action_list.append(si_fq_name) self.project.set_sec_group_for_allow_all() # Create a policy self.rules = [{'direction': '<>', 'protocol': 'any', 'source_network': self.vn1_name, 'src_ports': [0, -1], 'dest_network': self.vn2_name, 'dst_ports': [0, -1], 'simple_action': None, 'action_list': {'apply_service': action_list} }] self.svc_policy_fixture = self.config_policy(self.svc_policy_name, self.rules) self.vn1_policy_fix = self.attach_policy_to_vn( self.svc_policy_fixture, self.vn1_fixture) self.vn2_policy_fix = self.attach_policy_to_vn( self.svc_policy_fixture, self.vn2_fixture) time.sleep(180) return True
def config_st_si(self, st_name, si_name_prefix, si_count, svc_scaling=False, max_inst=1, domain='default-domain', project='admin', mgmt_vn=None, left_vn=None, right_vn=None, svc_type='firewall', svc_mode='transparent', flavor='contrail_flavor_2cpu', static_route=['None', 'None', 'None'], ordered_interfaces=True, svc_img_name="vsrx", st_version=1): if svc_scaling == True: if svc_mode == 'in-network-nat': if_list = [['management', False, False], ['left', True, False], ['right', False, False]] else: if_list = [['management', False, False], ['left', True, False], ['right', True, False]] else: if_list = [['management', False, False], ['left', False, False], ['right', False, False]] # svc_img_name = "vsrx" if left_vn and right_vn: # In network/routed mode if svc_mode == 'in-network': svc_img_name = 'ubuntu-in-net' if svc_scaling == True: if_list = [['left', True, False], ['right', True, False]] else: if_list = [['left', False, False], ['right', False, False]] elif left_vn: # Analyzer mode if svc_img_name != "analyzer": svc_img_name = svc_img_name else: svc_img_name = "analyzer" if_list = [['left', False, False]] if svc_mode == 'transparent': # No need to pass left vn for transparent mode. left_vn = None else: # Transperent/bridge mode svc_img_name = svc_img_name for entry in static_route: if entry != 'None': if_list[static_route.index(entry)][2] = True # create service template st_fixture = self.useFixture( SvcTemplateFixture(connections=self.connections, inputs=self.inputs, domain_name=domain, st_name=st_name, svc_img_name=svc_img_name, svc_type=svc_type, if_list=if_list, svc_mode=svc_mode, svc_scaling=svc_scaling, flavor=flavor, ordered_interfaces=ordered_interfaces, version=st_version)) assert st_fixture.verify_on_setup() # create service instances si_fixtures = [] for i in range(0, si_count): verify_vn_ri = True if i: verify_vn_ri = False si_name = si_name_prefix + str(i + 1) si_fixture = self.useFixture( SvcInstanceFixture(connections=self.connections, inputs=self.inputs, domain_name=domain, project_name=project, si_name=si_name, svc_template=st_fixture.st_obj, if_list=if_list, mgmt_vn_name=mgmt_vn, left_vn_name=left_vn, right_vn_name=right_vn, do_verify=verify_vn_ri, max_inst=max_inst, static_route=static_route)) if st_version == 2: self.logger.debug('Launching SVM') if svc_mode == 'transparent': self.trans_mgmt_vn_name = get_random_name('trans_mgmt_vn') self.trans_mgmt_vn_subnets = [ get_random_cidr(af=self.inputs.get_af()) ] self.trans_left_vn_name = get_random_name('trans_left_vn') self.trans_left_vn_subnets = [ get_random_cidr(af=self.inputs.get_af()) ] self.trans_right_vn_name = get_random_name( 'trans_right_vn') self.trans_right_vn_subnets = [ get_random_cidr(af=self.inputs.get_af()) ] self.trans_mgmt_vn_fixture = self.config_vn( self.trans_mgmt_vn_name, self.trans_mgmt_vn_subnets) self.trans_left_vn_fixture = self.config_vn( self.trans_left_vn_name, self.trans_left_vn_subnets) self.trans_right_vn_fixture = self.config_vn( self.trans_right_vn_name, self.trans_right_vn_subnets) for i in range(max_inst): svm_name = get_random_name("pt_svm" + str(i)) pt_name = get_random_name("port_tuple" + str(i)) if svc_mode == 'transparent': svm_fixture = self.config_and_verify_vm( svm_name, image_name=svc_img_name, vns=[ self.trans_mgmt_vn_fixture, self.trans_left_vn_fixture, self.trans_right_vn_fixture ], count=1, flavor='m1.large') else: svm_fixture = self.config_and_verify_vm( svm_name, image_name=svc_img_name, vns=[ self.mgmt_vn_fixture, self.vn1_fixture, self.vn2_fixture ], count=1, flavor='m1.large') si_fixture.add_port_tuple(svm_fixture, pt_name) si_fixture.verify_on_setup() si_fixtures.append(si_fixture) return (st_fixture, si_fixtures)