This patch fixes a number of outstanding bugs and code convention problems. (#31618)

* documentation was not inline with other Ansible modules
* Python 3 specific imports were missing
* monitor_type is no longer required when creating a new pool; it is now the default.
* A new monitor_type choice of "single" was added for a more intuitive way to specify "a single monitor". It uses "and_list" underneath, but provides additional checks to ensure that you are specifying only a single monitor.
* host and port arguments have been deprecated for now. Please use bigip_pool_member instead.
* 'partition' field was missing from documentation.
* A note that "python 2.7 or greater is required" has been added for those who were not aware that this applies for ALL F5 modules.
* Unit tests were fixed to support the above module
This commit is contained in:
Tim Rupp 2017-10-13 09:47:49 -07:00 committed by GitHub
parent 89428a40b3
commit ecee475a3a
2 changed files with 387 additions and 197 deletions

View file

@ -40,11 +40,13 @@ try:
from library.bigip_pool import Parameters
from library.bigip_pool import ModuleManager
from library.bigip_pool import ArgumentSpec
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
except ImportError:
try:
from ansible.modules.network.f5.bigip_pool import Parameters
from ansible.modules.network.f5.bigip_pool import ModuleManager
from ansible.modules.network.f5.bigip_pool import ArgumentSpec
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
except ImportError:
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
@ -82,10 +84,9 @@ class BigIpObj(object):
class TestParameters(unittest.TestCase):
def test_module_parameters(self):
m = ['/Common/Fake', '/Common/Fake2']
args = dict(
monitor_type='m_of_n',
monitors=m,
monitors=['/Common/Fake', '/Common/Fake2'],
quorum=1,
slow_ramp_time=200,
reselect_tries=5,
@ -97,8 +98,7 @@ class TestParameters(unittest.TestCase):
p = Parameters(args)
assert p.monitor_type == 'm_of_n'
assert p.quorum == 1
assert p.monitors == m
assert p.monitor == 'min 1 of { /Common/Fake /Common/Fake2 }'
assert p.monitors == 'min 1 of { /Common/Fake /Common/Fake2 }'
assert p.host == '192.168.1.1'
assert p.port == 8080
assert p.member_name == '192.168.1.1:8080'
@ -117,7 +117,7 @@ class TestParameters(unittest.TestCase):
)
p = Parameters(args)
assert p.monitor == '/Common/Fake and /Common/Fake2'
assert p.monitors == '/Common/Fake and /Common/Fake2'
assert p.slow_ramp_time == 200
assert p.reselect_tries == 5
assert p.service_down_action == 'drop'
@ -297,12 +297,12 @@ class TestManager(unittest.TestCase):
mm.create_on_device = Mock(return_value=True)
mm.exists = Mock(return_value=False)
msg = "The 'monitor_type' parameter cannot be empty when " \
"'monitors' parameter is specified."
with pytest.raises(F5ModuleError) as err:
mm.exec_module()
results = mm.exec_module()
assert str(err.value) == msg
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == '/Common/tcp and /Common/http'
assert results['monitor_type'] == 'and_list'
def test_create_pool_monitors_missing(self, *args):
set_module_args(dict(
@ -325,7 +325,7 @@ class TestManager(unittest.TestCase):
mm.create_on_device = Mock(return_value=True)
mm.exists = Mock(return_value=False)
msg = "The 'monitor' parameter cannot be empty when " \
msg = "The 'monitors' parameter cannot be empty when " \
"'monitor_type' parameter is specified"
with pytest.raises(F5ModuleError) as err:
mm.exec_module()
@ -385,9 +385,8 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Common/tcp', '/Common/http']
assert results['monitors'] == '/Common/tcp and /Common/http'
assert results['monitor_type'] == 'and_list'
assert results['monitor'] == '/Common/tcp and /Common/http'
def test_create_pool_monitor_m_of_n(self, *args):
set_module_args(dict(
@ -415,9 +414,8 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Common/tcp', '/Common/http']
assert results['monitors'] == 'min 1 of { /Common/tcp /Common/http }'
assert results['monitor_type'] == 'm_of_n'
assert results['monitor'] == 'min 1 of { /Common/tcp /Common/http }'
def test_update_monitors(self, *args):
set_module_args(dict(
@ -452,9 +450,8 @@ class TestManager(unittest.TestCase):
results = mm.exec_module()
assert results['changed'] is True
assert results['monitors'] == ['/Common/http', '/Common/tcp']
assert results['monitor_type'] == 'and_list'
assert results['monitor'] == '/Common/http and /Common/tcp'
assert results['monitors'] == '/Common/http and /Common/tcp'
def test_update_pool_new_member(self, *args):
set_module_args(dict(
@ -552,9 +549,8 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Common/tcp', '/Common/http']
assert results['monitors'] == '/Common/tcp and /Common/http'
assert results['monitor_type'] == 'and_list'
assert results['monitor'] == '/Common/tcp and /Common/http'
def test_create_pool_monitor_m_of_n_no_partition(self, *args):
set_module_args(dict(
@ -581,9 +577,8 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Common/tcp', '/Common/http']
assert results['monitors'] == 'min 1 of { /Common/tcp /Common/http }'
assert results['monitor_type'] == 'm_of_n'
assert results['monitor'] == 'min 1 of { /Common/tcp /Common/http }'
def test_create_pool_monitor_and_list_custom_partition(self, *args):
set_module_args(dict(
@ -610,9 +605,8 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Testing/tcp', '/Testing/http']
assert results['monitors'] == '/Testing/tcp and /Testing/http'
assert results['monitor_type'] == 'and_list'
assert results['monitor'] == '/Testing/tcp and /Testing/http'
def test_create_pool_monitor_m_of_n_custom_partition(self, *args):
set_module_args(dict(
@ -640,6 +634,5 @@ class TestManager(unittest.TestCase):
assert results['changed'] is True
assert results['name'] == 'fake_pool'
assert results['monitors'] == ['/Testing/tcp', '/Testing/http']
assert results['monitors'] == 'min 1 of { /Testing/tcp /Testing/http }'
assert results['monitor_type'] == 'm_of_n'
assert results['monitor'] == 'min 1 of { /Testing/tcp /Testing/http }'