Exemplo n.º 1
0
def getNativeWorkloads():
    # Get all available host interfaces
    lst_nodes = api.GetWorkloadNodeHostnames()
    lst_native_if = {}
    mgmt_intf = {}

    # Get host interfaces on all nodes
    for node in lst_nodes:
        lst_native_if[node] = list(api.GetWorkloadNodeHostInterfaces(node))
        # Exclude host side management interface from this test case on naples
        if api.IsNaplesNode(node):
            mgmt_intf[node] = list(
                naples_utils.GetHostInternalMgmtInterfaces(node))

    for node, infs in mgmt_intf.items():
        for inf in infs:
            if inf in lst_native_if[node]:
                lst_native_if[node].remove(inf)

    # Get workloads corresponding to host interfaces
    total_workloads = api.GetWorkloads()
    native_workloads = []
    for w1 in total_workloads:
        for node, infs in lst_native_if.items():
            if w1.interface in infs and w1.node_name == node:
                native_workloads.append(w1)

    return native_workloads
Exemplo n.º 2
0
def GetHostInterfaces(node, device=None):
    intfs = []
    devices = [device] if device else api.GetDeviceNames(node)
    for device_name in devices:
        for intf in api.GetWorkloadNodeHostInterfaces(node, device_name):
            api.Logger.debug("HostInterface for node:%s interface:%s " %
                             (node, intf))
            intfObj = NaplesInterface(node, intf, InterfaceType.HOST,
                                      api.GetNodeOs(node), device_name)
            intfs.append(intfObj)
    return intfs
Exemplo n.º 3
0
def setMaxMTU():
    MAX_MTU = 9000
    nodes = api.GetNodes()
    for node in nodes:
        host_intfs = api.GetWorkloadNodeHostInterfaces(node.Name())
        for intf in host_intfs:
            if setCheckMTU(node.Name(), intf,
                           MAX_MTU) != api.types.status.SUCCESS:
                api.Logger.error("MTU change unsucessfull on ", node.Name(),
                                 intf)
                return api.types.status.FAILURE

    workloads = api.GetWorkloads()
    api.Logger.info(api.GetWorkloadNodeHostInterfaces(
        api.GetNodes()[0].Name()))
    for w in workloads:
        if setCheckMTU(w.node_name, w.interface,
                       MAX_MTU) != api.types.status.SUCCESS:
            api.Logger.error("MTU change unsucessfull on ", w.node_name,
                             w.interface)
            return api.types.status.FAILURE
    return api.types.status.SUCCESS
Exemplo n.º 4
0
def getNativeWorkloadIntfs(tc):
    tc.host_nodes = api.GetWorkloadNodeHostnames()
    tmp_native_intf_list = {}
    tc.native_intf_list = {}
    tc.mgmt_intf_list = {}

    # Get host interfaces on all nodes
    for node in tc.host_nodes:
        tmp_native_intf_list[node] = list(api.GetWorkloadNodeHostInterfaces(node))
        if api.IsNaplesNode(node):
            tc.mgmt_intf_list[node] = list(naples_host_utils.GetHostInternalMgmtInterfaces(node))

    for node in tc.mgmt_intf_list:
        tc.native_intf_list[node] = list(set(tmp_native_intf_list.get(node))-set(tc.mgmt_intf_list.get(node)))
    return api.types.status.SUCCESS
Exemplo n.º 5
0
    def __init__(self, wlSpec, default_vlan):
        self.__wlSpec = wlSpec
        self.__node = wlSpec.node
        self.__default_vlan = default_vlan

        self.__interfaces = {}
        self.__nic_devices = api.GetDeviceNames(self.__node)
        # Since its multi-Naples scenario, regenerate wl.interfaces
        for idx, dev_name in enumerate(self.__nic_devices):
            iflist = []
            hostIfList = api.GetWorkloadNodeHostInterfaces(
                self.GetNodeName(), dev_name)
            ifType = api.GetWorkloadNodeHostInterfaceType(
                self.GetNodeName(), dev_name)
            for ifnum, hostIntf in enumerate(hostIfList):
                obj = parser.Dict2Object({})
                setattr(obj, 'HostInterface', hostIntf)
                setattr(
                    obj, 'ParentHostInterface',
                    api.GetNodeParentHostInterface(self.GetNodeName(),
                                                   dev_name, hostIntf))
                setattr(obj, 'LogicalInterface',
                        'host_if{0}'.format(ifnum + 1))
                setattr(
                    obj, 'InterfaceIndex',
                    api.GetNodeParentHostInterfaceIndex(
                        self.GetNodeName(), dev_name, hostIntf))
                setattr(obj, 'InterfaceType', ifType)
                iflist.append(obj)
            if iflist:
                self.__interfaces[dev_name] = iflist

        if self.__wlSpec.count == 'auto':
            # Review following with bug PS-724 is fixed
            self.__num_subifs = int((api.Testbed_GetVlanCount() - 2) /
                                    len(self.__nic_devices))  # 1 for native
            api.Logger.info(
                "With %d nic-devices, evaluating %d sub-ifs with %d vlans" %
                (len(self.__nic_devices), self.__num_subifs,
                 api.Testbed_GetVlanCount()))
            # self.__num_subifs = 32
        else:
            self.__num_subifs = int(self.__wlSpec.count)

        self.portUdpAllocator = resmgr.TestbedPortAllocator(20000)
        self.portTcpAllocator = resmgr.TestbedPortAllocator(30000)

        return
Exemplo n.º 6
0
def GetOneHostDataInterface(n):
    return api.GetWorkloadNodeHostInterfaces(n)[0]
Exemplo n.º 7
0
def Setup(tc):
    host1 = None
    host2 = None
    api.Logger.info("Nodes: %s" % api.GetWorkloadNodeHostnames())
    for _node in api.GetWorkloadNodeHostnames():
        if not host1 and api.IsNaplesNode(_node) and api.GetNodeOs(
                _node) == "linux":
            host1 = _node
        else:
            host2 = _node

    if not host1:
        api.Logger.error("Unable to find a Naples node with linux os")
        return api.types.status.ERROR
    if not host2:
        api.Logger.error("Unable to find a node with linux os")
        return api.types.status.ERROR

    tc.host1 = host1
    tc.host2 = host2
    tc.pf_1 = api.GetWorkloadNodeHostInterfaces(tc.host1)[0]
    tc.pf_2 = api.GetWorkloadNodeHostInterfaces(tc.host2)[0]

    api.Logger.info("Host interface pair[%s, %s]" % (tc.pf_1, tc.pf_2))

    tc.num_vfs = GetSupportedVFs(tc.host1, tc.pf_1)
    api.Logger.info("Host %s PF %s supports %d VFs" %
                    (tc.host1, tc.pf_1, tc.num_vfs))

    if tc.num_vfs == 0:
        api.Logger.warn(
            "Max supported VFs on host %s is 0, expected non-zero" % host)
        return api.types.status.ERROR

    if CreateVFs(tc.host1, tc.pf_1, tc.num_vfs) != api.types.status.SUCCESS:
        return api.types.status.ERROR

    tc.vfid = 0
    tc.vf_intf = GetVFName(tc.host1, tc.pf_1, tc.vfid)
    tc.remote_intf = tc.pf_2
    # Set trust on to set the mac addr
    if SetVFTrust(tc.host1, tc.pf_1, tc.vfid,
                  "on") != api.types.status.SUCCESS:
        return api.types.status.FAILURE
    # Assign mac addr to VF
    if SetVFNdevMac(host1, tc.pf_1, tc.vfid,
                    "00:22:44:66:88:a1") != api.types.status.SUCCESS:
        return api.types.status.ERROR

    # Assign Ips to the vf interface and corresponding PF on the remote node.
    tc.vf_ip = "30.0.0.1"
    tc.remote_ip = "30.0.0.2"

    if SetIp(host1, tc.vf_intf, tc.vf_ip, 24) != api.types.status.SUCCESS:
        return api.types.status.ERROR
    if SetIp(host2, tc.remote_intf, tc.remote_ip,
             24) != api.types.status.SUCCESS:
        return api.types.status.ERROR
    if SetVFNdevState(tc.host1, tc.pf_1, tc.vfid,
                      "up") != api.types.status.SUCCESS:
        return api.types.status.ERROR
    if ping_check(tc.host1, tc.vf_intf, tc.remote_ip,
                  retries=5) != api.types.status.SUCCESS:
        api.Logger.error("Unable to ping the remote interface")
        return api.types.status.ERROR
    return api.types.status.SUCCESS
Exemplo n.º 8
0
def initialize_tagged_config_workloads():
    # Get configuration from yaml
    spec = __get_topology_config()
    global __subifs_vlan_allocator
    global __ipv4_allocators
    global __ipv6_allocators
    global __mac_allocator
    global __ipv4_subnet_allocator
    global __ipv6_subnet_allocator
    global __pernode_network_spec
    global __node_native_ifs

    # Saving node IFs
    nodes = api.GetWorkloadNodeHostnames()
    for node in nodes:
        __node_native_ifs[node] = list(api.GetWorkloadNodeHostInterfaces(node))

# Reading network and workload specs
    network_specs = {}
    workload_specs = {}
    for net in spec.spec.networks:
        network_specs[net.network.name] = net.network
        if net.network.default:
            def_nw_spec = net.network
    for wl in spec.spec.workloads:
        workload_specs[wl.workload.name] = wl.workload

    # Store network spec for nodes
    for lst_nodes in spec.instances.workloads:
        nd = lst_nodes.workload
        if nd.spec == 'tagged':
            wl_spec = workload_specs[nd.spec]
            nw_spec = network_specs[wl_spec.network_spec]
            __pernode_network_spec[nd.node] = nw_spec

    for node_name in api.GetWorkloadNodeHostnames():
        if node_name not in __pernode_network_spec:
            __pernode_network_spec[node_name] = def_nw_spec

    # Store subnet allocators for network spec
    # case 1: Get subnet from wl_api
    for k, net in network_specs.items():
        ipv4_subnet = wl_api.GetIPv4Allocator(net.name)
        if ipv4_subnet is None and net.ipv4.enable:
            __ipv4_subnet_allocator[net.name] = resmgr.IpAddressStep(
                net.ipv4.ipam_base.split('/')[0],  # 10.255.0.0/16 \
                str(
                    ipaddress.IPv4Address(
                        1 << int(net.ipv4.ipam_base.split('/')[1]))))
        else:
            __ipv4_subnet_allocator[net.name] = ipv4_subnet

        ipv6_subnet = wl_api.GetIPv6Allocator(net.name)
        if ipv6_subnet is None and net.ipv6.enable:
            __ipv6_subnet_allocator[net.name] = resmgr.Ipv6AddressStep(
                net.ipv6.ipam_base.split('/')[0],  # 2000::/48\
                str(
                    ipaddress.IPv6Address(
                        1 << int(net.ipv6.ipv6.ipam_base.split('/')[1]))))
        else:
            __ipv6_subnet_allocator[net.name] = ipv6_subnet

    __mac_allocator = wl_api.GetMacAllocator()