diff --git a/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py b/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py index 07f0dd0e..b4f31903 100644 --- a/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py +++ b/plugins/module_utils/network/iosxr/config/route_maps/route_maps.py @@ -141,6 +141,7 @@ def _compare(self, want, have, policy_name): """ append_endif = False append_nested_endif = False + append_else_once = True order_list = [ "global", "if_", @@ -163,19 +164,29 @@ def _compare(self, want, have, policy_name): if self.state in ["replaced", "overridden"]: # cannot add commands on a adhoc manner it replaces the whole config h_policy_config = {} + render_condition = { "condition": w_policy_config.pop("condition", ""), "condition_type": w_policy_config.pop("conf_type"), - } + } # required to generate conditional statements + + begin_endif = len(self.commands) # handle elseif conditions + + if check_cond.startswith("elseHas_"): + if append_else_once: + self.commands.append("else") + append_else_once = False - begin_endif = len(self.commands) if render_condition.get("condition_type") != "global": - self.addcmd(render_condition, "condition", negate=False) + self.addcmd( + render_condition, "condition", negate=False + ) # condition commands added here if w_policy_config.get("apply"): # as apply is a list w_apply_config = w_policy_config.pop("apply", {}) h_apply_config = h_policy_config.pop("apply", {}) for w_name, w_apply in w_apply_config.items(): h_apply = h_apply_config.pop(w_name, {}) + # apply config added here self.compare( parsers=[ "apply", @@ -183,7 +194,7 @@ def _compare(self, want, have, policy_name): want={"apply": w_apply}, have={"apply": h_apply}, ) - + # route-policy configs added here self.compare(parsers=self.parsers, want=w_policy_config, have=h_policy_config) if len(self.commands) != begin_endif and w_condition.startswith("if_"): # if we want to add any condition we have to start with if @@ -225,17 +236,17 @@ def process_apply(apply_conf): if cond == "global": temp_rmap[cond] = rm_conf else: - temp_rmap[cond + "_" + (rm_conf.get("condition").replace(" ", "_"))] = ( - rm_conf - ) + temp_rmap[ + cond + "_" + (rm_conf.get("condition").replace(" ", "_")) + ] = rm_conf elif cond == "elseif": for elif_config in rm_conf: if elif_config.get("apply"): elif_config["apply"] = process_apply(elif_config.get("apply")) elif_config["conf_type"] = cond - temp_rmap[cond + "_" + (elif_config.get("condition").replace(" ", "_"))] = ( - elif_config - ) + temp_rmap[ + cond + "_" + (elif_config.get("condition").replace(" ", "_")) + ] = elif_config elif ( cond == "else" ): # wanted to do recursion but the overall performance is better this way diff --git a/plugins/modules/iosxr_route_maps.py b/plugins/modules/iosxr_route_maps.py index e8fb3f89..f950d11d 100644 --- a/plugins/modules/iosxr_route_maps.py +++ b/plugins/modules/iosxr_route_maps.py @@ -513,7 +513,863 @@ """ EXAMPLES = """ -#testExamples +# Using merged + +# Before state: +# ------------- +# +# viosxr#show running-config | include route-policy +# + +- name: Merge route-policy configuration + cisco.iosxr.iosxr_route_maps: + state: merged + config: + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: SIMPLE_CONDITION_ROUTE_POLICY + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + set: + community: + additive: true + community_name: (101010:1) + if: + condition: as-path in (ios-regex '_3117_', ios-regex '_600_') + drop: true + name: COMPLEX_ROUTE_POLICY + - else: + global: + pass: true + if: + condition: community matches-any (9119:1001) or community matches-any (11100:1001) + drop: true + name: COMPLEX_CONDITION_ROUTE_POLICY + +# Task Output +# ----------- +# +# before: +# - {} +# commands: +# - route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# - apply A_NEW_ROUTE_POLICY +# - set community (11011:1001) additive +# - set weight 20000 +# - end-policy +# - route-policy SIMPLE_CONDITION_ROUTE_POLICY +# - if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# - pass +# - else +# - drop +# - endif +# - end-policy +# - route-policy COMPLEX_ROUTE_POLICY +# - if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# - drop +# - else +# - if destination in A_RANDOM_POLICY then +# - pass +# - set community (101010:1) additive +# - else +# - drop +# - endif +# - endif +# - end-policy +# - route-policy COMPLEX_CONDITION_ROUTE_POLICY +# - if community matches-any (9119:1001) or community matches-any (11100:1001) then +# - drop +# - else +# - pass +# - endif +# - end-policy +# after: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# - else: +# global: +# pass: true +# if: +# condition: community matches-any (9119:1001) or community matches-any (11100:1001) +# drop: true +# name: COMPLEX_CONDITION_ROUTE_POLICY + +# After state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# if community matches-any (9119:1001) or community matches-any (11100:1001) then +# drop +# else +# pass +# endif +# end-policy + +# Using replaced + +# Before state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# if community matches-any (9119:1001) or community matches-any (11100:1001) then +# drop +# else +# pass +# endif +# end-policy + +- name: Replace the route-policy configuration + cisco.iosxr.iosxr_route_maps: + state: replaced + config: + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: VERY_SIMPLE_CONDITION_ROUTE_POLICY + +# Task Output +# ----------- +# +# before: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# - else: +# global: +# pass: true +# if: +# condition: community matches-any (9119:1001) or community matches-any (11100:1001) +# drop: true +# name: COMPLEX_CONDITION_ROUTE_POLICY +# commands: +# - route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# - if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# - pass +# - else +# - drop +# - endif +# - end-policy +# after: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# - else: +# global: +# pass: true +# if: +# condition: community matches-any (9119:1001) or community matches-any (11100:1001) +# drop: true +# name: COMPLEX_CONDITION_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: VERY_SIMPLE_CONDITION_ROUTE_POLICY + +# After state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# if community matches-any (9119:1001) or community matches-any (11100:1001) then +# drop +# else +# pass +# endif +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy + +# Using overridden + +# Before state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# if community matches-any (9119:1001) or community matches-any (11100:1001) then +# drop +# else +# pass +# endif +# end-policy + +- name: Override the route-policy configuration + cisco.iosxr.iosxr_route_maps: + state: overridden + config: + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: VERY_SIMPLE_CONDITION_ROUTE_POLICY + +# Task Output +# ----------- +# +# before: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# - else: +# global: +# pass: true +# if: +# condition: community matches-any (9119:1001) or community matches-any (11100:1001) +# drop: true +# name: COMPLEX_CONDITION_ROUTE_POLICY +# commands: +# - route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# - if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# - pass +# - else +# - drop +# - endif +# - end-policy +# - no route-policy SIMPLE_CONDITION_ROUTE_POLICY +# - no route-policy COMPLEX_ROUTE_POLICY +# - no route-policy COMPLEX_CONDITION_ROUTE_POLICY +# after: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: VERY_SIMPLE_CONDITION_ROUTE_POLICY + +# After state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy + +# Using purged + +# Before state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy + +- name: Purge or remove route-policy configuration + cisco.iosxr.iosxr_route_maps: + state: purged + config: + - name: COMPLEX_ROUTE_POLICY_NO_EXIST + - name: COMPLEX_ROUTE_POLICY + +# Task Output +# ----------- +# +# before: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# commands: +# - no route-policy COMPLEX_CONDITION_ROUTE_POLICY +# after: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY + +# After state: +# ------------- +# +# viosxr#show running-config | include route-policy +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# +# viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy + +# Using rendered + +- name: Render route-policy configuration + cisco.iosxr.iosxr_route_maps: + state: rendered + config: + - global: + apply: + - route_policy: A_NEW_ROUTE_POLICY + set: + community: + additive: true + community_name: (11011:1001) + weight: 20000 + name: SIMPLE_GLOBAL_ROUTE_POLICY + - else: + global: + drop: true + if: + condition: destination in SIMPLE_CONDITION_ROUTE_POLICY + pass: true + name: SIMPLE_CONDITION_ROUTE_POLICY + - else: + else: + drop: true + if: + condition: destination in A_RANDOM_POLICY + pass: true + set: + community: + additive: true + community_name: (101010:1) + if: + condition: as-path in (ios-regex '_3117_', ios-regex '_600_') + drop: true + name: COMPLEX_ROUTE_POLICY + - else: + global: + pass: true + if: + condition: community matches-any (9119:1001) or community matches-any (11100:1001) + drop: true + name: COMPLEX_CONDITION_ROUTE_POLICY + +# Task Output +# ----------- +# +# rendered: +# - route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# - apply A_NEW_ROUTE_POLICY +# - set community (11011:1001) additive +# - set weight 20000 +# - end-policy +# - route-policy SIMPLE_CONDITION_ROUTE_POLICY +# - if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# - pass +# - else +# - drop +# - endif +# - end-policy +# - route-policy COMPLEX_ROUTE_POLICY +# - if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# - drop +# - else +# - if destination in A_RANDOM_POLICY then +# - pass +# - set community (101010:1) additive +# - else +# - drop +# - endif +# - endif +# - end-policy +# - route-policy COMPLEX_CONDITION_ROUTE_POLICY +# - if community matches-any (9119:1001) or community matches-any (11100:1001) then +# - drop +# - else +# - pass +# - endif +# - end-policy + +# Using parsed + +# File: parsed.cfg +# ---------------- +# +# route-policy SIMPLE_GLOBAL_ROUTE_POLICY +# set weight 20000 +# set local-preference 200 +# set community (11011:1001) additive +# apply A_NEW_ROUTE_POLICY +# end-policy +# ! +# route-policy SIMPLE_CONDITION_ROUTE_POLICY +# if destination in SIMPLE_CONDITION_ROUTE_POLICY then +# pass +# else +# drop +# endif +# end-policy +# ! +# route-policy COMPLEX_ROUTE_POLICY +# if as-path in (ios-regex '_3117_', ios-regex '_600_') then +# drop +# else +# if destination in A_RANDOM_POLICY then +# pass +# set community (101010:1) additive +# set local-preference 200 +# else +# drop +# endif +# endif +# end-policy +# ! +# route-policy COMPLEX_CONDITION_ROUTE_POLICY +# if community matches-any (9119:1001) or community matches-any (11100:1001) then +# drop +# else +# pass +# endif +# end-policy + +- name: Parse the provided configuration + cisco.iosxr.iosxr_route_maps: + running_config: "{{ lookup('file', 'iosxr_route_maps_conf.cfg') }}" + state: parsed + +# Task Output +# ----------- +# +# parsed: +# - global: +# apply: +# - route_policy: A_NEW_ROUTE_POLICY +# set: +# community: +# additive: true +# community_name: (11011:1001) +# weight: 20000 +# name: SIMPLE_GLOBAL_ROUTE_POLICY +# - else: +# global: +# drop: true +# if: +# condition: destination in SIMPLE_CONDITION_ROUTE_POLICY +# pass: true +# name: SIMPLE_CONDITION_ROUTE_POLICY +# - else: +# else: +# drop: true +# if: +# condition: destination in A_RANDOM_POLICY +# pass: true +# set: +# community: +# additive: true +# community_name: (101010:1) +# if: +# condition: as-path in (ios-regex '_3117_', ios-regex '_600_') +# drop: true +# name: COMPLEX_ROUTE_POLICY +# - else: +# global: +# pass: true +# if: +# condition: community matches-any (9119:1001) or community matches-any (11100:1001) +# drop: true +# name: COMPLEX_CONDITION_ROUTE_POLICY """ RETURN = """ diff --git a/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py b/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py index 3a446661..02c4e15c 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_route_maps.py @@ -211,16 +211,10 @@ def test_iosxr_route_maps_merged_simple(self): result = self.execute_module(changed=True) commands = [ - "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", - "if destination in ILOVEROUTEPOLICY then", - "drop", - "pass", - "set community (24680:1) additive", - "endif", - "end-policy", "route-policy TEST_ROUTE_POLICY_BIT_SIMPLE", "if destination in TESTROUTES then", "drop", + "else", "if as-path in (ios-regex '_8888_') then", "pass", "else", @@ -228,6 +222,14 @@ def test_iosxr_route_maps_merged_simple(self): "endif", "endif", "end-policy", + "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", + "if destination in ILOVEROUTEPOLICY then", + "drop", + "else", + "pass", + "set community (24680:1) additive", + "endif", + "end-policy", ] self.assertEqual(sorted(result["commands"]), sorted(commands)) @@ -381,6 +383,25 @@ def test_iosxr_route_maps_merged_complex(self): result = self.execute_module(changed=True) commands = [ + "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", + "if destination in ILOVEROUTEPOLICY then", + "drop", + "else", + "pass", + "set community (24680:1) additive", + "endif", + "end-policy", + "route-policy TEST_ROUTE_POLICY_BIT_SIMPLE", + "if destination in TESTROUTES then", + "drop", + "else", + "if as-path in (ios-regex '_8888_') then", + "pass", + "else", + "drop", + "endif", + "endif", + "end-policy", "route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX", "if destination in DEFAULT then", "set spf-priority critical high medium", @@ -394,6 +415,7 @@ def test_iosxr_route_maps_merged_complex(self): "apply DUMMY-RMP-3", "set tag 2323", "set weight 23", + "else", "if destination in TEST-INTERNAL-IFCONDITION then", "unsuppress-route", "elseif destination in TEST-INTERNAL_ELIFCONDITION then", @@ -407,23 +429,6 @@ def test_iosxr_route_maps_merged_complex(self): "endif", "endif", "end-policy", - "route-policy TEST_ROUTE_POLICY_BIT_SIMPLE", - "if destination in TESTROUTES then", - "drop", - "if as-path in (ios-regex '_8888_') then", - "pass", - "else", - "drop", - "endif", - "endif", - "end-policy", - "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", - "if destination in ILOVEROUTEPOLICY then", - "drop", - "pass", - "set community (24680:1) additive", - "endif", - "end-policy", ] self.assertEqual(sorted(result["commands"]), sorted(commands)) @@ -590,6 +595,7 @@ def test_iosxr_route_maps_overridden(self): "apply DUMMY-RMP-3", "set tag 2323", "set weight 23", + "else", "if destination in TEST-INTERNAL-IFCONDITION then", "unsuppress-route", "elseif destination in TEST-INTERNAL_ELIFCONDITION then", @@ -606,6 +612,7 @@ def test_iosxr_route_maps_overridden(self): "route-policy TEST_ROUTE_POLICY_BIT_SIMPLE", "if destination in TESTROUTES then", "drop", + "else", "if as-path in 15446 then", "pass", "else", @@ -616,6 +623,7 @@ def test_iosxr_route_maps_overridden(self): "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", "if destination in ILOVEROUTEPOLICY then", "drop", + "else", "pass", "set community (24680:1) additive", "endif", @@ -787,6 +795,7 @@ def test_iosxr_route_maps_replaced(self): "apply DUMMY-RMP-3", "set tag 2323", "set weight 23", + "else", "if destination in TEST-INTERNAL-IFCONDITION then", "unsuppress-route", "elseif destination in TEST-INTERNAL_ELIFCONDITION then", @@ -803,6 +812,7 @@ def test_iosxr_route_maps_replaced(self): "route-policy TEST_ROUTE_POLICY_BIT_SIMPLE", "if destination in TESTROUTES then", "drop", + "else", "if as-path in 15446 then", "pass", "else", @@ -813,6 +823,7 @@ def test_iosxr_route_maps_replaced(self): "route-policy TEST_ROUTE_POLICY_SUPER_SIMPLE", "if destination in ILOVEROUTEPOLICY then", "drop", + "else", "pass", "set community (24680:1) additive", "endif",