mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Fixes for gtm wide ip (#33725)
Adds pools argument. Refactors code to support new conventions. Adds more unit tests
This commit is contained in:
parent
3283f46ffa
commit
7b76124c07
3 changed files with 395 additions and 92 deletions
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"kind": "tm:gtm:wideip:a:astate",
|
||||
"name": "foo.bar.com",
|
||||
"partition": "Common",
|
||||
"fullPath": "/Common/foo.bar.com",
|
||||
"generation": 135,
|
||||
"selfLink": "https://localhost/mgmt/tm/gtm/wideip/a/~Common~foo.bar.com?ver=13.0.0",
|
||||
"enabled": true,
|
||||
"failureRcode": "noerror",
|
||||
"failureRcodeResponse": "disabled",
|
||||
"failureRcodeTtl": 0,
|
||||
"lastResortPool": "",
|
||||
"minimalResponse": "enabled",
|
||||
"persistCidrIpv4": 32,
|
||||
"persistCidrIpv6": 128,
|
||||
"persistence": "disabled",
|
||||
"poolLbMode": "round-robin",
|
||||
"ttlPersistence": 3600,
|
||||
"pools": [
|
||||
{
|
||||
"name": "baz",
|
||||
"partition": "Common",
|
||||
"order": 0,
|
||||
"ratio": 10,
|
||||
"nameReference": {
|
||||
"link": "https://localhost/mgmt/tm/gtm/pool/a/~Common~baz?ver=13.0.0"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -22,7 +22,8 @@ from ansible.module_utils.f5_utils import AnsibleF5Client
|
|||
from ansible.module_utils.f5_utils import F5ModuleError
|
||||
|
||||
try:
|
||||
from library.bigip_gtm_wide_ip import Parameters
|
||||
from library.bigip_gtm_wide_ip import ApiParameters
|
||||
from library.bigip_gtm_wide_ip import ModuleParameters
|
||||
from library.bigip_gtm_wide_ip import ModuleManager
|
||||
from library.bigip_gtm_wide_ip import ArgumentSpec
|
||||
from library.bigip_gtm_wide_ip import UntypedManager
|
||||
|
@ -31,7 +32,8 @@ try:
|
|||
from test.unit.modules.utils import set_module_args
|
||||
except ImportError:
|
||||
try:
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import Parameters
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import ApiParameters
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import ModuleParameters
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import ModuleManager
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import ArgumentSpec
|
||||
from ansible.modules.network.f5.bigip_gtm_wide_ip import UntypedManager
|
||||
|
@ -67,28 +69,49 @@ class TestParameters(unittest.TestCase):
|
|||
def test_module_parameters(self):
|
||||
args = dict(
|
||||
name='foo.baz.bar',
|
||||
lb_method='round-robin'
|
||||
lb_method='round-robin',
|
||||
)
|
||||
p = Parameters(args)
|
||||
p = ModuleParameters(args)
|
||||
assert p.name == 'foo.baz.bar'
|
||||
assert p.lb_method == 'round-robin'
|
||||
assert p.pool_lb_method == 'round-robin'
|
||||
|
||||
def test_module_pools(self):
|
||||
args = dict(
|
||||
pools=[
|
||||
dict(
|
||||
name='foo',
|
||||
ratio='100'
|
||||
)
|
||||
]
|
||||
)
|
||||
p = ModuleParameters(args)
|
||||
assert len(p.pools) == 1
|
||||
|
||||
def test_api_parameters(self):
|
||||
args = dict(
|
||||
name='foo.baz.bar',
|
||||
poolLbMode='round-robin'
|
||||
)
|
||||
p = Parameters(args)
|
||||
p = ApiParameters(args)
|
||||
assert p.name == 'foo.baz.bar'
|
||||
assert p.lb_method == 'round-robin'
|
||||
assert p.pool_lb_method == 'round-robin'
|
||||
|
||||
def test_api_not_fqdn_name(self):
|
||||
def test_api_pools(self):
|
||||
args = load_fixture('load_gtm_wide_ip_with_pools.json')
|
||||
p = ApiParameters(args)
|
||||
assert len(p.pools) == 1
|
||||
assert 'name' in p.pools[0]
|
||||
assert 'ratio' in p.pools[0]
|
||||
assert p.pools[0]['name'] == '/Common/baz'
|
||||
assert p.pools[0]['ratio'] == 10
|
||||
|
||||
def test_module_not_fqdn_name(self):
|
||||
args = dict(
|
||||
name='foo.baz',
|
||||
poolLbMode='round-robin'
|
||||
lb_method='round-robin'
|
||||
)
|
||||
with pytest.raises(F5ModuleError) as excinfo:
|
||||
p = Parameters(args)
|
||||
p = ModuleParameters(args)
|
||||
assert p.name == 'foo.baz'
|
||||
assert 'The provided name must be a valid FQDN' in str(excinfo)
|
||||
|
||||
|
@ -238,3 +261,122 @@ class TestTypedManager(unittest.TestCase):
|
|||
assert results['name'] == 'foo.baz.bar'
|
||||
assert results['state'] == 'present'
|
||||
assert results['lb_method'] == 'global-availability'
|
||||
|
||||
def test_create_wideip_with_pool(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo.baz.bar',
|
||||
lb_method='round-robin',
|
||||
type='a',
|
||||
pools=[
|
||||
dict(
|
||||
name='foo',
|
||||
ratio=10
|
||||
)
|
||||
],
|
||||
password='passsword',
|
||||
server='localhost',
|
||||
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 = TypedManager(client)
|
||||
tm.exists = Mock(return_value=False)
|
||||
tm.create_on_device = Mock(return_value=True)
|
||||
|
||||
# Override methods to force specific logic in the module to happen
|
||||
mm = ModuleManager(client)
|
||||
mm.version_is_less_than_12 = Mock(return_value=False)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert results['name'] == 'foo.baz.bar'
|
||||
assert results['state'] == 'present'
|
||||
assert results['lb_method'] == 'round-robin'
|
||||
|
||||
def test_create_wideip_with_pool_idempotent(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo.bar.com',
|
||||
lb_method='round-robin',
|
||||
type='a',
|
||||
pools=[
|
||||
dict(
|
||||
name='baz',
|
||||
ratio=10
|
||||
)
|
||||
],
|
||||
password='passsword',
|
||||
server='localhost',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ApiParameters(load_fixture('load_gtm_wide_ip_with_pools.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 = TypedManager(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.version_is_less_than_12 = Mock(return_value=False)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is False
|
||||
|
||||
def test_update_wideip_with_pool(self, *args):
|
||||
set_module_args(dict(
|
||||
name='foo.bar.com',
|
||||
lb_method='round-robin',
|
||||
type='a',
|
||||
pools=[
|
||||
dict(
|
||||
name='baz',
|
||||
ratio=10
|
||||
),
|
||||
dict(
|
||||
name='alec',
|
||||
ratio=100
|
||||
)
|
||||
],
|
||||
password='passsword',
|
||||
server='localhost',
|
||||
user='admin'
|
||||
))
|
||||
|
||||
current = ApiParameters(load_fixture('load_gtm_wide_ip_with_pools.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 = TypedManager(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.version_is_less_than_12 = Mock(return_value=False)
|
||||
mm.get_manager = Mock(return_value=tm)
|
||||
|
||||
results = mm.exec_module()
|
||||
|
||||
assert results['changed'] is True
|
||||
assert 'pools' in results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue