From 111ad0edf6307891bf3181e5916477bae91033de Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Mon, 28 Sep 2020 22:22:43 -0400 Subject: [PATCH] eos_acls: Fixed typo and index out of range errors while handling protocol_options (#115) eos_acls: Fixed typo and index out of range errors while handling protocol_options Reviewed-by: https://github.com/apps/ansible-zuul --- .../fragments/115-protocol-options-acls.yaml | 3 + .../network/eos/config/acls/acls.py | 5 +- .../network/eos/facts/acls/acls.py | 57 +++++++++++++++---- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/115-protocol-options-acls.yaml diff --git a/changelogs/fragments/115-protocol-options-acls.yaml b/changelogs/fragments/115-protocol-options-acls.yaml new file mode 100644 index 000000000..3217c857d --- /dev/null +++ b/changelogs/fragments/115-protocol-options-acls.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fixed typo and index out of range errors while handling protocol_options. (https://github.com/ansible-collections/arista.eos/pull/115) diff --git a/plugins/module_utils/network/eos/config/acls/acls.py b/plugins/module_utils/network/eos/config/acls/acls.py index e82821e8b..5e5cf6ce6 100644 --- a/plugins/module_utils/network/eos/config/acls/acls.py +++ b/plugins/module_utils/network/eos/config/acls/acls.py @@ -521,10 +521,11 @@ def add_commands(want): + ace["protocol_options"][proto]["nexthop_group"] ) elif proto == "tcp": - for flag, val in ace["prtocol_options"][proto][ + for flag, val in ace["protocol_options"][proto][ "flags" ].items(): - command = command + " " + val + if val: + command = command + " " + flag if "hop_limit" in ace.keys(): for op, val in ace["hop_limit"].items(): command = command + " hop-limit " + op + " " + val diff --git a/plugins/module_utils/network/eos/facts/acls/acls.py b/plugins/module_utils/network/eos/facts/acls/acls.py index 87626fc95..5ff687805 100644 --- a/plugins/module_utils/network/eos/facts/acls/acls.py +++ b/plugins/module_utils/network/eos/facts/acls/acls.py @@ -156,10 +156,16 @@ def render_config(self, spec, conf): if seq: ace_dict.update({"sequence": dev_config_remainder.pop(0)}) ace_dict.update({"grant": dev_config_remainder.pop(0)}) - if dev_config_remainder[0] == "vlan": + if ( + dev_config_remainder + and dev_config_remainder[0] == "vlan" + ): vlan_str = "" dev_config_remainder.pop(0) - if dev_config_remainder[0] == "inner": + if ( + dev_config_remainder + and dev_config_remainder[0] == "inner" + ): vlan_str = dev_config_remainder.pop(0) + " " vlan_str = ( dev_config_remainder.pop(0) @@ -176,12 +182,18 @@ def render_config(self, spec, conf): src_address = re.search( r"[a-z\d:\.]+", dev_config_remainder[0] ) - if dev_config_remainder[0] == "host": + if ( + dev_config_remainder + and dev_config_remainder[0] == "host" + ): source_dict.update( {"host": dev_config_remainder.pop(1)} ) dev_config_remainder.pop(0) - elif dev_config_remainder[0] == "any": + elif ( + dev_config_remainder + and dev_config_remainder[0] == "any" + ): source_dict.update({"any": True}) dev_config_remainder.pop(0) elif src_prefix: @@ -196,7 +208,10 @@ def render_config(self, spec, conf): {"wildcard_bits": dev_config_remainder.pop(0)} ) if dev_config_remainder: - if dev_config_remainder[0] in operator: + if ( + dev_config_remainder + and dev_config_remainder[0] in operator + ): port_dict = {} src_port = "" src_opr = dev_config_remainder.pop(0) @@ -232,10 +247,16 @@ def render_config(self, spec, conf): dest_address = re.search( r"[a-z\d:\.]+", dev_config_remainder[0] ) - if dev_config_remainder[0] == "host": + if ( + dev_config_remainder + and dev_config_remainder[0] == "host" + ): dest_dict.update({"host": dev_config_remainder.pop(1)}) dev_config_remainder.pop(0) - elif dev_config_remainder[0] == "any": + elif ( + dev_config_remainder + and dev_config_remainder[0] == "any" + ): dest_dict.update({"any": True}) dev_config_remainder.pop(0) elif dest_prefix: @@ -282,7 +303,10 @@ def render_config(self, spec, conf): if protocol == "tcp" or "6": protocol = "tcp" flags_dict = {} - if dev_config_remainder[0] in flags: + if ( + dev_config_remainder + and dev_config_remainder[0] in flags + ): flaglist = dev_config_remainder.copy() for config_remainder in flaglist: if config_remainder not in flags: @@ -303,13 +327,19 @@ def render_config(self, spec, conf): protocol = "icmp" elif protocol == "58": protocol = "icmpv6" - if dev_config_remainder[0] not in others: + if ( + dev_config_remainder + and dev_config_remainder[0] not in others + ): icmp_dict.update({dev_config_remainder[0]: True}) dev_config_remainder.pop(0) if bool(icmp_dict): protocol_option_dict.update({protocol: icmp_dict}) - if protocol == "ip" or "ipv6": - if dev_config_remainder[0] == "nexthop_group": + if protocol in ["ip", "ipv6"]: + if ( + dev_config_remainder + and dev_config_remainder[0] == "nexthop_group" + ): dev_config_remainder.pop(0) ip_dict.update( {"nexthop_group": dev_config_remainder.pop(0)} @@ -320,7 +350,10 @@ def render_config(self, spec, conf): ace_dict.update( {"protocol_options": protocol_option_dict} ) - if dev_config_remainder[0] == "ttl": + if ( + dev_config_remainder + and dev_config_remainder[0] == "ttl" + ): dev_config_remainder.pop(0) op = dev_config_remainder.pop(0) ttl_dict = {op: dev_config_remainder.pop(0)}