ios_user module - implement sshkey option (#38782)

* ios_user module - add sshkey support

* ios_user - Add version_added to sshkey option

* ios_user - pep8 indentation fixes in unit tests

* ios_user - use b64decode method that works on python 2 and 3
This commit is contained in:
Matej Vadnjal 2018-07-19 16:28:52 +02:00 committed by Nathaniel Case
parent 0ca61e9d87
commit 7c318d4e30
6 changed files with 141 additions and 7 deletions

View file

@ -57,16 +57,21 @@ class TestIosUserModule(TestIosModule):
def test_ios_user_delete(self):
set_module_args(dict(name='ansible', state='absent'))
result = self.execute_module(changed=True)
cmd = {
"command": "no username ansible", "answer": "y", "newline": False,
"prompt": "This operation will remove all username related configurations with same name",
}
cmds = [
{
"command": "no username ansible", "answer": "y", "newline": False,
"prompt": "This operation will remove all username related configurations with same name",
},
'ip ssh pubkey-chain',
' no username ansible',
' exit'
]
result_cmd = []
for i in result['commands']:
result_cmd.append(i)
self.assertEqual(result_cmd, [cmd])
self.assertEqual(result_cmd, cmds)
def test_ios_user_password(self):
set_module_args(dict(name='ansible', configured_password='test'))
@ -114,3 +119,16 @@ class TestIosUserModule(TestIosModule):
set_module_args(dict(name='ansible', configured_password='test', update_password='always'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible secret test'])
def test_ios_user_set_sshkey(self):
set_module_args(dict(name='ansible', sshkey='dGVzdA=='))
commands = [
'ip ssh pubkey-chain',
' no username ansible',
' username ansible',
' key-hash ssh-rsa 098F6BCD4621D373CADE4E832627B4F6',
' exit',
' exit'
]
result = self.execute_module(changed=True, commands=commands)
self.assertEqual(result['commands'], commands)