Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel ios vrf submode #41659

Merged
merged 20 commits into from
Jul 12, 2018
Merged

Conversation

clementtrebuchet
Copy link
Contributor

@clementtrebuchet clementtrebuchet commented Jun 18, 2018

SUMMARY

This PR include 3 changes:

  • Add the submode configuration feature for the issue The module ios_vrf push only the vrf configuration in global mode. #41191.
  • Fix the indepotence of the module, the parameters both_ * were not idempotent, in what is read in the configuration we have a list with 2 entries (import, export) while the input parameter has only one parameter which will be applied twice. We should be able to mix the parameters for the routes targets , while remaining imdepotent. During the first implementation we did not take this into account, which did not correspond to the reality of the needs in production (to be able to use each parameter indifferently together)
  • Add a try/except to avoid the behavior describe in the issue ios_vrf python error when vrf is already removed and state: absent #41581 when a VRF is already removed and state: absent

Fixes:

ISSUE TYPE
  • Feature Pull Request
  • Bugfix Pull Request
COMPONENT NAME

ios_vrf

ANSIBLE VERSION
(venv) [clement@clemo ansible]$ ansible --version
ansible 2.7.0.dev0 (devel_ios_vrf_submode bae025818a) last updated 2018/06/18 18:44:35 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/clement/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/clement/Documents/PROJECTS/ansible_env_setup/ansible/lib/ansible
  executable location = /home/clement/Documents/PROJECTS/ansible_env_setup/ansible/bin/ansible
  python version = 3.6.5 (default, Mar 29 2018, 18:20:46) [GCC 8.0.1 20180317 (Red Hat 8.0.1-0.19)]
(venv) [clement@clemo ansible]$ 

ADDITIONAL INFORMATION
  • It is now possible to configure the VRF in submode if needed.
GEEK CONSULTING INC.

clementroutertest>
clementroutertest>en
clementroutertest>enable 
Password: 
clementroutertest#sh run
clementroutertest#sh running-config | s vrf
vrf definition management
 !
 address-family ipv4
 exit-address-family
 !
 address-family ipv6
 exit-address-family
vrf definition test_13
 rd 2:100
 !
 address-family ipv4
 exit-address-family
 !
 address-family ipv6
  route-target export 168.0.0.15:100
  route-target export 4:100
  route-target export 2:100
  route-target export 168.0.0.13:100
  route-target import 168.0.0.14:100
  route-target import 2:100
  route-target import 168.0.0.13:100
 exit-address-family
vrf definition test_20
 rd 10:700
 route-target export 2:102
 route-target export 2:103
 route-target export 2:100
 route-target export 2:101
 route-target import 2:104
 route-target import 2:105
 route-target import 2:100
 route-target import 2:101
!        
 address-family ipv4
  route-target export 2:102
  route-target export 2:103
  route-target export 2:100
  route-target export 2:101
  route-target import 2:104
  route-target import 2:105
  route-target import 2:100
  route-target import 2:101
 exit-address-family
 !
 address-family ipv6
  route-target export 2:102
  route-target export 2:103
  route-target export 2:100
  route-target export 2:101
  route-target import 2:104
  route-target import 2:105
  route-target import 2:100
  route-target import 2:101
 exit-address-family
vrf definition test_9
 rd 168.0.0.9:100
 !        
 address-family ipv4
  route-target export 168.0.0.10:100
  route-target export 168.0.0.9:100
  route-target export 3:100
  route-target import 168.0.0.9:100
  route-target import 3:100
  route-target import 168.0.0.10:600
 exit-address-family
 !        
 address-family ipv6
 exit-address-family
---
- name: Set the test_9 vrf route_both_ipv4 with route_export_ipv4 and route_import_ipv4
  ios_vrf:
    name: test_9
    rd: 168.0.0.9:100
    route_import_ipv4:
      - "168.0.0.10:600"
    route_export_ipv4:
      - "168.0.0.10:100"
    route_both_ipv4:
      - "168.0.0.9:100"
      - "3:100"
    state: present

- name: Test idempotence of the VRF module in a loop context
  ios_vrf:
    name: test_bug
    rd: 65004:100
    route_both_ipv4:
      -  65003:100
    route_export_ipv4:
      - "{{ item }}"
    state: present
  loop: "{{ ipv4_import_rd }}"

- name: Set the test_20 vrf route_both, route_export, route_import, route_both_ipv4/v6, route_export_ipv4v6, route_import_ipv4v6.
  ios_vrf:
    name: test_20
    rd: 10:700
    route_both:
      - 2:100
      - 2:101
    route_export:
      - 2:102
      - 2:103
    route_import:
      - 2:104
      - 2:105
    route_both_ipv4:
      - 2:100
      - 2:101
    route_export_ipv4:
      - 2:102
      - 2:103
    route_import_ipv4:
      - 2:104
      - 2:105
    route_both_ipv6:
      - 2:100
      - 2:101
    route_export_ipv6:
      - 2:102
      - 2:103
    route_import_ipv6:
      - 2:104
      - 2:105
    state: present

- name: Set the test_13 vrf route_both_ipv6 and route_import_ipv6 and route_export_ipv6
  ios_vrf:
    name: test_13
    rd: 2:100
    route_import_ipv6:
      - "168.0.0.14:100"
    route_both_ipv6:
      - 2:100
      - "168.0.0.13:100"
    route_export_ipv6:
      - "168.0.0.15:100"
      - 4:100
    state: present

image
image

@ansibot
Copy link
Contributor

ansibot commented Jun 18, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. networking Network category support:core This issue/PR relates to code supported by the Ansible Engineering Team. support:network This issue/PR relates to code supported by the Ansible Network Team. test This PR relates to tests. labels Jun 18, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 18, 2018

The test ansible-test sanity --test pylint [explain] failed with 1 error:

test/units/modules/network/ios/test_ios_vrf.py:191:0: missing-final-newline Final newline missing

The test ansible-test sanity --test pep8 [explain] failed with 11 errors:

lib/ansible/modules/network/ios/ios_vrf.py:184:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:208:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:224:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:690:67: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:158:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:164:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:168:100: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:174:46: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:180:48: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:186:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:191:41: W292 no newline at end of file

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jun 18, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 18, 2018

The test ansible-test sanity --test pylint [explain] failed with 1 error:

test/units/modules/network/ios/test_ios_vrf.py:191:0: missing-final-newline Final newline missing

The test ansible-test sanity --test pep8 [explain] failed with 11 errors:

lib/ansible/modules/network/ios/ios_vrf.py:184:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:208:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:224:1: W293 blank line contains whitespace
lib/ansible/modules/network/ios/ios_vrf.py:702:67: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:158:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:164:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:168:100: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:174:46: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:180:48: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:186:57: E231 missing whitespace after ','
test/units/modules/network/ios/test_ios_vrf.py:191:41: W292 no newline at end of file

click here for bot help

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jun 18, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 18, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/modules/network/ios/ios_vrf.py:224:1: W293 blank line contains whitespace

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jun 18, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 19, 2018

The test ansible-test sanity --test import --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/network/ios/ios_vrf.py:262:0: ImportError: cannot import name OrderedDict

click here for bot help

Copy link
Member

@ganeshrn ganeshrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

subcfg = '\n'.join(subcfg.children)
matches = re.findall(r'route-target\s+export\s+(.+)', subcfg, re.M)
return matches
except KeyError:
Copy link
Contributor

@justjais justjais Jun 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of KeyError, why are you returning empty list. If nothing specific, can you please use pass as used in other Ansible modules as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @justjais

OK done, I was testing the len() of the export_match and the import_match this is why I returned a list. However I changed this and used pass like you asked me.
Thanks for your support.

matches = re.findall(r'route-target\s+import\s+(.+)', subcfg, re.M)
return matches
except KeyError:
return []
Copy link
Contributor

@justjais justjais Jun 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: In case of KeyError, empty list returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @justjais

OK done, I was testing the len() of the export_match and the import_match this is why I returned a list. However I changed this and used pass like you asked me.
Thanks for your support.

subcfg = '\n'.join(subcfg.children)
matches = re.findall(r'route-target\s+export\s+(.+)', subcfg, re.M)
return matches
except KeyError:
Copy link
Contributor

@justjais justjais Jun 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: In case of KeyError, empty list returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @justjais

OK done, I was testing the len() of the export_match and the import_match this is why I returned a list. However I changed this and used pass like you asked me.
Thanks for your support.

set_module_args(dict(name='test_8', rd='5:100', route_both=['3:100', '4:100'], route_export=['3:100', '4:100']))
self.execute_module(failed=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please let me know of the context for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @justjais

you can use all the options [export *, import *, both *] in the same task. There is no more option that is exclusive. This is the way you can configure a router in BGP mode.

@ganeshrn
Copy link
Member

@clementtrebuchet Thank you!

@ganeshrn ganeshrn merged commit 7c97bb5 into ansible:devel Jul 12, 2018
@dagwieers dagwieers added ios Cisco IOS community cisco Cisco technologies labels Feb 27, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 cisco Cisco technologies core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. ios Cisco IOS community module This issue/PR relates to a module. networking Network category support:core This issue/PR relates to code supported by the Ansible Engineering Team. support:network This issue/PR relates to code supported by the Ansible Network Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants