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:
parent
bcda0db7db
commit
a4aa00f556
2 changed files with 152 additions and 164 deletions
|
@ -189,8 +189,7 @@ shell:
|
||||||
sample: tmsh
|
sample: tmsh
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import re
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from ansible.module_utils.f5_utils import AnsibleF5Client
|
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||||
|
@ -621,19 +620,16 @@ class RootUserManager(BaseManager):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
file = tempfile.NamedTemporaryFile()
|
result = self.update_on_device()
|
||||||
self.want.update({'tempfile': os.path.basename(file.name)})
|
return result
|
||||||
self.upload_password_file_to_device()
|
|
||||||
self.update_on_device()
|
|
||||||
self.remove_password_file_from_device()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update_on_device(self):
|
def update_on_device(self):
|
||||||
errors = [
|
escape_patterns = r'([$' + "'])"
|
||||||
'not confirmed',
|
errors = ['Bad password', 'password change canceled', 'based on a dictionary word']
|
||||||
'change canceled'
|
content = "{0}\n{0}\n".format(self.want.password_credential)
|
||||||
]
|
command = re.sub(escape_patterns, r'\\\1', content)
|
||||||
cmd = '-c "cat /var/config/rest/downloads/{0} | tmsh modify auth password root"'.format(self.want.tempfile)
|
cmd = '-c "printf \\\"{0}\\\" | tmsh modify auth password root"'.format(command)
|
||||||
|
try:
|
||||||
output = self.client.api.tm.util.bash.exec_cmd(
|
output = self.client.api.tm.util.bash.exec_cmd(
|
||||||
'run',
|
'run',
|
||||||
utilCmdArgs=cmd
|
utilCmdArgs=cmd
|
||||||
|
@ -642,19 +638,9 @@ class RootUserManager(BaseManager):
|
||||||
result = str(output.commandResult)
|
result = str(output.commandResult)
|
||||||
if any(x for x in errors if x in result):
|
if any(x for x in errors if x in result):
|
||||||
raise F5ModuleError(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
|
return True
|
||||||
|
except iControlUnexpectedHTTPError:
|
||||||
def remove_password_file_from_device(self):
|
return False
|
||||||
self.client.api.tm.util.unix_rm.exec_cmd(
|
|
||||||
'run',
|
|
||||||
utilCmdArgs='/var/config/rest/downloads/{0}'.format(self.want.tempfile)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
|
|
|
@ -16,10 +16,10 @@ if sys.version_info < (2, 7):
|
||||||
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
raise SkipTest("F5 Ansible modules require Python >= 2.7")
|
||||||
|
|
||||||
from ansible.compat.tests import unittest
|
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 AnsibleF5Client
|
||||||
from ansible.module_utils.f5_utils import F5ModuleError
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
from units.modules.utils import set_module_args
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from library.bigip_user import Parameters
|
from library.bigip_user import Parameters
|
||||||
|
@ -28,6 +28,7 @@ try:
|
||||||
from library.bigip_user import UnparitionedManager
|
from library.bigip_user import UnparitionedManager
|
||||||
from library.bigip_user import PartitionedManager
|
from library.bigip_user import PartitionedManager
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from test.unit.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_user import Parameters
|
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 UnparitionedManager
|
||||||
from ansible.modules.network.f5.bigip_user import PartitionedManager
|
from ansible.modules.network.f5.bigip_user import PartitionedManager
|
||||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
from units.modules.utils import set_module_args
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue