diff --git a/changelogs/fragments/319-bgp-communities-no-member-facts-fix.yaml b/changelogs/fragments/319-bgp-communities-no-member-facts-fix.yaml new file mode 100644 index 000000000..df499efda --- /dev/null +++ b/changelogs/fragments/319-bgp-communities-no-member-facts-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - sonic_bgp_communities - Fix incorrect "facts" handling for parsing of a BGP community list configured with an empty "members" list (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/319). diff --git a/plugins/module_utils/network/sonic/facts/bgp_communities/bgp_communities.py b/plugins/module_utils/network/sonic/facts/bgp_communities/bgp_communities.py index a673a7071..ff4827e61 100644 --- a/plugins/module_utils/network/sonic/facts/bgp_communities/bgp_communities.py +++ b/plugins/module_utils/network/sonic/facts/bgp_communities/bgp_communities.py @@ -74,11 +74,14 @@ def get_bgp_communities(self): result['permit'] = True if members: result['type'] = 'expanded' if 'REGEX' in members[0] else 'standard' - if result['type'] == 'expanded': - members = [':'.join(i.split(':')[1:]) for i in members] - members.sort() - result['members'] = {'regex': members} + if result['type'] == 'expanded': + members = [':'.join(i.split(':')[1:]) for i in members] + members.sort() + result['members'] = {'regex': members} else: + result['type'] = 'standard' + + if result['type'] == 'standard': result['local_as'] = None result['no_advertise'] = None result['no_export'] = None diff --git a/tests/regression/roles/sonic_bgp_communities/defaults/main.yml b/tests/regression/roles/sonic_bgp_communities/defaults/main.yml index cf27073be..cf2f82d43 100644 --- a/tests/regression/roles/sonic_bgp_communities/defaults/main.yml +++ b/tests/regression/roles/sonic_bgp_communities/defaults/main.yml @@ -66,8 +66,10 @@ tests: - "13" - name: test2 type: standard + permit: false match: ALL no_export: true + no_peer: true - name: test_case_05 description: Delete1 BGP properties state: deleted diff --git a/tests/unit/modules/network/sonic/fixtures/sonic_bgp_communities.yaml b/tests/unit/modules/network/sonic/fixtures/sonic_bgp_communities.yaml index cb827bfe0..5caca21b4 100644 --- a/tests/unit/modules/network/sonic/fixtures/sonic_bgp_communities.yaml +++ b/tests/unit/modules/network/sonic/fixtures/sonic_bgp_communities.yaml @@ -26,6 +26,14 @@ merged_01: - path: "data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets" response: code: 200 + value: + openconfig-bgp-policy:community-sets: + community-set: + - community-set-name: 'test2' + config: + community-set-name: 'test2' + openconfig-bgp-policy-ext:action: 'PERMIT' + match-set-options: 'ALL' expected_config_requests: - path: "data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets" method: "patch"