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
21 changed files with 251 additions and 163 deletions

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(
sync_device_to_group='yes',
device_group="foo",
password='passsword',
password='password',
server='localhost',
user='admin'
))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -68,6 +68,26 @@ class TestParameters(unittest.TestCase):
p = Parameters(params=args)
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):
@@ -78,7 +98,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module
set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'),
password='passsword',
password='password',
server='localhost',
user='admin'
))
@@ -101,7 +121,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module
set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'),
password='passsword',
password='password',
server='localhost',
user='admin'
))
@@ -130,7 +150,7 @@ class TestManager(unittest.TestCase):
def test_delete_iapp_template(self, *args):
set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'),
password='passsword',
password='password',
server='localhost',
user='admin',
state='absent'
@@ -153,7 +173,7 @@ class TestManager(unittest.TestCase):
def test_delete_iapp_template_idempotent(self, *args):
set_module_args(dict(
content=load_fixture('basic-iapp.tmpl'),
password='passsword',
password='password',
server='localhost',
user='admin',
state='absent'

View File

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

View File

@@ -136,10 +136,10 @@ class TestManager(unittest.TestCase):
results = mm.exec_module()
assert results['changed'] is True
assert results['enable_dns_express'] is True
assert results['enable_zone_transfer'] is True
assert results['enable_dnssec'] is True
assert results['enable_gtm'] is True
assert results['process_recursion_desired'] is True
assert results['use_local_bind'] is True
assert results['enable_dns_firewall'] is True
assert results['enable_dns_express'] == 'yes'
assert results['enable_zone_transfer'] == 'yes'
assert results['enable_dnssec'] == 'yes'
assert results['enable_gtm'] == 'yes'
assert results['process_recursion_desired'] == 'yes'
assert results['use_local_bind'] == 'yes'
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
set_module_args(dict(
module='gtm',
password='passsword',
password='password',
server='localhost',
user='admin'
))
@@ -130,7 +130,7 @@ class TestManager(unittest.TestCase):
# Configure the arguments that would be sent to the Ansible module
set_module_args(dict(
module=module,
password='passsword',
password='password',
server='localhost',
user='admin'
))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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