fix nxos_interface_ospf issues (#35988)

* fix nxos_interface_ospf issues

* review comment
pull/36096/head
saichint 7 years ago committed by Trishna Guha
parent 218f008dab
commit eab1b62cd2

@ -95,16 +95,16 @@ options:
message_digest_algorithm_type: message_digest_algorithm_type:
description: description:
- Algorithm used for authentication among neighboring routers - Algorithm used for authentication among neighboring routers
within an area. Valid values is 'md5'. within an area. Valid values are 'md5' and 'default'.
required: false required: false
choices: ['md5'] choices: ['md5', 'default']
default: null default: null
message_digest_encryption_type: message_digest_encryption_type:
description: description:
- Specifies the scheme used for encrypting message_digest_password. - Specifies the scheme used for encrypting message_digest_password.
Valid values are '3des' or 'cisco_type_7' encryption. Valid values are '3des' or 'cisco_type_7' encryption or 'default'.
required: false required: false
choices: ['cisco_type_7','3des'] choices: ['cisco_type_7','3des', 'default']
default: null default: null
message_digest_password: message_digest_password:
description: description:
@ -137,6 +137,8 @@ commands:
import re import re
import struct
import socket
from ansible.module_utils.network.nxos.nxos import get_config, load_config from ansible.module_utils.network.nxos.nxos import get_config, load_config
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -175,6 +177,7 @@ def get_value(arg, config, module):
value = value_list[0] value = value_list[0]
elif arg == 'area': elif arg == 'area':
value = value_list[2] value = value_list[2]
value = normalize_area(value, module)
elif command == 'ip ospf message-digest-key': elif command == 'ip ospf message-digest-key':
value = '' value = ''
if has_command_val: if has_command_val:
@ -359,7 +362,7 @@ def state_absent(module, existing, proposed, candidate):
def normalize_area(area, module): def normalize_area(area, module):
try: try:
area = int(area) area = int(area)
area = '0.0.0.{0}'.format(area) area = socket.inet_ntoa(struct.pack('!L', area))
except ValueError: except ValueError:
splitted_area = area.split('.') splitted_area = area.split('.')
if len(splitted_area) != 4: if len(splitted_area) != 4:
@ -378,8 +381,8 @@ def main():
passive_interface=dict(required=False, type='bool'), passive_interface=dict(required=False, type='bool'),
message_digest=dict(required=False, type='bool'), message_digest=dict(required=False, type='bool'),
message_digest_key_id=dict(required=False, type='str'), message_digest_key_id=dict(required=False, type='str'),
message_digest_algorithm_type=dict(required=False, type='str', choices=['md5']), message_digest_algorithm_type=dict(required=False, type='str', choices=['md5', 'default']),
message_digest_encryption_type=dict(required=False, type='str', choices=['cisco_type_7', '3des']), message_digest_encryption_type=dict(required=False, type='str', choices=['cisco_type_7', '3des', 'default']),
message_digest_password=dict(required=False, type='str', no_log=True), message_digest_password=dict(required=False, type='str', no_log=True),
state=dict(choices=['present', 'absent'], default='present', required=False) state=dict(choices=['present', 'absent'], default='present', required=False)
) )
@ -411,7 +414,7 @@ def main():
for param in ['message_digest_encryption_type', for param in ['message_digest_encryption_type',
'message_digest_algorithm_type', 'message_digest_algorithm_type',
'message_digest_password']: 'message_digest_password']:
if module.params[param] == 'default': if module.params[param] == 'default' and module.params['message_digest_key_id'] != 'default':
module.exit_json(msg='Use message_digest_key_id=default to remove an existing authentication configuration') module.exit_json(msg='Use message_digest_key_id=default to remove an existing authentication configuration')
state = module.params['state'] state = module.params['state']
@ -434,6 +437,8 @@ def main():
proposed[key] = value proposed[key] = value
proposed['area'] = normalize_area(proposed['area'], module) proposed['area'] = normalize_area(proposed['area'], module)
if 'hello_interval' in proposed and proposed['hello_interval'] == '10':
proposed['hello_interval'] = 'default'
candidate = CustomNetworkConfig(indent=3) candidate = CustomNetworkConfig(indent=3)
if state == 'present': if state == 'present':

@ -50,7 +50,7 @@
nxos_interface_ospf: &configure nxos_interface_ospf: &configure
interface: "{{ nxos_int1|upper }}" interface: "{{ nxos_int1|upper }}"
ospf: 1 ospf: 1
area: 1 area: 12345678
cost: 55 cost: 55
passive_interface: true passive_interface: true
hello_interval: 15 hello_interval: 15
@ -75,7 +75,7 @@
nxos_interface_ospf: &modify nxos_interface_ospf: &modify
interface: "{{ testint }}" interface: "{{ testint }}"
ospf: 1 ospf: 1
area: 1 area: 12345678
cost: 66 cost: 66
passive_interface: false passive_interface: false
hello_interval: 17 hello_interval: 17
@ -92,6 +92,70 @@
- assert: *false - assert: *false
- name: default properties
nxos_interface_ospf: &def
interface: "{{ testint }}"
ospf: 1
area: 12345678
cost: default
hello_interval: 10
dead_interval: default
state: present
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_interface_ospf: *def
register: result
- assert: *false
- name: Message_digest properties
nxos_interface_ospf: &md
interface: "{{ testint }}"
ospf: 1
area: 12345678
message_digest: True
message_digest_key_id: 10
message_digest_algorithm_type: md5
message_digest_encryption_type: 3des
message_digest_password: b69f7bc54725b1bfd1ea93afa7b09400
state: present
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_interface_ospf: *md
register: result
- assert: *false
- name: Message_digest defaults
nxos_interface_ospf: &mdd
interface: "{{ testint }}"
ospf: 1
area: 12345678
message_digest: False
message_digest_key_id: default
message_digest_algorithm_type: default
message_digest_encryption_type: default
message_digest_password: default
state: present
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_interface_ospf: *mdd
register: result
- assert: *false
- name: create port-channel and loopback interfaces - name: create port-channel and loopback interfaces
nxos_config: nxos_config:
commands: commands:
@ -117,7 +181,7 @@
nxos_interface_ospf: &configurepc nxos_interface_ospf: &configurepc
interface: Port-channel10 interface: Port-channel10
ospf: 1 ospf: 1
area: 1 area: 429496729
cost: 55 cost: 55
passive_interface: true passive_interface: true
hello_interval: 15 hello_interval: 15
@ -138,7 +202,7 @@
nxos_interface_ospf: &configurepclower nxos_interface_ospf: &configurepclower
interface: port-channel11 interface: port-channel11
ospf: 1 ospf: 1
area: 1 area: 42949672
cost: 55 cost: 55
passive_interface: true passive_interface: true
hello_interval: 15 hello_interval: 15
@ -159,7 +223,7 @@
nxos_interface_ospf: &configurelb nxos_interface_ospf: &configurelb
interface: LOOPBACK55 interface: LOOPBACK55
ospf: 1 ospf: 1
area: 1 area: 4.4.4.4
cost: 55 cost: 55
hello_interval: 15 hello_interval: 15
dead_interval: 75 dead_interval: 75
@ -179,7 +243,7 @@
nxos_interface_ospf: &configurelblower nxos_interface_ospf: &configurelblower
interface: loopback77 interface: loopback77
ospf: 1 ospf: 1
area: 1 area: 429496
cost: 77 cost: 77
hello_interval: 45 hello_interval: 45
dead_interval: 75 dead_interval: 75
@ -199,7 +263,7 @@
nxos_interface_ospf: &removeconfig nxos_interface_ospf: &removeconfig
interface: "{{ testint }}" interface: "{{ testint }}"
ospf: 1 ospf: 1
area: 1 area: 12345678
cost: 55 cost: 55
passive_interface: true passive_interface: true
hello_interval: 15 hello_interval: 15

Loading…
Cancel
Save