def main(): import sys from vn_test import VNFixture from vm_test import VMFixture # sys.settrace(tracefunc) # obj = LBaasFixture(api_type='neutron', name='LB', connections=setup_test_infra(), network_id='4b39a2bd-4528-40e8-b848-28084e59c944', members={'vms': ['a72ad607-f1ca-44f2-b31e-e825a3f2d408'], 'address': ['192.168.1.10']}, vip_net_id='4b39a2bd-4528-40e8-b848-28084e59c944', protocol='TCP', port='22', healthmonitors=[{'delay':5, 'timeout':5, 'max_retries':5, 'probe_type':'PING'}]) conn = setup_test_infra() vnfix = VNFixture(connections=conn, vn_name='admin-33688095') vnfix.setUp() fip_fix = VNFixture(connections=conn, router_external=True, vn_name='fip-vn') fip_fix.setUp() subnet = vnfix.get_cidrs()[0] vm_fix = VMFixture(connections=conn, vn_obj=vnfix.obj, vm_name='member-vm') vm_fix.setUp() obj = LBaasV2Fixture(lb_name='LB-Test', connections=conn, network_id=vnfix.uuid, fip_net_id=fip_fix.uuid, listener_name='Listener-Test', vip_port='80', vip_protocol='HTTP', pool_name='Pool-Test', pool_port='80', pool_protocol='HTTP', pool_algorithm='ROUND_ROBIN', members={'vms': [vm_fix.vm_id]}, hm_delay=5, hm_timeout=5, hm_max_retries=5, hm_probe_type='PING', ) obj.setUp() import pdb; pdb.set_trace() obj.verify_on_setup() obj.cleanUp() exit() import pdb; pdb.set_trace() # obj = LBaasFixture(api_type='neutron', uuid='58e5fb2c-ec47-4eb8-b4bf-9c66b0473f78', connections=setup_test_infra()) obj.verify_on_setup() obj.delete_custom_attr('max_sess_rate') obj.add_custom_attr('client_timeout', 20000) obj.delete_custom_attr('server_timeout') obj.add_custom_attr('max_sess_rate', 20000) obj.delete_custom_attr('rate_limit_sessions') obj.add_custom_attr('rate_limit_sessions', 20) obj.delete_custom_attr('max_conn') obj.add_custom_attr('max_conn', 20) obj.delete_custom_attr('http_server_close') obj.add_custom_attr('http_server_close', "False") obj.verify_on_setup() obj.create_fip_on_vip() obj.verify_on_setup() obj.delete_fip_on_vip() obj.verify_on_setup() obj.delete_vip() obj.verify_on_setup() obj.check_and_create_vip() obj.verify_on_setup() obj.delete_member(address=obj.member_ips[1]) obj.verify_on_setup() obj.create_member(address=get_random_ip(subnet)) obj.verify_on_setup() obj.delete_hmon(obj.hmons.keys()[0]) obj.verify_on_setup() obj.create_hmon({'delay': 5, 'max_retries': 5, 'probe_type': 'PING', 'timeout': 10}) obj.verify_on_setup() obj.cleanUp() vm_fix.cleanUp() vnfix.cleanUp() vip_fix.cleanUp() fip_fix.cleanUp()
def create_only_vm( cls, vn_fixture=None, vm_name=None, node_name=None, flavor="contrail_flavor_small", image_name="ubuntu-traffic", port_ids=[], **kwargs ): vn_obj = None if not vm_name: vm_name = "vm-%s" % (get_random_name(cls.inputs.project_name)) if vn_fixture: vn_obj = vn_fixture.obj vm_obj = VMFixture( project_name=cls.inputs.project_name, connections=cls.connections, vn_obj=vn_obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids, **kwargs ) vm_obj.setUp() return vm_obj
def create_only_vm(cls, vn_fixture=None, vm_name=None, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic', port_ids=[], **kwargs): vn_obj = None if vn_fixture: vn_obj = vn_fixture.obj project_name = kwargs.get( 'project_name') or cls.connections.project_name connections = kwargs.get('connections') or cls.connections vm_obj = VMFixture(project_name=project_name, connections=connections, vn_obj=vn_obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids, **kwargs) vm_obj.setUp() return vm_obj
def verify_vms(self, stack, vn_list, env, stack_name): op = stack.stacks.get(stack_name).outputs time.sleep(5) vm1_name = str(env['parameters']['left_vm_name']) vm2_name = str(env['parameters']['right_vm_name']) vm1_fix = self.useFixture( VMFixture(project_name=self.inputs.project_name, vn_obj=vn_list[0].obj, vm_name=vm1_name, connections=self.connections)) vm2_fix = self.useFixture( VMFixture(project_name=self.inputs.project_name, vn_obj=vn_list[1].obj, vm_name=vm2_name, connections=self.connections)) # ToDo: Do we need to wait here or should we check before accessing assert vm1_fix.wait_till_vm_is_up() assert vm2_fix.wait_till_vm_is_up() for output in op: if output['output_value'] == vm1_fix.vm_ip: self.logger.info('VM %s launched successfully' % vm1_fix.vm_name) elif output['output_value'] == vm2_fix.vm_ip: self.logger.info('VM %s launched successfully' % vm2_fix.vm_name) vms_list = [vm1_fix, vm2_fix] return vms_list
def config_vm(self, vm_name, vn_fix=None, node_name=None, image_name='ubuntu-traffic', flavor='contrail_flavor_small', vns=[], count=1, zone=None): if vn_fix: vm_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fix.obj, vm_name=vm_name, node_name=node_name, image_name=image_name, flavor=flavor, count=count, zone=zone)) elif vns: vm_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vm_name=vm_name, node_name=node_name, image_name=image_name, flavor=flavor, vn_objs=vns, count=count, zone=zone)) return vm_fixture
def svm_list(self): if not getattr(self, '_svm_list', None): self._svm_list = [] for vmid in self.svm_ids: vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.verify_on_setup() self._svm_list.append(vm) return self._svm_list
def svm_list(self): vms = getattr(self, '_svm_list', []) if not vms or len(vms) != len(self.svm_ids): # Reduce the svm_list to take care of reduce in ecmp instances self._svm_list = [vm for vm in vms if vm.get_uuid() in self.svm_ids] # Increase the svm_list to take care of increase in ecmp instances for vmid in set(self.svm_ids) - set([vm.get_uuid() for vm in self._svm_list]): vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.wait_till_vm_is_active() self._svm_list.append(vm) return self._svm_list
def vm_add_delete(self): vm1_name = 'vn11_vm1_mine' vm2_name = 'vn22_vm1_mine' vm3_name = 'fip_vn_vm1_mine' vm4_name = 'newvn_vm1_mine' vm5_name = 'newvn11_vm1_mine' vn_obj = self.res.vn11_fixture.obj self.vm11_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=vn_obj, vm_name=vm1_name, project_name=self.inputs.project_name)) assert self.vm11_fixture.verify_on_setup() vn_obj = self.res.vn22_fixture.obj self.vm22_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=vn_obj, vm_name=vm2_name, project_name=self.inputs.project_name)) assert self.vm22_fixture.verify_on_setup() vn_obj = self.res.fvn_fixture.obj self.vm33_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=vn_obj, vm_name=vm3_name, project_name=self.inputs.project_name)) assert self.vm33_fixture.verify_on_setup() vn_obj = self.newvn_fixture.obj self.vm4_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=vn_obj, vm_name=vm4_name, project_name=self.inputs.project_name)) assert self.vm4_fixture.verify_on_setup() vn_obj = self.newvn11_fixture.obj self.vm5_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=vn_obj, vm_name=vm5_name, project_name=self.inputs.project_name)) assert self.vm5_fixture.verify_on_setup() return True
def create_2_legs(self): vn1_name = get_random_name('bgpaas_vn') vn1_subnets = [get_random_cidr()] vn1_fixture = self.create_vn(vn1_name, vn1_subnets) test_vm = self.create_vm(vn1_fixture, 'test_vm', image_name='ubuntu-traffic') assert test_vm.wait_till_vm_is_up() vn2_name = get_random_name('bgpaas_vn') vn2_subnets = [get_random_cidr()] vn2_fixture = self.create_vn(vn2_name, vn2_subnets) bgpaas_vm1 = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_objs=[vn1_fixture.obj, vn2_fixture.obj], vm_name='bgpaas_vm1', node_name=None, image_name='vsrx')) assert bgpaas_vm1.wait_till_vm_is_up() ret_dict = { 'vn1_fixture': vn1_fixture, 'vn2_fixture': vn2_fixture, 'test_vm': test_vm, 'bgpaas_vm1': bgpaas_vm1, } return ret_dict
def create_dhcp_server_vm(self, vn1_fixture, vn2_fixture, vm_name=None, node_name=None, flavor='contrail_flavor_large', image_name='ubuntu-dns-server', port_ids=[]): if not vm_name: vm_name = get_random_name('dhcp-server') vm_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_objs=[vn1_fixture.obj, vn2_fixture.obj], vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids)) assert vm_fixture.verify_on_setup(), ( "DHCP Server VM Verification failed ") assert vm_fixture.wait_till_vm_is_up() vn2_fq_name = vn2_fixture.vn_fq_name vm_ip = vm_fixture.vm_ip_dict[vn2_fq_name][0] cmds = [ 'ifconfig eth1 up', 'ifconfig eth1 %s netmask 255.255.255.0' % (vm_ip), 'service isc-dhcp-server restart' ] vm_fixture.run_cmd_on_vm(cmds, as_sudo=True) self.sleep(5) return vm_fixture
def create_only_vm(cls, vn_fixture=None, vm_name=None, image_name='ubuntu-traffic', **kwargs): vn_obj = None if vn_fixture: vn_obj = vn_fixture.obj project_name = kwargs.pop('project_name', None) or cls.connections.project_name connections = kwargs.pop('connections', None) or cls.connections vm_obj = VMFixture( connections, project_name=project_name, vn_obj=vn_obj, vm_name=vm_name, image_name=image_name, **kwargs) vm_obj.setUp() return vm_obj
def create_vn(self): #Script has run till now with the same name and subnets. Lets change it! self.vn1_name = "test_DM_v4_only" self.vn1_net = ['12.6.2.0/24'] #router external tag will cause DM ip allocation problem. Changing it to false 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_net, router_external=False, shared=False)) #assert self.vn1_fixture.verify_on_setup() self.add_RT_basic_traffic() self.vn2_name = "test_DM_dual_stack" self.vn2_net = ['2001::101:0/120'] 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_net)) #assert self.vn2_fixture.verify_on_setup() self.vm1_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=self.vn1_fixture.obj, vm_name='sender', node_name=None, image_name='cirros', flavor='m1.tiny'))
def create_vn(self): self.vn1_name = "test_vn" self.vn1_net = ['1.1.1.0/24'] 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_net, router_external=True)) #assert self.vn1_fixture.verify_on_setup() self.add_RT_basic_traffic() self.vn2_name = "test_v6" self.vn2_net = ['2001::101:0/120'] 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_net)) #assert self.vn2_fixture.verify_on_setup() self.vm1_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=self.vn1_fixture.obj, vm_name='sender', node_name=None, image_name='cirros', flavor='m1.tiny'))
def config_pt_svm(self, stack_name, si_fqdn, vn_list, intf_rt_table_fqdn=''): template = self.get_template(stack_name) env = self.get_env(stack_name) env['parameters']['si_fqdn'] = si_fqdn env['parameters']['svm_name'] = get_random_name('svm') env['parameters']['right_net_id'] = vn_list[2].vn_fq_name env['parameters']['left_net_id'] = vn_list[1].vn_fq_name env['parameters']['mgmt_net_id'] = vn_list[0].vn_fq_name env['parameters']['intf_rt_table_fqdn'] = intf_rt_table_fqdn env['parameters']['def_sg_id'] = (':').join( self.project_fq_name) + ':default' if 'image' in env['parameters']: self.nova_h.get_image(env['parameters']['image']) vn_obj_list = [] for vn in vn_list: vn_obj_list.append(vn.obj) stack_name = get_random_name(stack_name) pt_svm_hs_obj = self.config_heat_obj(stack_name, template, env) pt_svm_fix = self.useFixture( VMFixture(project_name=self.inputs.project_name, vn_objs=vn_obj_list, vm_name=str(env['parameters']['svm_name']), connections=self.connections)) pt_svm_fix.wait_for_ssh_on_vm() return pt_svm_hs_obj, pt_svm_fix
def create_vm(self, vn_fixture, image_name='ubuntu', *args, **kwargs): return self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fixture.obj, image_name=image_name, *args, **kwargs))
def svm_list(self): vms = getattr(self, '_svm_list', []) if not vms or len(vms) != len(self.svm_ids): # Reduce the svm_list to take care of reduce in ecmp instances self._svm_list = [ vm for vm in vms if vm.get_uuid() in self.svm_ids ] self.svms = { k: v for k, v in self.svms.items() if k in self.svm_ids } # Increase the svm_list to take care of increase in ecmp instances for vmid in set(self.svm_ids) - set( [vm.get_uuid() for vm in self._svm_list]): vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.wait_till_vm_is_active() # Populate tap intf details on the VM objects # Faster than calling wait_till_vm_is_up() if not vm.verify_vm_in_agent(): self.logger.error('VM %s not found in vrouter agent' % (vmid)) self._svm_list.append(vm) self.svms[vmid] = vm return self._svm_list
def verify_vms(self, stack, vn_list, stack_name): op = stack.stacks.get(stack_name).outputs time.sleep(5) vm1_fix = self.useFixture(VMFixture(project_name=self.inputs.project_name, vn_obj=vn_list[0].obj, vm_name='left_vm', connections=self.connections)) vm2_fix = self.useFixture(VMFixture(project_name=self.inputs.project_name, vn_obj=vn_list[1].obj, vm_name='right_vm', connections=self.connections)) assert vm1_fix.wait_till_vm_is_up() assert vm2_fix.wait_till_vm_is_up() for output in op: if output['output_value'] == vm1_fix.vm_ip: self.logger.info( 'VM %s launched successfully' % vm1_fix.vm_name) elif output['output_value'] == vm2_fix.vm_ip: self.logger.info( 'VM %s launched successfully' % vm2_fix.vm_name) vms_list = [vm1_fix, vm2_fix] return vms_list
def create_only_vm(cls, vn_fixture, vm_name=None, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic', port_ids=[]): if not vm_name: vm_name = 'vm-%s' % (get_random_name(vn_fixture.vn_name)) vm_obj = VMFixture(project_name=cls.inputs.project_name, connections=cls.connections, vn_obj=vn_fixture.obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids) vm_obj.setUp() return vm_obj
def add_multiple_vns(self): self.vn3_name = "test_vn3" self.vn3_net = ['2.1.1.0/24'] self.vn3_fixture = self.useFixture(VNFixture( project_name=self.inputs.project_name, connections=self.connections, vn_name=self.vn3_name, inputs=self.inputs, subnets=self.vn3_net, router_external=True)) assert self.vn3_fixture.verify_on_setup() self.vm3_fixture = self.useFixture(VMFixture( project_name=self.inputs.project_name, connections=self.connections, vn_obj=self.vn3_fixture.obj, vm_name='receiver', node_name=None, image_name='cirros', flavor='m1.tiny'))
def create_vm(self, vn_fixture, vm_name, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic'): return self.useFixture( VMFixture( project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fixture.obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name))
def config_vm(self, vn): stack_name = 'single_vm' template = self.get_template('single_vm') env = self.get_env('single_vm') env['parameters']['vm_name'] = get_random_name( env['parameters']['vm_name']) env['parameters']['net_id'] = vn.vn_id vm_hs_obj = self.config_heat_obj(stack_name, template, env) vm_fix = self.useFixture(VMFixture(project_name=self.inputs.project_name, vn_obj=vn.obj, vm_name=str(env['parameters']['vm_name']), connections=self.connections)) assert vm_fix.wait_till_vm_is_up() return vm_hs_obj, vm_fix
def create_only_vm(cls, vn_fixture=None, vm_name=None, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic', port_ids=[], **kwargs): vn_obj = None if vn_fixture: vn_obj = vn_fixture.obj project_name = kwargs.pop('project_name', None) or cls.connections.project_name connections = kwargs.pop('connections', None) or cls.connections vm_obj = VMFixture( project_name=project_name, connections=connections, vn_obj=vn_obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids, **kwargs) vm_obj.setUp() return vm_obj
def config_vm(self, vn): stack_name = get_random_name('single_vm') template = self.get_template('single_vm') env = self.get_env('single_vm') env['parameters']['vm_name'] = get_random_name( env['parameters']['vm_name']) env['parameters']['net_id'] = vn.vn_id vm_hs_obj = self.config_heat_obj(stack_name, template, env) vm_fix = self.useFixture(VMFixture(project_name=self.inputs.project_name, vn_obj=vn.obj, vm_name=str(env['parameters']['vm_name']), connections=self.connections)) # ToDo: Do we really need to wait till the VMs are up, may be move it down where we login to the VM assert vm_fix.wait_till_vm_is_up() return vm_hs_obj, vm_fix
def create_vm(self, vn_fixture, vm_name, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic'): image_name = os.environ['ci_image'] if os.environ.has_key('ci_image') else 'ubuntu-traffic' return self.useFixture( VMFixture( project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fixture.obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name))
def setup_vm(self): # add VMs to VNs self.VM11_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=self.VN1_fixture.obj, vm_name='VM11', project_name=self.project.project_name)) self.VM21_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=self.VN2_fixture.obj, vm_name='VM21', project_name=self.project.project_name)) self.VM31_fixture = self.useFixture( VMFixture(connections=self.connections, vn_obj=self.VN3_fixture.obj, vm_name='VM31', project_name=self.project.project_name)) self.VM11_fixture.wait_till_vm_is_up() self.VM21_fixture.wait_till_vm_is_up() self.VM31_fixture.wait_till_vm_is_up()
def svm_list(self): if not getattr(self, '_svm_list', None): self._svm_list = [] for vmid in self.svm_ids: vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.wait_till_vm_is_active() self._svm_list.append(vm) return self._svm_list
def config_basic(self, vm2=False): self.vn1_fixture = self.create_vn(disable_dns=True) self.vn2_fixture = self.create_vn(disable_dns=True) self.vn1_name = self.vn1_fixture.vn_name self.vn2_name = self.vn2_fixture.vn_name self.left_vm_fixture = self.create_vm(self.vn1_fixture) self.right_vm_fixture = self.create_vm(self.vn2_fixture) self.left_vm_fixture.wait_till_vm_is_up() self.right_vm_fixture.wait_till_vm_is_up() vm1_name = 'middle_vm1' self.vm1_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_objs=[self.vn1_fixture.obj, self.vn2_fixture.obj], vm_name=vm1_name, node_name=None, image_name='ubuntu', flavor='m1.tiny')) self.vm1_fixture.wait_till_vm_is_up() cmd = 'echo 1 > /proc/sys/net/ipv4/ip_forward' self.vm1_fixture.run_cmd_on_vm(cmds=[cmd], as_sudo=True) vm2_name = 'middle_vm2' if vm2: self.vm2_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_objs=[self.vn1_fixture.obj, self.vn2_fixture.obj], vm_name=vm2_name, node_name=None, image_name='ubuntu', flavor='m1.tiny')) self.vm2_fixture.wait_till_vm_is_up() cmd = 'echo 1 > /proc/sys/net/ipv4/ip_forward' self.vm2_fixture.run_cmd_on_vm(cmds=[cmd], as_sudo=True)
def create_vm(self, vn_fixture, vm_name, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu', *args, **kwargs): image_name = self.inputs.get_ci_image() or image_name return self.useFixture( VMFixture( project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fixture.obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, *args, **kwargs))
def config_vm(self, vn_fix, vm_name, node_name=None, image_name='ubuntu-traffic', flavor='contrail_flavor_small'): vm_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fix.obj, vm_name=vm_name, node_name=node_name, image_name=image_name, flavor=flavor)) return vm_fixture
def create_vm(self, vn_fixture, vm_name=None, node_name=None, flavor='contrail_flavor_small', image_name='ubuntu-traffic', port_ids=[]): if not vm_name: vm_name = 'vm-%s' % (get_random_name(vn_fixture.vn_name)) return self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn_fixture.obj, vm_name=vm_name, image_name=image_name, flavor=flavor, node_name=node_name, port_ids=port_ids))
def setUp(self): super(VPCVMFixture, self).setUp() try: f = '/tmp/key%s'%self.inputs.stack_user lock = Lock(f) lock.acquire() self._create_keypair(self.key) finally: lock.release() self.create_vm() # Build up data structure for std VM verification to happen # Note that this Fixture does not create a VM if it is already present if self.vm_name: self.c_vm_fixture = self.useFixture(VMFixture( project_name=self.vpc_id, connections=self.connections, image_name=self.image_name, vn_obj=self.vn_obj, vm_name=self.vm_name, sg_ids=self.sg_ids))
def svm_list(self): vms = getattr(self, '_svm_list', []) if not vms or len(vms) != len(self.svm_ids): # Reduce the svm_list to take care of reduce in ecmp instances self._svm_list = [ vm for vm in vms if vm.get_uuid() in self.svm_ids ] # Increase the svm_list to take care of increase in ecmp instances for vmid in set(self.svm_ids) - set( [vm.get_uuid() for vm in self._svm_list]): vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.wait_till_vm_is_active() self._svm_list.append(vm) return self._svm_list
def verify_si(self, stack, stack_name, si_name, st_fix, max_inst, svc_mode, image): svc_inst = self.useFixture(SvcInstanceFixture( connections=self.connections, inputs=self.inputs, domain_name='default-domain', project_name=self.inputs.project_name, si_name=si_name, svc_template=st_fix.st_obj, if_list=st_fix.if_list)) assert svc_inst.verify_on_setup() if self.pt_based_svc: op = stack.stacks.get(stack_name).outputs for output in op: if output['output_key'] == 'svm_id': svm_id = output['output_value'] vm = VMFixture(self.connections, uuid=svm_id) vm.setUp() vm.verify_on_setup() image='ubuntu-in-net' (vm.vm_username, vm.vm_password) = vm.orch.get_image_account(image) svc_inst._svm_list.append(vm) if self.inputs.get_af() == 'v6': vm.run_cmd_on_vm(['dhclient -6 -pf /var/run/dhclient6.eth0.pid -lf /var/lib/dhcp/dhclient6.eth0.leases', 'dhclient -6 -pf /var/run/dhclient6.eth1.pid -lf /var/lib/dhcp/dhclient6.eth1.leases'], as_sudo=True) return svc_inst
def verify_si(self, stack, stack_name, si_name, st_fix, max_inst, svc_mode, image): svc_inst = self.useFixture(SvcInstanceFixture( connections=self.connections, inputs=self.inputs, domain_name='default-domain', project_name=self.inputs.project_name, si_name=si_name, svc_template=st_fix.st_obj, if_list=st_fix.if_list)) assert svc_inst.verify_on_setup() if self.pt_based_svc: op = stack.stacks.get(stack_name).outputs for output in op: if output['output_key'] == 'svm_id': svm_id = output['output_value'] vm = VMFixture(self.connections, uuid=svm_id) vm.setUp() vm.verify_on_setup() image='tiny-in-net' (vm.vm_username, vm.vm_password) = vm.orch.get_image_account(image) svc_inst._svm_list.append(vm) return svc_inst
def svm_list(self): vms = getattr(self, '_svm_list', []) if not vms or len(vms) != len(self.svm_ids): # Reduce the svm_list to take care of reduce in ecmp instances self._svm_list = [vm for vm in vms if vm.get_uuid() in self.svm_ids] self.svms = {k:v for k,v in self.svms.items() if k in self.svm_ids} # Increase the svm_list to take care of increase in ecmp instances for vmid in set(self.svm_ids) - set([vm.get_uuid() for vm in self._svm_list]): vm = VMFixture(self.connections, uuid=vmid) vm.setUp() vm.wait_till_vm_is_active() # Populate tap intf details on the VM objects # Faster than calling wait_till_vm_is_up() if not vm.verify_vm_in_agent(): self.logger.error('VM %s not found in vrouter agent' %( vmid)) self._svm_list.append(vm) self.svms[vmid] = vm return self._svm_list
def test_policy_protocol_summary(self): ''' Test to validate that when policy is created with multiple rules that can be summarized by protocol ''' proj_name = self.inputs.project_name vn1_name = 'vn40' vn1_subnets = ['10.1.1.0/24'] policy1_name = 'policy1' policy2_name = 'policy2' rules2 = [ { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'any', 'source_network': vn1_name, 'dest_network': vn1_name, }, { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'icmp', 'source_network': vn1_name, 'dest_network': vn1_name, }, ] rules1 = [ { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'any', 'source_network': vn1_name, 'dest_network': vn1_name, }, ] policy1_fixture = self.useFixture( PolicyFixture(policy_name=policy1_name, rules_list=rules1, inputs=self.inputs, connections=self.connections)) policy2_fixture = self.useFixture( PolicyFixture(policy_name=policy2_name, rules_list=rules2, inputs=self.inputs, connections=self.connections)) vn1_fixture = self.useFixture( VNFixture(project_name=self.inputs.project_name, connections=self.connections, vn_name=vn1_name, inputs=self.inputs, subnets=vn1_subnets, policy_objs=[policy1_fixture.policy_obj])) assert vn1_fixture.verify_on_setup() vn1_vm1_name = 'vm1' vm1_fixture = self.useFixture( VMFixture(project_name=self.inputs.project_name, connections=self.connections, vn_obj=vn1_fixture.obj, vm_name=vn1_vm1_name)) assert vm1_fixture.verify_on_setup() inspect_h = self.agent_inspect[vm1_fixture.vm_node_ip] vn_fq_name = inspect_h.get_vna_vn(domain='default-domain', project=proj_name, vn_name=vn1_name)['name'] vna_acl1 = inspect_h.get_vna_acl_by_vn(vn_fq_name) policy1_fixture.verify_policy_in_api_server() if vn1_fixture.policy_objs: policy_fq_names = [ self.quantum_h.get_policy_fq_name(x) for x in vn1_fixture.policy_objs ] policy_fq_name2 = self.quantum_h.get_policy_fq_name( policy2_fixture.policy_obj) policy_fq_names.append(policy_fq_name2) vn1_fixture.bind_policies(policy_fq_names, vn1_fixture.vn_id) vna_acl2 = inspect_h.get_vna_acl_by_vn(vn_fq_name) out = policy_test_utils.compare_args('policy_rules', vna_acl1['entries'], vna_acl2['entries']) if out: self.logger.info( "policy rules are not matching with expected %s and actual %s" % (vna_acl1['entries'], vna_acl2['entries'])) self.assertIsNone(out, "policy compare failed") return True
def test_policy_with_multi_vn_in_vm(self): ''' Test to validate policy action in VM with vnic's in multiple VN's with different policies. Test flow: vm1 in vn1 and vn2; vm3 in vn3. policy to allow traffic from vn2 to vn3 and deny from vn1 to vn3. Default route for vm1 in vn1, which has no reachability to vn3 - verify traffic - should fail. Add specific route to direct vn3 traffic through vn2 - verify traffic - should pass. ''' vm1_name = 'vm_mine1' vm2_name = 'vm_mine2' vn1_name = 'vn221' vn1_subnets = ['11.1.1.0/24'] vn2_name = 'vn222' vn2_subnets = ['22.1.1.0/24'] vn3_gateway = '22.1.1.254' vn3_name = 'vn223' vn3_subnets = ['33.1.1.0/24'] rules1 = [ { 'direction': '>', 'simple_action': 'deny', 'protocol': 'icmp', 'src_ports': 'any', 'dst_ports': 'any', 'source_network': 'any', 'dest_network': 'any', }, ] rules2 = [ { 'direction': '<>', 'simple_action': 'pass', 'protocol': 'any', 'src_ports': 'any', 'dst_ports': 'any', 'source_network': 'any', 'dest_network': 'any', }, ] policy1_name = 'p1' policy2_name = 'p2' policy1_fixture = self.useFixture( PolicyFixture(policy_name=policy1_name, rules_list=rules1, inputs=self.inputs, connections=self.connections)) policy2_fixture = self.useFixture( PolicyFixture(policy_name=policy2_name, rules_list=rules2, inputs=self.inputs, connections=self.connections)) vn1_fixture = self.useFixture( VNFixture(project_name=self.inputs.project_name, connections=self.connections, vn_name=vn1_name, inputs=self.inputs, subnets=vn1_subnets, policy_objs=[policy1_fixture.policy_obj])) vn2_fixture = self.useFixture( VNFixture(project_name=self.inputs.project_name, connections=self.connections, vn_name=vn2_name, inputs=self.inputs, subnets=vn2_subnets, disable_gateway=True, policy_objs=[policy2_fixture.policy_obj])) vn3_fixture = self.useFixture( VNFixture(project_name=self.inputs.project_name, connections=self.connections, vn_name=vn3_name, inputs=self.inputs, subnets=vn3_subnets, policy_objs=[policy2_fixture.policy_obj])) assert vn1_fixture.verify_on_setup() assert vn2_fixture.verify_on_setup() assert vn3_fixture.verify_on_setup() assert vn1_fixture.verify_vn_policy_in_api_server() assert vn2_fixture.verify_vn_policy_in_api_server() assert vn3_fixture.verify_vn_policy_in_api_server() vm1_fixture = self.useFixture( VMFixture(connections=self.connections, vn_objs=[vn1_fixture.obj, vn2_fixture.obj], vm_name=vm1_name, project_name=self.inputs.project_name)) vm2_fixture = self.useFixture( VMFixture(connections=self.connections, vn_objs=[vn3_fixture.obj], vm_name=vm2_name, project_name=self.inputs.project_name)) assert vm1_fixture.verify_on_setup() assert vm2_fixture.verify_on_setup() self.nova_h.wait_till_vm_is_up(vm1_fixture.vm_obj) self.nova_h.wait_till_vm_is_up(vm2_fixture.vm_obj) # For multi-vn vm, configure ip address for 2nd interface multivn_vm_ip_list = vm1_fixture.vm_ips intf_conf_cmd = "ifconfig eth1 %s netmask 255.255.255.0" % multivn_vm_ip_list[ 1] vm_cmds = (intf_conf_cmd, 'ifconfig -a') for cmd in vm_cmds: cmd_to_output = [cmd] vm1_fixture.run_cmd_on_vm(cmds=cmd_to_output, as_sudo=True) output = vm1_fixture.return_output_cmd_dict[cmd] for ip in multivn_vm_ip_list: if ip not in output: self.logger.error("IP %s not assigned to any eth intf of %s" % (ip, vm1_fixture.vm_name)) assert False # Ping test from multi-vn vm to peer vn, result will be based on action # defined in policy attached to VN which has the default gw of VM self.logger.info( "Ping from multi-vn vm to vm2, with no allow rule in the VN where default gw is part of, traffic should fail" ) result = vm1_fixture.ping_with_certainty(vm2_fixture.vm_ip, expectation=False) assertEqual(result, True, "ping passed which is not expected") # Configure VM to reroute traffic to interface belonging to different # VN self.logger.info( "Direct traffic to gw which is part of VN with allow policy to destination VN, traffic should pass now" ) i = ' route add -net %s netmask 255.255.255.0 gw %s dev eth1' % ( vn3_subnets[0].split('/')[0], multivn_vm_ip_list[1]) cmd_to_output = [i] vm1_fixture.run_cmd_on_vm(cmds=cmd_to_output, as_sudo=True) output = vm1_fixture.return_output_cmd_dict[i] # Ping test from multi-vn vm to peer vn, result will be based on action # defined in policy attached to VN which has the default gw for VM self.logger.info( "Ping from multi-vn vm to vm2, with allow rule in the VN where network gw is part of, traffic should pass" ) result = vm1_fixture.ping_with_certainty(vm2_fixture.vm_ip, expectation=True) assertEqual(result, True, "ping failed which is not expected") return True
if __name__ == "__main__": import sys from vn_test import VNFixture from vm_test import VMFixture # sys.settrace(tracefunc) # obj = LBaasFixture(api_type='neutron', name='LB', connections=setup_test_infra(), network_id='4b39a2bd-4528-40e8-b848-28084e59c944', members={'vms': ['a72ad607-f1ca-44f2-b31e-e825a3f2d408'], 'address': ['192.168.1.10']}, vip_net_id='4b39a2bd-4528-40e8-b848-28084e59c944', protocol='TCP', port='22', healthmonitors=[{'delay':5, 'timeout':5, 'max_retries':5, 'probe_type':'PING'}]) conn = setup_test_infra() vnfix = VNFixture(connections=conn) vnfix.setUp() vip_fix = VNFixture(connections=conn) vip_fix.setUp() fip_fix = VNFixture(connections=conn, router_external=True) fip_fix.setUp() subnet = vnfix.get_cidrs()[0] vm_fix = VMFixture(connections=conn, vn_obj=vnfix.obj) vm_fix.setUp() obj = LBaasFixture(api_type='neutron', name='LB', connections=conn, network_id=vnfix.uuid, members={'address': [get_random_ip(subnet)], 'vms': [vm_fix.vm_id]}, vip_net_id=vip_fix.uuid, fip_net_id=fip_fix.uuid, protocol='TCP', port='22', healthmonitors=[{'delay':5, 'timeout':5, 'max_retries':5, 'probe_type':'PING'}], custom_attr={'max_conn': 100, 'max_sess_rate': 20, 'server_timeout': 50000, 'rate_limit_sessions': 10, 'http_server_close': "True"}) obj.setUp() # obj = LBaasFixture(api_type='neutron', uuid='58e5fb2c-ec47-4eb8-b4bf-9c66b0473f78', connections=setup_test_infra()) obj.verify_on_setup() obj.delete_custom_attr('max_sess_rate') obj.add_custom_attr('client_timeout', 20000) obj.delete_custom_attr('server_timeout') obj.add_custom_attr('max_sess_rate', 20000) obj.delete_custom_attr('rate_limit_sessions') obj.add_custom_attr('rate_limit_sessions', 20)
def config_v2_svc_chain(self, stack_name): template = self.get_template(template_name=stack_name) env = self.get_env(env_name=stack_name) stack_name = get_random_name(stack_name) self.nova_h.get_image(env['parameters']['image']) self.nova_h.get_flavor(env['parameters']['flavor']) svc_pt_hs = self.config_heat_obj(stack_name, template, env) stack = svc_pt_hs.heat_client_obj op = stack.stacks.get(stack_name).outputs time.sleep(5) for output in op: if output['output_key'] == 'left_VM_ID': left_vm_id = output['output_value'] elif output['output_key'] == 'left_VM1_ID': left_vm1_id = output['output_value'] elif output['output_key'] == 'left_VM2_ID': left_vm2_id = output['output_value'] elif output['output_key'] == 'right_VM_ID': right_vm_id = output['output_value'] elif output['output_key'] == 'right_VM1_ID': right_vm1_id = output['output_value'] elif output['output_key'] == 'right_VM2_ID': right_vm2_id = output['output_value'] elif output['output_key'] == 'left_vn_FQDN': left_vn_fqdn = output['output_value'] elif output['output_key'] == 'right_vn_FQDN': right_vn_fqdn = output['output_value'] elif output['output_key'] == 'si_fqdn': si_fqdn = output['output_value'] elif output['output_key'] == 'si2_fqdn': si2_fqdn = output['output_value'] si2_fqdn=":".join(si2_fqdn) elif output['output_key'] == 'left_VM1_IP_ADDRESS': left_vm1_ip_address = output['output_value'] network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix = left_vm1_ip_address network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix_len = "32" elif output['output_key'] == 'right_VM1_IP_ADDRESS': right_vm1_ip_address = output['output_value'] network_policy_entries_policy_rule_dst_addresses_subnet_ip_prefix = right_vm1_ip_address network_policy_entries_policy_rule_dst_addresses_subnet_ip_prefix_len = "32" #Update the policy si_fqdn=":".join(si_fqdn) left_vn_fqdn=":".join(left_vn_fqdn) right_vn_fqdn=":".join(right_vn_fqdn) if 'multi' in stack_name: self.update_stack(svc_pt_hs, change_sets=[['left_vn_fqdn', left_vn_fqdn], ['right_vn_fqdn', right_vn_fqdn], ['service_instance1_fq_name', si_fqdn], ['service_instance2_fq_name', si2_fqdn]]) else: if 'cidr' in stack_name: if 'src_cidr' in stack_name: self.update_stack(svc_pt_hs, change_sets=[['left_vn_fqdn', left_vn_fqdn], ['right_vn_fqdn', right_vn_fqdn], ['service_instance_fq_name', si_fqdn], ['network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix', network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix], ['network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix_len', network_policy_entries_policy_rule_src_addresses_subnet_ip_prefix_len]]) else: self.update_stack(svc_pt_hs, change_sets=[['left_vn_fqdn', left_vn_fqdn], ['right_vn_fqdn', right_vn_fqdn], ['service_instance_fq_name', si_fqdn]]) if 'cidr' in stack_name: if 'src_cidr' in stack_name: # 2 VMs in the left_vn left_vm1 = VMFixture(connections=self.connections,uuid = left_vm1_id, image_name = 'cirros') left_vm1.read() left_vm1.verify_on_setup() left_vm2 = VMFixture(connections=self.connections,uuid = left_vm2_id, image_name = 'cirros') left_vm2.read() left_vm2.verify_on_setup() # One VM in the right_vn right_vm = VMFixture(connections=self.connections,uuid = right_vm_id, image_name = 'cirros') right_vm.read() right_vm.verify_on_setup() # Ping from left_vm1 to right_vm should pass assert left_vm1.ping_with_certainty(right_vm.vm_ip, expectation=True) # Ping from left_vm2 to right_vm should fail assert left_vm2.ping_with_certainty(right_vm.vm_ip, expectation=False) else: left_vm = VMFixture(connections=self.connections,uuid = left_vm_id, image_name = 'cirros') left_vm.read() left_vm.verify_on_setup() right_vm = VMFixture(connections=self.connections,uuid = right_vm_id, image_name = 'cirros') right_vm.read() right_vm.verify_on_setup() assert left_vm.ping_with_certainty(right_vm.vm_ip, expectation=True)
def config_v2_svc_chain(self, stack_name): svc_pt_hs = self.config_heat_obj(stack_name) stack = svc_pt_hs.heat_client_obj op = stack.stacks.get(stack_name).outputs time.sleep(5) for output in op: if output['output_key'] == 'left_VM_ID': left_vm_id = output['output_value'] elif output['output_key'] == 'right_VM_ID': right_vm_id = output['output_value'] elif output['output_key'] == 'left_vn_FQDN': left_vn_fqdn = output['output_value'] elif output['output_key'] == 'right_vn_FQDN': right_vn_fqdn = output['output_value'] elif output['output_key'] == 'si_fqdn': si_fqdn = output['output_value'] elif output['output_key'] == 'si2_fqdn': si2_fqdn = output['output_value'] si2_fqdn=":".join(si2_fqdn) #Update the policy si_fqdn=":".join(si_fqdn) left_vn_fqdn=":".join(left_vn_fqdn) right_vn_fqdn=":".join(right_vn_fqdn) if 'multi' in stack_name: self.update_stack(svc_pt_hs, change_sets=[['left_vn_fqdn', left_vn_fqdn], ['right_vn_fqdn', right_vn_fqdn], ['service_instance1_fq_name', si_fqdn], ['service_instance2_fq_name', si2_fqdn]]) else: self.update_stack(svc_pt_hs, change_sets=[['left_vn_fqdn', left_vn_fqdn], ['right_vn_fqdn', right_vn_fqdn], ['service_instance_fq_name', si_fqdn]]) left_vm = VMFixture(connections=self.connections,uuid = left_vm_id, image_name = 'cirros-0.3.0-x86_64-uec') left_vm.read() left_vm.verify_on_setup() right_vm = VMFixture(connections=self.connections,uuid = right_vm_id, image_name = 'cirros-0.3.0-x86_64-uec') right_vm.read() right_vm.verify_on_setup() assert left_vm.ping_with_certainty(right_vm.vm_ip, expectation=True)