1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Various bigip_user fixes (#33495)

There was a bit of refactoring that happened for coding standards.
Additionally, a bug fix was made for changing the root password
This commit is contained in:
Tim Rupp 2017-12-02 20:43:24 -08:00 committed by GitHub
parent bcda0db7db
commit a4aa00f556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 152 additions and 164 deletions

View file

@ -189,8 +189,7 @@ shell:
sample: tmsh
'''
import os
import tempfile
import re
from distutils.version import LooseVersion
from ansible.module_utils.f5_utils import AnsibleF5Client
@ -621,19 +620,16 @@ class RootUserManager(BaseManager):
return True
def update(self):
file = tempfile.NamedTemporaryFile()
self.want.update({'tempfile': os.path.basename(file.name)})
self.upload_password_file_to_device()
self.update_on_device()
self.remove_password_file_from_device()
return True
result = self.update_on_device()
return result
def update_on_device(self):
errors = [
'not confirmed',
'change canceled'
]
cmd = '-c "cat /var/config/rest/downloads/{0} | tmsh modify auth password root"'.format(self.want.tempfile)
escape_patterns = r'([$' + "'])"
errors = ['Bad password', 'password change canceled', 'based on a dictionary word']
content = "{0}\n{0}\n".format(self.want.password_credential)
command = re.sub(escape_patterns, r'\\\1', content)
cmd = '-c "printf \\\"{0}\\\" | tmsh modify auth password root"'.format(command)
try:
output = self.client.api.tm.util.bash.exec_cmd(
'run',
utilCmdArgs=cmd
@ -642,19 +638,9 @@ class RootUserManager(BaseManager):
result = str(output.commandResult)
if any(x for x in errors if x in result):
raise F5ModuleError(result)
def upload_password_file_to_device(self):
content = "{0}\n{0}\n".format(self.want.password_credential)
template = StringIO(content)
upload = self.client.api.shared.file_transfer.uploads
upload.upload_stringio(template, self.want.tempfile)
return True
def remove_password_file_from_device(self):
self.client.api.tm.util.unix_rm.exec_cmd(
'run',
utilCmdArgs='/var/config/rest/downloads/{0}'.format(self.want.tempfile)
)
except iControlUnexpectedHTTPError:
return False
class ArgumentSpec(object):

View file

@ -16,10 +16,10 @@ if sys.version_info < (2, 7):
raise SkipTest("F5 Ansible modules require Python >= 2.7")
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, Mock
from ansible.compat.tests.mock import Mock
from ansible.compat.tests.mock import patch
from ansible.module_utils.f5_utils import AnsibleF5Client
from ansible.module_utils.f5_utils import F5ModuleError
from units.modules.utils import set_module_args
try:
from library.bigip_user import Parameters
@ -28,6 +28,7 @@ try:
from library.bigip_user import UnparitionedManager
from library.bigip_user import PartitionedManager
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from test.unit.modules.utils import set_module_args
except ImportError:
try:
from ansible.modules.network.f5.bigip_user import Parameters
@ -36,6 +37,7 @@ except ImportError:
from ansible.modules.network.f5.bigip_user import UnparitionedManager
from ansible.modules.network.f5.bigip_user import PartitionedManager
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from units.modules.utils import set_module_args
except ImportError:
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")