Exemplo n.º 1
0
def test_ping_hosts():
    con_ssh = ControllerClient.get_active_controller()

    ping_failed_list = []
    for hostname in system_helper.get_hosts():
        LOG.tc_step(
            "Send 100 pings to {} from Active Controller".format(hostname))
        ploss_rate, untran_p = network_helper.ping_server(hostname,
                                                          con_ssh,
                                                          num_pings=100,
                                                          timeout=300,
                                                          fail_ok=True)
        if ploss_rate > 0:
            if ploss_rate == 100:
                ping_failed_list.append(
                    "{}: Packet loss rate: {}/100\n".format(
                        hostname, ploss_rate))
            else:
                ping_failed_list.append(
                    "{}: All packets dropped.\n".format(hostname))
        if untran_p > 0:
            ping_failed_list.append(
                "{}: {}/100 pings are untransmitted within 300 seconds".format(
                    hostname, untran_p))

    LOG.tc_step("Ensure all packets are received.")
    assert not ping_failed_list, "Dropped/Un-transmitted packets detected when ping hosts. " \
                                 "Details:\n{}".format(ping_failed_list)
Exemplo n.º 2
0
def ping_all_vms_from_nat_box():
    """

    :return:
    """
    natbox_client = NATBoxClient.get_natbox_client()
    vms = get_all_vms()
    ips_list = network_helper.get_mgmt_ips_for_vms(vms=vms)
    timeout = 1000
    vm_threads = []
    for vm in ips_list:
        new_thread = MThread(network_helper.ping_server(vm, natbox_client))
        new_thread.start_thread(timeout=timeout + 30)
        vm_threads.append(new_thread)
        time.sleep(5)

    for vm_thr in vm_threads:
        vm_thr.wait_for_thread_end()

    # param = ','.join(map(str, ips_list))
    # cmd1 = "cd /home/cgcs/bin"
    # cmd2 =  "python monitor.py --addresses " + param
    # code1, output1 = natbox_client.send(cmd=cmd1)
    # code, output = natbox_client.send(cmd=cmd2)
    # output = natbox_client.cmd_output
    # pattern = str(len(ips_list))+ "/" + str(len(ips_list))
    # pattern_to_look = re.compile(pattern=pattern)
    # if not pattern_to_look.findall(output):
    #     return False

    return True
Exemplo n.º 3
0
def _ping_server(vm_id, ip_addr, fail_ok):
    with vm_helper.ssh_to_vm_from_natbox(vm_id=vm_id) as vm_ssh:
        packet_loss_rate = network_helper.ping_server(ip_addr,
                                                      ssh_client=vm_ssh,
                                                      fail_ok=fail_ok,
                                                      retry=10)[0]

    return packet_loss_rate
Exemplo n.º 4
0
def test_port_trunking():
    """
    Port trunking feature test cases

    Test Steps:
        - Create networks
        - Create subnets
        - Create a parent port and subports
        - Create a truck with parent port and subports
        - Boot the first vm with the trunk
        - Create the second trunk without subport
        - Boot the second vm
        - Add support to trunk
        - Configure vlan interfaces inside guests
        - Verify connectivity via vlan interfaces
        - Remove the subport from trunk and verify connectivity
        - Add the support to trunk and verify connectivity
        - Do vm actions and verify connectivity


    Test Teardown:
        - Delete vms, ports, subnets, and networks created

    """
    vif_model = 'avp' if system_helper.is_avs() else None
    network_names = ['network11', 'network12', 'network13']
    net_ids = []
    sub_nets = ["30.0.0.0/24", "30.0.1.0/24", "30.0.2.0/24"]
    subnet_ids = []
    # parent ports and sub ports for trunk 1 and trunk 2
    trunk1_parent_port = 'vrf10'
    trunk1_subport_1 = 'vrf11'
    trunk1_subport_2 = 'vrf12'

    trunk2_parent_port = 'host10'
    trunk2_subport_1 = 'host11'
    trunk2_subport_2 = 'host12'

    # vlan id for the subports
    segment_1 = 1
    segment_2 = 2

    LOG.tc_step("Create Networks to be used by trunk")
    for net in network_names:
        net_ids.append(
            network_helper.create_network(name=net, cleanup='function')[1])

    LOG.tc_step("Create Subnet on the Network Created")
    for sub, network in zip(sub_nets, net_ids):
        subnet_ids.append(
            network_helper.create_subnet(network=network,
                                         subnet_range=sub,
                                         gateway='none',
                                         cleanup='function')[1])

    # Create Trunks
    LOG.tc_step("Create Parent port for trunk 1")
    t1_parent_port_id = network_helper.create_port(net_ids[0],
                                                   trunk1_parent_port,
                                                   wrs_vif=vif_model,
                                                   cleanup='function')[1]
    t1_parent_port_mac = network_helper.get_ports(
        field='mac address', port_name=trunk1_parent_port)[0]

    LOG.tc_step("Create Subport with parent port mac to be used by trunk 1")
    t1_sub_port1_id = network_helper.create_port(net_ids[1],
                                                 name=trunk1_subport_1,
                                                 mac_addr=t1_parent_port_mac,
                                                 wrs_vif=vif_model,
                                                 cleanup='function')[1]

    LOG.tc_step("Create Subport with parent port mac to be used by trunk 1")
    t1_sub_port2_id = network_helper.create_port(net_ids[2],
                                                 name=trunk1_subport_2,
                                                 mac_addr=t1_parent_port_mac,
                                                 wrs_vif=vif_model,
                                                 cleanup='function')[1]

    t1_sub_ports = [{
        'port': t1_sub_port1_id,
        'segmentation-type': 'vlan',
        'segmentation-id': segment_1
    }, {
        'port': t1_sub_port2_id,
        'segmentation-type': 'vlan',
        'segmentation-id': segment_2
    }]

    LOG.tc_step("Create port trunk 1")
    trunk1_id = network_helper.create_trunk(t1_parent_port_id,
                                            name='trunk-1',
                                            sub_ports=t1_sub_ports,
                                            cleanup='function')[1]

    LOG.tc_step("Boot a VM with mgmt net and trunk port")
    mgmt_net_id = network_helper.get_mgmt_net_id()
    nics = [{'net-id': mgmt_net_id}, {'port-id': t1_parent_port_id}]

    LOG.tc_step("Boot a vm with created ports")
    vm_id = vm_helper.boot_vm(name='vm-with-trunk1-port',
                              nics=nics,
                              cleanup='function')[1]
    LOG.tc_step("Setup vlan interfaces inside guest")
    _bring_up_vlan_interface(vm_id, 'eth1', [segment_1])

    # Create second trunk port  with out the subports and vm
    LOG.tc_step("Create Parent port for trunk 2")
    t2_parent_port_id = network_helper.create_port(net_ids[0],
                                                   trunk2_parent_port,
                                                   wrs_vif=vif_model,
                                                   cleanup='function')[1]
    t2_parent_port_mac = network_helper.get_ports(
        field='mac address', port_name=trunk2_parent_port)[0]
    LOG.tc_step("Create Subport with parent port mac to be used by trunk 2")
    t2_sub_port1_id = network_helper.create_port(net_ids[1],
                                                 name=trunk2_subport_1,
                                                 mac_addr=t2_parent_port_mac,
                                                 wrs_vif=vif_model,
                                                 cleanup='function')[1]
    LOG.tc_step("Create Subport with parent port mac to be used by trunk 2")
    t2_sub_port2_id = network_helper.create_port(net_ids[2],
                                                 name=trunk2_subport_2,
                                                 mac_addr=t2_parent_port_mac,
                                                 wrs_vif=vif_model,
                                                 cleanup='function')[1]

    t2_sub_ports = [{
        'port': t2_sub_port1_id,
        'segmentation-type': 'vlan',
        'segmentation-id': segment_1
    }, {
        'port': t2_sub_port2_id,
        'segmentation-type': 'vlan',
        'segmentation-id': segment_2
    }]

    LOG.tc_step("Create port trunk 2")
    trunk2_id = network_helper.create_trunk(t2_parent_port_id,
                                            name='trunk-2',
                                            cleanup='function')[1]

    LOG.tc_step("Boot a VM with mgmt net and trunk port")
    mgmt_net_id = network_helper.get_mgmt_net_id()
    nics_2 = [{'net-id': mgmt_net_id}, {'port-id': t2_parent_port_id}]

    LOG.tc_step("Boot a vm with created ports")
    vm2_id = vm_helper.boot_vm(name='vm-with-trunk2-port',
                               nics=nics_2,
                               cleanup='function')[1]

    LOG.tc_step("Add the sub ports to the second truck")
    network_helper.set_trunk(trunk2_id, sub_ports=t2_sub_ports)

    LOG.tc_step("Setup VLAN interfaces inside guest")
    _bring_up_vlan_interface(vm2_id, 'eth1', [segment_1])

    # ping b/w 2 vms using the vlan interfaces
    eth_name = 'eth1.1'

    with vm_helper.ssh_to_vm_from_natbox(vm_id) as vm_ssh:
        ip_addr = network_helper.get_ip_for_eth(eth_name=eth_name,
                                                ssh_client=vm_ssh)

    if ip_addr:
        with vm_helper.ssh_to_vm_from_natbox(vm2_id) as vm2_ssh:
            LOG.tc_step("Ping on vlan interface from guest")
            network_helper.ping_server(ip_addr,
                                       ssh_client=vm2_ssh,
                                       num_pings=20,
                                       fail_ok=False)

    # unset the subport on trunk_1 and try the ping (it will fail)
    LOG.tc_step(
        "Removing a subport from trunk and ping on vlan interface inside guest"
    )
    ret_code_10 = network_helper.unset_trunk(trunk1_id,
                                             sub_ports=[t1_sub_port1_id])[0]
    assert ret_code_10 == 0, "Subports not removed as expected."

    with vm_helper.ssh_to_vm_from_natbox(vm2_id) as vm2_ssh:
        LOG.tc_step("Ping on vlan interface from guest")
        ping = network_helper.ping_server(ip_addr,
                                          ssh_client=vm2_ssh,
                                          num_pings=20,
                                          fail_ok=True)[0]
        assert ping == 100, "Ping did not fail as expected."

    # set the subport on trunk_1 and try the ping (it will work)
    LOG.tc_step(
        " Add back the subport to trunk and ping on vlan interface inside guest"
    )
    t1_sub_port = [{
        'port': t1_sub_port1_id,
        'segmentation-type': 'vlan',
        'segmentation-id': segment_1
    }]
    network_helper.set_trunk(trunk1_id, sub_ports=t1_sub_port)

    with vm_helper.ssh_to_vm_from_natbox(vm2_id) as vm2_ssh:
        LOG.tc_step("Ping on vlan interface from guest")
        network_helper.ping_server(ip_addr,
                                   ssh_client=vm2_ssh,
                                   num_pings=20,
                                   fail_ok=False)

    # VM operation and ping
    for vm_actions in [['pause', 'unpause'], ['suspend', 'resume'],
                       ['live_migrate'], ['cold_migrate']]:

        LOG.tc_step("Perform following action(s) on vm {}: {}".format(
            vm2_id, vm_actions))
        for action in vm_actions:
            vm_helper.perform_action_on_vm(vm2_id, action=action)

        LOG.tc_step("Ping vm from natbox")
        vm_helper.wait_for_vm_pingable_from_natbox(vm_id)

        LOG.tc_step(
            "Verify ping from base_vm to vm_under_test over management networks still works "
            "after {}".format(vm_actions))
        vm_helper.ping_vms_from_vm(to_vms=vm_id,
                                   from_vm=vm2_id,
                                   net_types=['mgmt'])

        if vm_actions[0] == 'cold_migrate':
            LOG.tc_step("Setup VLAN interfaces inside guest")
            _bring_up_vlan_interface(vm2_id, 'eth1', [segment_1])

        with vm_helper.ssh_to_vm_from_natbox(vm2_id) as vm2_ssh:
            LOG.tc_step(
                "Ping on vlan interface from guest after action {}".format(
                    vm_actions))
            network_helper.ping_server(ip_addr,
                                       ssh_client=vm2_ssh,
                                       num_pings=20,
                                       fail_ok=False)

        vm_host = vm_helper.get_vm_host(vm2_id)

        vm_on_target_host = vm_helper.get_vms_on_host(vm_host)

    LOG.tc_step(
        "Reboot VMs host {} and ensure vms are evacuated to other host".format(
            vm_host))
    vm_helper.evacuate_vms(host=vm_host, vms_to_check=vm2_id, ping_vms=True)

    for vm_id_on_target_host in vm_on_target_host:
        LOG.tc_step("Setup VLAN interfaces inside guest")
        _bring_up_vlan_interface(vm_id_on_target_host, 'eth1', [segment_1])

    with vm_helper.ssh_to_vm_from_natbox(vm2_id) as vm2_ssh:
        LOG.tc_step("Ping on vlan interface from guest after evacuation")
        network_helper.ping_server(ip_addr,
                                   ssh_client=vm2_ssh,
                                   num_pings=20,
                                   fail_ok=False)

    LOG.tc_step(
        "Attempt to delete trunk when in use, expect pass for AVS only")
    code = network_helper.delete_trunks(trunks=trunk1_id, fail_ok=True)[0]

    if system_helper.is_avs():
        assert 0 == code, "Failed to delete port trunk when it's used by a running VM wiht AVS"
    else:
        assert 1 == code, "Trunk is deleted when it's used by a running VM with OVS"
Exemplo n.º 5
0
def update_dovetail_mgmt_interface():
    """
    Update dovetail vm mgmt interface on cumulus system.
    Since cumulus system is on different version. This helper function requires use cli matches the cumulus tis.

    Returns:

    """
    expt_mgmt_net = get_expt_mgmt_net()
    if not expt_mgmt_net:
        skip('{} mgmt net is not found in Cumulus tis-lab project'.format(
            ProjVar.get_var('LAB')['name']))

    with ssh_to_cumulus_server() as cumulus_con:
        cumulus_auth = CumulusCreds.TENANT_TIS_LAB
        vm_id = vm_helper.get_vm_id_from_name(vm_name='dovetail',
                                              con_ssh=cumulus_con,
                                              auth_info=cumulus_auth)

        dovetail_networks = vm_helper.get_vms(vms=vm_id,
                                              field='Networks',
                                              con_ssh=cumulus_con,
                                              auth_info=cumulus_auth)[0]

        actual_nets = dovetail_networks.split(sep=';')
        prev_mgmt_nets = []
        for net in actual_nets:
            net_name, net_ip = net.split('=')
            if '-MGMT-net' in net_name:
                prev_mgmt_nets.append(net_name)

        attach = True
        if expt_mgmt_net in prev_mgmt_nets:
            attach = False
            prev_mgmt_nets.remove(expt_mgmt_net)
            LOG.info("{} interface already attached to Dovetail vm".format(
                expt_mgmt_net))

        if prev_mgmt_nets:
            LOG.info("Detach interface(s) {} from dovetail vm".format(
                prev_mgmt_nets))
            vm_ports_table = table_parser.table(
                cli.nova('interface-list',
                         vm_id,
                         ssh_client=cumulus_con,
                         auth_info=cumulus_auth)[1])
            for prev_mgmt_net in prev_mgmt_nets:
                prev_net_id = network_helper.get_net_id_from_name(
                    net_name=prev_mgmt_net,
                    con_ssh=cumulus_con,
                    auth_info=cumulus_auth)

                prev_port = table_parser.get_values(vm_ports_table, 'Port ID',
                                                    **{'Net ID':
                                                       prev_net_id})[0]
                detach_arg = '{} {}'.format(vm_id, prev_port)
                cli.nova('interface-detach',
                         detach_arg,
                         ssh_client=cumulus_con,
                         auth_info=cumulus_auth)

        mgmt_net_id = network_helper.get_net_id_from_name(
            net_name=expt_mgmt_net,
            con_ssh=cumulus_con,
            auth_info=cumulus_auth)
        if attach:
            LOG.info("Attach {} to dovetail vm".format(expt_mgmt_net))
            args = '--net-id {} {}'.format(mgmt_net_id, vm_id)
            cli.nova('interface-attach',
                     args,
                     ssh_client=cumulus_con,
                     auth_info=cumulus_auth)

        vm_ports_table = table_parser.table(
            cli.nova('interface-list',
                     vm_id,
                     ssh_client=cumulus_con,
                     auth_info=cumulus_auth)[1])
        mgmt_mac = table_parser.get_values(vm_ports_table, 'MAC Addr',
                                           **{'Net ID': mgmt_net_id})[0]

    ComplianceCreds.set_host(Dovetail.TEST_NODE)
    ComplianceCreds.set_user(Dovetail.USERNAME)
    ComplianceCreds.set_password(Dovetail.PASSWORD)
    with ssh_to_compliance_server() as dovetail_ssh:
        if not attach and network_helper.ping_server('192.168.204.3',
                                                     ssh_client=dovetail_ssh,
                                                     fail_ok=True)[0] == 0:
            return
        LOG.info("Bring up dovetail mgmt interface and assign ip")
        eth_name = network_helper.get_eth_for_mac(dovetail_ssh,
                                                  mac_addr=mgmt_mac)
        dovetail_ssh.exec_sudo_cmd('ip link set dev {} up'.format(eth_name))
        dovetail_ssh.exec_sudo_cmd('dhclient {}'.format(eth_name),
                                   expect_timeout=180)
        dovetail_ssh.exec_cmd('ip addr')
        network_helper.ping_server(server='192.168.204.3',
                                   ssh_client=dovetail_ssh,
                                   fail_ok=False)