Refactors main() function and module manager in multiple modules in line with recent changes (#53983)

Adds variable types to docs
Refactors unit tests to remove deprecated parameters
This commit is contained in:
Wojciech Wypior
2019-03-19 07:12:34 +01:00
committed by Tim Rupp
parent 348b6e7da9
commit 648ac17be3
40 changed files with 497 additions and 470 deletions

View File

@@ -106,9 +106,11 @@ class TestMadmLocationManager(unittest.TestCase):
def test_create_qkview_default_options(self, *args):
set_module_args(dict(
dest='/tmp/foo.qkview',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -144,9 +146,11 @@ class TestBulkLocationManager(unittest.TestCase):
def test_create_qkview_default_options(self, *args):
set_module_args(dict(
dest='/tmp/foo.qkview',
server='localhost',
user='admin',
password='password'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -90,9 +90,11 @@ class TestManager(unittest.TestCase):
name='foo',
line_order=1000,
attribute_string='bar',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -106,14 +106,17 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
name='foo',
id=1234,
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_one_of=self.spec.required_one_of
)
mm = ModuleManager(module=module)

View File

@@ -149,9 +149,11 @@ class TestManager(unittest.TestCase):
state='present',
traffic_group='traffic-group-local-only',
vlan='net1',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -183,9 +185,11 @@ class TestManager(unittest.TestCase):
state='present',
traffic_group='traffic-group-local-only',
vlan='net1',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_tm_net_self.json'))

View File

@@ -109,9 +109,11 @@ class TestManager(unittest.TestCase):
port_misuse_policy='misuse1',
partition='Common',
state='present',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -124,9 +124,11 @@ class TestManager(unittest.TestCase):
from_address='no-reply@mydomain.com',
authentication=True,
partition='Common',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -99,14 +99,17 @@ class TestManager(unittest.TestCase):
name='my-snat-pool',
state='present',
members=['10.10.10.10', '20.20.20.20'],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
mm = ModuleManager(module=module)
@@ -126,16 +129,19 @@ class TestManager(unittest.TestCase):
name='asdasd',
state='present',
members=['1.1.1.1', '2.2.2.2'],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_ltm_snatpool.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
mm = ModuleManager(module=module)
@@ -152,16 +158,19 @@ class TestManager(unittest.TestCase):
name='asdasd',
state='present',
members=['30.30.30.30'],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_ltm_snatpool.json'))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
mm = ModuleManager(module=module)

View File

@@ -72,9 +72,6 @@ class TestParameters(unittest.TestCase):
contact='Alice@foo.org',
device_warning_traps='enabled',
location='Lunar orbit',
password='password',
server='localhost',
user='admin'
)
p = ModuleParameters(params=args)
assert p.agent_status_traps == 'enabled'
@@ -88,9 +85,6 @@ class TestParameters(unittest.TestCase):
agent_status_traps='disabled',
agent_authentication_traps='disabled',
device_warning_traps='disabled',
password='password',
server='localhost',
user='admin'
)
p = ModuleParameters(params=args)
assert p.agent_status_traps == 'disabled'
@@ -132,9 +126,11 @@ class TestManager(unittest.TestCase):
def test_update_agent_status_traps(self, *args):
set_module_args(dict(
agent_status_traps='enabled',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@@ -168,9 +164,11 @@ class TestManager(unittest.TestCase):
'foo',
'baz.foo.com'
],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@@ -204,9 +202,11 @@ class TestManager(unittest.TestCase):
allowed_addresses=[
'default'
],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the
@@ -236,9 +236,11 @@ class TestManager(unittest.TestCase):
def test_update_allowed_addresses_empty(self, *args):
set_module_args(dict(
allowed_addresses=[''],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the

View File

@@ -170,14 +170,17 @@ class TestManager(unittest.TestCase):
ip_version=4,
state='present',
partition='Common',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
m1 = V1Manager(module=module)
@@ -194,6 +197,7 @@ class TestManager(unittest.TestCase):
def test_create_v1_community_1(self, *args):
set_module_args(dict(
name='foo',
version='v1',
community='foo',
source='1.1.1.1',
@@ -203,14 +207,17 @@ class TestManager(unittest.TestCase):
ip_version=4,
state='present',
partition='Common',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
m1 = V1Manager(module=module)
@@ -237,14 +244,17 @@ class TestManager(unittest.TestCase):
snmp_privacy_password='secretsecret',
state='present',
partition='Common',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
m1 = V2Manager(module=module)
@@ -270,14 +280,17 @@ class TestManager(unittest.TestCase):
snmp_privacy_password='secretsecret',
state='present',
partition='Common',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
required_if=self.spec.required_if
)
m1 = V2Manager(module=module)

View File

@@ -79,9 +79,6 @@ class TestParameters(unittest.TestCase):
destination='10.10.10.10',
port=1000,
network='other',
password='password',
server='localhost',
user='admin'
)
p = V2Parameters(params=args)
assert p.name == 'foo'
@@ -99,9 +96,6 @@ class TestParameters(unittest.TestCase):
destination='10.10.10.10',
port=1000,
network='other',
password='password',
server='localhost',
user='admin'
)
p = V1Parameters(params=args)
assert p.name == 'foo'
@@ -142,9 +136,11 @@ class TestManager(unittest.TestCase):
destination='10.10.10.10',
port=1000,
network='other',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -177,9 +173,11 @@ class TestManager(unittest.TestCase):
community='public',
destination='10.10.10.10',
port=1000,
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -100,9 +100,11 @@ class TestManager(unittest.TestCase):
def test_create(self, *args):
set_module_args(dict(
image='/path/to/BIGIP-13.0.0.0.0.1645.iso',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_sys_software_image_1.json'))

View File

@@ -85,9 +85,11 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
image='BIGIP-13.0.0.0.0.1645.iso',
volume='HD1.2',
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters()

View File

@@ -94,9 +94,11 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
auto_check='no',
auto_phone_home='no',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the

View File

@@ -106,9 +106,11 @@ class TestCertificateManager(unittest.TestCase):
name='foo',
content=load_fixture('cert1.crt'),
state='present',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -130,9 +132,11 @@ class TestCertificateManager(unittest.TestCase):
name='foo',
content=load_fixture('chain1.crt'),
state='present',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -93,9 +93,11 @@ class TestModuleManager(unittest.TestCase):
name='foo',
content=load_fixture('cert1.key'),
state='present',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -106,14 +106,18 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
name='foo',
clock_skew=100,
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
argument_spec=self.spec.argument_spec,
supports_check_mode=self.spec.supports_check_mode
supports_check_mode=self.spec.supports_check_mode,
mutually_exclusive=self.spec.mutually_exclusive,
required_together=self.spec.required_together
)
mm = ModuleManager(module=module)

View File

@@ -157,13 +157,15 @@ class TestManager(unittest.TestCase):
def test_create_blackhole(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
destination='10.10.10.10',
netmask='255.255.255.255',
reject='yes'
reject='yes',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -183,13 +185,15 @@ class TestManager(unittest.TestCase):
def test_create_route_to_pool(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
destination='10.10.10.10',
netmask='255.255.255.255',
pool="test-pool"
pool="test-pool",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -210,13 +214,15 @@ class TestManager(unittest.TestCase):
def test_create_route_to_vlan(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
destination='10.10.10.10',
netmask='255.255.255.255',
vlan="test-vlan"
vlan="test-vlan",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -237,11 +243,13 @@ class TestManager(unittest.TestCase):
def test_update_description(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
description='foo description'
description='foo description',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -264,11 +272,13 @@ class TestManager(unittest.TestCase):
def test_update_description_idempotent(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
description='asdasd'
description='asdasd',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -292,10 +302,12 @@ class TestManager(unittest.TestCase):
def test_delete(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='absent'
state='absent',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -316,11 +328,13 @@ class TestManager(unittest.TestCase):
def test_invalid_unknown_params(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
foo="bar"
foo="bar",
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
with patch('ansible.module_utils.f5_utils.AnsibleModule.fail_json') as mo:
mo.return_value = True
@@ -334,14 +348,16 @@ class TestManager(unittest.TestCase):
def test_create_with_route_domain(self, *args):
set_module_args(dict(
name='test-route',
password='admin',
server='localhost',
user='admin',
state='present',
destination='10.10.10.10',
netmask='255.255.255.255',
route_domain=1,
reject='yes'
reject='yes',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -115,9 +115,11 @@ class TestManager(unittest.TestCase):
arp_log_level='debug',
layer4_log_level='debug',
password='admin',
server='localhost',
user='admin',
state='present'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the

View File

@@ -67,9 +67,6 @@ class TestParameters(unittest.TestCase):
args = dict(
key='foo',
value='bar',
password='password',
server='localhost',
user='admin'
)
p = Parameters(params=args)
assert p.key == 'foo'
@@ -79,10 +76,7 @@ class TestParameters(unittest.TestCase):
args = dict(
key='foo',
value='bar',
password='password',
server='localhost',
defaultValue='baz',
user='admin'
)
p = Parameters(params=args)
@@ -99,10 +93,12 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
key='provision.cpu.afm',
value='1',
password='admin',
server='localhost',
user='admin',
state='present'
state='present',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the

View File

@@ -108,10 +108,12 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
banner_text='this is a banner',
console_timeout=100,
password='admin',
server='localhost',
user='admin',
state='present'
state='present',
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
# Configure the parameters that would be returned by querying the