mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Removes deprecated code from bigip_monitor_tcp (#34520)
* Removes deprecated code from bigip_monitor_tcp The deprecated code was moved into its own modules. We let it lay here for a release, and now I'm removing it. * Fixing upstreaming tests
This commit is contained in:
parent
f189106ef6
commit
803e4124b6
2 changed files with 108 additions and 1148 deletions
|
@ -22,26 +22,16 @@ from ansible.module_utils.f5_utils import AnsibleF5Client
|
|||
from ansible.module_utils.f5_utils import F5ModuleError
|
||||
|
||||
try:
|
||||
from library.bigip_monitor_tcp import ParametersTcp
|
||||
from library.bigip_monitor_tcp import ParametersHalfOpen
|
||||
from library.bigip_monitor_tcp import ParametersEcho
|
||||
from library.bigip_monitor_tcp import Parameters
|
||||
from library.bigip_monitor_tcp import ModuleManager
|
||||
from library.bigip_monitor_tcp import ArgumentSpec
|
||||
from library.bigip_monitor_tcp import TcpManager
|
||||
from library.bigip_monitor_tcp import TcpEchoManager
|
||||
from library.bigip_monitor_tcp import TcpHalfOpenManager
|
||||
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_monitor_tcp import ParametersTcp
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import ParametersHalfOpen
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import ParametersEcho
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import Parameters
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import ModuleManager
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import ArgumentSpec
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import TcpManager
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import TcpEchoManager
|
||||
from ansible.modules.network.f5.bigip_monitor_tcp import TcpHalfOpenManager
|
||||
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||
from units.modules.utils import set_module_args
|
||||
except ImportError:
|
||||
|
@ -85,7 +75,7 @@ class TestParameters(unittest.TestCase):
|
|||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersTcp(args)
|
||||
p = Parameters(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.send == 'this is a send string'
|
||||
|
@ -113,7 +103,7 @@ class TestParameters(unittest.TestCase):
|
|||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersTcp(args)
|
||||
p = Parameters(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.send == 'this is a send string'
|
||||
|
@ -138,7 +128,7 @@ class TestParameters(unittest.TestCase):
|
|||
timeUntilUp=60
|
||||
)
|
||||
|
||||
p = ParametersTcp(args)
|
||||
p = Parameters(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.send == 'this is a send string'
|
||||
|
@ -182,14 +172,10 @@ class TestManager(unittest.TestCase):
|
|||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(side_effect=[False, True])
|
||||
tm.create_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(side_effect=[False, True])
|
||||
mm.create_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -213,7 +199,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -221,13 +207,9 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -243,7 +225,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -251,14 +233,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -275,7 +253,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -283,14 +261,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -307,7 +281,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -315,14 +289,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
@ -340,7 +310,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -348,14 +318,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
@ -372,7 +338,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -380,14 +346,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -404,7 +366,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -412,14 +374,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -436,7 +394,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -444,14 +402,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
@ -468,7 +422,7 @@ class TestManager(unittest.TestCase):
|
|||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
|
@ -476,635 +430,10 @@ class TestManager(unittest.TestCase):
|
|||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['time_until_up'] == 300
|
||||
|
||||
|
||||
class TestParametersEcho(unittest.TestCase):
|
||||
def test_module_parameters(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
parent='parent',
|
||||
ip='10.10.10.10',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersEcho(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.type == 'tcp_echo'
|
||||
assert p.destination == '10.10.10.10'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
def test_module_parameters_ints_as_strings(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
parent='parent',
|
||||
ip='10.10.10.10',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
interval='20',
|
||||
timeout='30',
|
||||
time_until_up='60',
|
||||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersEcho(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.type == 'tcp_echo'
|
||||
assert p.destination == '10.10.10.10'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
def test_api_parameters(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
defaultsFrom='/Common/parent',
|
||||
destination='10.10.10.10',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
timeUntilUp=60
|
||||
)
|
||||
|
||||
p = ParametersEcho(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.type == 'tcp_echo'
|
||||
assert p.destination == '10.10.10.10'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
|
||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
||||
return_value=True)
|
||||
class TestManagerEcho(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.spec = ArgumentSpec()
|
||||
|
||||
def test_create_monitor(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
ip='10.10.10.10',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
type='TTYPE_TCP_ECHO',
|
||||
parent_partition='Common',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(side_effect=[False, True])
|
||||
tm.create_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['parent'] == '/Common/tcp_echo'
|
||||
|
||||
def test_create_monitor_idempotent(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
ip='10.10.10.10',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
type='TTYPE_TCP_ECHO',
|
||||
parent_partition='Common',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is False
|
||||
|
||||
def test_update_interval(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=10,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['interval'] == 10
|
||||
|
||||
def test_update_interval_larger_than_existing_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=30,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
||||
assert "must be less than" in str(ex)
|
||||
|
||||
def test_update_interval_larger_than_new_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=10,
|
||||
timeout=5,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
||||
assert "must be less than" in str(ex)
|
||||
|
||||
def test_update_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
timeout=300,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
assert results['changed'] is True
|
||||
assert results['timeout'] == 300
|
||||
|
||||
def test_update_time_until_up(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
time_until_up=300,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_ECHO',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersEcho(load_fixture('load_ltm_monitor_tcp_echo.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpEchoManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['time_until_up'] == 300
|
||||
|
||||
|
||||
class TestParametersHalfOpen(unittest.TestCase):
|
||||
def test_module_parameters(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
parent='parent',
|
||||
ip='10.10.10.10',
|
||||
port=80,
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersHalfOpen(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.port == 80
|
||||
assert p.type == 'tcp_half_open'
|
||||
assert p.destination == '10.10.10.10:80'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
def test_module_parameters_ints_as_strings(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
parent='parent',
|
||||
ip='10.10.10.10',
|
||||
port=80,
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
interval='20',
|
||||
timeout='30',
|
||||
time_until_up='60',
|
||||
partition='Common'
|
||||
)
|
||||
|
||||
p = ParametersHalfOpen(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.port == 80
|
||||
assert p.type == 'tcp_half_open'
|
||||
assert p.destination == '10.10.10.10:80'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
def test_api_parameters(self):
|
||||
args = dict(
|
||||
name='foo',
|
||||
defaultsFrom='/Common/parent',
|
||||
destination='10.10.10.10:80',
|
||||
interval=20,
|
||||
timeout=30,
|
||||
timeUntilUp=60
|
||||
)
|
||||
|
||||
p = ParametersHalfOpen(args)
|
||||
assert p.name == 'foo'
|
||||
assert p.parent == '/Common/parent'
|
||||
assert p.ip == '10.10.10.10'
|
||||
assert p.port == 80
|
||||
assert p.type == 'tcp_half_open'
|
||||
assert p.destination == '10.10.10.10:80'
|
||||
assert p.interval == 20
|
||||
assert p.timeout == 30
|
||||
assert p.time_until_up == 60
|
||||
|
||||
|
||||
@patch('ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root',
|
||||
return_value=True)
|
||||
class TestManagerHalfOpen(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.spec = ArgumentSpec()
|
||||
|
||||
def test_create_monitor(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
ip='10.10.10.10',
|
||||
port=80,
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
parent_partition='Common',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(side_effect=[False, True])
|
||||
tm.create_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['parent'] == '/Common/tcp_half_open'
|
||||
|
||||
def test_create_monitor_idempotent(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
ip='10.10.10.10',
|
||||
port=80,
|
||||
interval=20,
|
||||
timeout=30,
|
||||
time_until_up=60,
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
parent_partition='Common',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is False
|
||||
|
||||
def test_update_interval(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=10,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['interval'] == 10
|
||||
|
||||
def test_update_interval_larger_than_existing_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=30,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
||||
assert "must be less than" in str(ex)
|
||||
|
||||
def test_update_interval_larger_than_new_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
interval=10,
|
||||
timeout=5,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
with pytest.raises(F5ModuleError) as ex:
|
||||
mm.exec_module()
|
||||
|
||||
assert "must be less than" in str(ex)
|
||||
|
||||
def test_update_timeout(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
timeout=300,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
assert results['changed'] is True
|
||||
assert results['timeout'] == 300
|
||||
|
||||
def test_update_time_until_up(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo',
|
||||
time_until_up=300,
|
||||
parent_partition='Common',
|
||||
type='TTYPE_TCP_HALF_OPEN',
|
||||
server='localhost',
|
||||
password='password',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ParametersHalfOpen(load_fixture('load_ltm_monitor_tcp_half_open.json'))
|
||||
client = AnsibleF5Client(
|
||||
argument_spec=self.spec.argument_spec,
|
||||
supports_check_mode=self.spec.supports_check_mode,
|
||||
f5_product_name=self.spec.f5_product_name
|
||||
)
|
||||
|
||||
# Override methods in the specific type of manager
|
||||
tm = TcpHalfOpenManager(client)
|
||||
tm.exists = Mock(return_value=True)
|
||||
tm.read_current_from_device = Mock(return_value=current)
|
||||
tm.update_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
mm.exists = Mock(return_value=True)
|
||||
mm.read_current_from_device = Mock(return_value=current)
|
||||
mm.update_on_device = Mock(return_value=True)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue