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])

    with test_lib.expected_failure('Create VIP with Pub vm IP', Exception):
        test_stub.create_vip(vip_name='test_vip',
                             required_ip=pub_l3_vm.get_vm().vmNics[0].ip)

    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

    test_vip = test_stub.create_vip('test_vip')
    test_obj_dict.add_vip(test_vip)

    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 - 1

    test_util.test_pass('pub vm volume network test pass')
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('Repeat creating test vm in a limited ip range environment. If dnsmasq lease ip has bug, or zstack allocation ip has bug, it will meet failure.')
    l3_name = os.environ.get('l3VlanNetworkName4')
    condition = res_ops.gen_query_conditions('name', '=', l3_name)
    l3_net = res_ops.query_resource(res_ops.L3_NETWORK, condition)[0]
    ip_cap_evt = net_ops.get_ip_capacity_by_l3s([l3_net.uuid])
    if not ip_cap_evt:
        test_util.test_fail('can not get ip capability for l3: %s' % l3_name)

    avail_ips = ip_cap_evt.availableCapacity
    if avail_ips > 5:
        test_util.test_skip('l3: %s available ip address: %d is large than 5, which will bring a lot of testing burden. Suggest to reduce ip address setting and retest.' % (l3_name, avail_ips))

    while avail_ips > 0:
        vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
        test_obj_dict.add_vm(vm)
        avail_ips -= 1
        test_util.test_logger('available ips: %d' % avail_ips)

    vm_list = list(test_obj_dict.get_vm_list())
    for vm in vm_list:
        avail_ips +=1
        test_util.test_logger('check No.%d vm' % avail_ips)
        vm.check()
        vm.destroy()
        test_obj_dict.rm_vm(vm)

    #after using all ip resource, create a new vm, which will use previous ip.
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
    test_obj_dict.add_vm(vm)
    vm.check()
    vm.destroy()

    test_util.test_pass('Repeat Create VMs with limited ip range successfully.')
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])

    with test_lib.expected_failure('Create VIP with Pub vm IP', Exception):
        test_stub.create_vip(vip_name='test_vip', required_ip=pub_l3_vm.get_vm().vmNics[0].ip)

    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

    test_vip = test_stub.create_vip('test_vip')
    test_obj_dict.add_vip(test_vip)

    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 - 1

    test_util.test_pass('pub vm volume network test pass')
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():
    global exception
    test_util.test_dsc('Simutanously creating several test vm in a limited ip range environment. If zstack allocation IP has bug, vms might be assigned same IP addresses.')
    l3_name = os.environ.get('l3VlanNetworkName4')
    condition = res_ops.gen_query_conditions('name', '=', l3_name)
    l3_net = res_ops.query_resource(res_ops.L3_NETWORK, condition)[0]
    ip_cap_evt = net_ops.get_ip_capacity_by_l3s([l3_net.uuid])
    if not ip_cap_evt:
        test_util.test_fail('can not get ip capability for l3: %s' % l3_name)

    avail_ips = ip_cap_evt.availableCapacity
    if avail_ips > 5:
        test_util.test_skip('l3: %s available ip address: %d is large than 5, which will bring a lot of testing burden. Suggest to reduce ip address setting and retest.' % (l3_name, avail_ips))

    while avail_ips > 0:
        thread = threading.Thread(target=create_vm, \
                args=(os.environ.get('l3VlanNetworkName4'),))
        avail_ips -= 1
        test_util.test_logger('available ips: %d' % avail_ips)
        thread.start()

    while threading.activeCount() > 1:
        time.sleep(1)
        print('wait for vm creationg finished ...')

    if exception:
        print 'Meet exception when create VM'
        info1 = exception[0][1]
        info2 = exception[0][2]
        raise info1, None, info2

    vm_list = list(test_obj_dict.get_vm_list())
    ip_list = []
    for vm in vm_list:
        avail_ips +=1
        vm_ip = vm.get_vm().vmNics[0].ip
        if vm_ip in ip_list:
            test_util.test_fail('duplicate vm [ip] %s was found' % vm_ip)
        ip_list.append(vm_ip)

        test_util.test_logger('check No.%d vm; its ip is: %s' % (avail_ips, vm.get_vm().vmNics[0].ip))
        vm.check()
        vm.destroy()
        test_obj_dict.rm_vm(vm)

    test_util.test_pass('Repeat Create VMs with limited ip range successfully.')
Example #7
0
def test():
    test_util.test_dsc(
        'Repeat creating test vm in a limited ip range environment. If dnsmasq lease ip has bug, or zstack allocation ip has bug, it will meet failure.'
    )
    l3_name = os.environ.get('l3VlanNetworkName4')
    condition = res_ops.gen_query_conditions('name', '=', l3_name)
    l3_net = res_ops.query_resource(res_ops.L3_NETWORK, condition)[0]
    ip_cap_evt = net_ops.get_ip_capacity_by_l3s([l3_net.uuid])
    if not ip_cap_evt:
        test_util.test_fail('can not get ip capability for l3: %s' % l3_name)

    avail_ips = ip_cap_evt.availableCapacity
    if avail_ips > 5:
        test_util.test_skip(
            'l3: %s available ip address: %d is large than 5, which will bring a lot of testing burden. Suggest to reduce ip address setting and retest.'
            % (l3_name, avail_ips))

    while avail_ips > 0:
        vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
        test_obj_dict.add_vm(vm)
        avail_ips -= 1
        test_util.test_logger('available ips: %d' % avail_ips)

    vm_list = list(test_obj_dict.get_vm_list())
    for vm in vm_list:
        avail_ips += 1
        test_util.test_logger('check No.%d vm' % avail_ips)
        vm.check()
        vm.destroy()
        test_obj_dict.rm_vm(vm)

    #after using all ip resource, create a new vm, which will use previous ip.
    vm = test_stub.create_vlan_vm(os.environ.get('l3VlanNetworkName4'))
    test_obj_dict.add_vm(vm)
    vm.check()
    vm.destroy()

    test_util.test_pass(
        'Repeat Create VMs with limited ip range successfully.')