Introduces numerous fixes for bigip command (#34550)

A bug in the parsing of single commands with commas
Token cleanup
Password argument now defaults to false
Addition of coding conventions from v3 conventions
This commit is contained in:
Tim Rupp 2018-01-06 23:23:32 -08:00 committed by GitHub
parent 460deb08cb
commit 2916ff0a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 122 additions and 28 deletions

View file

@ -15,21 +15,23 @@ 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 patch
from ansible.compat.tests.mock import Mock
from ansible.module_utils.f5_utils import AnsibleF5Client
from units.modules.utils import set_module_args
try:
from library.bigip_command import Parameters
from library.bigip_command import ModuleManager
from library.bigip_command import ArgumentSpec
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_command import Parameters
from ansible.modules.network.f5.bigip_command import ModuleManager
from ansible.modules.network.f5.bigip_command import ArgumentSpec
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")
@ -68,10 +70,6 @@ class TestParameters(unittest.TestCase):
class TestManager(unittest.TestCase):
def setUp(self):
self.mock_run_commands = patch('ansible.modules.network.f5.bigip_command.run_commands')
self.run_commands = self.mock_run_commands.start()
self.mock_execute_on_device = patch('ansible.modules.network.f5.bigip_command.ModuleManager.execute_on_device')
self.execute_on_device = self.mock_execute_on_device.start()
self.spec = ArgumentSpec()
def test_run_single_command(self, *args):
@ -90,12 +88,14 @@ class TestManager(unittest.TestCase):
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
mm._run_commands = Mock(return_value=[])
mm.execute_on_device = Mock(return_value=[])
results = mm.exec_module()
assert results['changed'] is False
self.assertEqual(self.run_commands.call_count, 0)
self.assertEqual(self.execute_on_device.call_count, 1)
assert mm._run_commands.call_count == 0
assert mm.execute_on_device.call_count == 1
def test_run_single_modification_command(self, *args):
set_module_args(dict(
@ -113,12 +113,14 @@ class TestManager(unittest.TestCase):
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
mm._run_commands = Mock(return_value=[])
mm.execute_on_device = Mock(return_value=[])
results = mm.exec_module()
assert results['changed'] is True
self.assertEqual(self.run_commands.call_count, 0)
self.assertEqual(self.execute_on_device.call_count, 1)
assert mm._run_commands.call_count == 0
assert mm.execute_on_device.call_count == 1
def test_cli_command(self, *args):
set_module_args(dict(
@ -136,6 +138,38 @@ class TestManager(unittest.TestCase):
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
mm.exec_module()
self.assertEqual(self.run_commands.call_count, 1)
self.assertEqual(self.execute_on_device.call_count, 0)
mm._run_commands = Mock(return_value=[])
mm.execute_on_device = Mock(return_value=[])
results = mm.exec_module()
assert results['changed'] is False
assert mm._run_commands.call_count == 1
assert mm.execute_on_device.call_count == 0
def test_command_with_commas(self, *args):
set_module_args(dict(
commands="""
tmsh create /auth ldap system-auth {bind-dn uid=binduser,
cn=users,dc=domain,dc=com bind-pw $ENCRYPTEDPW check-roles-group
enabled search-base-dn cn=users,dc=domain,dc=com servers add {
ldap.server.com } }"
""",
server='localhost',
user='admin',
password='password'
))
client = AnsibleF5Client(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode,
f5_product_name=self.spec.f5_product_name
)
mm = ModuleManager(client)
mm._run_commands = Mock(return_value=[])
mm.execute_on_device = Mock(return_value=[])
results = mm.exec_module()
assert results['changed'] is True
assert mm._run_commands.call_count == 0
assert mm.execute_on_device.call_count == 1