2017-06-06 19:54:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-10-25 21:57:21 +02:00
|
|
|
# Copyright (c) 2017 F5 Networks Inc.
|
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-06-16 11:36:53 +02:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import pytest
|
2017-06-06 19:54:02 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info < (2, 7):
|
2018-11-21 05:34:01 +01:00
|
|
|
pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7")
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
try:
|
2018-04-25 16:16:11 +02:00
|
|
|
from library.modules.bigip_pool import ApiParameters
|
|
|
|
from library.modules.bigip_pool import ModuleParameters
|
|
|
|
from library.modules.bigip_pool import ModuleManager
|
|
|
|
from library.modules.bigip_pool import ArgumentSpec
|
2018-11-09 21:31:07 +01:00
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
2018-11-09 21:31:07 +01:00
|
|
|
|
|
|
|
# In Ansible 2.8, Ansible changed import paths.
|
|
|
|
from test.units.compat import unittest
|
|
|
|
from test.units.compat.mock import Mock
|
|
|
|
from test.units.compat.mock import patch
|
|
|
|
|
|
|
|
from test.units.modules.utils import set_module_args
|
2017-06-06 19:54:02 +02:00
|
|
|
except ImportError:
|
2018-11-20 04:02:02 +01:00
|
|
|
from ansible.modules.network.f5.bigip_pool import ApiParameters
|
|
|
|
from ansible.modules.network.f5.bigip_pool import ModuleParameters
|
|
|
|
from ansible.modules.network.f5.bigip_pool import ModuleManager
|
|
|
|
from ansible.modules.network.f5.bigip_pool import ArgumentSpec
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
2018-11-09 21:31:07 +01:00
|
|
|
|
2018-11-20 04:02:02 +01:00
|
|
|
# Ansible 2.8 imports
|
|
|
|
from units.compat import unittest
|
|
|
|
from units.compat.mock import Mock
|
|
|
|
from units.compat.mock import patch
|
2018-11-09 21:31:07 +01:00
|
|
|
|
2018-11-20 04:02:02 +01:00
|
|
|
from units.modules.utils import set_module_args
|
2018-11-09 21:31:07 +01:00
|
|
|
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
|
|
|
fixture_data = {}
|
|
|
|
|
|
|
|
|
|
|
|
def load_fixture(name):
|
|
|
|
path = os.path.join(fixture_path, name)
|
|
|
|
|
|
|
|
if path in fixture_data:
|
|
|
|
return fixture_data[path]
|
|
|
|
|
|
|
|
with open(path) as f:
|
|
|
|
data = f.read()
|
|
|
|
|
|
|
|
try:
|
|
|
|
data = json.loads(data)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
fixture_data[path] = data
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
class TestParameters(unittest.TestCase):
|
|
|
|
def test_module_parameters(self):
|
|
|
|
args = dict(
|
|
|
|
monitor_type='m_of_n',
|
2017-10-13 18:47:49 +02:00
|
|
|
monitors=['/Common/Fake', '/Common/Fake2'],
|
2017-06-06 19:54:02 +02:00
|
|
|
quorum=1,
|
|
|
|
slow_ramp_time=200,
|
|
|
|
reselect_tries=5,
|
2017-12-22 21:39:19 +01:00
|
|
|
service_down_action='drop'
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
p = ModuleParameters(params=args)
|
2017-06-06 19:54:02 +02:00
|
|
|
assert p.monitor_type == 'm_of_n'
|
|
|
|
assert p.quorum == 1
|
2017-10-13 18:47:49 +02:00
|
|
|
assert p.monitors == 'min 1 of { /Common/Fake /Common/Fake2 }'
|
2017-06-06 19:54:02 +02:00
|
|
|
assert p.slow_ramp_time == 200
|
|
|
|
assert p.reselect_tries == 5
|
|
|
|
assert p.service_down_action == 'drop'
|
|
|
|
|
|
|
|
def test_api_parameters(self):
|
|
|
|
args = dict(
|
2017-12-22 21:39:19 +01:00
|
|
|
monitor="/Common/Fake and /Common/Fake2 ",
|
2017-06-06 19:54:02 +02:00
|
|
|
slowRampTime=200,
|
|
|
|
reselectTries=5,
|
|
|
|
serviceDownAction='drop'
|
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
p = ApiParameters(params=args)
|
2017-10-13 18:47:49 +02:00
|
|
|
assert p.monitors == '/Common/Fake and /Common/Fake2'
|
2017-06-06 19:54:02 +02:00
|
|
|
assert p.slow_ramp_time == 200
|
|
|
|
assert p.reselect_tries == 5
|
|
|
|
assert p.service_down_action == 'drop'
|
|
|
|
|
|
|
|
def test_unknown_module_lb_method(self):
|
|
|
|
args = dict(
|
|
|
|
lb_method='obscure_hyphenated_fake_method',
|
|
|
|
)
|
|
|
|
with pytest.raises(F5ModuleError):
|
2018-01-13 06:49:12 +01:00
|
|
|
p = ModuleParameters(params=args)
|
2017-06-06 19:54:02 +02:00
|
|
|
assert p.lb_method == 'foo'
|
|
|
|
|
|
|
|
def test_unknown_api_lb_method(self):
|
|
|
|
args = dict(
|
|
|
|
loadBalancingMode='obscure_hypenated_fake_method'
|
|
|
|
)
|
|
|
|
with pytest.raises(F5ModuleError):
|
2018-01-13 06:49:12 +01:00
|
|
|
p = ApiParameters(params=args)
|
2017-06-06 19:54:02 +02:00
|
|
|
assert p.lb_method == 'foo'
|
|
|
|
|
|
|
|
|
|
|
|
class TestManager(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.spec = ArgumentSpec()
|
|
|
|
|
|
|
|
def test_create_pool(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
|
|
|
description='fakepool',
|
|
|
|
service_down_action='drop',
|
2017-12-22 21:39:19 +01:00
|
|
|
lb_method='round-robin',
|
2017-06-06 19:54:02 +02:00
|
|
|
partition='Common',
|
|
|
|
slow_ramp_time=10,
|
|
|
|
reselect_tries=1,
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-10-25 21:57:21 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
|
|
|
assert results['description'] == 'fakepool'
|
|
|
|
assert results['service_down_action'] == 'drop'
|
|
|
|
assert results['lb_method'] == 'round-robin'
|
|
|
|
assert results['slow_ramp_time'] == 10
|
|
|
|
assert results['reselect_tries'] == 1
|
|
|
|
|
|
|
|
def test_create_pool_monitor_type_missing(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
lb_method='round-robin',
|
2017-06-06 19:54:02 +02:00
|
|
|
partition='Common',
|
|
|
|
monitors=['/Common/tcp', '/Common/http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
2017-10-13 18:47:49 +02:00
|
|
|
results = mm.exec_module()
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2017-10-13 18:47:49 +02:00
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Common/http', '/Common/tcp']
|
2017-10-13 18:47:49 +02:00
|
|
|
assert results['monitor_type'] == 'and_list'
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
def test_create_pool_monitors_missing(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
lb_method='round-robin',
|
2017-06-06 19:54:02 +02:00
|
|
|
partition='Common',
|
|
|
|
monitor_type='and_list',
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
2017-10-13 18:47:49 +02:00
|
|
|
msg = "The 'monitors' parameter cannot be empty when " \
|
2017-06-06 19:54:02 +02:00
|
|
|
"'monitor_type' parameter is specified"
|
|
|
|
with pytest.raises(F5ModuleError) as err:
|
|
|
|
mm.exec_module()
|
|
|
|
|
|
|
|
assert str(err.value) == msg
|
|
|
|
|
|
|
|
def test_create_pool_quorum_missing(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
lb_method='round-robin',
|
2017-06-06 19:54:02 +02:00
|
|
|
partition='Common',
|
|
|
|
monitor_type='m_of_n',
|
|
|
|
monitors=['/Common/tcp', '/Common/http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
msg = "Quorum value must be specified with monitor_type 'm_of_n'."
|
|
|
|
with pytest.raises(F5ModuleError) as err:
|
|
|
|
mm.exec_module()
|
|
|
|
|
|
|
|
assert str(err.value) == msg
|
|
|
|
|
|
|
|
def test_create_pool_monitor_and_list(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
|
|
|
partition='Common',
|
|
|
|
monitor_type='and_list',
|
|
|
|
monitors=['/Common/tcp', '/Common/http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Common/http', '/Common/tcp']
|
2017-06-06 19:54:02 +02:00
|
|
|
assert results['monitor_type'] == 'and_list'
|
|
|
|
|
|
|
|
def test_create_pool_monitor_m_of_n(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
|
|
|
partition='Common',
|
|
|
|
monitor_type='m_of_n',
|
|
|
|
quorum=1,
|
|
|
|
monitors=['/Common/tcp', '/Common/http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Common/http', '/Common/tcp']
|
2017-06-06 19:54:02 +02:00
|
|
|
assert results['monitor_type'] == 'm_of_n'
|
|
|
|
|
|
|
|
def test_update_monitors(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
name='test_pool',
|
|
|
|
partition='Common',
|
|
|
|
monitor_type='and_list',
|
|
|
|
monitors=['/Common/http', '/Common/tcp'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
2019-02-02 03:04:49 +01:00
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
current = ApiParameters(params=load_fixture('load_ltm_pool.json'))
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
mm.update_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=True)
|
|
|
|
mm.read_current_from_device = Mock(return_value=current)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['monitor_type'] == 'and_list'
|
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
def test_create_pool_monitor_and_list_no_partition(self, *args):
|
2017-06-06 19:54:02 +02:00
|
|
|
set_module_args(dict(
|
2017-12-22 21:39:19 +01:00
|
|
|
pool='fake_pool',
|
|
|
|
monitor_type='and_list',
|
|
|
|
monitors=['tcp', 'http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-12-22 21:39:19 +01:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
2017-06-06 19:54:02 +02:00
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
|
|
|
assert results['monitors'] == ['/Common/http', '/Common/tcp']
|
|
|
|
assert results['monitor_type'] == 'and_list'
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
def test_create_pool_monitor_m_of_n_no_partition(self, *args):
|
2017-06-06 19:54:02 +02:00
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
monitor_type='m_of_n',
|
|
|
|
quorum=1,
|
2017-06-06 19:54:02 +02:00
|
|
|
monitors=['tcp', 'http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Common/http', '/Common/tcp']
|
|
|
|
assert results['monitor_type'] == 'm_of_n'
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
def test_create_pool_monitor_and_list_custom_partition(self, *args):
|
2017-06-06 19:54:02 +02:00
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
partition='Testing',
|
|
|
|
monitor_type='and_list',
|
2017-06-06 19:54:02 +02:00
|
|
|
monitors=['tcp', 'http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Testing/http', '/Testing/tcp']
|
|
|
|
assert results['monitor_type'] == 'and_list'
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
def test_create_pool_monitor_m_of_n_custom_partition(self, *args):
|
2017-06-06 19:54:02 +02:00
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
|
|
|
partition='Testing',
|
2017-12-22 21:39:19 +01:00
|
|
|
monitor_type='m_of_n',
|
|
|
|
quorum=1,
|
2017-06-06 19:54:02 +02:00
|
|
|
monitors=['tcp', 'http'],
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert results['monitors'] == ['/Testing/http', '/Testing/tcp']
|
|
|
|
assert results['monitor_type'] == 'm_of_n'
|
2017-06-06 19:54:02 +02:00
|
|
|
|
2017-12-22 21:39:19 +01:00
|
|
|
def test_create_pool_with_metadata(self, *args):
|
2017-06-06 19:54:02 +02:00
|
|
|
set_module_args(dict(
|
|
|
|
pool='fake_pool',
|
2017-12-22 21:39:19 +01:00
|
|
|
metadata=dict(ansible='2.4'),
|
2019-02-02 03:04:49 +01:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-06-06 19:54:02 +02:00
|
|
|
))
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
module = AnsibleModule(
|
2017-06-06 19:54:02 +02:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2019-02-02 03:04:49 +01:00
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
2017-06-06 19:54:02 +02:00
|
|
|
)
|
|
|
|
|
2018-01-13 06:49:12 +01:00
|
|
|
mm = ModuleManager(module=module)
|
2017-06-06 19:54:02 +02:00
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['name'] == 'fake_pool'
|
2017-12-22 21:39:19 +01:00
|
|
|
assert 'metadata' in results
|
|
|
|
assert 'ansible' in results['metadata']
|
|
|
|
assert results['metadata']['ansible'] == '2.4'
|
2019-02-02 03:04:49 +01:00
|
|
|
|
|
|
|
def test_create_aggregate_pools(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
aggregate=[
|
|
|
|
dict(
|
|
|
|
pool='fake_pool',
|
|
|
|
description='fakepool',
|
|
|
|
service_down_action='drop',
|
|
|
|
lb_method='round-robin',
|
|
|
|
partition='Common',
|
|
|
|
slow_ramp_time=10,
|
|
|
|
reselect_tries=1,
|
|
|
|
),
|
|
|
|
dict(
|
|
|
|
pool='fake_pool2',
|
|
|
|
description='fakepool2',
|
|
|
|
service_down_action='drop',
|
|
|
|
lb_method='predictive-node',
|
|
|
|
partition='Common',
|
|
|
|
slow_ramp_time=110,
|
|
|
|
reselect_tries=2,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
|
|
|
))
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=self.spec.argument_spec,
|
|
|
|
supports_check_mode=self.spec.supports_check_mode,
|
|
|
|
mutually_exclusive=self.spec.mutually_exclusive,
|
|
|
|
required_one_of=self.spec.required_one_of
|
|
|
|
)
|
|
|
|
|
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.create_on_device = Mock(return_value=True)
|
|
|
|
mm.exists = Mock(return_value=False)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
|
|
|
|
|
|
|
assert results['changed'] is True
|