Adding admin option for iosxr_config (#26509)
* Adding admin option for iosxr_config. Adding unit test for new admin option for iosxr_config. Fixes #24308 * Removing space on empty line.pull/4420/head
parent
f31d3ddeb7
commit
58ade65ea6
|
@ -102,9 +102,12 @@ def run_commands(module, commands, check_rc=True):
|
||||||
return responses
|
return responses
|
||||||
|
|
||||||
|
|
||||||
def load_config(module, commands, warnings, commit=False, replace=False, comment=None):
|
def load_config(module, commands, warnings, commit=False, replace=False, comment=None, admin=False):
|
||||||
|
cmd = 'configure terminal'
|
||||||
|
if admin:
|
||||||
|
cmd = 'admin ' + cmd
|
||||||
|
|
||||||
rc, out, err = exec_command(module, 'configure terminal')
|
rc, out, err = exec_command(module, cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg='unable to enter configuration mode', err=to_text(err, errors='surrogate_or_strict'))
|
module.fail_json(msg='unable to enter configuration mode', err=to_text(err, errors='surrogate_or_strict'))
|
||||||
|
|
||||||
|
@ -137,6 +140,7 @@ def load_config(module, commands, warnings, commit=False, replace=False, comment
|
||||||
else:
|
else:
|
||||||
cmd = 'abort'
|
cmd = 'abort'
|
||||||
diff = None
|
diff = None
|
||||||
|
|
||||||
rc, out, err = exec_command(module, cmd)
|
rc, out, err = exec_command(module, cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
exec_command(module, 'abort')
|
exec_command(module, 'abort')
|
||||||
|
|
|
@ -146,6 +146,14 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: 'configured by iosxr_config'
|
default: 'configured by iosxr_config'
|
||||||
version_added: "2.2"
|
version_added: "2.2"
|
||||||
|
admin:
|
||||||
|
description:
|
||||||
|
- Enters into administration configuration mode for making config
|
||||||
|
changes to the device.
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
version_added: "2.4"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
|
@ -218,6 +226,7 @@ def run(module, result):
|
||||||
replace_config = replace == 'config'
|
replace_config = replace == 'config'
|
||||||
path = module.params['parents']
|
path = module.params['parents']
|
||||||
comment = module.params['comment']
|
comment = module.params['comment']
|
||||||
|
admin = module.params['admin']
|
||||||
check_mode = module.check_mode
|
check_mode = module.check_mode
|
||||||
|
|
||||||
candidate = get_candidate(module)
|
candidate = get_candidate(module)
|
||||||
|
@ -243,7 +252,7 @@ def run(module, result):
|
||||||
result['commands'] = commands
|
result['commands'] = commands
|
||||||
|
|
||||||
diff = load_config(module, commands, result['warnings'],
|
diff = load_config(module, commands, result['warnings'],
|
||||||
not check_mode, replace_config, comment)
|
not check_mode, replace_config, comment, admin)
|
||||||
if diff:
|
if diff:
|
||||||
result['diff'] = dict(prepared=diff)
|
result['diff'] = dict(prepared=diff)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
@ -270,6 +279,7 @@ def main():
|
||||||
config=dict(),
|
config=dict(),
|
||||||
backup=dict(type='bool', default=False),
|
backup=dict(type='bool', default=False),
|
||||||
comment=dict(default=DEFAULT_COMMIT_COMMENT),
|
comment=dict(default=DEFAULT_COMMIT_COMMENT),
|
||||||
|
admin=dict(type='bool', default=False)
|
||||||
)
|
)
|
||||||
|
|
||||||
argument_spec.update(iosxr_argument_spec)
|
argument_spec.update(iosxr_argument_spec)
|
||||||
|
|
|
@ -107,6 +107,11 @@ class TestIosxrConfigModule(TestIosxrModule):
|
||||||
set_module_args(dict(lines=lines, force=True))
|
set_module_args(dict(lines=lines, force=True))
|
||||||
self.execute_module(changed=True, commands=lines)
|
self.execute_module(changed=True, commands=lines)
|
||||||
|
|
||||||
|
def test_iosxr_config_admin(self):
|
||||||
|
lines = ['username admin', 'group root-system', 'secret P@ssw0rd']
|
||||||
|
set_module_args(dict(lines=lines, admin=True))
|
||||||
|
self.execute_module(changed=True, commands=lines)
|
||||||
|
|
||||||
def test_iosxr_config_match_none(self):
|
def test_iosxr_config_match_none(self):
|
||||||
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
|
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
|
||||||
parents = ['interface GigabitEthernet0/0']
|
parents = ['interface GigabitEthernet0/0']
|
||||||
|
|
Loading…
Reference in New Issue