Beispiel #1
0
def __update_nexthops_from_uplink_info():
    nodes = api.GetNaplesHostnames()
    nhClient = config_api.GetObjClient('nexthop')
    interfaceClient = config_api.GetObjClient('interface')
    for targetNode in nodes:
        nexthops = nhClient.GetUnderlayNexthops(targetNode)
        if len(nexthops) == 0:
            # Skip updating nexthops if none of them are created via config
            api.Logger.verbose(f"Skipping nexthops updates as "
                               f"none exist in {targetNode}")
            continue
        num = 0
        for nh in nexthops:
            api.Logger.verbose(f"Updating NH {nh} in node {targetNode}")
            for srcNode in nodes:
                if targetNode == srcNode:
                    continue
                peer_intf_mac = interfaceClient.GetNHInterfaceMac(srcNode, 'dsc0')
                if peer_intf_mac is None:
                    # ignore for dry run
                    api.Logger.error(f"Failed to retrive dsc0 intf mac from "
                                     f"{srcNode} - Skip updating NH {nh} "
                                     f"in {targetNode}")
                    continue
                api.Logger.debug(f"Updating NH {nh} with intf-mac "
                                 f"{peer_intf_mac} of {srcNode}")
                nh.underlayMACAddr = peer_intf_mac
                num += 1
        nhClient.UpdateUnderlayObjects(targetNode)
        api.Logger.debug(f"Updated {num} NH Objects in {targetNode}")
    return
Beispiel #2
0
def ValidateLearnInfo(node=None):
    if node is None:
        nodes = api.GetNaplesHostnames()
    else:
        nodes = [node]
    for n in nodes:
        if not config_api.GetObjClient('vnic').ValidateLearnMACInfo(n):
            api.Logger.error("MAC validation failed on node %s" % n)
            return False
        if not config_api.GetObjClient('lmapping').ValidateLearnIPInfo(n):
            api.Logger.error("IP validation failed on node %s" % n)
            return False

    remote_nodes = api.GetNaplesHostnames()
    for remote_node in remote_nodes:
        for n in nodes:
            if n == remote_node:
                continue
            if not config_api.GetObjClient('rmapping').\
                      ValidateLearnIPWithRMapInfo(remote_node, n):
                api.Logger.error("RMap validation failed on node %s" %
                                 remote_node)
                return False

    api.Logger.verbose("MAC and IP validation successful")
    return True
Beispiel #3
0
def __generate_rmappings_from_lmappings():
    nodes = api.GetNaplesHostnames()
    lmapClient = config_api.GetObjClient('lmapping')
    rmapClient = config_api.GetObjClient('rmapping')
    rmapSpec = dict()
    for targetNode in nodes:
        isOverlayRoutingEnabled = EzAccessStoreClient[targetNode].IsDeviceOverlayRoutingEnabled()
        if isOverlayRoutingEnabled:
            rmapSpec['origin'] = 'discovered'
        else:
            rmapSpec['origin'] = 'fixed'
        if rmapClient.GetNumObjects(targetNode) != 0:
            # Skip since Remote mapping configs are already generated from cfgspec
            api.Logger.verbose(f"Skipping Remote mapping generation "
                               f"since they already exist")
            continue
        for srcNode in nodes:
            num = 0
            if targetNode == srcNode:
                continue
            lmappings = lmapClient.Objects(srcNode)
            for lmap in lmappings:
                if lmap.VNIC.IsIgwVnic():
                    api.Logger.verbose(f"Skipping Remote mapping generation "
                                       f"for IgwVnic's lmapping {lmap.GID()}")
                    continue
                mac = "macaddr/%s" %lmap.VNIC.MACAddr.get()
                rmapSpec['rmacaddr'] = objects.TemplateFieldObject(mac)
                rmapSpec['ripaddr'] = lmap.IP
                if lmap.AddrFamily == 'IPV6':
                    ipversion = utils.IP_VERSION_6
                else:
                    ipversion = utils.IP_VERSION_4
                parent = config_api.GetObjClient('subnet').GetSubnetObject(targetNode, lmap.VNIC.SUBNET.SubnetId)
                rmapClient.GenerateObj(targetNode, parent, rmapSpec, ipversion)
                num += 1
            api.Logger.info(f"Generated {num} RMAPPING Objects in {targetNode}")
        # Create the generated objects if their origin is fixed.
        if not isOverlayRoutingEnabled:
            if not rmapClient.CreateObjects(targetNode):
                api.Logger.error(f"Failed to create remote mappings on "
                                 f"{targetNode}, Aborting!!!")
                return False
            if not rmapClient.ReadObjects(targetNode):
                api.Logger.error(f"Failed to read remote mappings on "
                                 f"{targetNode}, Aborting!!!")
                return False
    return True
Beispiel #4
0
def GetLearnIPObjects(node, vnic=None):
    if vnic is None:
        return list(config_api.GetObjClient('lmapping').Objects(node))
    else:
        ip_objs = list(
            filter(lambda x: (x.ObjType == APIObjTypes.LMAPPING and x.IsV4()),
                   vnic.Children))
        return ip_objs
Beispiel #5
0
def Setup(tc):
    api.Logger.info(f"API_CRUD_CFG_SCALE : TC for {tc.iterators.objtype}")
    result = api.types.status.SUCCESS
    tc.objClient = config_api.GetObjClient(tc.iterators.objtype)
    tc.Nodes = api.GetNaplesHostnames()
    tc.ValidateTrigger = 'ReadObjects'
    if tc.iterators.oper == 'delete':
        tc.cfgTrigger = 'DeleteObjects'
        tc.RollbackTrigger = 'RestoreObjects'
    elif tc.iterators.oper == 'update':
        tc.cfgTrigger = 'UpdateObjects'
        tc.RollbackTrigger = 'RollbackUpdateObjects'
    else:
        api.Logger.critical(f"Unsupported operation {tc.iterators.oper}")
        return api.types.status.FAILURE
    result = verifyDataPortState(tc.Nodes, "up", "up")
    api.Logger.info(f"API_CRUD_CFG_SCALE : Setup final result {result}")
    return result
Beispiel #6
0
def verify_dhclient_lease():
    api.Logger.info("Verifying dhclient leases")
    if not api.IsSimulation():
        req = api.Trigger_CreateExecuteCommandsRequest(serial=True)
    else:
        req = api.Trigger_CreateExecuteCommandsRequest(serial=False)
    for workload in workloads.keys():
        cmd = "cat /var/lib/dhclient/dhclient.leases"
        api.Trigger_AddCommand(req, workload.node_name, workload.workload_name,
                               cmd)
    resp = api.Trigger(req)

    dhcp_proxy_client = config_api.GetObjClient("dhcp_proxy")
    for workload, cmd in zip(workloads.keys(), resp.commands):
        match = False
        dhclient_info = dhclient_db(cmd.stdout)
        dhcp_policies = dhcp_proxy_client.Objects(workload.node_name)
        if not dhcp_policies:
            continue
        for dhcp_policy in dhcp_policies:
            # Currently we have only one dhcp interface per workload
            lease = list(dhclient_info.values())[0]
            prefix = ".".join(str(dhcp_policy.serverip).split(".")[:3])
            if prefix in lease["fixed-address"]:
                for ntpserver in dhcp_policy.ntpserver:
                    assert str(ntpserver) in lease["ntp-servers"]
                assert str(dhcp_policy.interfacemtu) in lease["interface-mtu"]
                assert str(dhcp_policy.domainname) in lease["domain-name"]
                for dnsserver in dhcp_policy.dnsserver:
                    assert str(dnsserver) in lease["domain-name-servers"]
                assert "255.255.255.0" in lease["subnet-mask"]
                match = True
                break

        assert match

    return api.types.status.SUCCESS
Beispiel #7
0
import iota.harness.api as api
import iota.harness.infra.store as store
import iota.test.apulu.config.api as config_api
import iota.test.apulu.config.bringup_workloads as wl_api
import iota.test.utils.arping as arp
import iota.test.utils.host as host_utils
import iota.harness.infra.utils.parser as parser
import iota.test.apulu.utils.connectivity as conn_utils
import iota.test.apulu.utils.learn as learn_utils
import pdb

# DOL
import infra.common.objects as objects
import apollo.config.utils as utils

lmap_client = config_api.GetObjClient('lmapping')
rmap_client = config_api.GetObjClient('rmapping')
vnic_client = config_api.GetObjClient('vnic')
subnet_client = config_api.GetObjClient('subnet')
intf_client = config_api.GetObjClient('interface')


def __add_ip_to_workloads(workload, ip_addr, secondary=False):
    """
    Adds IP addresses to workload Interface.
    """
    if not api.IsSimulation():
        req = api.Trigger_CreateAllParallelCommandsRequest()
    else:
        req = api.Trigger_CreateExecuteCommandsRequest(serial=False)
Beispiel #8
0
def UpdateConfigAfterUpgrade(tc):
    api.Logger.info("Updating Host Interfaces after Upgrade")
    SubnetClient = config_api.GetObjClient('subnet')
    for n in tc.Nodes:
        SubnetClient.UpdateHostInterfaces(n)
Beispiel #9
0
def __update_host_interfaces():
    interfaceClient = config_api.GetObjClient('interface')
    nodes = api.GetNaplesHostnames()
    for targetNode in nodes:
        interfaceClient.PublishHostInterfaces(targetNode)
    return
Beispiel #10
0
#! /usr/bin/python3
import random

import iota.harness.api as api
import iota.test.apulu.config.api as config_api
import iota.test.apulu.config.bringup_workloads as wl_api
import iota.test.apulu.utils.learn as learn_utils
import iota.test.apulu.utils.misc as misc_utils
import iota.test.apulu.config.add_routes as add_routes
import iota.test.apulu.utils.move as move_utils
import iota.harness.infra.store as store
import iota.test.utils.arping as arp

intf_client = config_api.GetObjClient('interface')


def Setup(tc):
    # select one of the LearnIP objects from dictionary
    tc.node = random.choice(api.GetNaplesHostnames())
    tc.learn_mac_obj = random.choice(learn_utils.GetLearnMACObjects(tc.node))
    tc.subnet = tc.learn_mac_obj.SUBNET
    if api.IsDryrun():
        tc.hostifidx = 'dryrun'
    else:
        tc.hostifidx = tc.subnet.HostIfIdx[0]
    tc.wload = config_api.FindWorkloadByVnic(tc.learn_mac_obj)
    api.Logger.debug("Chosen subnet %s" % tc.subnet)
    return api.types.status.SUCCESS


def __modify_workload_interface(tc):
Beispiel #11
0
def GetLearnMACObjects(node):
    return list(config_api.GetObjClient('vnic').Objects(node))
Beispiel #12
0
#! /usr/bin/python3
import iota.harness.api as api
import iota.test.apulu.config.api as config_api
import iota.test.apulu.utils.connectivity as conn_utils
import iota.test.apulu.utils.move as move_utils
import iota.test.apulu.utils.flow as flow_utils
import iota.test.apulu.utils.learn_stats as stats_utils
import iota.test.apulu.utils.learn as learn_utils
import iota.test.apulu.utils.misc as misc_utils

from apollo.config.resmgr import client as ResmgrClient
from iota.harness.infra.glopts import GlobalOptions

subnet_client = config_api.GetObjClient('subnet')


def __get_skip(subnet_mov, mac_mov, ip_mov):

    # TODO: Need topology change to support this.
    # if "inter-subnet" in subnet_mov and (mac_mov != "same" or ip_mov in ["subset", "all"])
    #
    #     return True
    if "inter-subnet" in subnet_mov:
        api.Logger.info(
            f"Skipping subnet_mov: {subnet_mov}, mac_mov: {mac_mov}, ip_mov: {ip_mov}"
        )
        return True
    else:
        return False