def create_vip(vip_name=None, l3_uuid=None): if not vip_name: vip_name = 'test vip' if not l3_uuid: l3_name = os.environ.get('l3PublicNetworkName') l3_uuid = test_lib.lib_get_l3_by_name(l3_name).uuid vip_creation_option = test_util.VipOption() vip_creation_option.set_name(vip_name) vip_creation_option.set_l3_uuid(l3_uuid) vip = zstack_vip_header.ZstackTestVip() vip.set_creation_option(vip_creation_option) vip.create() return vip
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(): global vm1, vm2, vip l3_vr_network = os.environ['l3vCenterNoVlanNetworkName'] image_name = os.environ['image_dhcp_name'] # create vm1 vm2 vm1 = test_stub.create_vm_in_vcenter(vm_name='test_vm1', image_name=image_name, l3_name=l3_vr_network) vm2 = test_stub.create_vm_in_vcenter(vm_name='test_vm2', image_name=image_name, l3_name=l3_vr_network) test_obj_dict.add_vm(vm1) test_obj_dict.add_vm(vm2) vm1.check() vm2.check() l3_vr_network = os.environ['l3vCenterNoVlanNetworkName1'] vr1 = test_stub.create_vm_in_vcenter(vm_name='vm1', image_name=image_name, l3_name=l3_vr_network) l3_vr_network = os.environ['l3vCenterNoVlanNetworkName2'] vr2 = test_stub.create_vm_in_vcenter(vm_name='vm2', image_name=image_name, l3_name=l3_vr_network) test_obj_dict.add_vm(vr1) test_obj_dict.add_vm(vr2) vr1_nic = vr1.get_vm().vmNics[0] pri_l3_uuid = vr1_nic.l3NetworkUuid vr1 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr1_pub_ip = test_lib.lib_find_vr_pub_ip(vr1) vr2_nic = vr2.get_vm().vmNics[0] pri_l3_uuid = vr2_nic.l3NetworkUuid vr2 = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr2_pub_ip = test_lib.lib_find_vr_pub_ip(vr2) vm1_nic = vm1.get_vm().vmNics[0] vm1_nic_uuid = vm1_nic.uuid vm2_nic = vm2.get_vm().vmNics[0] vm2_nic_uuid = vm2_nic.uuid pri_l3_uuid = vm1_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_ip = test_lib.lib_find_vr_pub_ip(vr) vip = zstack_vip_header.ZstackTestVip() vip.get_snat_ip_as_vip(vr_pub_ip) vip.isVcenter = True vip_uuid = vip.get_vip().uuid 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) vm1.check() vip.check() # pf_1_attach_vm1 pf_2_attach_vm2 test_pf1.attach(vm1_nic_uuid, vm1) test_pf2.attach(vm2_nic_uuid, vm2) vip.check() vm1.stop() vip.check() # pf_1_detach pf_1_attach_vm2 test_pf1.detach() vip.check() test_pf1.attach(vm2_nic_uuid, vm2) vip.check() vm1.start() time.sleep(30) vip.check() vm1.stop() test_pf1.detach() test_pf2.detach() vip.check() # pf_1_attach_vm1 pf_2_attach_vm1 test_pf1.attach(vm1_nic_uuid, vm1) test_pf2.attach(vm1_nic_uuid, vm1) vm1.start() time.sleep(50) vip.check() # pf_1_delete pf_2_delete test_pf1.delete() test_pf2.delete() # clean_up test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass("Test Port Forwarding Attach/Detach Successfully")
def test(): global vm1, vm2, vip l3_vr_network = os.environ['l3vCenterNoVlanNetworkName'] image_name = os.environ['image_dhcp_name'] test_util.test_dsc('Create test vm with lb.') vm1 = test_stub.create_vm_in_vcenter(vm_name='test_vip_lb_1', image_name=image_name, l3_name=l3_vr_network) test_obj_dict.add_vm(vm1) vm2 = test_stub.create_vm_in_vcenter(vm_name='test_vip_lb_2', image_name=image_name, l3_name=l3_vr_network) test_obj_dict.add_vm(vm2) time.sleep(50) 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_stub.set_httpd_in_vm(vm1.get_vm(), vm_nic1_ip) test_stub.set_httpd_in_vm(vm2.get_vm(), vm_nic2_ip) pri_l3_uuid = vm_nic1.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(pri_l3_uuid)[0] vr_pub_ip = test_lib.lib_find_vr_pub_ip(vr) vip = zstack_vip_header.ZstackTestVip() vip.get_snat_ip_as_vip(vr_pub_ip) vip.isVcenter = True 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) lb.isVcenter = True lb2.isVcenter = True 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(lbl_port=222, lbi_port=22) 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() 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')