def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable() != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail('vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
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(): 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(): 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 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(): global l2_net_uuid global cluster_uuid global vm cluster1 = res_ops.get_resource(res_ops.CLUSTER)[0] cluster2 = res_ops.get_resource(res_ops.CLUSTER)[1] vm_creation_option = test_util.VmOption() image_name = os.environ.get('imageName_s') 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 l2_net_uuid = test_lib.lib_get_l3_by_name(l3_name).l2NetworkUuid l2_net_type = res_ops.get_resource(res_ops.L2_NETWORK, uuid=l2_net_uuid)[0].type test_util.test_logger("l2_network.type@@:%s" %(l2_net_type)) if l2_net_type == "VxlanNetwork": test_util.test_skip("Vxlan network not support detach l2 network, therefore, skip the test") conditions = res_ops.gen_query_conditions('type', '=', 'UserVm') instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid vm_creation_option.set_l3_uuids([l3_net_uuid]) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_cluster_uuid(cluster1.uuid) vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_name('multicluster_basic_vm') vm = test_vm_header.ZstackTestVm() vm.set_creation_option(vm_creation_option) vm.create() vm2 = test_vm_header.ZstackTestVm() vm_creation_option.set_cluster_uuid(cluster2.uuid) vm2.set_creation_option(vm_creation_option) vm2.create() vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) if len(vrs) == 0: test_util.test_skip("skip the test for non vr") vr = vrs[0] cluster_uuid = vr.clusterUuid net_ops.detach_l2(l2_net_uuid, cluster_uuid) vrs = test_lib.lib_find_vr_by_l3_uuid(l3_net_uuid) if len(vrs) == 0: test_util.test_skip("skip the test for non vr") vr = vrs[0] if vr.clusterUuid == cluster_uuid: test_util.test_logger('vr is expected to migrate to another cluster') vm.destroy() vm2.destroy() net_ops.attach_l2(l2_net_uuid, cluster_uuid) test_util.test_pass('Create detach l2 from clsuter vr migrate Test 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 create_vr_vm(test_obj_dict, l3_uuid, session_uuid=None): ''' ''' vrs = test_lib.lib_find_vr_by_l3_uuid(l3_uuid) if not vrs: #create temp_vm1 for getting vlan1's vr for test pf_vm portforwarding instance_offering_uuid = test_lib.lib_get_instance_offering_by_name( os.environ.get('instanceOfferingName_s')).uuid cond = res_ops.gen_query_conditions('mediaType', '!=', 'ISO') cond = res_ops.gen_query_conditions('platform', '=', 'Linux', cond) cond = res_ops.gen_query_conditions('system', '=', 'false', cond) image_uuid = res_ops.query_resource(res_ops.IMAGE, cond, session_uuid=session_uuid)[0].uuid vm_creation_option = test_util.VmOption() vm_creation_option.set_instance_offering_uuid(instance_offering_uuid) vm_creation_option.set_image_uuid(image_uuid) vm_creation_option.set_l3_uuids([l3_uuid]) temp_vm = create_vm(vm_creation_option, session_uuid=session_uuid) test_obj_dict.add_vm(temp_vm) vr = test_lib.lib_find_vr_by_vm(temp_vm.vm)[0] temp_vm.destroy(session_uuid) test_obj_dict.rm_vm(temp_vm) else: vr = vrs[0] if not test_lib.lib_is_vm_running(vr): test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_skip('vr: %s is not running. Will skip test.' % vr.uuid) return vr
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 check_eip_denied_tcp(self): if not self.denied_vr_ip: test_util.test_logger('No denied vm for eip testing. Skip EIP deined TCP checking') return True vip = self.test_obj.get_vip() vip_ip = vip.ip eip_obj = self.test_obj.get_eip() eip = eip_obj.get_eip() if not eip_obj.get_target_vm(): #eip is not attached yet. use vip's VR vm l3_uuid = self.test_obj.get_vip().l3NetworkUuid target_vm = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)[0] else: target_vm = eip_obj.get_target_vm().vm all_ports = port_header.all_ports try: test_lib.lib_check_ports_in_a_command(self.denied_vr, self.denied_vr_ip, vip_ip, [], all_ports, target_vm) except: traceback.print_exc(file=sys.stdout) test_util.test_logger("Unexpected Result: Catch failure when checking [vip:] %s EIP: %s for denied ip: %s from [vm:] %s. All ports should be denied." % \ (vip.uuid, eip.uuid, self.denied_vr_ip, self.denied_vr.uuid)) return False test_util.test_logger("Expected Result: Network checking pass for [vip:] %s EIP: %s by denied ip: %s from [vm:] %s . " % \ (vip.uuid, eip.uuid, self.denied_vr_ip, self.denied_vr.uuid)) return True
def check_denied_pf(self, pf): pf_rule = pf.get_port_forwarding() test_result = True all_ports = port_header.all_ports #all pf with same vip should have same l3. allowed_ports = [] denied_ports = all_ports if not pf.get_target_vm(): #Pf is not attached, use vip's VR VM. This wont' impact testing result. l3_uuid = self.test_obj.get_vip().l3NetworkUuid target_vm = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)[0] vm_nic_uuid = None else: target_vm = pf.get_target_vm().vm vm_nic_uuid = pf_rule.vmNicUuid allowedCidr = pf_rule.allowedCidr allowed_vr_ip = allowedCidr.split('/')[0] allowed_vr_vm, denied_vr_vm = \ self.get_allowed_denied_vr_vm(allowed_vr_ip, vm_nic_uuid) vipIp = self.test_obj.get_vip().ip try: test_lib.lib_check_ports_in_a_command(allowed_vr_vm, \ allowed_vr_ip, vipIp, allowed_ports, \ denied_ports, target_vm) except: traceback.print_exc(file=sys.stdout) test_util.test_logger("Catch failure when checking [vip:] %s Port Forwarding TCP [rules] for allowed Cidr: %s from [vm:] %s . " % \ (self.test_obj.get_vip().uuid, allowed_vr_ip, \ allowed_vr_vm.uuid)) test_result = False return test_result
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") if bss[0].type != inventory.CEPH_BACKUP_STORAGE_TYPE: test_util.test_skip("not find available ceph backup storage. Skip test") test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.delete() #volume.expunge() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to runnning when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.suspend() vm.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid allow_ps_list = [inventory.CEPH_PRIMARY_STORAGE_TYPE, "SharedBlock"] test_lib.skip_test_when_ps_type_not_in_list(allow_ps_list) test_util.test_dsc('Create test vm and check') bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \ None) if not bss: test_util.test_skip("not find available backup storage. Skip test") test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.attach(vm) #ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) #ps_uuid = ps.uuid #ps_ops.change_primary_storage_state(ps_uuid, 'disable') test_stub.disable_all_pss() if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.delete() volume.check() volume.expunge() volume.check() #ps_ops.change_primary_storage_state(ps_uuid, 'enable') test_stub.enable_all_pss() host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test 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(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_system_tags( ['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.recover() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) volume.delete() volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test Success')
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system( "echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() test_util.test_dsc('Detach ISO to VM') img_ops.detach_iso(vm.vm.uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() vm.check() #vm.expunge() vm.check() test_util.test_pass('PS disable mode Test Success')
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 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) priority_actions = [test_state.TestAction.sg_rule_operations]*2 priority_action_obj = action_select.ActionPriority() priority_action_obj.add_priority_action_list(priority_actions) test_util.test_dsc('Random Test Begin. Test target: 4 coexisting running VM (not include VR and SG target test VMs.).') 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) robot_test_obj.set_priority_actions(priority_action_obj) robot_test_obj.set_exclusive_actions_list(\ test_state.TestAction.volume_actions \ + test_state.TestAction.image_actions \ + test_state.TestAction.vip_actions \ + test_state.TestAction.snapshot_actions) rounds = 1 while len(test_dict.get_vm_list(vm_header.RUNNING)) < target_running_vm: 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(): 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(): ''' 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(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(): 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(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') test_lib.lib_set_delete_policy('vm', 'Delay') test_lib.lib_set_delete_policy('volume', 'Delay') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid #l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('rootDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) #volume_creation_option.set_system_tags(['ephemeral::shareable', 'capability::virtio-scsi']) volume = test_stub.create_volume(volume_creation_option) test_obj_dict.add_volume(volume) volume.check() volume.delete() volume.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() volume.recover() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) volume.delete() #volume.expunge() volume.check() vm.destroy() test_lib.lib_set_delete_policy('vm', 'Direct') test_lib.lib_set_delete_policy('volume', 'Direct') test_util.test_pass('Delete volume under PS disable mode Test Success')
def get_all_available_vr_ip(self): vip = self.test_obj.get_vip() l3_uuid = vip.l3NetworkUuid vrs = test_lib.lib_find_vr_by_l3_uuid(l3_uuid) eip_vm_vr_uuids = [] if self.vm_nic_uuid: #target_vm's VRs should be excluded, otherwise the ip package will be routed to this VR directly. vm_nic = test_lib.lib_get_nic_by_uuid(self.vm_nic_uuid) vr_l3_uuid = vm_nic.l3NetworkUuid vr = test_lib.lib_find_vr_by_l3_uuid(vr_l3_uuid)[0] eip_vm_vr_uuids.append(vr.uuid) for vr in vrs: vnic = test_lib.lib_get_vm_nic_by_l3(vr, l3_uuid) if vr.uuid in eip_vm_vr_uuids: continue ip = vnic.ip self.available_vr_dict[ip] = vr
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() test_util.test_dsc('Add ISO Image') cond = res_ops.gen_query_conditions("status", '=', "Connected") bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid img_option = test_util.ImageOption() img_option.set_name('iso') img_option.set_backup_storage_uuid_list([bs_uuid]) os.system("echo fake iso for test only > %s/apache-tomcat/webapps/zstack/static/test.iso" % (os.environ.get('zstackInstallPath'))) img_option.set_url('http://%s:8080/zstack/static/test.iso' % (os.environ.get('node1Ip'))) image_inv = img_ops.add_iso_template(img_option) image = test_image.ZstackTestImage() image.set_image(image_inv) image.set_creation_option(img_option) test_obj_dict.add_image(image) test_util.test_dsc('Attach ISO to VM') cond = res_ops.gen_query_conditions('name', '=', 'iso') iso_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid img_ops.attach_iso(iso_uuid, vm.vm.uuid) ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() test_util.test_dsc('Detach ISO to VM') img_ops.detach_iso(vm.vm.uuid) ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() vm.check() #vm.expunge() vm.check() test_util.test_pass('PS disable mode Test 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 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 get_vr_by_private_l3_name(l3_name): 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) if not vrs: #create temp_vm for getting vlan1's vr temp_vm = create_vlan_vm(l3_name) vr = test_lib.lib_find_vr_by_vm(temp_vm.vm)[0] temp_vm.destroy() else: vr = vrs[0] return vr
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.destroy_vm(vr1.uuid) vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() test_util.test_pass('destroy VR VM 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(): 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(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.reconnect_vr(vr1.uuid) cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if not vms[0].status == 'Connected': test_util.test_fail('VR VM: %s is not connected' % vr1.uuid) test_util.test_pass('Test Reconnect VR VM start VRs success')
def check(self): super(vip_icmp_checker, self).check() test_result = True vip = self.test_obj.get_vip() vipIp = vip.ip vip_l3_uuid = vip.l3NetworkUuid any_vr = test_lib.lib_find_vr_by_l3_uuid(vip_l3_uuid)[0] try: test_lib.lib_check_ping(any_vr, vipIp) except: test_util.test_logger("Catch exception: [vip:] %s [IP:] %s is not pingable from [vm:] %s " % (vip.uuid, vipIp, any_vr.uuid)) test_result = False else: test_util.test_logger("Successful ping [vip:] %s [IP:] %s from [vm:] %s " % (vip.uuid, vipIp, any_vr.uuid)) return self.judge(test_result)
def test(): global session_uuid session_uuid = acc_ops.login_as_admin() l3_1_name = os.environ.get('l3VlanNetworkName1') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) #create VRs. vrs = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid) if not vrs: vm = test_stub.create_vlan_vm(l3_name=l3_1_name) vm.destroy() vr1 = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] else: vr1 = vrs[0] vm_ops.stop_vm(vr1.uuid) if test_lib.lib_get_ha_enable( ) != 'true' or vr1.applianceVmType != "vrouter": vm_ops.start_vm(vr1.uuid) vr1_mgmt_ip = test_lib.lib_find_vr_mgmt_ip(vr1) if not test_lib.lib_wait_target_up(vr1_mgmt_ip, '7272', 120): test_util.test_fail( 'vr: %s is not startup in 120 seconds. Fail to reboot it. ' % vr1.uuid) timeout = time.time() + 60 while time.time() < timeout: cond = res_ops.gen_query_conditions('uuid', '=', vr1.uuid) vms = res_ops.query_resource(res_ops.VM_INSTANCE, cond) if vms[0].status == 'Connected': test_util.test_pass('Test Reconnect VR VM start VRs success') time.sleep(1) test_util.test_fail('VR VM: %s is not connected within 60 seconds' % vr1.uuid)
def test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.stop() vm.check() test_util.test_dsc('Use snapshot, volume and check') snapshots.use_snapshot(snapshot1) snapshots.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test 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(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') l3_1_name = os.environ.get('l3VlanNetworkName1') vm = test_stub.create_vlan_vm(l3_name=l3_1_name) l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid test_obj_dict.add_vm(vm) vm.check() root_volume_uuid = test_lib.lib_get_root_volume_uuid(vm.get_vm()) test_util.test_dsc('create snapshot and check') snapshots = test_obj_dict.get_volume_snapshot(root_volume_uuid) snapshots.set_utility_vm(vm) vm.check() snapshots.create_snapshot('create_root_snapshot1') snapshots.check() snapshot1 = snapshots.get_current_snapshot() host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to running when PS change to disable state') vm.set_state(vm_header.RUNNING) vm.check() vm.stop() vm.check() test_util.test_dsc('Use snapshot, volume and check') snapshots.use_snapshot(snapshot1) snapshots.check() ps_ops.change_primary_storage_state(ps_uuid, 'enable') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) vm.destroy() test_util.test_pass('PS disable mode Test 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(): 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(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find ceph type backup storage.') l3_1_name = os.environ.get('l3VlanNetwork3') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail( 'VM is expected to stop when PS change to disable state') vm.set_state(vm_header.STOPPED) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'Enabled') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test 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.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 test(): global test_obj_dict global ps_uuid global host_uuid global vr_uuid test_util.test_dsc('Create test vm and check') vm = test_stub.create_vr_vm('vm1', 'imageName_net', 'l3VlanNetwork3') test_obj_dict.add_vm(vm) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm) for bs in backup_storage_list: if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE: break else: vm.destroy() test_util.test_skip('Not find ceph type backup storage.') l3_1_name = os.environ.get('l3VlanNetwork3') l3_1 = test_lib.lib_get_l3_by_name(l3_1_name) vr = test_lib.lib_find_vr_by_l3_uuid(l3_1.uuid)[0] vr_uuid = vr.uuid host = test_lib.lib_get_vm_host(vm.get_vm()) host_uuid = host.uuid test_obj_dict.add_vm(vm) vm.check() ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) ps_uuid = ps.uuid ps_ops.change_primary_storage_state(ps_uuid, 'disable') if not test_lib.lib_wait_target_down(vm.get_vm().vmNics[0].ip, '22', 90): test_util.test_fail('VM is expected to stop when PS change to disable state') vm.set_state(vm_header.STOPPED) vm.check() test_stub.migrate_vm_to_random_host(vm) vm.check() volume.check() ps_ops.change_primary_storage_state(ps_uuid, 'Enabled') host_ops.reconnect_host(host_uuid) vm_ops.reconnect_vr(vr_uuid) test_util.test_pass('PS disable mode Test Success')
def check(self): super(zstack_kvm_pf_vip_icmp_checker, self).check() test_result = True pf_rule = self.test_obj.get_port_forwarding() vip_uuid = pf_rule.vipUuid cond = res_ops.gen_query_conditions('uuid', '=', vip_uuid) vipIp = res_ops.query_resource(res_ops.VIP, cond)[0].ip vip_l3_uuid = test_lib.lib_get_vip_by_uuid(pf_rule.vipUuid).l3NetworkUuid any_vr = test_lib.lib_find_vr_by_l3_uuid(vip_l3_uuid)[0] try: test_lib.lib_check_ping(any_vr, vipIp) except: test_util.test_logger("Catch exception: Port Forwarding [rule:] %s is not pingable from [vm:] %s " % (pf_rule.uuid, any_vr.uuid)) test_result = False if test_result != self.exp_result: return self.judge(test_result) else: test_util.test_logger("Port Forwarding [rule:] %s is pingable from [vm:] %s" % (pf_rule.uuid, any_vr.uuid)) return self.judge(test_result)
def test(): global curr_deploy_conf global l3_name global l3 curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config) test_util.test_dsc('Create test vm and delete l3.') l3_name = os.environ.get('l3VlanNetworkName1') l3 = res_ops.get_resource(res_ops.L3_NETWORK, name = l3_name)[0] vm = test_stub.create_vlan_vm(l3_name) test_obj_dict.add_vm(vm) vm.check() net_ops.delete_l3(l3.uuid) if len(test_lib.lib_find_vr_by_l3_uuid(l3.uuid)) != 0: test_util.test_fail('VR VM should be delete when associated L3 is deleted') vm.destroy() net_ops.add_l3_resource(curr_deploy_conf, l3_name) test_util.test_pass('Create VirtualRouter VM delete l3 Test Success')
def check(self): super(zstack_vcenter_pf_vip_icmp_checker, self).check() test_result = True pf_rule = self.test_obj.get_port_forwarding() vip_uuid = pf_rule.vipUuid cond = res_ops.gen_query_conditions('uuid', '=', vip_uuid) vipIp = res_ops.query_resource(res_ops.VIP, cond)[0].ip vip_l3_uuid = test_lib.lib_get_vip_by_uuid(pf_rule.vipUuid).l3NetworkUuid any_vr = test_lib.lib_find_vr_by_l3_uuid(vip_l3_uuid)[0] try: test_lib.lib_check_ping(any_vr, vipIp) except: test_util.test_logger("Catch exception: Port Forwarding [rule:] %s is not pingable from [vm:] %s " % (pf_rule.uuid, any_vr.uuid)) test_result = False if test_result != self.exp_result: return self.judge(test_result) else: test_util.test_logger("Port Forwarding [rule:] %s is pingable from [vm:] %s" % (pf_rule.uuid, any_vr.uuid)) return self.judge(test_result)