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

Adds variable types to docs
Refactors unit tests to remove deprecated parameters
This commit is contained in:
Wojciech Wypior
2019-03-19 06:40:40 +01:00
committed by Tim Rupp
parent 4ed3735cda
commit 739df1c348
27 changed files with 447 additions and 326 deletions

View File

@@ -134,11 +134,13 @@ class TestManager(unittest.TestCase):
def test_create_datacenter(self, *args):
set_module_args(dict(
name='foo',
state='present',
password='admin',
server='localhost',
user='admin',
name='foo'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -158,11 +160,14 @@ class TestManager(unittest.TestCase):
def test_create_disabled_datacenter(self, *args):
set_module_args(dict(
name='foo',
state='disabled',
password='admin',
server='localhost',
user='admin',
name='foo'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -183,11 +188,14 @@ class TestManager(unittest.TestCase):
def test_create_enabled_datacenter(self, *args):
set_module_args(dict(
name='foo',
state='enabled',
password='admin',
server='localhost',
user='admin',
name='foo'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -208,11 +216,14 @@ class TestManager(unittest.TestCase):
def test_idempotent_disable_datacenter(self, *args):
set_module_args(dict(
name='foo',
state='disabled',
password='admin',
server='localhost',
user='admin',
name='foo'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -96,9 +96,11 @@ class TestManager(unittest.TestCase):
synchronization="yes",
synchronization_group_name='foo',
synchronize_zone_files="yes",
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_gtm_global_settings_general_1.json'))

View File

@@ -156,9 +156,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -133,9 +133,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -139,9 +139,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -147,9 +147,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -139,9 +139,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -166,9 +168,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_gtm_monitor_tcp_1.json'))
@@ -193,9 +197,11 @@ class TestManager(unittest.TestCase):
set_module_args(dict(
name='foo',
ignore_down_response=True,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_gtm_monitor_tcp_1.json'))

View File

@@ -170,9 +170,11 @@ class TestManager(unittest.TestCase):
port=80,
interval=20,
timeout=30,
server='localhost',
password='password',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -145,14 +145,17 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict(
name='foo',
preferred_lb_method='round-robin',
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
)
# Override methods in the specific type of manager
@@ -178,14 +181,17 @@ class TestUntypedManager(unittest.TestCase):
preferred_lb_method='topology',
alternate_lb_method='drop-packet',
fallback_lb_method='cpu',
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
)
current = ApiParameters(params=load_fixture('load_gtm_pool_untyped_default.json'))
@@ -214,14 +220,17 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict(
name='foo',
state='absent',
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
)
# Override methods in the specific type of manager
@@ -263,14 +272,17 @@ class TestTypedManager(unittest.TestCase):
name='foo',
preferred_lb_method='round-robin',
type='a',
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
)
# Override methods in the specific type of manager
@@ -297,14 +309,17 @@ class TestTypedManager(unittest.TestCase):
alternate_lb_method='drop-packet',
fallback_lb_method='cpu',
type='a',
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
)
current = ApiParameters(params=load_fixture('load_gtm_pool_a_default.json'))
@@ -334,14 +349,17 @@ class TestTypedManager(unittest.TestCase):
name='foo',
type='a',
state='absent',
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
)
# Override methods in the specific type of manager

View File

@@ -164,9 +164,6 @@ class TestV1Manager(unittest.TestCase):
def test_create(self, *args):
set_module_args(dict(
server='lb.mydomain.com',
user='admin',
password='secret',
name='GTM_Server',
datacenter='/Common/New York',
server_type='bigip',
@@ -209,7 +206,12 @@ class TestV1Manager(unittest.TestCase):
)
]
)
]
],
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -265,9 +267,6 @@ class TestV2Manager(unittest.TestCase):
def test_create(self, *args):
set_module_args(dict(
server='lb.mydomain.com',
user='admin',
password='secret',
name='GTM_Server',
datacenter='/Common/New York',
server_type='bigip',
@@ -310,7 +309,12 @@ class TestV2Manager(unittest.TestCase):
)
]
)
]
],
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -111,7 +111,12 @@ class TestManager(unittest.TestCase):
destination=dict(
region='Foobar',
),
weight=10
weight=10,
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(

View File

@@ -110,7 +110,7 @@ class TestManager(unittest.TestCase):
def setUp(self):
self.spec = ArgumentSpec()
def test_create_topology_record(self, *args):
def test_create_topology_region(self, *args):
set_module_args(dict(
name='foobar',
region_members=[
@@ -122,7 +122,12 @@ class TestManager(unittest.TestCase):
datacenter='bazcenter'
)
],
partition='Common'
partition='Common',
provider=dict(
server='localhost',
password='password',
user='admin'
)
)
)
@@ -133,7 +138,7 @@ class TestManager(unittest.TestCase):
# Override methods in the specific type of manager
mm = ModuleManager(module=module)
mm.exists = Mock(side_effect=[False, True])
mm.exists = Mock(return_value=False)
mm.create_on_device = Mock(return_value=True)
results = mm.exec_module()

View File

@@ -143,9 +143,11 @@ class TestUntypedManager(unittest.TestCase):
set_module_args(dict(
name='foo.baz.bar',
lb_method='round-robin',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -192,9 +194,11 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar',
lb_method='round-robin',
type='a',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -224,9 +228,11 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar',
lb_method='round_robin',
type='a',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -256,9 +262,11 @@ class TestTypedManager(unittest.TestCase):
name='foo.baz.bar',
lb_method='global_availability',
type='a',
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -294,9 +302,11 @@ class TestTypedManager(unittest.TestCase):
ratio=10
)
],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
module = AnsibleModule(
@@ -332,9 +342,11 @@ class TestTypedManager(unittest.TestCase):
ratio=10
)
],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_gtm_wide_ip_with_pools.json'))
@@ -372,9 +384,11 @@ class TestTypedManager(unittest.TestCase):
ratio=100
)
],
password='password',
server='localhost',
user='admin'
provider=dict(
server='localhost',
password='password',
user='admin'
)
))
current = ApiParameters(params=load_fixture('load_gtm_wide_ip_with_pools.json'))