Correct unit tests and module fixes (#44488)

Cleanup of unit tests. Modules fixes in iapp_template nad profile_dns
to support unit tests.
This commit is contained in:
Tim Rupp 2018-08-21 22:02:11 -04:00 committed by GitHub
parent bda074d34e
commit 49f34fec13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 251 additions and 163 deletions

View file

@ -115,6 +115,7 @@ try:
from library.module_utils.network.f5.common import AnsibleF5Parameters from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import fq_name
try: try:
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
from f5.utils.iapp_parser import NonextantTemplateNameException from f5.utils.iapp_parser import NonextantTemplateNameException
@ -127,6 +128,7 @@ except ImportError:
from ansible.module_utils.network.f5.common import AnsibleF5Parameters from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import fq_name
try: try:
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
from f5.utils.iapp_parser import NonextantTemplateNameException from f5.utils.iapp_parser import NonextantTemplateNameException
@ -163,8 +165,7 @@ class Parameters(AnsibleF5Parameters):
if self._values['content'] is None: if self._values['content'] is None:
return None return None
result = self._squash_template_name_prefix() result = self._squash_template_name_prefix()
if self._values['name']: result = self._replace_template_name(result)
result = self._replace_template_name(result)
return result return result
@property @property
@ -206,7 +207,13 @@ class Parameters(AnsibleF5Parameters):
:return string :return string
""" """
pattern = r'sys\s+application\s+template\s+[^ ]+' pattern = r'sys\s+application\s+template\s+[^ ]+'
replace = 'sys application template {0}'.format(self._values['name'])
if self._values['name']:
name = self._values['name']
else:
name = self._get_template_name()
replace = 'sys application template {0}'.format(fq_name(self.partition, name))
return re.sub(pattern, replace, template) return re.sub(pattern, replace, template)
def _get_template_name(self): def _get_template_name(self):
@ -214,7 +221,7 @@ class Parameters(AnsibleF5Parameters):
# using it in all cases to get the name of an iApp. So we'll use this # using it in all cases to get the name of an iApp. So we'll use this
# pattern for now and file a bug with the F5 SDK # pattern for now and file a bug with the F5 SDK
pattern = r'sys\s+application\s+template\s+(?P<path>\/[^\{}"\'*?|#]+\/)?(?P<name>[^\{}"\'*?|#]+)' pattern = r'sys\s+application\s+template\s+(?P<path>\/[^\{}"\'*?|#]+\/)?(?P<name>[^\{}"\'*?|#]+)'
matches = re.search(pattern, self.content) matches = re.search(pattern, self._values['content'])
try: try:
result = matches.group('name').strip() result = matches.group('name').strip()
except IndexError: except IndexError:
@ -392,6 +399,8 @@ class ModuleManager(object):
result = output.commandResult result = output.commandResult
if 'Syntax Error' in result: if 'Syntax Error' in result:
raise F5ModuleError(output.commandResult) raise F5ModuleError(output.commandResult)
if 'ERROR' in result:
raise F5ModuleError(output.commandResult)
def remove(self): def remove(self):
if self.module.check_mode: if self.module.check_mode:

View file

@ -17,7 +17,7 @@ DOCUMENTATION = r'''
module: bigip_profile_dns module: bigip_profile_dns
short_description: Manage DNS profiles on a BIG-IP short_description: Manage DNS profiles on a BIG-IP
description: description:
- Manage DNS profiles on a BIG-IP. There are a variety of DNS profiles, each with their - Manage DNS profiles on a BIG-IP. Many DNS profiles; each with their
own adjustments to the standard C(dns) profile. Users of this module should be aware own adjustments to the standard C(dns) profile. Users of this module should be aware
that many of the adjustable knobs have no module default. Instead, the default is that many of the adjustable knobs have no module default. Instead, the default is
assigned by the BIG-IP system itself which, in most cases, is acceptable. assigned by the BIG-IP system itself which, in most cases, is acceptable.
@ -35,8 +35,8 @@ options:
enable_dns_express: enable_dns_express:
description: description:
- Specifies whether the DNS Express engine is enabled. - Specifies whether the DNS Express engine is enabled.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(yes). is provided by the parent profile.
- The DNS Express engine receives zone transfers from the authoritative DNS server - The DNS Express engine receives zone transfers from the authoritative DNS server
for the zone. If the C(enable_zone_transfer) setting is also C(yes) on this profile, for the zone. If the C(enable_zone_transfer) setting is also C(yes) on this profile,
the DNS Express engine also responds to zone transfer requests made by the nameservers the DNS Express engine also responds to zone transfer requests made by the nameservers
@ -46,8 +46,8 @@ options:
description: description:
- Specifies whether the system answers zone transfer requests for a DNS zone created - Specifies whether the system answers zone transfer requests for a DNS zone created
on the system. on the system.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(no). is provided by the parent profile.
- The C(enable_dns_express) and C(enable_zone_transfer) settings on a DNS profile - The C(enable_dns_express) and C(enable_zone_transfer) settings on a DNS profile
affect how the system responds to zone transfer requests. affect how the system responds to zone transfer requests.
- When the C(enable_dns_express) and C(enable_zone_transfer) settings are both C(yes), - When the C(enable_dns_express) and C(enable_zone_transfer) settings are both C(yes),
@ -61,21 +61,21 @@ options:
description: description:
- Specifies whether the system signs responses with DNSSEC keys and replies to DNSSEC - Specifies whether the system signs responses with DNSSEC keys and replies to DNSSEC
specific queries (e.g., DNSKEY query type). specific queries (e.g., DNSKEY query type).
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(yes). is provided by the parent profile.
type: bool type: bool
enable_gtm: enable_gtm:
description: description:
- Specifies whether the system uses Global Traffic Manager to manage the response. - Specifies whether the system uses Global Traffic Manager to manage the response.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(yes). is provided by the parent profile.
type: bool type: bool
process_recursion_desired: process_recursion_desired:
description: description:
- Specifies whether to process client-side DNS packets with Recursion Desired set in - Specifies whether to process client-side DNS packets with Recursion Desired set in
the header. the header.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(yes). is provided by the parent profile.
- If set to C(no), processing of the packet is subject to the unhandled-query-action - If set to C(no), processing of the packet is subject to the unhandled-query-action
option. option.
type: bool type: bool
@ -84,15 +84,54 @@ options:
- Specifies whether the system forwards non-wide IP queries to the local BIND server - Specifies whether the system forwards non-wide IP queries to the local BIND server
on the BIG-IP system. on the BIG-IP system.
- For best performance, disable this setting when using a DNS cache. - For best performance, disable this setting when using a DNS cache.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(yes). is provided by the parent profile.
type: bool type: bool
enable_dns_firewall: enable_dns_firewall:
description: description:
- Specifies whether DNS firewall capability is enabled. - Specifies whether DNS firewall capability is enabled.
- When creating a new profile, if this parameter is not specified, the default is - When creating a new profile, if this parameter is not specified, the default
C(no). is provided by the parent profile.
type: bool type: bool
enable_cache:
description:
- Specifies whether the system caches DNS responses.
- When creating a new profile, if this parameter is not specified, the default
is provided by the parent profile.
- When C(yes), the BIG-IP system caches DNS responses handled by the virtual
servers associated with this profile. When you enable this setting, you must
also specify a value for C(cache_name).
- When C(no), the BIG-IP system does not cache DNS responses handled by the
virtual servers associated with this profile. However, the profile retains
the association with the DNS cache in the C(cache_name) parameter. Disable
this setting when you want to debug the system.
type: bool
version_added: 2.7
cache_name:
description:
- Specifies the user-created cache that the system uses to cache DNS responses.
- When you select a cache for the system to use, you must also set C(enable_dns_cache)
to C(yes)
version_added: 2.7
unhandled_query_action:
description:
- Specifies the action to take when a query does not match a Wide IP or a DNS Express Zone.
- When C(allow), the BIG-IP system forwards queries to a DNS server or pool member.
If a pool is not associated with a listener and the Use BIND Server on BIG-IP setting
is set to Enabled, requests are forwarded to the local BIND server.
- When C(drop), the BIG-IP system does not respond to the query.
- When C(reject), the BIG-IP system returns the query with the REFUSED return code.
- When C(hint), the BIG-IP system returns the query with a list of root name servers.
- When C(no-error), the BIG-IP system returns the query with the NOERROR return code.
- When creating a new profile, if this parameter is not specified, the default
is provided by the parent profile.
choices:
- allow
- drop
- reject
- hint
- no-error
version_added: 2.7
partition: partition:
description: description:
- Device partition to manage resources on. - Device partition to manage resources on.
@ -132,37 +171,52 @@ enable_dns_express:
description: Whether DNS Express is enabled on the resource or not. description: Whether DNS Express is enabled on the resource or not.
returned: changed returned: changed
type: bool type: bool
sample: True sample: yes
enable_zone_transfer: enable_zone_transfer:
description: Whether zone transfer are enabled on the resource or not. description: Whether zone transfer are enabled on the resource or not.
returned: changed returned: changed
type: bool type: bool
sample: False sample: no
enable_dnssec: enable_dnssec:
description: Whether DNSSEC is enabled on the resource or not. description: Whether DNSSEC is enabled on the resource or not.
returned: changed returned: changed
type: bool type: bool
sample: False sample: no
enable_gtm: enable_gtm:
description: Whether GTM is used to manage the resource or not. description: Whether GTM is used to manage the resource or not.
returned: changed returned: changed
type: bool type: bool
sample: True sample: yes
process_recursion_desired: process_recursion_desired:
description: Whether client-side DNS packets are processed with Recursion Desired set. description: Whether client-side DNS packets are processed with Recursion Desired set.
returned: changed returned: changed
type: bool type: bool
sample: True sample: yes
use_local_bind: use_local_bind:
description: Whether non-wide IP queries are forwarded to the local BIND server or not. description: Whether non-wide IP queries are forwarded to the local BIND server or not.
returned: changed returned: changed
type: bool type: bool
sample: False sample: no
enable_dns_firewall: enable_dns_firewall:
description: Whether DNS firewall capability is enabled or not. description: Whether DNS firewall capability is enabled or not.
returned: changed returned: changed
type: bool type: bool
sample: False sample: no
enable_cache:
description: Whether DNS caching is enabled or not.
returned: changed
type: bool
sample: no
cache_name:
description: Name of the cache used by DNS.
returned: changed
type: string
sample: /Common/cache1
unhandled_query_action:
description: What to do with unhandled queries
returned: changed
type: string
sample: allow
''' '''
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -204,6 +258,9 @@ class Parameters(AnsibleF5Parameters):
'processXfr': 'enable_zone_transfer', 'processXfr': 'enable_zone_transfer',
'enableDnsExpress': 'enable_dns_express', 'enableDnsExpress': 'enable_dns_express',
'defaultsFrom': 'parent', 'defaultsFrom': 'parent',
'enableCache': 'enable_cache',
'cache': 'cache_name',
'unhandledQueryAction': 'unhandled_query_action',
} }
api_attributes = [ api_attributes = [
@ -214,7 +271,10 @@ class Parameters(AnsibleF5Parameters):
'enableDnssec', 'enableDnssec',
'processXfr', 'processXfr',
'enableDnsExpress', 'enableDnsExpress',
'defaultsFrom' 'defaultsFrom',
'cache',
'enableCache',
'unhandledQueryAction',
] ]
returnables = [ returnables = [
@ -225,6 +285,9 @@ class Parameters(AnsibleF5Parameters):
'enable_dnssec', 'enable_dnssec',
'enable_zone_transfer', 'enable_zone_transfer',
'enable_dns_express', 'enable_dns_express',
'cache_name',
'enable_cache',
'unhandled_query_action',
] ]
updatables = [ updatables = [
@ -235,6 +298,9 @@ class Parameters(AnsibleF5Parameters):
'enable_dnssec', 'enable_dnssec',
'enable_zone_transfer', 'enable_zone_transfer',
'enable_dns_express', 'enable_dns_express',
'cache_name',
'enable_cache',
'unhandled_query_action',
] ]
@ -271,6 +337,14 @@ class ApiParameters(Parameters):
return True return True
return False return False
@property
def enable_cache(self):
if self._values['enable_cache'] is None:
return None
if self._values['enable_cache'] == 'yes':
return True
return False
@property @property
def enable_dnssec(self): def enable_dnssec(self):
if self._values['enable_dnssec'] is None: if self._values['enable_dnssec'] is None:
@ -295,6 +369,14 @@ class ApiParameters(Parameters):
return True return True
return False return False
@property
def unhandled_query_action(self):
if self._values['unhandled_query_action'] is None:
return None
elif self._values['unhandled_query_action'] == 'noerror':
return 'no-error'
return self._values['unhandled_query_action']
class ModuleParameters(Parameters): class ModuleParameters(Parameters):
@property @property
@ -304,6 +386,15 @@ class ModuleParameters(Parameters):
result = fq_name(self.partition, self._values['parent']) result = fq_name(self.partition, self._values['parent'])
return result return result
@property
def cache_name(self):
if self._values['cache_name'] is None:
return None
if self._values['cache_name'] == '':
return ''
result = fq_name(self.partition, self._values['cache_name'])
return result
class Changes(Parameters): class Changes(Parameters):
def to_return(self): def to_return(self):
@ -350,6 +441,14 @@ class UsableChanges(Changes):
return 'yes' return 'yes'
return 'no' return 'no'
@property
def enable_cache(self):
if self._values['enable_cache'] is None:
return None
if self._values['enable_cache']:
return 'yes'
return 'no'
@property @property
def enable_dnssec(self): def enable_dnssec(self):
if self._values['enable_dnssec'] is None: if self._values['enable_dnssec'] is None:
@ -374,63 +473,17 @@ class UsableChanges(Changes):
return 'yes' return 'yes'
return 'no' return 'no'
@property
def unhandled_query_action(self):
if self._values['unhandled_query_action'] is None:
return None
elif self._values['unhandled_query_action'] == 'no-error':
return 'noerror'
return self._values['unhandled_query_action']
class ReportableChanges(Changes): class ReportableChanges(Changes):
@property pass
def enable_dns_firewall(self):
if self._values['enable_dns_firewall'] is None:
return None
if self._values['enable_dns_firewall'] == 'yes':
return True
return False
@property
def use_local_bind(self):
if self._values['use_local_bind'] is None:
return None
if self._values['use_local_bind'] == 'yes':
return True
return False
@property
def process_recursion_desired(self):
if self._values['process_recursion_desired'] is None:
return None
if self._values['process_recursion_desired'] == 'yes':
return True
return False
@property
def enable_gtm(self):
if self._values['enable_gtm'] is None:
return None
if self._values['enable_gtm'] == 'yes':
return True
return False
@property
def enable_dnssec(self):
if self._values['enable_dnssec'] is None:
return None
if self._values['enable_dnssec'] == 'yes':
return True
return False
@property
def enable_zone_transfer(self):
if self._values['enable_zone_transfer'] is None:
return None
if self._values['enable_zone_transfer'] == 'yes':
return True
return False
@property
def enable_dns_express(self):
if self._values['enable_dns_express'] is None:
return None
if self._values['enable_dns_express'] == 'yes':
return True
return False
class Difference(object): class Difference(object):
@ -540,6 +593,11 @@ class ModuleManager(object):
self.have = self.read_current_from_device() self.have = self.read_current_from_device()
if not self.should_update(): if not self.should_update():
return False return False
if self.changes.enable_cache is True or self.have.enable_cache is True:
if not self.have.cache_name or self.changes.cache_name == '':
raise F5ModuleError(
"To enable DNS cache, a DNS cache must be specified."
)
if self.module.check_mode: if self.module.check_mode:
return True return True
self.update_on_device() self.update_on_device()
@ -554,22 +612,12 @@ class ModuleManager(object):
return True return True
def create(self): def create(self):
if self.want.enable_dns_express is None:
self.want.update({'enable_dns_express': True})
if self.want.enable_zone_transfer is None:
self.want.update({'enable_zone_transfer': False})
if self.want.enable_dnssec is None:
self.want.update({'enable_dnssec': True})
if self.want.enable_gtm is None:
self.want.update({'enable_gtm': True})
if self.want.process_recursion_desired is None:
self.want.update({'process_recursion_desired': True})
if self.want.use_local_bind is None:
self.want.update({'use_local_bind': True})
if self.want.enable_dns_firewall is None:
self.want.update({'enable_dns_firewall': False})
self._set_changed_options() self._set_changed_options()
if self.want.enable_cache is True and not self.want.cache_name:
raise F5ModuleError(
"You must specify a 'cache_name' when creating a DNS profile that sets 'enable_cache' to 'yes'."
)
if self.module.check_mode: if self.module.check_mode:
return True return True
self.create_on_device() self.create_on_device()
@ -626,6 +674,11 @@ class ArgumentSpec(object):
process_recursion_desired=dict(type='bool'), process_recursion_desired=dict(type='bool'),
use_local_bind=dict(type='bool'), use_local_bind=dict(type='bool'),
enable_dns_firewall=dict(type='bool'), enable_dns_firewall=dict(type='bool'),
enable_cache=dict(type='bool'),
unhandled_query_action=dict(
choices=['allow', 'drop', 'reject', 'hint', 'no-error']
),
cache_name=dict(),
state=dict( state=dict(
default='present', default='present',
choices=['present', 'absent'] choices=['present', 'absent']

File diff suppressed because one or more lines are too long

View file

@ -101,7 +101,7 @@ class TestManager(unittest.TestCase):
set_module_args(dict( set_module_args(dict(
sync_device_to_group='yes', sync_device_to_group='yes',
device_group="foo", device_group="foo",
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -171,6 +171,7 @@ class TestModuleManager(unittest.TestCase):
# Override methods to force specific logic in the module to happen # Override methods to force specific logic in the module to happen
mm.exists = Mock(side_effect=[True, False]) mm.exists = Mock(side_effect=[True, False])
mm.remove_from_device = Mock(return_value=True) mm.remove_from_device = Mock(return_value=True)
mm.remove_members_in_group_from_device = Mock(return_value=True)
results = mm.exec_module() results = mm.exec_module()
assert results['changed'] is True assert results['changed'] is True

View file

@ -115,7 +115,7 @@ class TestManager(unittest.TestCase):
def test_get_typed_pool_facts(self, *args): def test_get_typed_pool_facts(self, *args):
set_module_args(dict( set_module_args(dict(
include='pool', include='pool',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -130,7 +130,7 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict( set_module_args(dict(
name='foo', name='foo',
preferred_lb_method='round-robin', preferred_lb_method='round-robin',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -162,7 +162,7 @@ class TestUntypedManager(unittest.TestCase):
preferred_lb_method='topology', preferred_lb_method='topology',
alternate_lb_method='drop-packet', alternate_lb_method='drop-packet',
fallback_lb_method='cpu', fallback_lb_method='cpu',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -197,7 +197,7 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict( set_module_args(dict(
name='foo', name='foo',
state='absent', state='absent',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -233,7 +233,7 @@ class TestTypedManager(unittest.TestCase):
name='foo', name='foo',
preferred_lb_method='round-robin', preferred_lb_method='round-robin',
type='a', type='a',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -266,7 +266,7 @@ class TestTypedManager(unittest.TestCase):
alternate_lb_method='drop-packet', alternate_lb_method='drop-packet',
fallback_lb_method='cpu', fallback_lb_method='cpu',
type='a', type='a',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -302,7 +302,7 @@ class TestTypedManager(unittest.TestCase):
name='foo', name='foo',
type='a', type='a',
state='absent', state='absent',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -126,7 +126,7 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict( set_module_args(dict(
name='foo.baz.bar', name='foo.baz.bar',
lb_method='round-robin', lb_method='round-robin',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -164,7 +164,7 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar', name='foo.baz.bar',
lb_method='round-robin', lb_method='round-robin',
type='a', type='a',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -196,7 +196,7 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar', name='foo.baz.bar',
lb_method='round_robin', lb_method='round_robin',
type='a', type='a',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -228,7 +228,7 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar', name='foo.baz.bar',
lb_method='global_availability', lb_method='global_availability',
type='a', type='a',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -266,7 +266,7 @@ class TestTypedManager(unittest.TestCase):
ratio=10 ratio=10
) )
], ],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -304,7 +304,7 @@ class TestTypedManager(unittest.TestCase):
ratio=10 ratio=10
) )
], ],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -344,7 +344,7 @@ class TestTypedManager(unittest.TestCase):
ratio=100 ratio=100
) )
], ],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -78,7 +78,7 @@ class TestManager(unittest.TestCase):
def test_update_hostname(self, *args): def test_update_hostname(self, *args):
set_module_args(dict( set_module_args(dict(
hostname='foo2.internal.com', hostname='foo2.internal.com',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -21,6 +21,8 @@ from ansible.module_utils.basic import AnsibleModule
try: try:
from library.modules.bigip_iapp_service import Parameters from library.modules.bigip_iapp_service import Parameters
from library.modules.bigip_iapp_service import ApiParameters
from library.modules.bigip_iapp_service import ModuleParameters
from library.modules.bigip_iapp_service import ModuleManager from library.modules.bigip_iapp_service import ModuleManager
from library.modules.bigip_iapp_service import ArgumentSpec from library.modules.bigip_iapp_service import ArgumentSpec
from library.module_utils.network.f5.common import F5ModuleError from library.module_utils.network.f5.common import F5ModuleError
@ -29,6 +31,8 @@ try:
except ImportError: except ImportError:
try: try:
from ansible.modules.network.f5.bigip_iapp_service import Parameters from ansible.modules.network.f5.bigip_iapp_service import Parameters
from ansible.modules.network.f5.bigip_iapp_service import ApiParameters
from ansible.modules.network.f5.bigip_iapp_service import ModuleParameters
from ansible.modules.network.f5.bigip_iapp_service import ModuleManager from ansible.modules.network.f5.bigip_iapp_service import ModuleManager
from ansible.modules.network.f5.bigip_iapp_service import ArgumentSpec from ansible.modules.network.f5.bigip_iapp_service import ArgumentSpec
from ansible.module_utils.network.f5.common import F5ModuleError from ansible.module_utils.network.f5.common import F5ModuleError
@ -63,13 +67,13 @@ class TestParameters(unittest.TestCase):
def test_module_parameters_keys(self): def test_module_parameters_keys(self):
args = load_fixture('create_iapp_service_parameters_f5_http.json') args = load_fixture('create_iapp_service_parameters_f5_http.json')
p = Parameters(params=args) p = ModuleParameters(params=args)
# Assert the top-level keys # Assert the top-level keys
assert p.name == 'http_example' assert p.name == 'http_example'
assert p.partition == 'Common' assert p.partition == 'Common'
assert p.template == '/Common/f5.http' assert p.template == '/Common/f5.http'
assert p.deviceGroup == 'none' assert p.device_group is None
assert p.inheritedTrafficGroup == 'true' assert p.inheritedTrafficGroup == 'true'
assert p.inheritedDevicegroup == 'true' assert p.inheritedDevicegroup == 'true'
assert p.traffic_group == '/Common/traffic-group-local-only' assert p.traffic_group == '/Common/traffic-group-local-only'
@ -119,7 +123,7 @@ class TestParameters(unittest.TestCase):
def test_module_parameters_variables(self): def test_module_parameters_variables(self):
args = load_fixture('create_iapp_service_parameters_f5_http.json') args = load_fixture('create_iapp_service_parameters_f5_http.json')
p = Parameters(params=args) p = ModuleParameters(params=args)
assert 'variables' in p._values assert 'variables' in p._values
assert len(p.variables) == 34 assert len(p.variables) == 34
@ -142,13 +146,13 @@ class TestParameters(unittest.TestCase):
args = dict( args = dict(
strict_updates=True strict_updates=True
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'enabled' assert p.strict_updates == 'enabled'
args = dict( args = dict(
strict_updates=False strict_updates=False
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'disabled' assert p.strict_updates == 'disabled'
def test_module_strict_updates_override_from_top_level(self): def test_module_strict_updates_override_from_top_level(self):
@ -158,7 +162,7 @@ class TestParameters(unittest.TestCase):
strictUpdates='disabled' strictUpdates='disabled'
) )
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'enabled' assert p.strict_updates == 'enabled'
args = dict( args = dict(
@ -167,7 +171,7 @@ class TestParameters(unittest.TestCase):
strictUpdates='enabled' strictUpdates='enabled'
) )
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'disabled' assert p.strict_updates == 'disabled'
def test_module_strict_updates_only_parameters(self): def test_module_strict_updates_only_parameters(self):
@ -176,7 +180,7 @@ class TestParameters(unittest.TestCase):
strictUpdates='disabled' strictUpdates='disabled'
) )
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'disabled' assert p.strict_updates == 'disabled'
args = dict( args = dict(
@ -184,7 +188,7 @@ class TestParameters(unittest.TestCase):
strictUpdates='enabled' strictUpdates='enabled'
) )
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.strict_updates == 'enabled' assert p.strict_updates == 'enabled'
def test_api_strict_updates_from_top_level(self): def test_api_strict_updates_from_top_level(self):
@ -242,7 +246,7 @@ class TestParameters(unittest.TestCase):
} }
] ]
) )
p = Parameters(params=args) p = ApiParameters(params=args)
assert p.tables[0]['name'] == 'pool__members' assert p.tables[0]['name'] == 'pool__members'
assert p.tables[0]['columnNames'] == ['addr', 'port', 'connection_limit'] assert p.tables[0]['columnNames'] == ['addr', 'port', 'connection_limit']
assert len(p.tables[0]['rows']) == 2 assert len(p.tables[0]['rows']) == 2
@ -255,8 +259,8 @@ class TestParameters(unittest.TestCase):
args = dict( args = dict(
deviceGroup='none' deviceGroup='none'
) )
p = Parameters(params=args) p = ApiParameters(params=args)
assert p.deviceGroup == 'none' assert p.device_group is None
def test_api_parameters_inherited_traffic_group(self): def test_api_parameters_inherited_traffic_group(self):
args = dict( args = dict(
@ -284,7 +288,7 @@ class TestParameters(unittest.TestCase):
template='foo', template='foo',
partition='bar' partition='bar'
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.template == '/bar/foo' assert p.template == '/bar/foo'
def test_module_template_same_partition_full_path(self): def test_module_template_same_partition_full_path(self):
@ -292,7 +296,7 @@ class TestParameters(unittest.TestCase):
template='/bar/foo', template='/bar/foo',
partition='bar' partition='bar'
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.template == '/bar/foo' assert p.template == '/bar/foo'
def test_module_template_different_partition_full_path(self): def test_module_template_different_partition_full_path(self):
@ -300,7 +304,7 @@ class TestParameters(unittest.TestCase):
template='/Common/foo', template='/Common/foo',
partition='bar' partition='bar'
) )
p = Parameters(params=args) p = ModuleParameters(params=args)
assert p.template == '/Common/foo' assert p.template == '/Common/foo'
@ -316,7 +320,7 @@ class TestManager(unittest.TestCase):
template='f5.http', template='f5.http',
parameters=parameters, parameters=parameters,
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -330,6 +334,7 @@ class TestManager(unittest.TestCase):
# Override methods to force specific logic in the module to happen # Override methods to force specific logic in the module to happen
mm.exists = Mock(return_value=False) mm.exists = Mock(return_value=False)
mm.create_on_device = Mock(return_value=True) mm.create_on_device = Mock(return_value=True)
mm.template_exists = Mock(return_value=True)
results = mm.exec_module() results = mm.exec_module()
assert results['changed'] is True assert results['changed'] is True
@ -341,7 +346,7 @@ class TestManager(unittest.TestCase):
template='f5.http', template='f5.http',
parameters=parameters, parameters=parameters,
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -68,6 +68,26 @@ class TestParameters(unittest.TestCase):
p = Parameters(params=args) p = Parameters(params=args)
assert p.name == 'foo.iapp' assert p.name == 'foo.iapp'
def test_module_parameters_custom_name(self):
iapp = load_fixture('create_iapp_template.iapp')
args = dict(
content=iapp,
name='foobar'
)
p = Parameters(params=args)
assert p.name == 'foobar'
assert 'sys application template /Common/foobar' in p.content
def test_module_parameters_custom_partition(self):
iapp = load_fixture('create_iapp_template.iapp')
args = dict(
content=iapp,
partition='foobar'
)
p = Parameters(params=args)
assert p.name == 'foo.iapp'
assert 'sys application template /foobar/foo.iapp' in p.content
class TestManager(unittest.TestCase): class TestManager(unittest.TestCase):
@ -78,7 +98,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module # Configure the arguments that would be sent to the Ansible module
set_module_args(dict( set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'), content=load_fixture('basic-iapp.tmpl'),
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -101,7 +121,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module # Configure the arguments that would be sent to the Ansible module
set_module_args(dict( set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'), content=load_fixture('basic-iapp.tmpl'),
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -130,7 +150,7 @@ class TestManager(unittest.TestCase):
def test_delete_iapp_template(self, *args): def test_delete_iapp_template(self, *args):
set_module_args(dict( set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'), content=load_fixture('basic-iapp.tmpl'),
password='passsword', password='password',
server='localhost', server='localhost',
user='admin', user='admin',
state='absent' state='absent'
@ -153,7 +173,7 @@ class TestManager(unittest.TestCase):
def test_delete_iapp_template_idempotent(self, *args): def test_delete_iapp_template_idempotent(self, *args):
set_module_args(dict( set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'), content=load_fixture('basic-iapp.tmpl'),
password='passsword', password='password',
server='localhost', server='localhost',
user='admin', user='admin',
state='absent' state='absent'

View file

@ -95,7 +95,7 @@ class TestManager(unittest.TestCase):
], ],
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -123,7 +123,7 @@ class TestManager(unittest.TestCase):
], ],
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -153,7 +153,7 @@ class TestManager(unittest.TestCase):
], ],
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -182,7 +182,7 @@ class TestManager(unittest.TestCase):
], ],
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -214,7 +214,7 @@ class TestManager(unittest.TestCase):
], ],
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -136,10 +136,10 @@ class TestManager(unittest.TestCase):
results = mm.exec_module() results = mm.exec_module()
assert results['changed'] is True assert results['changed'] is True
assert results['enable_dns_express'] is True assert results['enable_dns_express'] == 'yes'
assert results['enable_zone_transfer'] is True assert results['enable_zone_transfer'] == 'yes'
assert results['enable_dnssec'] is True assert results['enable_dnssec'] == 'yes'
assert results['enable_gtm'] is True assert results['enable_gtm'] == 'yes'
assert results['process_recursion_desired'] is True assert results['process_recursion_desired'] == 'yes'
assert results['use_local_bind'] is True assert results['use_local_bind'] == 'yes'
assert results['enable_dns_firewall'] is True assert results['enable_dns_firewall'] == 'yes'

View file

@ -85,7 +85,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module # Configure the arguments that would be sent to the Ansible module
set_module_args(dict( set_module_args(dict(
module='gtm', module='gtm',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -130,7 +130,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module # Configure the arguments that would be sent to the Ansible module
set_module_args(dict( set_module_args(dict(
module=module, module=module,
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -143,7 +143,7 @@ class TestManager(unittest.TestCase):
state='present', state='present',
traffic_group='traffic-group-local-only', traffic_group='traffic-group-local-only',
vlan='net1', vlan='net1',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -177,7 +177,7 @@ class TestManager(unittest.TestCase):
state='present', state='present',
traffic_group='traffic-group-local-only', traffic_group='traffic-group-local-only',
vlan='net1', vlan='net1',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -106,7 +106,7 @@ class TestManager(unittest.TestCase):
port_misuse_policy='misuse1', port_misuse_policy='misuse1',
partition='Common', partition='Common',
state='present', state='present',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -94,7 +94,7 @@ class TestManager(unittest.TestCase):
name='my-snat-pool', name='my-snat-pool',
state='present', state='present',
members=['10.10.10.10', '20.20.20.20'], members=['10.10.10.10', '20.20.20.20'],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -121,7 +121,7 @@ class TestManager(unittest.TestCase):
name='asdasd', name='asdasd',
state='present', state='present',
members=['1.1.1.1', '2.2.2.2'], members=['1.1.1.1', '2.2.2.2'],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -147,7 +147,7 @@ class TestManager(unittest.TestCase):
name='asdasd', name='asdasd',
state='present', state='present',
members=['30.30.30.30'], members=['30.30.30.30'],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -129,7 +129,7 @@ class TestManager(unittest.TestCase):
def test_update_agent_status_traps(self, *args): def test_update_agent_status_traps(self, *args):
set_module_args(dict( set_module_args(dict(
agent_status_traps='enabled', agent_status_traps='enabled',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -165,7 +165,7 @@ class TestManager(unittest.TestCase):
'foo', 'foo',
'baz.foo.com' 'baz.foo.com'
], ],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -201,7 +201,7 @@ class TestManager(unittest.TestCase):
allowed_addresses=[ allowed_addresses=[
'default' 'default'
], ],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))
@ -233,7 +233,7 @@ class TestManager(unittest.TestCase):
def test_update_allowed_addresses_empty(self, *args): def test_update_allowed_addresses_empty(self, *args):
set_module_args(dict( set_module_args(dict(
allowed_addresses=[''], allowed_addresses=[''],
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -91,7 +91,7 @@ class TestManager(unittest.TestCase):
set_module_args(dict( set_module_args(dict(
auto_check='no', auto_check='no',
auto_phone_home='no', auto_phone_home='no',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -94,7 +94,7 @@ class TestV1Manager(unittest.TestCase):
force='yes', force='yes',
fail_on_missing='no', fail_on_missing='no',
src='remote.ucs', src='remote.ucs',
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))

View file

@ -101,7 +101,7 @@ class TestManager(unittest.TestCase):
def test_wait_already_available(self, *args): def test_wait_already_available(self, *args):
set_module_args(dict( set_module_args(dict(
password='passsword', password='password',
server='localhost', server='localhost',
user='admin' user='admin'
)) ))