Beispiel #1
0
    def __init_allocators(self):
        # Forming subnet allocators
        self.__subnet_allocator = {}
        self.__sec_ipv4_subnet_allocator = {}
        self.__sec_ipv6_subnet_allocator = {}
        # global ipv4_subnet_allocator
        self.__ipv4_subnet_allocator.clear()

        # global ipv6_subnet_allocator
        self.__ipv6_subnet_allocator.clear()

        for k, net in self.__network_specs.items():
            if net.ipv4.enable:
                self.__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]))))
                self.__sec_ipv4_subnet_allocator[net.name] = []
                for ipb in getattr(net.ipv4, "secondary_ipam_base", []):
                    s = ipaddress.IPv4Network(ipb)
                    self.__sec_ipv4_subnet_allocator[net.name].append(
                        s.subnets(new_prefix=net.ipv4.prefix_length))

            if net.ipv6.enable:
                self.__ipv6_subnet_allocator[
                    net.name] = resmgr.Ipv6AddressStep(
                        net.ipv6.ipam_base.split('/')[0],  # 2000::/48 \ 
                        str(
                            ipaddress.IPv6Address(
                                1 << int(net.ipv6.ipam_base.split('/')[1]))))
                self.__sec_ipv6_subnet_allocator[net.name] = []
                for ipb in getattr(net.ipv6, "secondary_ipam_base", []):
                    s = ipaddress.IPv6Network(ipb)
                    self.__sec_ipv6_subnet_allocator[net.name].append(
                        s.subnets(new_prefix=net.ipv6.prefix_length))
        self.__classic_mac_allocator = resmgr.MacAddressStep(
            "00AA.0000.0001", "0000.0000.0001")
Beispiel #2
0
#! /usr/bin/python3

import json
import iota.harness.api as api
import iota.harness.infra.resmgr as resmgr
import iota.harness.infra.store as store
import iota.test.utils.naples_host as naples_host

IntMgmtIpAllocator = resmgr.IpAddressStep("192.169.1.2", "0.0.0.1")
InbandIpAllocator = resmgr.IpAddressStep("192.170.1.2", "0.0.0.1")
OobIpAllocator = resmgr.IpAddressStep("192.171.1.2", "0.0.0.1")


class InterfaceType:
    HOST = 1
    HOST_MGMT = 2
    HOST_INTERNAL = 3
    NAPLES_INT_MGMT = 4
    NAPLES_IB_100G = 5
    NAPLES_OOB_1G = 6
    NAPLES_IB_BOND = 7


def GetHostMgmtInterface(node):

    req = api.Trigger_CreateExecuteCommandsRequest(serial=True)

    os = api.GetNodeOs(node)
    if os == "linux":
        cmd = "ip -o -4 route show to default | awk '{print $5}'"
        api.Trigger_AddHostCommand(req, node, cmd)
Beispiel #3
0
import time
import copy
from collections import defaultdict

import iota.harness.api as api
import iota.harness.infra.utils.parser as parser
import iota.test.iris.config.netagent.api as netagent_api
import iota.test.iris.config.workload.base as wl_orch
import iota.harness.infra.resmgr as resmgr
from iota.harness.infra.glopts import GlobalOptions as GlobalOptions

import iota.protos.pygen.topo_svc_pb2 as topo_svc

vmotion_mac_allocator = resmgr.MacAddressStep("00CC.0000.0001",
                                              "0000.0000.0001")
vmotion_ip_allocator = resmgr.IpAddressStep("172.16.0.1", "0.0.0.1")


def __get_l2segment_vlan_for_endpoint(ep):
    nw_filter = "meta.name=" + ep.spec.network_name + ";"
    objects = netagent_api.QueryConfigs(kind='Network', filter=nw_filter)
    assert (len(objects) == 1)
    return objects[0].spec.vlan_id


def __setup_vmotion_on_hosts(nodes=None):
    vmotion_workloads = {}
    ep_objs = netagent_api.QueryConfigs(kind='Endpoint')
    ep_ref = None
    for ep in ep_objs:
        node_name = getattr(ep.spec, "_node_name", None)
Beispiel #4
0
def ConfigWorkloadSecondaryIp(workload, is_add, sec_ip_count_per_intf=1):
    res = api.types.status.SUCCESS
    wl_sec_ip_list = []
    if (workload.uplink_vlan != 0):
        return wl_sec_ip_list

    nodes = api.GetWorkloadNodeHostnames()
    max_untag_wl = 0
    max_tag_wl = 0
    if is_add == True:
        op = "add"
    else:
        op = "del"

    is_wl_bm_type = False
    for node in nodes:
        if api.IsBareMetalWorkloadType(node):
            is_wl_bm_type = True
        workloads = api.GetWorkloads(node)
        num_untag_wl_in_node = 0
        num_tag_wl_in_node = 0
        for wl in workloads:
            if (wl.uplink_vlan == 0):
                num_untag_wl_in_node += 1
            else:
                num_tag_wl_in_node += 1
        if num_untag_wl_in_node > max_untag_wl:
            max_untag_wl = num_untag_wl_in_node
        if num_tag_wl_in_node > max_tag_wl:
            max_tag_wl = num_tag_wl_in_node
        #api.Logger.info("Node {} WL #untag {} #tag {} ".format(node, num_untag_wl_in_node, num_tag_wl_in_node))

    #api.Logger.info("Topo Max untag WL {} Max tag WL {} ".format(max_untag_wl, max_tag_wl))
    sec_ip_incr_step = max_untag_wl
    if is_wl_bm_type == False:
        sec_ip_incr_step += max_tag_wl

    req = api.Trigger_CreateExecuteCommandsRequest(serial=True)

    wl = workload
    sec_ipv4_allocator = resmgr.IpAddressStep(
        wl.ip_prefix.split('/')[0],
        str(ipaddress.IPv4Address(sec_ip_incr_step)), sec_ip_count_per_intf)
    sec_ip4_addr_str = str(sec_ipv4_allocator.Alloc())
    for i in range(sec_ip_count_per_intf):
        sec_ip4_addr_str = str(sec_ipv4_allocator.Alloc())
        sec_ip_prefix = sec_ip4_addr_str + "/" + str(
            wl.ip_prefix.split('/')[1])
        wl_sec_ip_list.append(sec_ip4_addr_str)
        #api.Logger.info("Node {} WL {} Intf {} Secondary IP {} Op {}".format(
        #                 wl.node_name, wl.workload_name, wl.interface, sec_ip_prefix, op))
        api.Trigger_AddCommand(
            req, wl.node_name, wl.workload_name,
            "ip address %s %s dev %s " % (op, sec_ip_prefix, wl.interface))
    trig_resp = api.Trigger(req)

    #api.Logger.info("Response ")
    #for cmd in trig_resp.commands:
    #    api.PrintCommandResults(cmd)

    return wl_sec_ip_list
Beispiel #5
0
 def AllocIpv4SubnetAllocator(self, nw_spec_name):
     ipv4_subnet = self.__ipv4_subnet_allocator.get(nw_spec_name,
                                                    None).Alloc()
     return resmgr.IpAddressStep(ipv4_subnet, "0.0.0.1")
Beispiel #6
0
def __create_new_workload_outside_store(req, node_name, parent_inf,
                                        subifs_count):
    global __pernode_network_spec
    global __perhost_subifs
    global __subifs_vlan_allocator
    global __perhost_subifs
    global __ipv4_subnet_allocator
    global __ipv6_subnet_allocator
    global __node_native_ifs
    global __free_vlans

    __add_subifs_wl = []

    assert (req.workload_op == topo_svc.ADD)
    ifs = __node_native_ifs[node_name]
    key = "host_" + str(ifs.index(str(parent_inf)))

    for j in range(subifs_count):
        index = key + "_" + str(j)
        if index not in __perhost_subifs:
            __perhost_subifs[index] = 1
        else:
            __perhost_subifs[index] += 1

        if index not in __subifs_vlan_allocator:
            nw_spec = __pernode_network_spec[node_name]
            # Check if free vlans available already, reuse it
            if len(__free_vlans):
                __subifs_vlan_allocator[index] = __free_vlans.pop(0)
                api.Logger.info("Reassigned vlan id: %d" %
                                __subifs_vlan_allocator[index])
            else:
                for count in range(api.Testbed_GetVlanCount()):
                    vlan_id = api.Testbed_AllocateVlan()
                    if vlan_id == api.Testbed_GetVlanBase():
                        vlan_id = api.Testbed_AllocateVlan()
                    if vlan_id not in __subifs_vlan_allocator.values():
                        break
                else:
                    api.Logger.info(
                        "No vlans available. Delete existing subifs to add new subifs. Exiting, vlan count: %d\n"
                        % api.Testbed_GetVlanCount())
                    return
                __subifs_vlan_allocator[index] = vlan_id

            ipv4_subnet = (__ipv4_subnet_allocator[nw_spec.name]).Alloc()
            ipv6_subnet = (__ipv6_subnet_allocator[nw_spec.name]).Alloc()
            __ipv4_allocators[index] = resmgr.IpAddressStep(
                ipv4_subnet, "0.0.0.1")
            __ipv6_allocators[index] = resmgr.Ipv6AddressStep(
                ipv6_subnet, "0::1")
            __ipv4_allocators[index].Alloc()  # To skip 0 ip
            __ipv6_allocators[index].Alloc()  # To skip 0 ip

        subif_spec = __pernode_network_spec[node_name]
        ipv4_allocator = __ipv4_allocators[index]
        ipv6_allocator = __ipv6_allocators[index]
        vlan = __subifs_vlan_allocator[index]
        workload_name = node_name + "_" + parent_inf + "_subif_" + str(vlan)
        res = False
        for wreq in req.workloads:
            if wreq.workload_name == workload_name:
                res = True
                break
        if res:
            continue
        #assert(not api.IsWorkloadRunning(workload_name))
        wl_msg = req.workloads.add()
        ip4_addr_str = str(ipv4_allocator.Alloc())
        ip6_addr_str = str(ipv6_allocator.Alloc())
        intf = wl_msg.interfaces.add()
        intf.ip_prefix = ip4_addr_str + "/" + str(
            subif_spec.ipv4.prefix_length)
        intf.ipv6_prefix = ip6_addr_str + "/" + str(
            subif_spec.ipv6.prefix_length)
        intf.mac_address = __mac_allocator.Alloc().get()
        intf.encap_vlan = vlan
        intf.uplink_vlan = intf.encap_vlan
        wl_msg.workload_name = workload_name
        wl_msg.node_name = node_name
        intf.pinned_port = 1
        intf.interface_type = topo_svc.INTERFACE_TYPE_VSS
        intf.interface = parent_inf + "_" + str(vlan)
        intf.parent_interface = parent_inf
        wl_msg.workload_type = api.GetWorkloadTypeForNode(node_name)
        wl_msg.workload_image = api.GetWorkloadImageForNode(node_name)
        __add_subifs_wl.append(wl_msg.interface)

        # Safety check
        if vlan in __free_vlans:
            __free_vlans.remove(vlan)

    api.Logger.info("Created workload: %s for host: %s  on node: %s" %
                    (__add_subifs_wl, parent_inf, node_name))
    # store these workloads locally
    __storeWorkloads_outisde_store(req, __add_subifs_wl)
    return __add_subifs_wl
Beispiel #7
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()
Beispiel #8
0
#! /usr/bin/python3
import iota.harness.api as api
from iota.harness.infra.utils import parser
import iota.harness.infra.resmgr as resmgr
import iota.test.iris.utils.address as address_utils
import iota.test.iris.utils.debug as debug_utils
import iota.test.iris.utils.hal_show as hal_show_utils
import iota.test.iris.utils.host as host_utils
import iota.test.iris.testcases.filters.filters_utils as filters_utils
from collections import defaultdict
import operator
import time
import yaml

ipv4_allocator = resmgr.IpAddressStep("239.1.5.1", "0.0.0.1")
__HPING_COUNT = 8

def getAllmcastEndPointsView(naples_node, device_name):
    # Host interface mcast endpoints
    host_mc_ep_set = filters_utils.getHostIntfMcastEndPoints(naples_node, device_name)

    # Naples intf mcast endpoints
    naples_mc_ep_set = filters_utils.getNaplesIntfMcastEndPoints(naples_node, device_name)

    # HAL view of endpoints
    hal_mc_ep_set = filters_utils.getNaplesHALmcastEndPoints(naples_node, device_name)

    #Keeping them separate as it is useful for debugging in scale
    return host_mc_ep_set, naples_mc_ep_set, hal_mc_ep_set

def verifyMCEndPoints(tc):