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)
    
    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()
    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')
    vm.destroy()
    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('not expected to be able to ping vip while it succeed')

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Create EIP for VM Success')
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(
        tbj=test_obj_dict)

    ip_status_before = net_ops.get_ip_capacity_by_l3s(
        l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])

    flat_vip = test_stub.create_vip('create_flat_vip')
    test_obj_dict.add_vip(flat_vip)
    vr_vip = test_stub.create_vip('create_vr_vip')
    test_obj_dict.add_vip(vr_vip)

    ip_status_after = net_ops.get_ip_capacity_by_l3s(
        l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])

    assert ip_status_before.availableCapacity == ip_status_after.availableCapacity + 2

    test.flat_eip = test_stub.create_eip(
        'create flat eip',
        vip_uuid=flat_vip.get_vip().uuid,
        vnic_uuid=flat_l3_vm.get_vm().vmNics[0].uuid,
        vm_obj=flat_l3_vm)

    test.vr_eip = test_stub.create_eip(
        'create vr eip',
        vip_uuid=vr_vip.get_vip().uuid,
        vnic_uuid=vr_l3_vm.get_vm().vmNics[0].uuid,
        vm_obj=vr_l3_vm)

    flat_vip.attach_eip(test.flat_eip)
    vr_vip.attach_eip(test.vr_eip)

    for vm in (flat_l3_vm, vr_l3_vm):
        vm.check()

    time.sleep(30)
    l3 = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName'))
    if 'DHCP' in [
            service.networkServiceType for service in l3.networkServices
    ]:
        ip_list = [
            pub_l3_vm.get_vm().vmNics[0].ip,
            flat_vip.get_vip().ip,
            vr_vip.get_vip().ip
        ]
        for ip in ip_list:
            if not test_lib.lib_check_directly_ping(ip):
                test_util.test_fail(
                    'expected to be able to ping vip while it fail')

    test_lib.lib_error_cleanup(test_obj_dict)
    ip_status_final = net_ops.get_ip_capacity_by_l3s(
        l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])
    assert ip_status_final.availableCapacity == ip_status_after.availableCapacity + 3

    test_util.test_pass('pub vm volume network test pass')
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)

    host = test_lib.lib_get_vm_host(vm.get_vm())
    host_uuid = host.uuid

    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()

    host_ops.reconnect_host(host_uuid)

    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    vm.destroy()

    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail(
            'not expected to be able to ping vip while it succeed')

    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)

    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()
    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    pri_l3_gateway = os.environ.get('vlanIpRangeGateway1')
    reply = os.popen("nping --arp %s" % (pri_l3_gateway)).read()
    if reply.count('RCVD') > 5:
        test_util.test_fail("gateway IP conflict check failed: %s" % (reply))

    vm.destroy()
    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail(
            'not expected to be able to ping vip while it succeed')

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Create EIP for VM Success')
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(tbj=test_obj_dict)

    with test_lib.expected_failure('create vm use system network', Exception):
        test_stub.create_vm_with_random_offering(vm_name='test_vm',
                                                 image_name='imageName_net',
                                                 l3_name='l3ManagementNetworkName')

    vr = test_lib.lib_find_vr_by_vm(vr_l3_vm.get_vm())[0]

    for nic in vr.vmNics:
        test_util.test_logger(nic.ip)
        if not test_lib.lib_check_directly_ping(nic.ip):
            test_util.test_fail('IP:{} expected to be able to ping vip while it fail'.format(nic.ip))
def test():
    test_util.test_dsc('Create test vm migration with EIP and check.')
    vm = test_stub.create_vr_vm('migrate_vm', 'imageName_net',
                                'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)

    pri_l3_name = os.environ.get('l3VlanNetwork2')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()

    ping_ret = []
    cycle = 180
    migration_pid = os.fork()
    if migration_pid == 0:
        test_stub.migrate_vm_to_random_host(vm)
        sys.exit(0)
    for _ in xrange(cycle):
        ping_ret.append(test_lib.lib_check_directly_ping(vip.get_vip().ip))
        time.sleep(1)

    package_loss = float(cycle - ping_ret.count(True)) / cycle

    if package_loss > 0.03:
        test_util.test_fail('expected to be able to ping vip while it fail')

    vm.destroy()
    test_obj_dict.rm_vm(vm)

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Migrate VM with EIP connectable Success')
def test():
    test_util.test_dsc('Create test vm migration with EIP and check.')
    vm = test_stub.create_vr_vm('migrate_vm', 'imageName_net', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    
    pri_l3_name = os.environ.get('l3VlanNetwork2')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()

    ping_ret = []
    cycle = 180
    migration_pid = os.fork()
    if migration_pid == 0:
        test_stub.migrate_vm_to_random_host(vm)
        sys.exit(0)
    for _ in xrange(cycle):
        ping_ret.append(test_lib.lib_check_directly_ping(vip.get_vip().ip))
        time.sleep(1)

    package_loss = float(cycle - ping_ret.count(True)) / cycle

    if package_loss > 0.03:
        test_util.test_fail('expected to be able to ping vip while it fail')

    vm.destroy()
    test_obj_dict.rm_vm(vm)

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Migrate VM with EIP connectable Success')
Esempio n. 8
0
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(
        tbj=test_obj_dict)

    with test_lib.expected_failure('create vm use system network', Exception):
        test_stub.create_vm_with_random_offering(
            vm_name='test_vm',
            image_name='imageName_net',
            l3_name='l3ManagementNetworkName')

    vr = test_lib.lib_find_vr_by_vm(vr_l3_vm.get_vm())[0]

    for nic in vr.vmNics:
        test_util.test_logger(nic.ip)
        if not test_lib.lib_check_directly_ping(nic.ip):
            test_util.test_fail(
                'IP:{} expected to be able to ping vip while it fail'.format(
                    nic.ip))
def test():

    pub_l3_vm, flat_l3_vm, vr_l3_vm = test_stub.generate_pub_test_vm(tbj=test_obj_dict)

    ip_status_before = net_ops.get_ip_capacity_by_l3s(l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])

    flat_vip = test_stub.create_vip('create_flat_vip')
    test_obj_dict.add_vip(flat_vip)
    vr_vip = test_stub.create_vip('create_vr_vip')
    test_obj_dict.add_vip(vr_vip)

    ip_status_after = net_ops.get_ip_capacity_by_l3s(l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])

    assert ip_status_before.availableCapacity == ip_status_after.availableCapacity + 2

    test.flat_eip = test_stub.create_eip('create flat eip', vip_uuid=flat_vip.get_vip().uuid,
                                    vnic_uuid=flat_l3_vm.get_vm().vmNics[0].uuid, vm_obj=flat_l3_vm)

    test.vr_eip = test_stub.create_eip('create vr eip', vip_uuid=vr_vip.get_vip().uuid,
                                    vnic_uuid=vr_l3_vm.get_vm().vmNics[0].uuid, vm_obj=vr_l3_vm)

    flat_vip.attach_eip(test.flat_eip)
    vr_vip.attach_eip(test.vr_eip)

    for vm in (flat_l3_vm, vr_l3_vm):
        vm.check()
    
    time.sleep(30)
    l3 = test_lib.lib_get_l3_by_name(os.environ.get('l3PublicNetworkName'))
    if 'DHCP' in [service.networkServiceType for service in l3.networkServices]:
        ip_list = [pub_l3_vm.get_vm().vmNics[0].ip, flat_vip.get_vip().ip, vr_vip.get_vip().ip]
        for ip in ip_list:
            if not test_lib.lib_check_directly_ping(ip):
                test_util.test_fail('expected to be able to ping vip while it fail')

    test_lib.lib_error_cleanup(test_obj_dict)
    ip_status_final = net_ops.get_ip_capacity_by_l3s(l3_network_list=[pub_l3_vm.get_vm().vmNics[0].l3NetworkUuid])
    assert ip_status_final.availableCapacity == ip_status_after.availableCapacity + 3

    test_util.test_pass('pub vm volume network test pass')
def test():
    test_util.test_dsc('Create test vm migration with EIP and check.')
    vm = test_stub.create_vr_vm('migrate_vm', 'imageName_s', 'l3VlanNetwork2')
    test_obj_dict.add_vm(vm)
    
    pri_l3_name = os.environ.get('l3VlanNetwork2')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()

    migration_pid = os.fork()
    if migration_pid == 0:
        test_stub.migrate_vm_to_random_host(vm)
        sys.exit(0)
    for _ in xrange(300):
        if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
            test_util.test_fail('expected to be able to ping vip while it fail')
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Migrate VM with EIP connectable Success')
Esempio n. 11
0
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)

    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()
    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(),
                                                   script_file.name):
        test_util.test_fail("fail to tracepath in [vm:] %s" %
                            (vm.get_vm().uuid))
    os.unlink(script_file.name)

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('''
while [ 1 -eq 1 ]; do
	route -n | grep 0.0.0.0
	if [ $? -ne 0 ]; then
		pkill dhclient
		dhclient
	fi
	sleep 40
done
''')
    script_file.close()
    try:
        test_lib.lib_execute_shell_script_in_vm(vm.get_vm(),
                                                script_file.name,
                                                timeout=2)
    except:
        test_util.test_logger('ignore')
    os.unlink(script_file.name)

    net_ops.detach_l3(vm_nic_uuid)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail(
            'expected to not be able to ping vip while it success')

    #vm.stop()
    net_ops.attach_l3(pri_l3_uuid, vm.get_vm().uuid)

    #vm.start()
    vm.check()
    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    net_ops.attach_eip(eip.get_eip().uuid, vm_nic_uuid)
    vm.check()
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(),
                                                   script_file.name):
        test_util.test_fail("fail to tracepath in [vm:] %s" %
                            (vm.get_vm().uuid))
    os.unlink(script_file.name)

    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    vm.destroy()
    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail(
            'not expected to be able to ping vip while it succeed')

    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)
    
    pri_l3_name = os.environ.get('l3VlanNetworkName1')
    pri_l3_uuid = test_lib.lib_get_l3_by_name(pri_l3_name).uuid

    pub_l3_name = os.environ.get('l3PublicNetworkName')
    pub_l3_uuid = test_lib.lib_get_l3_by_name(pub_l3_name).uuid

    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    vip = test_stub.create_vip('create_eip_test', pub_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()
    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name):
        test_util.test_fail("fail to tracepath in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('''
while [ 1 -eq 1 ]; do
	route -n | grep 0.0.0.0
	if [ $? -ne 0 ]; then
		pkill dhclient
		dhclient
	fi
	sleep 40
done
''')
    script_file.close()
    try:
        test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name, timeout=2)
    except:
        test_util.test_logger('ignore')
    os.unlink(script_file.name)

    net_ops.detach_l3(vm_nic_uuid)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to not be able to ping vip while it success')

    #vm.stop()
    net_ops.attach_l3(pri_l3_uuid, vm.get_vm().uuid)

    #vm.start()
    vm.check()
    vm_nic = vm.vm.vmNics[0]
    vm_nic_uuid = vm_nic.uuid
    net_ops.attach_eip(eip.get_eip().uuid, vm_nic_uuid)
    vm.check()
    script_file = tempfile.NamedTemporaryFile(delete=False)
    script_file.write('ping -c 4 223.5.5.5')
    script_file.close()
    if not test_lib.lib_execute_shell_script_in_vm(vm.get_vm(), script_file.name):
        test_util.test_fail("fail to tracepath in [vm:] %s" % (vm.get_vm().uuid))
    os.unlink(script_file.name)

    if not test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('expected to be able to ping vip while it fail')

    vm.destroy()
    test_obj_dict.rm_vm(vm)
    if test_lib.lib_check_directly_ping(vip.get_vip().ip):
        test_util.test_fail('not expected to be able to ping vip while it succeed')

    eip.delete()
    vip.delete()

    test_obj_dict.rm_vip(vip)
    test_util.test_pass('Create EIP for VM Success')