Skip to content

Commit

Permalink
Fixed regex to support standard naming with port breakout mode and re…
Browse files Browse the repository at this point in the history
…solved other minor bugs (#110)

* Fixed regex to support standard naming with port breakout mode and resolved other minor bugs

* Resolved sanity check error

* Resolved sanity check error

* Reverted l2 interface standard naming bug fix

* Removed dead code

Co-authored-by: Shade Talabi <shade.talabi@dell.com>
  • Loading branch information
stalabi1 and Shade Talabi authored Sep 7, 2022
1 parent 1e8c93e commit 0f0962d
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
with:
path: ansible_collections/dellemc/enterprise_sonic

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
Expand Down
3 changes: 1 addition & 2 deletions plugins/action/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@

class ActionModule(ActionNetworkModule):

def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect
def run(self, task_vars=None):

module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'sonic_config' else False
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/network/sonic/config/bgp/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _state_deleted(self, want, have, diff):

def get_delete_single_bgp_request(self, vrf_name):
delete_path = '%s=%s/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
return({'path': delete_path, 'method': DELETE})
return ({'path': delete_path, 'method': DELETE})

def get_delete_max_med_requests(self, vrf_name, max_med, match):
requests = []
Expand Down
10 changes: 5 additions & 5 deletions plugins/module_utils/network/sonic/config/bgp_af/bgp_af.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def get_modify_address_family_request(self, vrf_name, conf_afi, conf_safi):
afi_safis_load = {'afi-safis': {'afi-safi': [afi_safi_load]}}
pay_load = {'openconfig-network-instance:global': afi_safis_load}

return({"path": url, "method": PATCH, "data": pay_load})
return ({"path": url, "method": PATCH, "data": pay_load})

def get_modify_advertise_request(self, vrf_name, conf_afi, conf_safi, conf_addr_fam):
request = None
Expand Down Expand Up @@ -494,21 +494,21 @@ def get_delete_advertise_default_gw_request(self, vrf_name, conf_afi, conf_safi)
url = '%s=%s/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '/%s=%s/%s/advertise-default-gw' % (self.afi_safi_path, afi_safi, self.l2vpn_evpn_config_path)

return({"path": url, "method": DELETE})
return ({"path": url, "method": DELETE})

def get_delete_dampening_request(self, vrf_name, conf_afi, conf_safi):
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '/%s=%s/openconfig-bgp-ext:route-flap-damping/config/enabled' % (self.afi_safi_path, afi_safi)

return({"path": url, "method": DELETE})
return ({"path": url, "method": DELETE})

def get_delete_advertise_all_vni_request(self, vrf_name, conf_afi, conf_safi):
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '/%s=%s/%s/advertise-all-vni' % (self.afi_safi_path, afi_safi, self.l2vpn_evpn_config_path)

return({"path": url, "method": DELETE})
return ({"path": url, "method": DELETE})

def get_delete_address_family_request(self, vrf_name, conf_afi, conf_safi):
request = None
Expand Down Expand Up @@ -676,7 +676,7 @@ def get_delete_route_map_request(self, vrf_name, conf_afi, conf_redis, conf_rout
dst_protocol = "openconfig-policy-types:BGP"
url = '%s=%s/%s=' % (self.network_instance_path, vrf_name, self.table_connection_path)
url += '%s,%s,%s/config/import-policy=%s' % (src_protocol, dst_protocol, addr_family, conf_route_map)
return({'path': url, 'method': DELETE})
return ({'path': url, 'method': DELETE})

def get_delete_redistribute_requests(self, vrf_name, conf_afi, conf_safi, conf_redis_arr, is_delete_all, mat_redis_arr):
requests = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def get_new_add_request(self, conf):
]
}
}"""
env = jinja2.Environment(autoescape=False, extensions=['jinja2.ext.autoescape'])
env = jinja2.Environment(autoescape=False)
t = env.from_string(payload_template)
intended_payload = t.render(input_data)
ret_payload = json.loads(intended_payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def get_new_add_request(self, conf):
]
}
}"""
env = jinja2.Environment(autoescape=False, extensions=['jinja2.ext.autoescape'])
env = jinja2.Environment(autoescape=False)
t = env.from_string(payload_template)
intended_payload = t.render(input_data)
ret_payload = json.loads(intended_payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def get_delete_specific_bgp_param_request(self, vrf_name, cmd, want_match):
def delete_neighbor_whole_request(self, vrf_name, neighbor):
requests = []
url = '%s=%s/%s/%s=%s/' % (self.network_instance_path, vrf_name, self.protocol_bgp_path, self.neighbor_path, neighbor)
return({'path': url, 'method': DELETE})
return ({'path': url, 'method': DELETE})

def delete_specific_param_request(self, vrf_name, cmd):
requests = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _state_deleted(self, want, have, diff):

def get_trunk_delete_switchport_request(self, config, match_config):
method = "DELETE"
name = config['name'].replace('/', '%2F')
name = config['name']
requests = []
match_trunk = match_config.get('trunk')
if match_trunk:
Expand All @@ -273,7 +273,7 @@ def get_trunk_delete_switchport_request(self, config, match_config):
def get_access_delete_switchport_request(self, config, match_config):
method = "DELETE"
request = None
name = config['name'].replace('/', '%2F')
name = config['name']
match_access = match_config.get('access')
if match_access and match_access.get('vlan') == config['access'].get('vlan'):
key = intf_key
Expand All @@ -291,7 +291,7 @@ def get_delete_all_switchport_requests(self, configs):
url = "data/openconfig-interfaces:interfaces/interface={}/{}/openconfig-vlan:switched-vlan/config"
method = "DELETE"
for intf in configs:
name = intf.get("name").replace('/', '%2F')
name = intf.get("name")
key = intf_key
if name.startswith('PortChannel'):
key = port_chnl_key
Expand Down Expand Up @@ -371,7 +371,7 @@ def get_create_l2_interface_request(self, configs):
url = "data/openconfig-interfaces:interfaces/interface={}/{}/openconfig-vlan:switched-vlan/config"
method = "PATCH"
for conf in configs:
name = conf.get('name').replace('/', '%2F')
name = conf.get('name')
if name == "eth0":
continue
key = intf_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def build_create_payload_member(self, name):
payload_template = """{\n"openconfig-if-aggregate:aggregate-id": "{{name}}"\n}"""
temp = name.split("PortChannel", 1)[1]
input_data = {"name": temp}
env = jinja2.Environment(autoescape=False, extensions=['jinja2.ext.autoescape'])
env = jinja2.Environment(autoescape=False)
t = env.from_string(payload_template)
intended_payload = t.render(input_data)
ret_payload = json.loads(intended_payload)
Expand All @@ -351,7 +351,7 @@ def build_create_payload_portchannel(self, name, mode):
payload_template += """,\n "openconfig-if-aggregation:aggregation": {\n"config": {\n"lag-type": "{{mode}}"\n}\n}\n"""
input_data["mode"] = mode.upper()
payload_template += """}\n]\n}\n}"""
env = jinja2.Environment(autoescape=False, extensions=['jinja2.ext.autoescape'])
env = jinja2.Environment(autoescape=False)
t = env.from_string(payload_template)
intended_payload = t.render(input_data)
ret_payload = json.loads(intended_payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ def update_loop_backs(self, loop_back):
self.loop_backs += "{0},".format(loop_back)

def is_loop_back_already_esist(self, loop_back):
return(",{0},".format(loop_back) in self.loop_backs)
return (",{0},".format(loop_back) in self.loop_backs)
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_l2_interfaces_from_interfaces(self, interfaces):
new_det['name'] = name
if name == "eth0":
continue
if(open_cfg_vlan['config'].get('access-vlan')):
if (open_cfg_vlan['config'].get('access-vlan')):
new_det['access'] = dict({'vlan': open_cfg_vlan['config'].get('access-vlan')})
if(open_cfg_vlan['config'].get('trunk-vlans')):
if (open_cfg_vlan['config'].get('trunk-vlans')):
new_det['trunk'] = {}
new_det['trunk']['allowed_vlans'] = []
new_det['trunk']['allowed_vlans'].extend([dict({'vlan': vlan}) for vlan in open_cfg_vlan['config'].get('trunk-vlans')])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ def update_loop_backs(self, loop_back):
self.loop_backs += "{Loopback},".format(Loopback=loop_back)

def is_loop_back_already_esist(self, loop_back):
return(",{0},".format(loop_back) in self.loop_backs)
return (",{0},".format(loop_back) in self.loop_backs)
2 changes: 1 addition & 1 deletion plugins/module_utils/network/sonic/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import NetworkConfig, ConfigLine

_DEVICE_CONFIGS = {}
STANDARD_ETH_REGEXP = r"Eth\d+/\d+"
STANDARD_ETH_REGEXP = r"Eth\d+(/\d+)+"
PATTERN = re.compile(STANDARD_ETH_REGEXP)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build_interfaces_create_request(interface_name):
method = "PATCH"
payload_template = """{"openconfig-interfaces:interfaces": {"interface": [{"name": "{{interface_name}}", "config": {"name": "{{interface_name}}"}}]}}"""
input_data = {"interface_name": interface_name}
env = jinja2.Environment(autoescape=False, extensions=['jinja2.ext.autoescape'])
env = jinja2.Environment(autoescape=False)
t = env.from_string(payload_template)
intended_payload = t.render(input_data)
ret_payload = json.loads(intended_payload)
Expand Down

0 comments on commit 0f0962d

Please sign in to comment.