Skip to content

Commit

Permalink
Fix irror (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
indraniBh committed Aug 22, 2024
1 parent 50c401d commit 353f90b
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 319 deletions.
5 changes: 2 additions & 3 deletions do.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def test(card="novus100g"):
coverage_threshold = 0
username = os.environ.get("TEST_USERNAME", "admin")
psd = os.environ.get("TEST_PASSWORD", "admin")

if card == "novus100g":
args = [
'--location="https://snappi-ixn-ci-novus100g.lbj.is.keysight.com:5000"',
'--location=\
"https://snappi-ixn-ci-novus100g.lbj.is.keysight.com:5000"',
(
'--ports="snappi-ixn-ci-novus100g.lbj.is.keysight.com;1;1'
" snappi-ixn-ci-novus100g.lbj.is.keysight.com;1;2"
Expand All @@ -65,7 +65,6 @@ def test(card="novus100g"):
]
else:
raise Exception("card %s is not supported for testing" % card)

args += [
"--ext=ixnetwork",
"--username=" + username,
Expand Down
7 changes: 5 additions & 2 deletions snappi_ixnetwork/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def config(self):
imports.append(capture)
for capture_item in self._api.snappi_config.captures:
if capture_item.format == "pcap":
self._api.warning("pcap format is not supported for IxNetwork, setting capture format to pcapng")
self._api.warning(
"pcap format is not supported for IxNetwork, \
setting capture format to pcapng"
)
capture_item.format = "pcapng"
if capture_item.port_names is None:
continue
Expand Down Expand Up @@ -348,7 +351,7 @@ def results(self, request):
self._api._request("POST", url, payload)

path = "%s/capture" % self._api._ixnetwork.Globals.PersistencePath
#Todo: Revert dc to merged capture after fix is available in 9.20
# Todo: Revert dc to merged capture after fix is available in 9.20
url = "%s/files?absolute=%s&filename=%s" % (
self._api._ixnetwork.href,
path,
Expand Down
37 changes: 17 additions & 20 deletions snappi_ixnetwork/device/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from snappi_ixnetwork.logger import get_ixnet_logger

__all__ = ['Base', 'MultiValue', 'PostCalculated']

__all__ = ["Base", "MultiValue", "PostCalculated"]


class MultiValue(object):
Expand All @@ -25,9 +24,7 @@ def value(self):
value = None
if self._key == "connectedTo":
value = self._ref_obj.get("xpath")
self.logger.debug("Post Calculated %s - %s" % (
self._key, value
))
self.logger.debug("Post Calculated %s - %s" % (self._key, value))
return value


Expand Down Expand Up @@ -57,7 +54,7 @@ def create_node_elemet(self, ixn_obj, node_name, name=None):
- We are setting name as multivalue for farther processing
- It will return that newly created dict
"""
self.logger.debug("Creating node for %s" %node_name)
self.logger.debug("Creating node for %s" % node_name)
node = self.create_node(ixn_obj, node_name)
return self.add_element(node, name)

Expand All @@ -75,14 +72,10 @@ def multivalue(self, value, enum=None):
return MultiValue(value)

def as_multivalue(self, snappi_obj, name, enum=None):
return self.multivalue(
snappi_obj.get(name), enum
)
return self.multivalue(snappi_obj.get(name), enum)

def post_calculated(self, key, ref_ixnobj=None, ixnobj=None):
return PostCalculated(
key, ref_ixnobj, ixnobj
)
return PostCalculated(key, ref_ixnobj, ixnobj)

def get_name(self, object):
name = object.get("name")
Expand Down Expand Up @@ -219,9 +212,9 @@ def config_values(self, ixn_obj, attr_map):
raise NameError("ixn_attr is missing within ", ixn_map)
enum_map = ixn_map.get("enum_map")
values = self.get_multivalues(
snappi_attr, enum_map=enum_map, default=ixn_map.get(
"default_value"
)
snappi_attr,
enum_map=enum_map,
default=ixn_map.get("default_value"),
)
else:
ixn_attr = ixn_map
Expand Down Expand Up @@ -257,7 +250,8 @@ def get_group_nodes(self, tab_name):
Fill with other nodes and active_list as False
It will raise error if all elements are not same length
Finally return list of NodesInfo
It will use some IxNetwork tab which do not have enable/disable features"""
It will use some IxNetwork tab which don't have enable/disable features
"""
dummy_tab = None
for node in self._symmetric_nodes:
dummy_tab = node.get(tab_name)
Expand All @@ -279,7 +273,9 @@ def get_group_nodes(self, tab_name):
tab_lengths.append(len(tab))
active_list.append(True)
if len(set(tab_lengths)) > 1:
raise Exception("All the attributes %s should have same lengths" % tab_name)
raise Exception(
"All the attributes %s should have same lengths" % tab_name
)
for idx in range(tab_lengths[-1]):
if len(group_nodes) <= idx:
group_nodes.append([tab[idx]])
Expand All @@ -300,7 +296,8 @@ def get_active_group_nodes(self, tab_name):
tab_name
)
if len(set(active_list)) > 1:
raise Exception("All the attributes %s should configure with equal length"
% tab_name)
raise Exception(
"All the attributes %s should configure with equal length"
% tab_name
)
return node_info_list

59 changes: 37 additions & 22 deletions snappi_ixnetwork/device/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from snappi_ixnetwork.logger import get_ixnet_logger
from snappi_ixnetwork.device.bgpevpn import BgpEvpn


class Bgp(Base):
_BGP = {
"peer_address": "dutIp",
Expand All @@ -10,7 +11,7 @@ class Bgp(Base):
"enum_map": {
"ibgp": "internal",
"ebgp": "external"
}
},
},
}

Expand All @@ -19,7 +20,7 @@ class Bgp(Base):
"keep_alive_interval": "keepaliveTimer",
"update_interval": "updateInterval",
"time_to_live": "ttl",
"md5_key": "md5Key"
"md5_key": "md5Key",
}

_CAPABILITY = {
Expand All @@ -45,7 +46,7 @@ class Bgp(Base):
"ipv6_multicast_mpls_vpn": "ipv6MulticastBgpMplsVpn",
"ipv6_unicast_flow_spec": "capabilityipv6UnicastFlowSpec",
"ipv6_sr_te_policy": "capabilitySRTEPoliciesV6",
"ipv6_unicast_add_path": "capabilityIpv6UnicastAddPath"
"ipv6_unicast_add_path": "capabilityIpv6UnicastAddPath",
}

_CAPABILITY_IPv6 = {
Expand All @@ -57,24 +58,24 @@ class Bgp(Base):
"address": "networkAddress",
"prefix": "prefixLength",
"count": "numberOfAddressesAsy",
"step": "prefixAddrStep"
"step": "prefixAddrStep",
}

_ROUTE = {
"next_hop_mode" : {
"next_hop_mode": {
"ixn_attr": "nextHopType",
"enum_map": {
"local_ip": "sameaslocalip",
"manual": "manually"
}
},
},
"next_hop_address_type": "nextHopIPType",
"next_hop_ipv4_address": "ipv4NextHop",
"next_hop_ipv6_address": "ipv6NextHop",
}

_COMMUNITY = {
"type" : {
"type": {
"ixn_attr": "type",
"enum_map": {
"manual_as_number": "manual",
Expand All @@ -83,10 +84,10 @@ class Bgp(Base):
"no_export_subconfed": "noexport_subconfed",
"llgr_stale": "llgr_stale",
"no_llgr": "no_llgr",
}
},
},
"as_number": "asNumber",
"as_custom": "lastTwoOctets"
"as_custom": "lastTwoOctets",
}

_BGP_AS_MODE = {
Expand Down Expand Up @@ -141,16 +142,18 @@ def _get_interface_info(self):
def _is_valid(self, ip_name):
is_invalid = True
same_dg_ips, invalid_ips = self._get_interface_info()
self.logger.debug("Validating %s against interface same_dg_ips : %s invalid_ips %s" % (
ip_name, same_dg_ips, invalid_ips
))
self.logger.debug(
"Validating %s against interface same_dg_ips : %s invalid_ips %s" %
(ip_name, same_dg_ips, invalid_ips))
if ip_name in invalid_ips:
self._ngpf.api.add_error("Multiple IP {name} on top of name Ethernet".format(
name=ip_name
))
self._ngpf.api.add_error(
"Multiple IP {name} on top of name Ethernet".format
(name=ip_name))
is_invalid = False
if len(same_dg_ips) > 0 and ip_name not in same_dg_ips:
self._ngpf.api.add_error("BGP should not configured on top of different device")
self._ngpf.api.add_error(
"BGP should not configured on top of different device"
)
is_invalid = False
return is_invalid

Expand Down Expand Up @@ -211,7 +214,9 @@ def _config_bgpv4(self, bgp_peers, ixn_ipv4):
self.configure_multivalues(advanced, ixn_bgpv4, Bgp._ADVANCED)
capability = bgp_peer.get("capability")
if capability is not None:
self.configure_multivalues(capability, ixn_bgpv4, Bgp._CAPABILITY)
self.configure_multivalues(
capability, ixn_bgpv4, Bgp._CAPABILITY
)
self._bgp_route_builder(bgp_peer, ixn_bgpv4)
self._bgp_evpn.config(bgp_peer, ixn_bgpv4)

Expand All @@ -231,7 +236,9 @@ def _config_bgpv6(self, bgp_peers, ixn_ipv6):
self.configure_multivalues(advanced, ixn_bgpv6, Bgp._ADVANCED)
capability = bgp_peer.get("capability")
if capability is not None:
self.configure_multivalues(capability, ixn_bgpv6, Bgp._CAPABILITY)
self.configure_multivalues(
capability, ixn_bgpv6, Bgp._CAPABILITY
)
self.configure_multivalues(
capability, ixn_bgpv6, Bgp._CAPABILITY_IPv6
)
Expand Down Expand Up @@ -293,7 +300,9 @@ def _configure_bgpv6_route(self, v6_routes, ixn_bgp):
"connectedTo", ref_ixnobj=ixn_bgp
)
self.configure_multivalues(addresse, ixn_ip_pool, Bgp._IP_POOL)
ixn_route = self.create_node_elemet(ixn_ip_pool, "bgpV6IPRouteProperty")
ixn_route = self.create_node_elemet(
ixn_ip_pool, "bgpV6IPRouteProperty"
)
self._ngpf.set_device_info(route, ixn_ip_pool)
self._configure_route(route, ixn_route)

Expand All @@ -306,7 +315,9 @@ def _configure_route(self, route, ixn_route):
self.logger.debug("Configuring BGP route advance")
multi_exit_discriminator = advanced.get("multi_exit_discriminator")
if multi_exit_discriminator is not None:
ixn_route["enableMultiExitDiscriminator"] = self.multivalue(True)
ixn_route["enableMultiExitDiscriminator"] = self.multivalue(
True
)
ixn_route["multiExitDiscriminator"] = self.multivalue(
multi_exit_discriminator
)
Expand All @@ -321,7 +332,9 @@ def _configure_route(self, route, ixn_route):
ixn_community = self.create_node_elemet(
ixn_route, "bgpCommunitiesList"
)
self.configure_multivalues(community, ixn_community, Bgp._COMMUNITY)
self.configure_multivalues(
community, ixn_community, Bgp._COMMUNITY
)

as_path = route.get("as_path")
if as_path is not None:
Expand All @@ -333,7 +346,9 @@ def _configure_route(self, route, ixn_route):
segments = as_path.get("segments")
ixn_route["noOfASPathSegmentsPerRouteRange"] = len(segments)
for segment in segments:
ixn_segment = self.create_node_elemet(ixn_route, "bgpAsPathSegmentList")
ixn_segment = self.create_node_elemet(
ixn_route, "bgpAsPathSegmentList"
)
ixn_segment["segmentType"] = self.multivalue(
segment.get(type), Bgp._BGP_SEG_TYPE
)
Expand Down
Loading

0 comments on commit 353f90b

Please sign in to comment.