def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [os.environ['secondZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [os.environ['firstZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vip1.delete() if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [os.environ['secondZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [os.environ['firstZStackCidrs']]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): pf_vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm1) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) pf_vm1.check() vm_nic1 = pf_vm1.vm.vmNics[0] vm_nic_uuid1 = vm_nic1.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid test_util.test_dsc("attach, detach and delete pf for many times") for i in range(1, 451): test_util.test_logger('round %s' % (i)) starttime = datetime.datetime.now() pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule5_ports, private_target_rule=Port.rule5_ports, vip_uuid=vip_uuid) pf_creation_opt1.set_vip_ports(i, i) pf_creation_opt1.set_private_ports(i, i) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) if i < 151: test_pf1.attach(vm_nic_uuid1, pf_vm1) pf_dict[i] = test_pf1.get_port_forwarding().uuid elif i < 301: test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf1.detach() pf_dict[i] = test_pf1.get_port_forwarding().uuid else : test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf1.detach() test_pf1.delete() endtime = datetime.datetime.now() optime = (endtime - starttime).seconds test_util.test_dsc("round %s, pf operation time: %s" % (i, optime)) test_util.test_logger("the pf operation time is %s seconds" % optime) if optime > 240: test_util.test_fail("the pf operation time is %s seconds, more than 240 seconds" % optime) vip.delete() test_obj_dict.rm_vip(vip) pf_vm1.destroy() test_obj_dict.rm_vm(pf_vm1) for j in pf_dict: net_ops.delete_port_forwarding(pf_dict[j]) test_util.test_pass("Test Port Forwarding Attach/Detach Successfully")
def test(): pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) vr_pub_ip = vr_pub_nic.ip l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('delete_vip_before_attach_PF_to_VM', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt = PfRule.generate_pf_rule_option(vr_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) vip.attach_pf(test_pf) vip.check() vip.delete() test_obj_dict.rm_vip(vip) pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) test_util.test_pass("Test Delete VIP before attach Port Forwarding to any VM Successfully")
def test(): test_util.test_dsc("set global config anti-spoofing value to true ") cfg_ops.change_global_config(category="vm", name="cleanTraffic", value="true") test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") for vpc_name in vpc_name_list: vr_list.append(test_stub.create_vpc_vrouter(vpc_name)) for vr, l3_list in izip(vr_list, vpc_l3_list): test_stub.attach_l3_to_vpc_vr(vr, l3_list) test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format(VLAN1_NAME, VLAN2_NAME)) vm1 = test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(VLAN1_NAME), l3_name=VLAN1_NAME) test_obj_dict.add_vm(vm1) vm1.check() vm2 = test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(VLAN2_NAME), l3_name=VLAN2_NAME) test_obj_dict.add_vm(vm2) vm2.check() vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr_list[0].inv) test_util.test_dsc("Create vip") vip = test_stub.create_vip('vip1', vr_pub_nic.l3NetworkUuid) test_obj_dict.add_vip(vip) test_util.test_dsc("Create eip") eip = test_stub.create_eip('eip1', vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) vip.check() test_util.test_dsc("set global config anti-spoofing value to default value false ") cfg_ops.change_global_config(category="vm", name="cleanTraffic", value="false") test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") for vpc_name in vpc_name_list: vr_list.append(test_stub.create_vpc_vrouter(vpc_name)) for vr, l3_list in izip(vr_list, vpc_l3_list): test_stub.attach_l3_to_vpc_vr(vr, l3_list) test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format( flavor['vm1l3'], flavor['vm2l3'])) vm1, vm2 = [ test_stub.create_vm_with_random_offering( vm_name='vpc_vm_{}'.format(name), l3_name=name) for name in (flavor['vm1l3'], flavor['vm2l3']) ] [test_obj_dict.add_vm(vm) for vm in (vm1, vm2)] [vm.check() for vm in (vm1, vm2)] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr_list[0].inv) vip_list = [] for vm in (vm1, vm2): test_util.test_dsc("Create vip for vm {}".format(vm.get_vm().name)) vip = test_stub.create_vip('vip_{}'.format(vm.get_vm().name), vr_pub_nic.l3NetworkUuid) test_obj_dict.add_vip(vip) vip_list.append(vip) test_util.test_dsc("Create eip for vm {}".format(vm.get_vm().name)) eip = test_stub.create_eip('eip_{}'.format(vm.get_vm().name), vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) eip.attach(vm.get_vm().vmNics[0].uuid, vm) vip.check() vm.check() for vm in (vm1, vm2): vm.check() vm1_inv, vm2_inv = [vm.get_vm() for vm in (vm1, vm2)] vip1, vip2 = vip_list test_util.test_dsc("test two vm EIP connectivity") test_stub.run_command_in_vm(vm1_inv, 'iptables -F') test_stub.run_command_in_vm(vm2_inv, 'iptables -F') test_lib.lib_check_ping(vm1_inv, vip2.get_vip().ip) test_lib.lib_check_ping(vm2_inv, vip1.get_vip().ip) test_lib.lib_check_ports_in_a_command(vm1_inv, vip1.get_vip().ip, vip2.get_vip().ip, ["22"], [], vm2_inv) test_lib.lib_check_ports_in_a_command(vm2_inv, vip2.get_vip().ip, vip1.get_vip().ip, ["22"], [], vm1_inv) test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm.check() vip.check() vm.destroy() test_obj_dict.rm_vm(vm) vip.check() eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Create EIP for VM Success')
def test(): test_util.test_dsc('Create test vm with lb.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) vm3 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm3) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid vm_nic3 = vm3.get_vm().vmNics[0] vm_nic3_uuid = vm_nic3.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lbl_creation_option = test_lib.lib_create_lb_listener_option() lbl_creation_option.set_load_balancer_uuid(lb.get_load_balancer().uuid) lbl = zstack_lb_header.ZstackTestLoadBalancerListener() lbl.set_creation_option(lbl_creation_option) lbl.set_algorithm(lb_header.LB_ALGORITHM_LC) lbl.create() lb.add_load_balancer_listener(lbl) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid, vm_nic3_uuid]) vm1.check() vm2.check() vm3.check() lb.check() vm3.stop() import time time.sleep(5) lb.check() vm3.start() time.sleep(60) lb.check() lb.delete() test_obj_dict.rm_load_balancer(lb) lb.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create Load Balancer Test Success')
def test(): ''' PF test needs at least 3 VR existence. Besides of PF_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. The 2nd VR VM should not be able to access PF_VM. ''' pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_vm_ops', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) vip.attach_pf(test_pf) pf_vm.check() vip.check() #stop vm pf_vm.stop() test_pf.check() pf_vm.start() pf_vm.check() vip.check() pf_vm.reboot() pf_vm.check() vip.check() test_pf.delete() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass("Test Port Forwarding with VM Operations Successfully")
def test(): test_util.test_dsc('Create test vm with lb.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) vm3 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm3) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid vm_nic3 = vm3.get_vm().vmNics[0] vm_nic3_uuid = vm_nic3.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lbl_creation_option = test_lib.lib_create_lb_listener_option() lbl_creation_option.set_load_balancer_uuid(lb.get_load_balancer().uuid) lbl = zstack_lb_header.ZstackTestLoadBalancerListener() lbl.set_creation_option(lbl_creation_option) lbl.set_algorithm(lb_header.LB_ALGORITHM_LC) lbl.create() lb.add_load_balancer_listener(lbl) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid, vm_nic3_uuid]) vm1.check() vm2.check() vm3.check() lb.check() vm3.stop() import time time.sleep(5) lb.check() vm3.start() time.sleep(5) lb.check() lb.delete() test_obj_dict.rm_load_balancer(lb) lb.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create Load Balancer Test Success')
def test(): vip_bandwidth = 1*1024 vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm1) vm1.check() vm1_nic = vm1.vm.vmNics[0] vm1_nic_uuid = vm1_nic.uuid pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('qos_vip', l3_uuid1) test_obj_dict.add_vip(vip1) eip1 = test_stub.create_eip('create qos test', vip_uuid=vip1.get_vip().uuid, vnic_uuid=vm1_nic_uuid, vm_obj=vm1) vip1.attach_eip(eip1) vip1_ip = vip1.get_vip().ip vip1_qos = net_ops.set_vip_qos(vip_uuid=vip1.get_vip().uuid, inboundBandwidth=vip_bandwidth*8*1024, outboundBandwidth=vip_bandwidth*8*1024) vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict.add_vm(vm2) vm2.check() vm2_nic = vm2.vm.vmNics[0] vm2_nic_uuid = vm2_nic.uuid pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('qos_vip', l3_uuid2) test_obj_dict.add_vip(vip2) eip2 = test_stub.create_eip('create qos test', vip_uuid=vip2.get_vip().uuid, vnic_uuid=vm2_nic_uuid, vm_obj=vm2) vip2.attach_eip(eip2) vip2_ip = vip2.get_vip().ip vm1_inv = vm1.get_vm() vm2_inv = vm2.get_vm() test_stub.make_ssh_no_password(vm1_inv) test_stub.make_ssh_no_password(vm2_inv) test_stub.install_iperf(vm1_inv) test_stub.install_iperf(vm2_inv) iptables_cmd = "iptables -F" exec_cmd_in_vm(vm1, iptables_cmd, "Failed to clean iptables.") exec_cmd_in_vm(vm2, iptables_cmd, "Failed to clean iptables.") test_stub.test_iperf_bandwidth(vm1_inv,vm2_inv,vip1_ip,5001,5001,vip_bandwidth) test_stub.test_iperf_bandwidth(vm2_inv,vm1_inv,vip2_ip,5001,5001,vip_bandwidth) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create VIP Qos for EIP Success')
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) vm_nic = vm.vm.vmNics[0] vm2_nic = vm2.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] if vr.applianceVmType == "VirtualRouter": test_util.test_skip("This test only for vrouter network") vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm.check() vm2.check() test_stub.make_ssh_no_password(vm2.get_vm()) vm_ip = vm_nic.ip vm2_ip = vm2_nic.ip ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null' cmd = 'ping -c 8 %s' % (eip.get_eip().vipIp) shell.call("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) cmd = '''"echo quit | timeout 4 telnet %s 22|grep 'Escape character'"''' % (eip.get_eip().vipIp) shell.call("%s %s %s" % (ssh_cmd, vm2_ip, cmd)) vm.destroy() test_obj_dict.rm_vm(vm) vip.check() eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Create EIP for VM Success')
def test(): ''' PF test needs at least 3 VR existence. Besides of PF_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. The 2nd VR VM should not be able to access PF_VM. ''' pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_tcp_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) vip.attach_pf(test_pf) pf_vm.check() vip.check() test_pf.delete() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass("Test Port Forwarding TCP Rule Successfully")
def test(): vip_bandwidth = 1*1024 pf_vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm1) pf_vm2 = test_stub.create_vlan_sg_vm() test_obj_dict.add_vm(pf_vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) pf_vm1.check() pf_vm2.check() vm1_inv=pf_vm1.get_vm() vm2_inv=pf_vm2.get_vm() vm_nic1 = pf_vm1.vm.vmNics[0] vm_nic_uuid1 = vm_nic1.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vip_ip = vip.get_vip().ip #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) pf_vm1.check() test_pf1.attach(vm_nic_uuid1, pf_vm1) vip_qos = net_ops.set_vip_qos(vip_uuid=vip_uuid, inboundBandwidth=vip_bandwidth*8*1024, outboundBandwidth=vip_bandwidth*8*1024) test_stub.make_ssh_no_password(vm1_inv) test_stub.make_ssh_no_password(vm2_inv) test_stub.install_iperf(vm1_inv) test_stub.install_iperf(vm2_inv) iptables_cmd = "iptables -F" exec_cmd_in_vm(pf_vm1, iptables_cmd, "Failed to clean iptables.") test_stub.test_iperf_bandwidth(vm1_inv,vm2_inv,vip_ip,20502,20502,vip_bandwidth) vip.delete() test_obj_dict.rm_vip(vip) pf_vm1.destroy() test_obj_dict.rm_vm(pf_vm1) pf_vm2.destroy() test_obj_dict.rm_vm(pf_vm2) test_util.test_pass("Test Port Forwarding Vip Qos Successfully.")
def test(): pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('test_pf_after_destroy_vm', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vr_pub_ip = test_lib.lib_find_vr_pub_ip(vr) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) vip.attach_pf(test_pf) pf_vm.check() vip.check() pf_vm.stop() pf_vm.check() vip.check() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) vip.check() test_pf.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass( "Port Forwarding Rule checking pass when stopping VM and destroying VM." )
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") for vpc_name in vpc_name_list: vr_list.append(test_stub.create_vpc_vrouter(vpc_name)) for vr, l3_list in izip(vr_list, vpc_l3_list): test_stub.attach_l3_to_vpc_vr(vr, l3_list) test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format(flavor['vm1l3'], flavor['vm2l3'])) vm1 = test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(flavor['vm1l3']), l3_name=flavor['vm1l3']) test_obj_dict.add_vm(vm1) vm1.check() vm2 = test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(flavor['vm2l3']), l3_name=flavor['vm2l3']) test_obj_dict.add_vm(vm2) vm2.check() vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr_list[0].inv) test_util.test_dsc("Create vip") vip = test_stub.create_vip('vip1', vr_pub_nic.l3NetworkUuid) test_obj_dict.add_vip(vip) test_util.test_dsc("Create eip") eip = test_stub.create_eip('eip1', vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) vip.check() if flavor['one_vpc']: for vm in (vm1, vm2): eip.attach(vm.get_vm().vmNics[0].uuid, vm) vip.check() eip.detach() vip.check() else: eip.attach(vm1.get_vm().vmNics[0].uuid, vm1) vip.check() eip.detach() vip.check() eip.delete() test_util.test_dsc("Create a new eip") eip = test_stub.create_eip('eip2', vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) vip.check() eip.attach(vm2.get_vm().vmNics[0].uuid, vm2) vip.check() eip.detach() vip.check() eip.delete() test_lib.lib_error_cleanup(test_obj_dict) test_stub.remove_all_vpc_vrouter()
def test(): pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('2 pfs with same vip', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule2_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create(pf_vm) vip.attach_pf(test_pf1) pf_creation_opt2 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule3_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf2 = zstack_pf_header.ZstackTestPortForwarding() test_pf2.set_creation_option(pf_creation_opt2) test_pf2.create(pf_vm) vip.attach_pf(test_pf2) pf_vm.check() vip.check() test_pf1.delete() test_pf2.delete() import time time.sleep(1) vip.check() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass("Test Port Forwarding TCP Rule Successfully")
def create_ipsec_vpn_connection(self, check_connectivity=True, check_status=False, use_1_vip=False): self.vm = create_vlan_vm(os.environ.get('l3VlanNetworkName1')) # test_obj_dict.add_vm(self.vm) self.vm.check() vm_ip = self.vm.vm.vmNics[0].ip pri_l3_uuid = self.vm.vm.vmNics[0].l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] l3_uuid = test_lib.lib_find_vr_pub_nic(vr).l3NetworkUuid vip_for_vr = [vip for vip in res_ops.query_resource(res_ops.VIP) if 'vip-for-vrouter' in vip.name] if use_1_vip: vip = vip_for_vr[0] else: vip_not_for_vr = [vip for vip in res_ops.query_resource(res_ops.VIP) if 'vip-for-vrouter' not in vip.name] if vip_not_for_vr: vip = vip_not_for_vr[0] else: vip = create_vip('ipsec_vip', l3_uuid).get_vip() cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid) self.zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr self.dst_cidr_block = self.zstack_cidrs.replace('1/', '0/') # _vm_ip = zstack_cidrs.replace('1/', '254/') # cmd = 'ip a add dev br_eth0_1101 %s' % _vm_ip time.sleep(10) if check_connectivity: self.create_ecs_instance(need_vpn_gateway=True, connect=True) self.get_eip() self.attach_eip_to_ecs() else: self.add_datacenter_iz(check_vpn_gateway=True) self.get_vpc(has_vpn_gateway=True) self.get_vswitch() self.get_vr() self.get_user_vpn_gateway(vip) self.create_vpn_connection() if check_status: condition = res_ops.gen_query_conditions('connectionId', '=', self.vpn_connection.connectionId) vpn_conn = hyb_ops.query_vpc_vpn_connection_local(condition)[0] assert vpn_conn.status == 'ike_sa_not_established' self.create_ipsec(pri_l3_uuid, vip) if check_connectivity: # Add route entry self.route_entry = hyb_ops.create_aliyun_vpc_virtualrouter_entry_remote(self.dst_cidr_block, self.vr.uuid, vrouter_type='vrouter', next_hop_type='VpnGateway', next_hop_uuid=self.vpn_gateway.uuid) ping_ecs_cmd = "sshpass -p password ssh -o StrictHostKeyChecking=no root@%s 'ping %s -c 5 | grep time='" % (vm_ip, self.ecs_instance.privateIpAddress) # ZStack VM ping Ecs ping_ecs_cmd_status = commands.getstatusoutput(ping_ecs_cmd)[0] assert ping_ecs_cmd_status == 0 ping_vm_cmd = "sshpass -p Password123 ssh -o StrictHostKeyChecking=no root@%s 'ping %s -c 5 | grep time='" % (self.eip.eipAddress, vm_ip) # Ecs ping ZStack VM ping_vm_cmd_status = commands.getstatusoutput(ping_vm_cmd)[0] assert ping_vm_cmd_status == 0 test_util.test_pass('Create hybrid IPsec Vpn Connection Test Success')
def test(): test_util.test_dsc('Create test vm with lb for LB different ports testing.') vip_bandwidth = 1*1024 vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) vm3 = test_stub.create_vlan_sg_vm() test_obj_dict.add_vm(vm3) vm1_inv=vm1.get_vm() vm3_inv=vm3.get_vm() vm_nic1 = vm1_inv.vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2_inv.vmNics[0] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vip_ip = vip.get_vip().ip vip_qos = net_ops.set_vip_qos(vip_uuid=vip_uuid, inboundBandwidth=vip_bandwidth*8*1024, outboundBandwidth=vip_bandwidth*8*1024) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lb_creation_option = test_lib.lib_create_lb_listener_option(lbl_port = 5001, lbi_port = 5001 ) lbl = lb.create_listener(lb_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid]) vm1.check() vm2.check() lb.check() test_stub.make_ssh_no_password(vm1_inv) test_stub.make_ssh_no_password(vm3_inv) test_stub.install_iperf(vm1_inv) test_stub.install_iperf(vm3_inv) iptables_cmd = "iptables -F" exec_cmd_in_vm(vm1, iptables_cmd, "Failed to clean iptables.") test_stub.test_iperf_bandwidth(vm1_inv,vm3_inv,vip_ip,5001,5001,vip_bandwidth) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Test Load Balancer VIP Qos Success')
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm.check() test_stub.make_ssh_no_password(vm.get_vm()) vm_ip = vm_nic.ip ssh_cmd = 'ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null' cmd = 'ping -c 8 %s' % (eip.get_eip().vipIp) shell.call("%s %s %s" % (ssh_cmd, vm_ip, cmd)) vm.destroy() test_obj_dict.rm_vm(vm) vip.check() eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Create EIP for VM Success')
def test(): test_util.test_dsc( 'Create test vm with lb for LB different ports testing.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) #l3_name = os.environ.get('l3VlanNetworkName1') #vr1 = test_stub.get_vr_by_private_l3_name(l3_name) #l3_name = os.environ.get('l3NoVlanNetworkName1') #vr2 = test_stub.get_vr_by_private_l3_name(l3_name) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lb_creation_option = test_lib.lib_create_lb_listener_option(\ lbl_port = 2222, lbi_port = 22) lbl = lb.create_listener(lb_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid]) vm1.check() vm2.check() lb.check() lb.delete() test_obj_dict.rm_load_balancer(lb) lb.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass( 'Create Load Balancer with Different Ports Test Success')
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] test_util.test_dsc("create vpc vrouter and attach vpc l3 to vpc") for vpc_name in vpc_name_list: vr_list.append(test_stub.create_vpc_vrouter(vpc_name)) time.sleep(120) #waiting for vrouter boot up for vr, l3_list in izip(vr_list, vpc_l3_list): test_stub.attach_l3_to_vpc_vr(vr, l3_list) test_util.test_dsc("create two vm, vm1 in l3 {}, vm2 in l3 {}".format(flavor['vm1l3'], flavor['vm2l3'])) vm1, vm2 = [test_stub.create_vm_with_random_offering(vm_name='vpc_vm_{}'.format(name), l3_name=name) for name in (flavor['vm1l3'], flavor['vm2l3'])] [test_obj_dict.add_vm(vm) for vm in (vm1,vm2)] [vm.check() for vm in (vm1,vm2)] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr_list[0].inv) vip_list = [] for vm in (vm1, vm2): test_util.test_dsc("Create vip for vm {}".format(vm.get_vm().name)) vip = test_stub.create_vip('vip_{}'.format(vm.get_vm().name), vr_pub_nic.l3NetworkUuid) test_obj_dict.add_vip(vip) vip_list.append(vip) test_util.test_dsc("Create eip for vm {}".format(vm.get_vm().name)) eip = test_stub.create_eip('eip_{}'.format(vm.get_vm().name), vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) eip.attach(vm.get_vm().vmNics[0].uuid, vm) time.sleep(10) #waiting for eip attach to vm vip.check() vm.check() for vm in (vm1, vm2): vm.check() vm1_inv, vm2_inv = [vm.get_vm() for vm in (vm1, vm2)] vip1, vip2 = vip_list test_util.test_dsc("test two vm EIP connectivity") test_stub.run_command_in_vm(vm1_inv, 'iptables -F') test_stub.run_command_in_vm(vm2_inv, 'iptables -F') test_lib.lib_check_ping(vm1_inv, vip2.get_vip().ip) test_lib.lib_check_ping(vm2_inv, vip1.get_vip().ip) test_lib.lib_check_ports_in_a_command(vm1_inv, vip1.get_vip().ip, vip2.get_vip().ip, ["22"], [], vm2_inv) test_lib.lib_check_ports_in_a_command(vm2_inv, vip2.get_vip().ip, vip1.get_vip().ip, ["22"], [], vm1_inv)
def test(): test_util.test_dsc('Create test vm with lb for LB different ports testing.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) #l3_name = os.environ.get('l3VlanNetworkName1') #vr1 = test_stub.get_vr_by_private_l3_name(l3_name) #l3_name = os.environ.get('l3NoVlanNetworkName1') #vr2 = test_stub.get_vr_by_private_l3_name(l3_name) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lb_creation_option = test_lib.lib_create_lb_listener_option(\ lbl_port = 2222, lbi_port = 22) lbl = lb.create_listener(lb_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid]) vm1.check() vm2.check() lb.check() lb.delete() test_obj_dict.rm_load_balancer(lb) lb.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create Load Balancer with Different Ports Test Success')
def test(): pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('test_pf_after_destroy_vm', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vr_pub_ip = test_lib.lib_find_vr_pub_ip(vr) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) vip.attach_pf(test_pf) pf_vm.check() vip.check() pf_vm.stop() pf_vm.check() vip.check() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) vip.check() test_pf.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass("Port Forwarding Rule checking pass when stopping VM and destroying VM.")
def test(): test_util.test_dsc('Create test vm with lb.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) vm3 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm3) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid vm_nic3 = vm3.get_vm().vmNics[0] vm_nic3_uuid = vm_nic3.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb.set_separated_vr() lb.create('create lb test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) lb_creation_option = test_lib.lib_create_lb_listener_option() lbl = lb.create_listener(lb_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid, vm_nic3_uuid]) vm1.check() vm2.check() vm3.check() lb.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create Load Balancer with alone VR Test Success')
def create(self, target_vm=None): if not self.pf_creation_option.get_vm_nic_uuid(): self.state = pf_header.DETACHED else: if not self.pf_creation_option.get_vip_uuid(): l3_uuid = test_lib.lib_get_l3_uuid_by_nic(self.pf_creation_option.get_vm_nic_uuid()) if not 'PortForwarding' in test_lib.lib_get_l3_service_type(l3_uuid): test_util.test_fail('[l3:] %s is not available PortForwarding network for [vm:] %s' % (l3_uuid, target_vm.get_vm().uuid)) vr = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) vip = net_ops.create_vip(vr_pub_nic.l3NetworkUuid) self.pf_creation_option.set_vip_uuid(vip.uuid) self.state = pf_header.ATTACHED if not target_vm: test_util.test_fail('You forget to add target_vm object when calling pf.create(target_vm). ') self.port_forwarding = net_ops.create_port_forwarding(self.pf_creation_option) self.target_vm = target_vm super(ZstackTestPortForwarding, self).create() return self.port_forwarding
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) vm.check() vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('delete_vip_before_attach_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) vip.check() vip.delete() test_obj_dict.rm_vip(vip) vm.destroy() test_obj_dict.rm_vm(vm) test_util.test_pass('Delete VIP before Attach EIP to Any VM Success')
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] if vr1.applianceVmType == "vrouter": test_util.test_skip("vrouter VR does not support single VM multiple EIP") l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] if vr1.applianceVmType == "vrouter": test_util.test_skip("vrouter VR does not support single VM multiple EIP") #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic1 = vm1.vm.vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm2.vm.vmNics[0] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip1 = test_stub.create_vip('create_vip 1', l3_uuid) test_obj_dict.add_vip(vip1) eip1 = test_stub.create_eip('create eip 1', vip_uuid=vip1.get_vip().uuid, \ vnic_uuid=vm_nic1_uuid, vm_obj=vm1) vip1.attach_eip(eip1) vip2 = test_stub.create_vip('create_vip 2', l3_uuid) test_obj_dict.add_vip(vip2) eip2 = test_stub.create_eip('create eip 2', vip_uuid=vip2.get_vip().uuid, \ vnic_uuid=vm_nic2_uuid, vm_obj=vm2) vip2.attach_eip(eip2) vm1.check() vip1.check() vm2.check() vip2.check() test_lib.lib_check_ports_in_a_command(vm1.get_vm(), vip1.get_vip().ip, \ vip2.get_vip().ip, test_stub.target_ports, [], vm2.get_vm()) test_lib.lib_check_ports_in_a_command(vm2.get_vm(), vip2.get_vip().ip, \ vip1.get_vip().ip, test_stub.target_ports, [], vm1.get_vm()) vm1.destroy() test_obj_dict.rm_vm(vm1) test_lib.lib_check_ports_in_a_command(vm2.get_vm(), vip2.get_vip().ip, \ vip1.get_vip().ip, [], test_stub.target_ports, vm1.get_vm()) vm2.destroy() test_obj_dict.rm_vm(vm2) vip1.delete() test_obj_dict.rm_vip(vip1) vip2.delete() test_obj_dict.rm_vip(vip2) test_util.test_pass('Test 2 EIPs for 2 VMs Success')
def test(): try: conf_ops.change_global_config('virtualRouter', 'ssh.passwordAuth', 'true') except: test_util.test_logger('No global config ssh.passwordAuth') pf_vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm1) pf_vm2 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm1.check() pf_vm2.check() vm_nic1 = pf_vm1.vm.vmNics[0] vm_nic_uuid1 = vm_nic1.uuid vm_nic2 = pf_vm2.vm.vmNics[0] vm_nic_uuid2 = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) pf_creation_opt2 = PfRule.generate_pf_rule_option(vr2_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule5_ports, private_target_rule=Port.rule5_ports, vip_uuid=vip_uuid) test_pf2 = zstack_pf_header.ZstackTestPortForwarding() test_pf2.set_creation_option(pf_creation_opt2) test_pf2.create() vip.attach_pf(test_pf2) pf_vm1.check() vip.check() test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf2.attach(vm_nic_uuid2, pf_vm2) vip.check() pf_vm1.stop() vip.check() test_pf1.detach() test_pf1.attach(vm_nic_uuid2, pf_vm2) pf_vm1.start() pf_vm1.check() vip.check() pf_vm1.stop() test_pf1.detach() test_pf2.detach() test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf2.attach(vm_nic_uuid1, pf_vm1) pf_vm1.start() pf_vm1.check() vip.check() vip.delete() test_obj_dict.rm_vip(vip) pf_vm1.destroy() test_obj_dict.rm_vm(pf_vm1) pf_vm2.destroy() test_obj_dict.rm_vm(pf_vm2) test_util.test_pass("Test Port Forwarding Attach/Detach Successfully")
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs], ike_auth_algorithm="md5") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs], ike_auth_algorithm="md5") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) vip1.delete() test_obj_dict1.rm_vip(vip1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) vip2.delete() test_obj_dict2.rm_vip(vip2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm_ip = vm_nic.ip user_name = 'root' user_password = '******' vm.check() vip.check() cmd = "ping -c 4 172.20.0.1" rsp_ping = os.system("sshpass -p '%s' ssh %s@%s '%s'"%(user_password, user_name, vm_ip, cmd)) #Try to download webpage from Jenkins server cmd = "curl http://192.168.200.100" rsp_curl = os.system("sshpass -p '%s' ssh %s@%s '%s'"%(user_password, user_name, vm_ip, cmd)) if rsp_ping != 0: test_util.test_fail('Attach EIP but cannot ping from VM') if rsp_ping == 0 and rsp_curl != 0: test_util.test_fail('Attach EIP and can ping from the VM, but cannot download anything in VM') vm.destroy() test_obj_dict.rm_vm(vm) vip.check() eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Attached EIP and download webpage in VM Success')
def test(): ''' EIP test needs at least 3 VR existence. Besides of EIP_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. The 2nd VR VM should not be able to access PF_VM. ''' test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) vm.check() l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid) vip.attach_eip(eip) vip.check() eip.attach(vm_nic_uuid, vm) vip.check() eip.detach() vip.check() vm.destroy() test_obj_dict.rm_vm(vm) eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Attach/Detach EIP Success')
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm3) vm3.check() vm_nic3 = vm3.get_vm().vmNics[0] vm_nic3_uuid = vm_nic3.uuid pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vip1 = test_stub.create_vip('vip for multi-services', l3_uuid1) vip_uuid = vip1.get_vip().uuid cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create PF in mevoco1') l3_name = os.environ.get('l3NoVlanNetworkName1') vr = test_stub.create_vr_vm(test_obj_dict1, l3_name) l3_name = os.environ.get('l3VlanNetworkName4') vr = test_stub.create_vr_vm(test_obj_dict1, l3_name) vr_pub_ip = test_lib.lib_find_vr_pub_ip(vr) pf_creation_opt1 = PfRule.generate_pf_rule_option( vr_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip1.attach_pf(test_pf1) vip1.check() test_pf1.attach(vm_nic1_uuid, vm1) vip1.check() test_util.test_dsc('Create LB in mevoco1') lb = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip1.get_vip().uuid) test_obj_dict1.add_load_balancer(lb) vip1.attach_lb(lb) lb_creation_option = test_lib.lib_create_lb_listener_option(lbl_port=222, lbi_port=22) lbl = lb.create_listener(lb_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic3_uuid]) lb.check() vip1.check() test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs]) vip1_db = test_lib.lib_get_vip_by_uuid(vip_uuid) assert "IPsec" in vip1_db.useFor assert vip1_db.useFor.count("IPsec") == 1 os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) # delete ipsec os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vip1_db = test_lib.lib_get_vip_by_uuid(vip_uuid) assert "IPsec" not in vip1_db.useFor # delete PF test_pf1.delete() vip1_db = test_lib.lib_get_vip_by_uuid(vip_uuid) assert "PortForwarding" not in vip1_db.useFor # delete LB lb.delete() vip1_db = test_lib.lib_get_vip_by_uuid(vip_uuid) assert vip1_db.useFor is None test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) vip2.delete() test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip vip1.delete() test_util.test_pass('Create multiple service with 1 snat IP Success')
def test(): vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_dnat_vm() test_obj_dict.add_vm(vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) #stop vm vm1.stop() vm1_nic = vm1.vm.vmNics[0] vm1_nic_uuid = vm1_nic.uuid vm2_nic = vm2.vm.vmNics[0] vm2_nic_uuid = vm2_nic.uuid pri_l3_uuid = vm2_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vm_ops', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vip2 = test_stub.create_vip('vm_ops2', l3_uuid) test_obj_dict.add_vip(vip2) vip2_uuid = vip2.get_vip().uuid eip = test_stub.create_eip('eip vm ops test', vip_uuid, vm2_nic_uuid, vm2) vip.attach_eip(eip) test_util.test_dsc("start vm1") vm1.start() #vip.check() eip2 = test_stub.create_eip('eip vm ops test2', vip2_uuid, vm1_nic_uuid, vm1) vip2.attach_eip(eip2) vm1.destroy() test_obj_dict.rm_vm(vm1) vm2.destroy() test_obj_dict.rm_vm(vm2) vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass("Test EIP with VM ops2 Successfully")
def test(): test_util.test_dsc('Create test vm with EIP and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vm_ip = vm_nic.ip user_name = 'root' user_password = '******' vm.check() vip.check() cmd = "ping -c 4 172.20.0.1" rsp_ping = os.system("sshpass -p '%s' ssh %s@%s '%s'" % (user_password, user_name, vm_ip, cmd)) #Try to download webpage from Jenkins server cmd = "curl http://192.168.200.100" rsp_curl = os.system("sshpass -p '%s' ssh %s@%s '%s'" % (user_password, user_name, vm_ip, cmd)) if rsp_ping != 0: test_util.test_fail('Attach EIP but cannot ping from VM') if rsp_ping == 0 and rsp_curl != 0: test_util.test_fail( 'Attach EIP and can ping from the VM, but cannot download anything in VM' ) vm.destroy() test_obj_dict.rm_vm(vm) vip.check() eip.delete() vip.delete() test_obj_dict.rm_vip(vip) test_util.test_pass('Attached EIP and download webpage in VM Success')
def test(): global mevoco1_ip global mevoco2_ip global mevoco3_ip global ipsec11 global ipsec12 global ipsec2 global ipsec3 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] mevoco3_ip = os.environ['thirdZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip11 = test_stub.create_vip('ipsec1_vip', l3_uuid1) #vip12 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco3_ip test_util.test_dsc('Create test vm in mevoco3') vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName3')) test_obj_dict2.add_vm(vm3) vm3.check() pri_l3_uuid3 = vm3.vm.vmNics[0].l3NetworkUuid vr3 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid3)[0] l3_uuid3 = test_lib.lib_find_vr_pub_nic(vr3).l3NetworkUuid vip3 = test_stub.create_vip('ipsec3_vip', l3_uuid3) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid3) third_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr cond = res_ops.gen_query_conditions('l3Network.uuid', '=', pri_l3_uuid3) cond = res_ops.gen_query_conditions('vmInstanceUuid', '=', vr3.uuid, cond) vr3_pri_ip = res_ops.query_resource(res_ops.VM_NIC, cond)[0].ip cmd = 'route del default; route add default gw %s' %vr3_pri_ip os.system("sshpass -p 'password' ssh root@%s '%s'" %(vm3.vm.vmNics[0].ip, cmd)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec11 = ipsec_ops.create_ipsec_connection('ipsec11', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip11.get_vip().uuid, [second_zstack_cidrs]) #ipsec12 = ipsec_ops.create_ipsec_connection('ipsec12', pri_l3_uuid1, vip3.get_vip().ip, '123456', vip12.get_vip().uuid, [third_zstack_cidrs]) ipsec12 = ipsec_ops.create_ipsec_connection('ipsec12', pri_l3_uuid1, vip3.get_vip().ip, '123456', vip11.get_vip().uuid, [third_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip11.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco3_ip test_util.test_dsc('Create ipsec in mevoco3') #ipsec3 = ipsec_ops.create_ipsec_connection('ipsec3', pri_l3_uuid3, vip12.get_vip().ip, '123456', vip3.get_vip().uuid, [first_zstack_cidrs]) ipsec3 = ipsec_ops.create_ipsec_connection('ipsec3', pri_l3_uuid3, vip11.get_vip().ip, '123456', vip3.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) if not test_lib.lib_check_ping(vm1.vm, vm3.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco3[MN:%s]' % (mevoco1_ip, mevoco3_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco2[MN:%s] could not connect to vm in mevoco1[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco3_ip if not test_lib.lib_check_ping(vm3.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco3[MN:%s] could not connect to vm in mevoco1[MN:%s]' % (mevoco3_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec11.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm3.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco3[MN:%s]' % (mevoco1_ip, mevoco3_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco3_ip ipsec_ops.delete_ipsec_connection(ipsec3.uuid) if test_lib.lib_check_ping(vm3.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco3[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco3_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec12.uuid) test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): ''' Since VR ip address is assigned by zstack, so we need to use VR to test PF rules' connectibility. PF test needs at least 3 VR existence. The PF VM's VR is for set PF rule. The PF rule will add VIP for PF_VM. Besides of PF_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. So the 2nd VR VM should not be able to access PF_VM. In this test, will also add SG rules to check the coexistence between PF and SG. SG rule will be added onto PF_VM's internal IP. ''' pf_vm = test_stub.create_vr_vm('migrate_pf_sg_vm1', 'imageName_net', 'l3VlanNetwork2') test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vr_vm('migrate_temp_vm1', 'imageName_net', 'l3VlanNetworkName1') test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3VlanNetwork3') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_vr_vm('migrate_temp_vm2', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip_option = test_util.VipOption() vip_option.set_l3_uuid(l3_uuid) vip_uuid = net_ops.create_vip(vip_option).uuid pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid) test_pf = zstack_pf_header.ZstackTestPortForwarding() test_pf.set_creation_option(pf_creation_opt) test_pf.create(pf_vm) pf_vm.check() #Ignore this check, since it has been checked many times in other PF cases. #test_pf.check() sg1 = test_stub.create_sg() test_obj_dict.add_sg(sg1.security_group.uuid) sg_vm = zstack_sg_vm_header.ZstackTestSgVm() sg_vm.check() vm_nics = (vm_nic_uuid, pf_vm) rule1 = test_lib.lib_gen_sg_rule(Port.rule1_ports, inventory.TCP, inventory.INGRESS, vr1_pub_ip) rule2 = test_lib.lib_gen_sg_rule(Port.rule2_ports, inventory.TCP, inventory.INGRESS, vr2_pub_ip) sg1.add_rule([rule1]) test_util.test_dsc("Add nic to security group 1.") test_util.test_dsc("PF rule is allowed, since VR1's IP is granted by SG Rule1.") sg_vm.attach(sg1, [vm_nics]) test_pf.check() test_stub.migrate_vm_to_random_host(pf_vm) test_util.test_dsc("Remove rule1 from security group 1.") test_util.test_dsc("PF rule is still allowed") sg1.delete_rule([rule1]) test_pf.check() test_util.test_dsc("Add rule2") test_util.test_dsc("PF rule is not allowed, since rule2 only allowed the ingress from VR2, but VR2 can't pass PF rule. ") sg1.add_rule([rule2]) test_pf.check() test_util.test_dsc("Delete SG") sg_vm.delete_sg(sg1) test_util.test_dsc("PF rule is allowed") test_pf.check() if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) test_pf.delete() pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) net_ops.delete_vip(vip_uuid) test_util.test_pass("Test Port Forwarding TCP Rule Successfully")
def test(): global eip_snatInboundTraffic_default_value global pf_snatInboundTraffic_default_value #enable snatInboundTraffic and save global config value eip_snatInboundTraffic_default_value = \ conf_ops.change_global_config('eip', 'snatInboundTraffic', 'true') pf_snatInboundTraffic_default_value = \ conf_ops.change_global_config('portForwarding', \ 'snatInboundTraffic', 'true') image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list = [l3_net_uuid] l3_name = os.environ.get('l3VlanDNATNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list.append(l3_net_uuid) vm = test_stub.create_vm(l3_net_list, image_uuid, '2_l3_pf_vm') test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3NoVlanNetworkName1') vr_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] #we do not need temp_vm1, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vm.check() vm_nic1 = vm.vm.vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm.vm.vmNics[1] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip1 = test_stub.create_vip('vip1_2l3s_vm_test', l3_uuid) test_obj_dict.add_vip(vip1) vip1_uuid = vip1.get_vip().uuid vip2 = test_stub.create_vip('vip2_2l3s_vm_test', l3_uuid) test_obj_dict.add_vip(vip2) vip2_uuid = vip2.get_vip().uuid eip1 = test_stub.create_eip('2l3 eip test1', vip_uuid=vip1.get_vip().uuid) vip1.attach_eip(eip1) vip1.check() eip1.attach(vm_nic1_uuid, vm) vip1.check() eip2 = test_stub.create_eip('2l3 eip test2', vip_uuid=vip2.get_vip().uuid) vip2.attach_eip(eip2) vip2.check() eip2.attach(vm_nic2_uuid, vm) vip2.check() vm.stop() vm.start() vm.check() vip1.check() vip2.check() eip1.detach() eip2.detach() vip1.check() vip2.check() vip1.delete() test_obj_dict.rm_vip(vip1) vip2.delete() test_obj_dict.rm_vip(vip2) vm.destroy() test_obj_dict.rm_vm(vm) conf_ops.change_global_config('eip', 'snatInboundTraffic', \ eip_snatInboundTraffic_default_value ) conf_ops.change_global_config('portForwarding', 'snatInboundTraffic', \ pf_snatInboundTraffic_default_value) test_util.test_pass('Create 1 VM with 2 l3_network with 2 VIP PF testing successfully.')
def test(): test_util.test_dsc(''' Will doing random test Security Group operations, including SG create/delete, rule add/remove, vm nics attach/detach. If reach max 4 coexisting running vm, testing will success and quit. Volume actions and Image actions are removed in this robot test. VM resources: Since SG testing will create target test vm, there might be max 12 running VMs: 4 VR VMs, 4 SG target test VMs and 4 test VMs. ''') target_running_vm = 4 target_l3s = test_lib.lib_get_limited_l3_network(2, 5) vr_num = 0 for target_l3 in target_l3s: vr_l3_uuid = target_l3.uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) temp_vm = None if not vrs: #create temp_vm for getting its vr for test pf_vm portforwarding vm_create_option = test_util.VmOption() vm_create_option.set_l3_uuids([vr_l3_uuid]) temp_vm = test_lib.lib_create_vm(vm_create_option) test_dict.add_vm(temp_vm) #we only need temp_vm's VR temp_vm.destroy() test_dict.rm_vm(temp_vm) vr_num += 1 #VIP testing need 3 VRs if vr_num > 2: break utility_vm_create_option = test_util.VmOption() utility_vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) l3_uuid = test_lib.lib_get_l3_by_name( os.environ.get('l3VlanNetworkName1')).uuid utility_vm_create_option.set_l3_uuids([l3_uuid]) utility_vm = test_lib.lib_create_vm(utility_vm_create_option) test_dict.add_utility_vm(utility_vm) utility_vm.check() vm_create_option = test_util.VmOption() #image has to use network test image, as it needs to do port checking vm_create_option.set_image_uuid( test_lib.lib_get_image_by_name( img_name=os.environ.get('imageName_net')).uuid) #Add 3 times sg_rule_operations, vip_operations and 2 times vm creation priority_actions = [test_state.TestAction.sg_rule_operations] * 2 + \ [test_state.TestAction.vip_operations] * 2 + \ [test_state.TestAction.create_vm] vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) public_l3 = test_lib.lib_find_vr_pub_nic(vrs[0]).l3NetworkUuid robot_test_obj = test_util.Robot_Test_Object() robot_test_obj.set_test_dict(test_dict) robot_test_obj.set_vm_creation_option(vm_create_option) priority_action_obj = action_select.ActionPriority() priority_action_obj.add_priority_action_list(priority_actions) robot_test_obj.set_priority_actions(priority_action_obj) robot_test_obj.set_public_l3(public_l3) robot_test_obj.set_utility_vm(utility_vm) robot_test_obj.set_random_type(action_select.weight_fair_strategy) test_util.test_dsc( 'Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).' ) rounds = 1 current_time = time.time() timeout_time = current_time + 7200 while time.time() <= timeout_time: test_util.test_dsc('New round %s starts: random operation pickup.' % rounds) test_lib.lib_vm_random_operation(robot_test_obj) test_util.test_dsc('Round %s finished. Begin status checking.' % rounds) rounds += 1 test_lib.lib_robot_status_check(test_dict) test_util.test_dsc('Reach test pass exit criterial.') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('Create random VM Test Success')
def test(): zstack_pri_name = os.environ['l3VlanDNATNetworkName'] zstack_image = os.environ['imageName_net'] zstack_vr_name = os.environ['virtualRouterOfferingName_s'] cond = res_ops.gen_query_conditions('name', '=', zstack_vr_name) zstack_vr_instance = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] cond = res_ops.gen_query_conditions('name', '=', zstack_pri_name) zstack_pri = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0] zstack_pri_uuid = zstack_pri.uuid zstack_tag = "guestL3Network::" + zstack_pri_uuid tag_ops.create_system_tag("InstanceOfferingVO", zstack_vr_instance.uuid, zstack_tag) vcenter_pri_name = os.environ['l3vCenterNoVlanNetworkName'] vcenter_image = os.environ['image_dhcp_name'] vcenter_vr_name = os.environ['vCenterVirtualRouterOfferingName'] cond = res_ops.gen_query_conditions('name', '=', vcenter_vr_name) vcenter_vr_instance = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0] cond = res_ops.gen_query_conditions('name', '=', vcenter_pri_name) vcenter_pri = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0] vcenter_pri_uuid = vcenter_pri.uuid vcenter_tag = "guestL3Network::" + vcenter_pri_uuid tag_ops.create_system_tag("InstanceOfferingVO", vcenter_vr_instance.uuid, vcenter_tag) test_util.test_dsc('Create test vm') vm1 = test_stub.create_vm(vm_name='test_ipsec_1', image_name = zstack_image, l3_name=zstack_pri_name) test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vm_in_vcenter(vm_name='test_ipsec_2', image_name = vcenter_image, l3_name=vcenter_pri_name) test_obj_dict.add_vm(vm2) time.sleep(50) test_util.test_dsc('Create 2 vip with 2 snat ip') pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vip1 = zstack_vip_header.ZstackTestVip() vip1.get_snat_ip_as_vip(vr1_pub_ip) vip1.isVcenter = True test_obj_dict.add_vip(vip1) pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) vip2 = zstack_vip_header.ZstackTestVip() vip2.get_snat_ip_as_vip(vr2_pub_ip) vip2.isVcenter = True test_obj_dict.add_vip(vip2) test_util.test_dsc('Create ipsec with 2 vip') zstack_pri_cidr = zstack_pri.ipRanges[0].networkCidr vcenter_pri_cidr = vcenter_pri.ipRanges[0].networkCidr ipsec1 = ipsec_ops.create_ipsec_connection('zstack_vcenter', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [vcenter_pri_cidr]) ipsec2 = ipsec_ops.create_ipsec_connection('vcenter_zstack', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [zstack_pri_cidr]) #conditions = res_ops.gen_query_conditions('name', '=', 'test_ipsec_1') #vm1 = res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0] #conditions = res_ops.gen_query_conditions('name', '=', 'test_ipsec_2') #vm2 = res_ops.query_resource(res_ops.VM_INSTANCE, conditions)[0] if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm1 in zstack could not connect to vm2 in vcenter with IPsec') if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm2 in vcenter could not connect to vm1 in zstack with IPsec') ipsec_ops.delete_ipsec_connection(ipsec1.uuid) ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict) test_util.test_pass('Create Ipsec Success')
def test(): ''' EIP test needs at least 3 VR existence. Besides of EIP_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. The 2nd VR VM should not be able to access PF_VM. ''' test_util.test_dsc('Detach EIP from running & Stopped VM and check.') vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict.add_vm(vm) vm.check() l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vm_nic = vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('create_eip_test', l3_uuid) test_obj_dict.add_vip(vip) eip = test_stub.create_eip('create eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=vm) vip.attach_eip(eip) vip.check() vm_destroy_pid = os.fork() if vm_destroy_pid == 0: vm.destroy() sys.exit(0) eip.delete() vip.delete() test_obj_dict.rm_vm(vm) test_obj_dict.rm_vip(vip) test_util.test_pass('Detach EIP From Stopped VM Success')
def test(): test_util.test_dsc('Create test vm with lb.') vm1 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm1) vm2 = test_stub.create_lb_vm() test_obj_dict.add_vm(vm2) #l3_name = os.environ.get('l3VlanNetworkName1') #vr1 = test_stub.get_vr_by_private_l3_name(l3_name) #l3_name = os.environ.get('l3NoVlanNetworkName1') #vr2 = test_stub.get_vr_by_private_l3_name(l3_name) vm_nic1 = vm1.get_vm().vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic1_ip = vm_nic1.ip vm_nic2 = vm2.get_vm().vmNics[0] vm_nic2_uuid = vm_nic2.uuid vm_nic2_ip = vm_nic2.ip test_lib.lib_wait_target_up(vm_nic1_ip, "root", 120) test_lib.lib_wait_target_up(vm_nic2_ip, "root", 120) test_stub.set_httpd_in_vm(vm_nic1_ip, "root", "password") test_stub.set_httpd_in_vm(vm_nic2_ip, "root", "password") pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('vip_for_lb_test', l3_uuid) test_obj_dict.add_vip(vip) lb = zstack_lb_header.ZstackTestLoadBalancer() lb2 = zstack_lb_header.ZstackTestLoadBalancer() lb.create('create lb test', vip.get_vip().uuid) lb2.create('create lb2 test', vip.get_vip().uuid) test_obj_dict.add_load_balancer(lb) test_obj_dict.add_load_balancer(lb2) vip.attach_lb(lb) vip.attach_lb(lb2) lb_creation_option = test_lib.lib_create_lb_listener_option() lb2_creation_option = test_lib.lib_create_lb_listener_option(lbl_port = 2222, lbi_port = 80) lbl = lb.create_listener(lb_creation_option) lbl2 = lb2.create_listener(lb2_creation_option) lbl.add_nics([vm_nic1_uuid, vm_nic2_uuid]) lbl2.add_nics([vm_nic1_uuid, vm_nic2_uuid]) vm1.check() vm2.check() lb.check() lb2.check() vip.check() lb.delete() lb2.delete() vip.delete() test_obj_dict.rm_vip(vip) test_obj_dict.rm_load_balancer(lb) test_obj_dict.rm_load_balancer(lb2) lb.check() lb2.check() test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create Load Balancer Test Success')
def test(): pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get('l3VlanNetworkName1') vr1_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr1_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] l3_name = os.environ.get('l3NoVlanNetworkName1') vr2_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr2_l3_uuid) temp_vm2 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm2 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm2) vr2 = test_lib.lib_find_vr_by_vm(temp_vm2.vm)[0] else: vr2 = vrs[0] #we do not need temp_vm1 and temp_vm2, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) if temp_vm2: temp_vm2.destroy() test_obj_dict.rm_vm(temp_vm2) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) pf_creation_opt2 = PfRule.generate_pf_rule_option(vr2_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule5_ports, private_target_rule=Port.rule5_ports, vip_uuid=vip_uuid) test_pf2 = zstack_pf_header.ZstackTestPortForwarding() test_pf2.set_creation_option(pf_creation_opt2) test_pf2.create() vip.attach_pf(test_pf2) pf_vm.check() test_pf1.attach(vm_nic.uuid, pf_vm) test_pf2.attach(vm_nic.uuid, pf_vm) vip.check() test_pf1.detach() test_pf1.delete() test_pf2.delete() vip.check() eip = test_stub.create_eip('create pf/eip test', vip_uuid=vip.get_vip().uuid, vnic_uuid=vm_nic_uuid, vm_obj=pf_vm) vip.attach_eip(eip) vip.check() vip.delete() test_obj_dict.rm_vip(vip) pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) test_util.test_pass("Test Port Forwarding and EIP with same VIP Successfully")
def test(): global eip_snatInboundTraffic_default_value global pf_snatInboundTraffic_default_value #enable snatInboundTraffic and save global config value eip_snatInboundTraffic_default_value = \ conf_ops.change_global_config('eip', 'snatInboundTraffic', 'true') pf_snatInboundTraffic_default_value = \ conf_ops.change_global_config('portForwarding', \ 'snatInboundTraffic', 'true') image_name = os.environ.get('imageName_net') image_uuid = test_lib.lib_get_image_by_name(image_name).uuid l3_name = os.environ.get('l3VlanNetworkName1') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list = [l3_net_uuid] l3_name = os.environ.get('l3VlanDNATNetworkName') l3_net_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid l3_net_list.append(l3_net_uuid) vm = test_stub.create_vm(l3_net_list, image_uuid, '2_l3_pf_vm') test_obj_dict.add_vm(vm) l3_name = os.environ.get('l3NoVlanNetworkName1') vr_l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vrs = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid) temp_vm1 = None if not vrs: #create temp_vm2 for getting novlan's vr for test pf_vm portforwarding temp_vm1 = test_stub.create_user_vlan_vm() test_obj_dict.add_vm(temp_vm1) vr1 = test_lib.lib_find_vr_by_vm(temp_vm1.vm)[0] else: vr1 = vrs[0] if vr1.applianceVmType == "vrouter": test_util.test_skip( "vrouter VR does not support single VM multiple VIP") #we do not need temp_vm1, since we just use their VRs. if temp_vm1: temp_vm1.destroy() test_obj_dict.rm_vm(temp_vm1) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vm.check() vm_nic1 = vm.vm.vmNics[0] vm_nic1_uuid = vm_nic1.uuid vm_nic2 = vm.vm.vmNics[1] vm_nic2_uuid = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] if vr.applianceVmType == "vrouter": test_util.test_skip( "vrouter VR does not support single VM multiple VIP") vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip1 = test_stub.create_vip('vip1_2l3s_vm_test', l3_uuid) test_obj_dict.add_vip(vip1) vip1_uuid = vip1.get_vip().uuid vip2 = test_stub.create_vip('vip2_2l3s_vm_test', l3_uuid) test_obj_dict.add_vip(vip2) vip2_uuid = vip2.get_vip().uuid eip1 = test_stub.create_eip('2l3 eip test1', vip_uuid=vip1.get_vip().uuid) vip1.attach_eip(eip1) vip1.check() eip1.attach(vm_nic1_uuid, vm) vip1.check() pf_creation_opt1 = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule3_ports, private_target_rule=Port.rule3_ports, vip_uuid=vip2_uuid, vm_nic_uuid=vm_nic2_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create(vm) vip2.attach_pf(test_pf1) vip2.check() vm.stop() vm.start() vm.check() vip1.check() vip2.check() vm.destroy() vip1.check() vip2.check() vip1.delete() test_obj_dict.rm_vip(vip1) vip2.delete() test_obj_dict.rm_vip(vip2) conf_ops.change_global_config('eip', 'snatInboundTraffic', \ eip_snatInboundTraffic_default_value ) conf_ops.change_global_config('portForwarding', 'snatInboundTraffic', \ pf_snatInboundTraffic_default_value) test_util.test_pass( 'Create 1 VM with 2 l3_network with 1 eip and 1 PF testing successfully.' )
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 global ipsec3 global ipsec4 mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vip1 = test_stub.get_snat_ip_as_vip(vr1_pub_ip) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr test_util.test_dsc('Create test vm in mevoco2') vm3 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4')) test_obj_dict2.add_vm(vm3) vm3.check() pri_l3_uuid3 = vm3.vm.vmNics[0].l3NetworkUuid vr3 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid3 = test_lib.lib_find_vr_pub_nic(vr3).l3NetworkUuid vip3 = test_stub.create_vip('ipsec3_vip', l3_uuid3) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid3) third_zstack_cidrs = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs]) ipsec3 = ipsec_ops.create_ipsec_connection('ipsec3', pri_l3_uuid1, vip3.get_vip().ip, '123456', vip1.get_vip().uuid, [third_zstack_cidrs]) vip1_uuid = vip1.get_vip().uuid vip1_db = test_lib.lib_get_vip_by_uuid(vip1_uuid) assert "IPsec" in vip1_db.useFor assert vip1_db.useFor.count("IPsec") == 1 os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) ipsec4 = ipsec_ops.create_ipsec_connection('ipsec4', pri_l3_uuid3, vip1.get_vip().ip, '123456', vip3.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) if not test_lib.lib_check_ping(vm1.vm, vm3.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) if not test_lib.lib_check_ping(vm3.vm, vm1.vm.vmNics[0].ip): test_util.test_fail('vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) ipsec_ops.delete_ipsec_connection(ipsec3.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) if test_lib.lib_check_ping(vm1.vm, vm3.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) if test_lib.lib_check_ping(vm3.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail('vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) ipsec_ops.delete_ipsec_connection(ipsec4.uuid) test_lib.lib_error_cleanup(test_obj_dict2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): vip_bandwidth = 1 * 1024 pf_vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm1) pf_vm2 = test_stub.create_vlan_sg_vm() test_obj_dict.add_vm(pf_vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) pf_vm1.check() pf_vm2.check() vm1_inv = pf_vm1.get_vm() vm2_inv = pf_vm2.get_vm() vm_nic1 = pf_vm1.vm.vmNics[0] vm_nic_uuid1 = vm_nic1.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid vip_ip = vip.get_vip().ip #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) pf_vm1.check() test_pf1.attach(vm_nic_uuid1, pf_vm1) vip_qos = net_ops.set_vip_qos(vip_uuid=vip_uuid, inboundBandwidth=vip_bandwidth * 8 * 1024, outboundBandwidth=vip_bandwidth * 8 * 1024) test_stub.make_ssh_no_password(vm1_inv) test_stub.make_ssh_no_password(vm2_inv) test_stub.install_iperf(vm1_inv) test_stub.install_iperf(vm2_inv) iptables_cmd = "iptables -F" exec_cmd_in_vm(pf_vm1, iptables_cmd, "Failed to clean iptables.") test_stub.test_iperf_bandwidth(vm1_inv, vm2_inv, vip_ip, 20502, 20502, vip_bandwidth) vip.delete() test_obj_dict.rm_vip(vip) pf_vm1.destroy() test_obj_dict.rm_vm(pf_vm1) pf_vm2.destroy() test_obj_dict.rm_vm(pf_vm2) test_util.test_pass("Test Port Forwarding Vip Qos Successfully.")
def test(): pf_vm1 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm1) pf_vm2 = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm2) l3_name = os.environ.get('l3VlanNetworkName1') vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get('l3NoVlanNetworkName1') vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm1.check() pf_vm2.check() vm_nic1 = pf_vm1.vm.vmNics[0] vm_nic_uuid1 = vm_nic1.uuid vm_nic2 = pf_vm2.vm.vmNics[0] vm_nic_uuid2 = vm_nic2.uuid pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip('pf_attach_test', l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid #pf_creation_opt = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports) pf_creation_opt1 = PfRule.generate_pf_rule_option(vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule4_ports, private_target_rule=Port.rule4_ports, vip_uuid=vip_uuid) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt1) test_pf1.create() vip.attach_pf(test_pf1) pf_creation_opt2 = PfRule.generate_pf_rule_option(vr2_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule5_ports, private_target_rule=Port.rule5_ports, vip_uuid=vip_uuid) test_pf2 = zstack_pf_header.ZstackTestPortForwarding() test_pf2.set_creation_option(pf_creation_opt2) test_pf2.create() vip.attach_pf(test_pf2) pf_vm1.check() vip.check() test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf2.attach(vm_nic_uuid2, pf_vm2) vip.check() pf_vm1.stop() vip.check() test_pf1.detach() test_pf1.attach(vm_nic_uuid2, pf_vm2) pf_vm1.start() pf_vm1.check() vip.check() pf_vm1.stop() test_pf1.detach() test_pf2.detach() test_pf1.attach(vm_nic_uuid1, pf_vm1) test_pf2.attach(vm_nic_uuid1, pf_vm1) pf_vm1.start() pf_vm1.check() vip.check() vip.delete() test_obj_dict.rm_vip(vip) pf_vm1.destroy() test_obj_dict.rm_vm(pf_vm1) pf_vm2.destroy() test_obj_dict.rm_vm(pf_vm2) test_util.test_pass("Test Port Forwarding Attach/Detach Successfully")
def test(): global mevoco1_ip global mevoco2_ip global ipsec1 global ipsec2 test_util.test_skip( 'According issue #2720, the similar issue are won\'t fix ') mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] mevoco2_ip = os.environ['secondZStackMnIp'] test_util.test_dsc('Create test vm in mevoco1') vm1 = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName1')) test_obj_dict1.add_vm(vm1) vm1.check() pri_l3_uuid1 = vm1.vm.vmNics[0].l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid1)[0] l3_uuid1 = test_lib.lib_find_vr_pub_nic(vr1).l3NetworkUuid vip1 = test_stub.create_vip('ipsec1_vip', l3_uuid1) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid1) first_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create test vm in mevoco2') vm2 = test_stub.create_vlan_vm(os.environ.get('l3VlanDNATNetworkName')) test_obj_dict2.add_vm(vm2) vm2.check() pri_l3_uuid2 = vm2.vm.vmNics[0].l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid2)[0] l3_uuid2 = test_lib.lib_find_vr_pub_nic(vr2).l3NetworkUuid vip2 = test_stub.create_vip('ipsec2_vip', l3_uuid2) cond = res_ops.gen_query_conditions('uuid', '=', pri_l3_uuid2) second_zstack_cidrs = res_ops.query_resource( res_ops.L3_NETWORK, cond)[0].ipRanges[0].networkCidr os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_dsc('Create ipsec in mevoco1') ipsec1 = ipsec_ops.create_ipsec_connection('ipsec1', pri_l3_uuid1, vip2.get_vip().ip, '123456', vip1.get_vip().uuid, [second_zstack_cidrs], pfs="dh-group2") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs], pfs="dh-group5") os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] even pfs is different' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] even pfs is different' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_util.test_dsc('Create ipsec in mevoco2') ipsec2 = ipsec_ops.create_ipsec_connection('ipsec2', pri_l3_uuid2, vip1.get_vip().ip, '123456', vip2.get_vip().uuid, [first_zstack_cidrs]) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip if not test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if not test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip): test_util.test_fail( 'vm in mevoco1[MN:%s] could not connect to vm in mevoco2[MN:%s]' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip ipsec_ops.delete_ipsec_connection(ipsec1.uuid) if test_lib.lib_check_ping(vm1.vm, vm2.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco1[MN:%s] could still connect to vm in mevoco2[MN:%s] after Ipsec is deleted' % (mevoco1_ip, mevoco2_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip if test_lib.lib_check_ping(vm2.vm, vm1.vm.vmNics[0].ip, no_exception=True): test_util.test_fail( 'vm in mevoco2[MN:%s] could still connect to vm in mevoco1[MN:%s] after Ipsec is deleted' % (mevoco2_ip, mevoco1_ip)) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_lib.lib_error_cleanup(test_obj_dict1) vip1.delete() test_obj_dict1.rm_vip(vip1) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip ipsec_ops.delete_ipsec_connection(ipsec2.uuid) test_lib.lib_error_cleanup(test_obj_dict2) vip2.delete() test_obj_dict2.rm_vip(vip2) os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip test_util.test_pass('Create Ipsec Success')
def test(): """ PF test needs at least 3 VR existence. Besides of PF_VM's VR, there are needed another 2 VR VMs. 1st VR public IP address will be set as allowedCidr. The 1st VR VM should be able to access PF_VM. The 2nd VR VM should not be able to access PF_VM. """ global eip_snatInboundTraffic_default_value global pf_snatInboundTraffic_default_value # enable snatInboundTraffic and save global config value eip_snatInboundTraffic_default_value = conf_ops.change_global_config("eip", "snatInboundTraffic", "true") pf_snatInboundTraffic_default_value = conf_ops.change_global_config("portForwarding", "snatInboundTraffic", "true") pf_vm = test_stub.create_dnat_vm() test_obj_dict.add_vm(pf_vm) l3_name = os.environ.get("l3VlanNetworkName1") vr1 = test_stub.create_vr_vm(test_obj_dict, l3_name) l3_name = os.environ.get("l3NoVlanNetworkName1") vr2 = test_stub.create_vr_vm(test_obj_dict, l3_name) vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) pf_vm.check() vm_nic = pf_vm.vm.vmNics[0] vm_nic_uuid = vm_nic.uuid pri_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) l3_uuid = vr_pub_nic.l3NetworkUuid vip = test_stub.create_vip("multi_rule_vip", l3_uuid) test_obj_dict.add_vip(vip) vip_uuid = vip.get_vip().uuid pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid, ) test_pf1 = zstack_pf_header.ZstackTestPortForwarding() test_pf1.set_creation_option(pf_creation_opt) test_pf1.create(pf_vm) vip.attach_pf(test_pf1) vip.check() pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.UDP, vip_target_rule=Port.rule1_ports, private_target_rule=Port.rule1_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid, ) test_pf2 = zstack_pf_header.ZstackTestPortForwarding() test_pf2.set_creation_option(pf_creation_opt) test_pf2.create(pf_vm) vip.attach_pf(test_pf2) vip.check() pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.UDP, vip_target_rule=Port.rule2_ports, private_target_rule=Port.rule2_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid, ) test_pf3 = zstack_pf_header.ZstackTestPortForwarding() test_pf3.set_creation_option(pf_creation_opt) test_pf3.create(pf_vm) vip.attach_pf(test_pf3) vip.check() pf_creation_opt = PfRule.generate_pf_rule_option( vr1_pub_ip, protocol=inventory.TCP, vip_target_rule=Port.rule2_ports, private_target_rule=Port.rule2_ports, vip_uuid=vip_uuid, vm_nic_uuid=vm_nic_uuid, ) test_pf4 = zstack_pf_header.ZstackTestPortForwarding() test_pf4.set_creation_option(pf_creation_opt) test_pf4.create(pf_vm) vip.attach_pf(test_pf4) vip.check() pf_vm.check() test_pf1.delete() test_pf2.delete() test_pf3.delete() test_pf4.delete() vip.delete() test_obj_dict.rm_vip(vip) pf_vm.destroy() test_obj_dict.rm_vm(pf_vm) conf_ops.change_global_config("eip", "snatInboundTraffic", eip_snatInboundTraffic_default_value) conf_ops.change_global_config("portForwarding", "snatInboundTraffic", pf_snatInboundTraffic_default_value) test_util.test_pass("Test Port Forwarding TCP Rule Successfully")