1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02: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:
Tim Rupp 2018-01-05 15:22:50 -08:00 committed by GitHub
parent f189106ef6
commit 803e4124b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 1148 deletions

View file

@ -190,6 +190,26 @@ except ImportError:
class Parameters(AnsibleF5Parameters): class Parameters(AnsibleF5Parameters):
api_map = {
'timeUntilUp': 'time_until_up',
'defaultsFrom': 'parent',
'recv': 'receive'
}
api_attributes = [
'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send',
'destination'
]
returnables = [
'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout',
'time_until_up'
]
updatables = [
'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up'
]
def __init__(self, params=None): def __init__(self, params=None):
self._values = defaultdict(lambda: None) self._values = defaultdict(lambda: None)
self._values['__warnings'] = [] self._values['__warnings'] = []
@ -220,6 +240,11 @@ class Parameters(AnsibleF5Parameters):
# If the mapped value is not a @property # If the mapped value is not a @property
self._values[map_key] = v self._values[map_key] = v
def _fqdn_name(self, value):
if value is not None and not value.startswith('/'):
return '/{0}/{1}'.format(self.partition, value)
return value
def to_return(self): def to_return(self):
result = {} result = {}
try: try:
@ -278,58 +303,11 @@ class Parameters(AnsibleF5Parameters):
@property @property
def parent(self): def parent(self):
if self._values['parent_partition']:
if self._values['parent_partition'] is None:
return None
if self._values['parent_partition'].startswith('/'):
partition = os.path.basename(self._values['parent_partition'])
result = '/{0}/{1}'.format(partition, self.type)
else:
result = '/{0}/{1}'.format(self.parent_partition, self.type)
else:
if self._values['parent'] is None: if self._values['parent'] is None:
return None return None
if self._values['parent'].startswith('/'): result = self._fqdn_name(self._values['parent'])
parent = os.path.basename(self._values['parent'])
result = '/{0}/{1}'.format(self.partition, parent)
else:
result = '/{0}/{1}'.format(self.partition, self._values['parent'])
return result return result
@property
def parent_partition(self):
if self._values['parent_partition'] is None:
return None
self._values['__warnings'].append(
dict(
msg="The parent_partition param is deprecated",
version='2.4'
)
)
return self._values['parent_partition']
class ParametersTcp(Parameters):
api_map = {
'timeUntilUp': 'time_until_up',
'defaultsFrom': 'parent',
'recv': 'receive'
}
api_attributes = [
'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'recv', 'send',
'destination'
]
returnables = [
'parent', 'send', 'receive', 'ip', 'port', 'interval', 'timeout',
'time_until_up'
]
updatables = [
'destination', 'send', 'receive', 'interval', 'timeout', 'time_until_up'
]
@property @property
def port(self): def port(self):
if self._values['port'] is None: if self._values['port'] is None:
@ -355,148 +333,6 @@ class ParametersTcp(Parameters):
def type(self): def type(self):
return 'tcp' return 'tcp'
@type.setter
def type(self, value):
if value:
self._values['__warnings'].append(
dict(
msg="The type param is deprecated",
version='2.4'
)
)
class ParametersEcho(Parameters):
api_map = {
'timeUntilUp': 'time_until_up',
'defaultsFrom': 'parent',
'destination': 'ip'
}
api_attributes = [
'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination'
]
returnables = [
'parent', 'ip', 'interval', 'timeout', 'time_until_up'
]
updatables = [
'destination', 'interval', 'timeout', 'time_until_up'
]
@property
def type(self):
return 'tcp_echo'
@type.setter
def type(self, value):
if value:
self._values['__warnings'].append(
dict(
msg="The type param is deprecated",
version='2.4'
)
)
@property
def destination(self):
return self.ip
@destination.setter
def destination(self, value):
self._values['ip'] = value
@property
def send(self):
if self._values['send'] is None:
return None
raise F5ModuleError(
"The 'send' parameter is not available for TCP echo"
)
@property
def receive(self):
if self._values['receive'] is None:
return None
raise F5ModuleError(
"The 'receive' parameter is not available for TCP echo"
)
@property
def port(self):
return None
class ParametersHalfOpen(Parameters):
api_map = {
'timeUntilUp': 'time_until_up',
'defaultsFrom': 'parent'
}
api_attributes = [
'timeUntilUp', 'defaultsFrom', 'interval', 'timeout', 'destination'
]
returnables = [
'parent', 'ip', 'port', 'interval', 'timeout', 'time_until_up'
]
updatables = [
'destination', 'interval', 'timeout', 'time_until_up'
]
@property
def destination(self):
if self.ip is None and self.port is None:
return None
result = '{0}:{1}'.format(self.ip, self.port)
return result
@destination.setter
def destination(self, value):
ip, port = value.split(':')
self._values['ip'] = ip
self._values['port'] = port
@property
def port(self):
if self._values['port'] is None:
return None
elif self._values['port'] == '*':
return '*'
return int(self._values['port'])
@property
def type(self):
return 'tcp_half_open'
@type.setter
def type(self, value):
if value:
self._values['__warnings'].append(
dict(
msg="The type param is deprecated",
version='2.4'
)
)
@property
def send(self):
if self._values['send'] is None:
return None
raise F5ModuleError(
"The 'send' parameter is not available for TCP half open"
)
@property
def receive(self):
if self._values['receive'] is None:
return None
raise F5ModuleError(
"The 'receive' parameter is not available for TCP half open"
)
class Difference(object): class Difference(object):
def __init__(self, want, have=None): def __init__(self, want, have=None):
@ -513,17 +349,13 @@ class Difference(object):
@property @property
def parent(self): def parent(self):
if self.want.parent != self.want.parent: if self.want.parent != self.have.parent:
raise F5ModuleError( raise F5ModuleError(
"The parent monitor cannot be changed" "The parent monitor cannot be changed"
) )
@property @property
def destination(self): def destination(self):
if self.want.type == 'tcp_echo':
if self.want.ip is None:
return None
else:
if self.want.ip is None and self.want.port is None: if self.want.ip is None and self.want.port is None:
return None return None
if self.want.port is None: if self.want.port is None:
@ -569,26 +401,36 @@ class Difference(object):
return attr1 return attr1
# TODO: Remove all of this in 2.5
class ModuleManager(object): class ModuleManager(object):
def __init__(self, client): def __init__(self, client):
self.client = client self.client = client
self.have = None
self.want = Parameters(self.client.module.params)
self.changes = Parameters()
def exec_module(self): def _set_changed_options(self):
type = self.client.module.params.get('type', 'tcp') changed = {}
manager = self.get_manager(type) for key in Parameters.returnables:
return manager.exec_module() if getattr(self.want, key) is not None:
changed[key] = getattr(self.want, key)
if changed:
self.changes = Parameters(changed)
def get_manager(self, type): def _update_changed_options(self):
if type in [None, 'tcp', 'TTYPE_TCP']: diff = Difference(self.want, self.have)
return TcpManager(self.client) updatables = Parameters.updatables
elif type in ['tcp_echo', 'TTYPE_TCP_ECHO']: changed = dict()
return TcpEchoManager(self.client) for k in updatables:
elif type in ['tcp_half_open', 'TTYPE_TCP_HALF_OPEN']: change = diff.compare(k)
return TcpHalfOpenManager(self.client) if change is None:
continue
else:
changed[k] = change
if changed:
self.changes = Parameters(changed)
return True
return False
class BaseManager(object):
def _announce_deprecations(self): def _announce_deprecations(self):
warnings = [] warnings = []
if self.want: if self.want:
@ -662,37 +504,6 @@ class BaseManager(object):
raise F5ModuleError("Failed to delete the monitor.") raise F5ModuleError("Failed to delete the monitor.")
return True return True
class TcpManager(BaseManager):
def __init__(self, client):
self.client = client
self.have = None
self.want = ParametersTcp(self.client.module.params)
self.changes = ParametersTcp()
def _set_changed_options(self):
changed = {}
for key in ParametersTcp.returnables:
if getattr(self.want, key) is not None:
changed[key] = getattr(self.want, key)
if changed:
self.changes = ParametersTcp(changed)
def _update_changed_options(self):
diff = Difference(self.want, self.have)
updatables = ParametersTcp.updatables
changed = dict()
for k in updatables:
change = diff.compare(k)
if change is None:
continue
else:
changed[k] = change
if changed:
self.changes = ParametersTcp(changed)
return True
return False
def _set_default_creation_values(self): def _set_default_creation_values(self):
if self.want.timeout is None: if self.want.timeout is None:
self.want.update({'timeout': 16}) self.want.update({'timeout': 16})
@ -711,7 +522,7 @@ class TcpManager(BaseManager):
partition=self.want.partition partition=self.want.partition
) )
result = resource.attrs result = resource.attrs
return ParametersTcp(result) return Parameters(result)
def exists(self): def exists(self):
result = self.client.api.tm.ltm.monitor.tcps.tcp.exists( result = self.client.api.tm.ltm.monitor.tcps.tcp.exists(
@ -745,199 +556,19 @@ class TcpManager(BaseManager):
result.delete() result.delete()
# TODO: Remove this in 2.5 and put it its own module
class TcpEchoManager(BaseManager):
def __init__(self, client):
self.client = client
self.have = None
self.want = ParametersEcho(self.client.module.params)
self.changes = ParametersEcho()
def _set_default_creation_values(self):
if self.want.timeout is None:
self.want.update({'timeout': 16})
if self.want.interval is None:
self.want.update({'interval': 5})
if self.want.time_until_up is None:
self.want.update({'time_until_up': 0})
if self.want.ip is None:
self.want.update({'ip': '*'})
def _set_changed_options(self):
changed = {}
for key in ParametersEcho.returnables:
if getattr(self.want, key) is not None:
changed[key] = getattr(self.want, key)
if changed:
self.changes = ParametersEcho(changed)
def _update_changed_options(self):
diff = Difference(self.want, self.have)
updatables = ParametersEcho.updatables
changed = dict()
for k in updatables:
change = diff.compare(k)
if change is None:
continue
else:
changed[k] = change
if changed:
self.changes = ParametersEcho(changed)
return True
return False
def read_current_from_device(self):
resource = self.client.api.tm.ltm.monitor.tcp_echos.tcp_echo.load(
name=self.want.name,
partition=self.want.partition
)
result = resource.attrs
return ParametersEcho(result)
def exists(self):
result = self.client.api.tm.ltm.monitor.tcp_echos.tcp_echo.exists(
name=self.want.name,
partition=self.want.partition
)
return result
def update_on_device(self):
params = self.want.api_params()
result = self.client.api.tm.ltm.monitor.tcp_echos.tcp_echo.load(
name=self.want.name,
partition=self.want.partition
)
result.modify(**params)
def create_on_device(self):
params = self.want.api_params()
self.client.api.tm.ltm.monitor.tcp_echos.tcp_echo.create(
name=self.want.name,
partition=self.want.partition,
**params
)
def remove_from_device(self):
result = self.client.api.tm.ltm.monitor.tcp_echos.tcp_echo.load(
name=self.want.name,
partition=self.want.partition
)
if result:
result.delete()
# TODO: Remove this in 2.5 and put it its own module
class TcpHalfOpenManager(BaseManager):
def __init__(self, client):
self.client = client
self.have = None
self.want = ParametersHalfOpen(self.client.module.params)
self.changes = ParametersHalfOpen()
def _set_changed_options(self):
changed = {}
for key in ParametersHalfOpen.returnables:
if getattr(self.want, key) is not None:
changed[key] = getattr(self.want, key)
if changed:
self.changes = ParametersHalfOpen(changed)
def _update_changed_options(self):
diff = Difference(self.want, self.have)
updatables = ParametersHalfOpen.updatables
changed = dict()
for k in updatables:
change = diff.compare(k)
if change is None:
continue
else:
changed[k] = change
if changed:
self.changes = ParametersHalfOpen(changed)
return True
return False
def _set_default_creation_values(self):
if self.want.timeout is None:
self.want.update({'timeout': 16})
if self.want.interval is None:
self.want.update({'interval': 5})
if self.want.time_until_up is None:
self.want.update({'time_until_up': 0})
if self.want.ip is None:
self.want.update({'ip': '*'})
if self.want.port is None:
self.want.update({'port': '*'})
def read_current_from_device(self):
resource = self.client.api.tm.ltm.monitor.tcp_half_opens.tcp_half_open.load(
name=self.want.name,
partition=self.want.partition
)
result = resource.attrs
return ParametersHalfOpen(result)
def exists(self):
result = self.client.api.tm.ltm.monitor.tcp_half_opens.tcp_half_open.exists(
name=self.want.name,
partition=self.want.partition
)
return result
def update_on_device(self):
params = self.want.api_params()
result = self.client.api.tm.ltm.monitor.tcp_half_opens.tcp_half_open.load(
name=self.want.name,
partition=self.want.partition
)
result.modify(**params)
def create_on_device(self):
params = self.want.api_params()
self.client.api.tm.ltm.monitor.tcp_half_opens.tcp_half_open.create(
name=self.want.name,
partition=self.want.partition,
**params
)
def remove_from_device(self):
result = self.client.api.tm.ltm.monitor.tcp_half_opens.tcp_half_open.load(
name=self.want.name,
partition=self.want.partition
)
if result:
result.delete()
class ArgumentSpec(object): class ArgumentSpec(object):
def __init__(self): def __init__(self):
self.supports_check_mode = True self.supports_check_mode = True
self.argument_spec = dict( self.argument_spec = dict(
name=dict(required=True), name=dict(required=True),
parent=dict(default='/Common/tcp'),
# Make this assume "tcp" in the partition specified. The user
# is required to specify the full path if they want to use a different
# partition.
parent=dict(default='tcp'),
send=dict(), send=dict(),
receive=dict(), receive=dict(),
ip=dict(), ip=dict(),
port=dict(type='int'), port=dict(type='int'),
interval=dict(type='int'), interval=dict(type='int'),
timeout=dict(type='int'), timeout=dict(type='int'),
time_until_up=dict(type='int'), time_until_up=dict(type='int')
# Deprecated params
type=dict(
removed_in_version='2.4',
choices=[
'tcp', 'TTYPE_TCP', 'TTYPE_TCP_ECHO', 'TTYPE_TCP_HALF_OPEN'
]
),
parent_partition=dict(
removed_in_version='2.4'
)
) )
self.f5_product_name = 'bigip' self.f5_product_name = 'bigip'
self.mutually_exclusive = [ self.mutually_exclusive = [

View file

@ -22,26 +22,16 @@ from ansible.module_utils.f5_utils import AnsibleF5Client
from ansible.module_utils.f5_utils import F5ModuleError from ansible.module_utils.f5_utils import F5ModuleError
try: try:
from library.bigip_monitor_tcp import ParametersTcp from library.bigip_monitor_tcp import Parameters
from library.bigip_monitor_tcp import ParametersHalfOpen
from library.bigip_monitor_tcp import ParametersEcho
from library.bigip_monitor_tcp import ModuleManager from library.bigip_monitor_tcp import ModuleManager
from library.bigip_monitor_tcp import ArgumentSpec 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 ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from test.unit.modules.utils import set_module_args from test.unit.modules.utils import set_module_args
except ImportError: except ImportError:
try: try:
from ansible.modules.network.f5.bigip_monitor_tcp import ParametersTcp from ansible.modules.network.f5.bigip_monitor_tcp import Parameters
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 ModuleManager 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 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 ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
from units.modules.utils import set_module_args from units.modules.utils import set_module_args
except ImportError: except ImportError:
@ -85,7 +75,7 @@ class TestParameters(unittest.TestCase):
partition='Common' partition='Common'
) )
p = ParametersTcp(args) p = Parameters(args)
assert p.name == 'foo' assert p.name == 'foo'
assert p.parent == '/Common/parent' assert p.parent == '/Common/parent'
assert p.send == 'this is a send string' assert p.send == 'this is a send string'
@ -113,7 +103,7 @@ class TestParameters(unittest.TestCase):
partition='Common' partition='Common'
) )
p = ParametersTcp(args) p = Parameters(args)
assert p.name == 'foo' assert p.name == 'foo'
assert p.parent == '/Common/parent' assert p.parent == '/Common/parent'
assert p.send == 'this is a send string' assert p.send == 'this is a send string'
@ -138,7 +128,7 @@ class TestParameters(unittest.TestCase):
timeUntilUp=60 timeUntilUp=60
) )
p = ParametersTcp(args) p = Parameters(args)
assert p.name == 'foo' assert p.name == 'foo'
assert p.parent == '/Common/parent' assert p.parent == '/Common/parent'
assert p.send == 'this is a send string' assert p.send == 'this is a send string'
@ -182,14 +172,10 @@ class TestManager(unittest.TestCase):
f5_product_name=self.spec.f5_product_name 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 # Override methods to force specific logic in the module to happen
mm = ModuleManager(client) 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() results = mm.exec_module()
@ -213,7 +199,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -221,13 +207,9 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -243,7 +225,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -251,14 +233,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -275,7 +253,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -283,14 +261,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -307,7 +281,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -315,14 +289,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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: with pytest.raises(F5ModuleError) as ex:
mm.exec_module() mm.exec_module()
@ -340,7 +310,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -348,14 +318,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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: with pytest.raises(F5ModuleError) as ex:
mm.exec_module() mm.exec_module()
@ -372,7 +338,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -380,14 +346,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -404,7 +366,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -412,14 +374,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -436,7 +394,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -444,14 +402,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() results = mm.exec_module()
@ -468,7 +422,7 @@ class TestManager(unittest.TestCase):
user='admin' user='admin'
)) ))
current = ParametersTcp(load_fixture('load_ltm_monitor_tcp.json')) current = Parameters(load_fixture('load_ltm_monitor_tcp.json'))
client = AnsibleF5Client( client = AnsibleF5Client(
argument_spec=self.spec.argument_spec, argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode, supports_check_mode=self.spec.supports_check_mode,
@ -476,635 +430,10 @@ class TestManager(unittest.TestCase):
) )
# Override methods in the specific type of manager # 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 = 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() mm.update_on_device = Mock(return_value=True)
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)
results = mm.exec_module() results = mm.exec_module()