2017-05-18 19:21:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2017-11-01 17:37:23 +00: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-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-06-16 09:36:53 +00:00
|
|
|
import os
|
|
|
|
import json
|
2017-05-18 19:21:18 +00:00
|
|
|
import pytest
|
2017-06-16 09:36:53 +00:00
|
|
|
import sys
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
if sys.version_info < (2, 7):
|
2018-11-21 04:34:01 +00:00
|
|
|
pytestmark = pytest.mark.skip("F5 Ansible modules require Python >= 2.7")
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
try:
|
2018-04-23 22:46:09 +00:00
|
|
|
from library.modules.bigip_user import Parameters
|
|
|
|
from library.modules.bigip_user import ModuleManager
|
|
|
|
from library.modules.bigip_user import ArgumentSpec
|
2018-11-02 18:25:18 +00:00
|
|
|
from library.modules.bigip_user import UnpartitionedManager
|
2018-04-23 22:46:09 +00:00
|
|
|
from library.modules.bigip_user import PartitionedManager
|
2018-10-29 17:10:11 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
2018-10-29 17:10:11 +00: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.modules.utils import set_module_args
|
2017-05-18 19:21:18 +00:00
|
|
|
except ImportError:
|
2018-11-20 03:02:02 +00:00
|
|
|
from ansible.modules.network.f5.bigip_user import Parameters
|
|
|
|
from ansible.modules.network.f5.bigip_user import ModuleManager
|
|
|
|
from ansible.modules.network.f5.bigip_user import ArgumentSpec
|
|
|
|
from ansible.modules.network.f5.bigip_user import UnpartitionedManager
|
|
|
|
from ansible.modules.network.f5.bigip_user import PartitionedManager
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
|
|
|
|
|
|
|
# Ansible 2.8 imports
|
|
|
|
from units.compat import unittest
|
|
|
|
from units.compat.mock import Mock
|
|
|
|
|
|
|
|
from units.modules.utils import set_module_args
|
|
|
|
|
2017-05-18 19:21:18 +00: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):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
args = dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
full_name='Fake Person',
|
|
|
|
partition_access=access,
|
|
|
|
update_password='always'
|
|
|
|
)
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
p = Parameters(params=args)
|
2017-05-18 19:21:18 +00:00
|
|
|
assert p.username_credential == 'someuser'
|
|
|
|
assert p.password_credential == 'testpass'
|
|
|
|
assert p.full_name == 'Fake Person'
|
|
|
|
assert p.partition_access == access
|
|
|
|
assert p.update_password == 'always'
|
|
|
|
|
|
|
|
def test_api_parameters(self):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
args = dict(
|
|
|
|
name='someuser',
|
|
|
|
description='Fake Person',
|
|
|
|
partitionAccess=access,
|
|
|
|
shell='none'
|
|
|
|
)
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
p = Parameters(params=args)
|
2017-05-18 19:21:18 +00:00
|
|
|
assert p.name == 'someuser'
|
|
|
|
assert p.full_name == 'Fake Person'
|
|
|
|
assert p.partition_access == access
|
|
|
|
assert p.shell == 'none'
|
|
|
|
|
|
|
|
|
|
|
|
class TestManager(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.spec = ArgumentSpec()
|
|
|
|
|
|
|
|
def test_create_user(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
2019-03-19 06:30:58 +00:00
|
|
|
update_password='on_create',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.create_on_device = Mock(return_value=True)
|
|
|
|
pm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_no_password(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
partition_access=access,
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.create_on_device = Mock(return_value=True)
|
|
|
|
pm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_partition_access_raises(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.create_on_device = Mock(return_value=True)
|
|
|
|
pm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "The 'partition_access' option " \
|
|
|
|
"is required when creating a resource."
|
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|
|
|
|
|
|
|
|
def test_create_user_shell_bash(self, *args):
|
|
|
|
access = [{'name': 'all', 'role': 'admin'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
|
|
|
update_password='on_create',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.create_on_device = Mock(return_value=True)
|
|
|
|
pm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_shell_not_permitted_raises(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
|
|
|
update_password='on_create',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.create_on_device = Mock(return_value=True)
|
|
|
|
pm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "Shell access is only available to 'admin' or " \
|
2018-11-02 18:25:18 +00:00
|
|
|
"'resource-admin' roles."
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|
|
|
|
|
|
|
|
def test_update_user_password_no_pass(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
2018-01-13 07:03:41 +00:00
|
|
|
current = Parameters(params=load_fixture('load_auth_user_no_pass.json'))
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.exists = Mock(return_value=True)
|
|
|
|
pm.update_on_device = Mock(return_value=True)
|
|
|
|
pm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
|
|
|
|
def test_update_user_password_with_pass(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
2018-01-13 07:03:41 +00:00
|
|
|
current = Parameters(params=load_fixture('load_auth_user_with_pass.json'))
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.exists = Mock(return_value=True)
|
|
|
|
pm.update_on_device = Mock(return_value=True)
|
|
|
|
pm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
|
|
|
|
def test_update_user_shell_to_none(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='none',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.exists = Mock(return_value=True)
|
|
|
|
pm.update_on_device = Mock(return_value=True)
|
|
|
|
pm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['shell'] == 'none'
|
|
|
|
|
|
|
|
def test_update_user_shell_to_none_shell_attribute_missing(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='none',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-01-13 07:03:41 +00:00
|
|
|
pm = PartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
pm.exists = Mock(return_value=True)
|
|
|
|
pm.update_on_device = Mock(return_value=True)
|
|
|
|
pm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=False)
|
|
|
|
mm.get_manager = Mock(return_value=pm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is False
|
|
|
|
assert not hasattr(results, 'shell')
|
|
|
|
|
|
|
|
def test_update_user_shell_to_bash(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [{'name': 'all', 'role': 'admin'}]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['shell'] == 'bash'
|
|
|
|
|
|
|
|
def test_update_user_shell_to_bash_mutliple_roles(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [
|
|
|
|
{'name': 'Common', 'role': 'operator'},
|
|
|
|
{'name': 'all', 'role': 'guest'}
|
|
|
|
]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "Shell access is only available to 'admin' or " \
|
2018-11-02 18:25:18 +00:00
|
|
|
"'resource-admin' roles."
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|
|
|
|
|
|
|
|
|
|
|
|
class TestLegacyManager(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.spec = ArgumentSpec()
|
|
|
|
|
|
|
|
def test_create_user(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
2019-03-19 06:30:58 +00:00
|
|
|
update_password='on_create',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.create_on_device = Mock(return_value=True)
|
|
|
|
upm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_no_password(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
partition_access=access,
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.create_on_device = Mock(return_value=True)
|
|
|
|
upm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_partition_access_raises(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.create_on_device = Mock(return_value=True)
|
|
|
|
upm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "The 'partition_access' option " \
|
|
|
|
"is required when creating a resource."
|
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|
|
|
|
|
|
|
|
def test_create_user_shell_bash(self, *args):
|
|
|
|
access = [{'name': 'all', 'role': 'admin'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
|
|
|
update_password='on_create',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.create_on_device = Mock(return_value=True)
|
|
|
|
upm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['partition_access'] == access
|
|
|
|
|
|
|
|
def test_create_user_shell_not_permitted_raises(self, *args):
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
|
|
|
partition_access=access,
|
|
|
|
update_password='on_create',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.create_on_device = Mock(return_value=True)
|
|
|
|
upm.exists = Mock(return_value=False)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "Shell access is only available to 'admin' or " \
|
2018-11-02 18:25:18 +00:00
|
|
|
"'resource-admin' roles."
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|
|
|
|
|
|
|
|
def test_update_user_password(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
|
|
|
password_credential='testpass',
|
2019-03-19 06:30:58 +00:00
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
shell='tmsh',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
|
|
|
|
def test_update_user_shell_to_none(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='none',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['shell'] == 'none'
|
|
|
|
|
|
|
|
def test_update_user_shell_to_none_shell_attribute_missing(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='none',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [{'name': 'Common', 'role': 'guest'}]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is False
|
|
|
|
assert not hasattr(results, 'shell')
|
|
|
|
|
|
|
|
def test_update_user_shell_to_bash(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [{'name': 'all', 'role': 'admin'}]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
|
|
|
results = mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
assert results['changed'] is True
|
|
|
|
assert results['shell'] == 'bash'
|
|
|
|
|
|
|
|
def test_update_user_shell_to_bash_mutliple_roles(self, *args):
|
|
|
|
set_module_args(dict(
|
|
|
|
username_credential='someuser',
|
2019-03-19 06:30:58 +00:00
|
|
|
shell='bash',
|
|
|
|
provider=dict(
|
|
|
|
server='localhost',
|
|
|
|
password='password',
|
|
|
|
user='admin'
|
|
|
|
)
|
2017-05-18 19:21:18 +00:00
|
|
|
))
|
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
module = AnsibleModule(
|
2017-05-18 19:21:18 +00:00
|
|
|
argument_spec=self.spec.argument_spec,
|
2018-01-13 07:03:41 +00:00
|
|
|
supports_check_mode=self.spec.supports_check_mode
|
2017-05-18 19:21:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Configure the parameters that would be returned by querying the
|
|
|
|
# remote device
|
|
|
|
access = [
|
|
|
|
{'name': 'Common', 'role': 'operator'},
|
|
|
|
{'name': 'all', 'role': 'guest'}
|
|
|
|
]
|
|
|
|
current = Parameters(
|
2018-01-13 07:03:41 +00:00
|
|
|
params=dict(
|
2017-05-18 19:21:18 +00:00
|
|
|
user='admin',
|
|
|
|
shell='tmsh',
|
|
|
|
partition_access=access
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Override methods to force specific logic in the module to happen
|
2018-11-02 18:25:18 +00:00
|
|
|
upm = UnpartitionedManager(module=module, params=module.params)
|
2017-06-16 09:36:53 +00:00
|
|
|
upm.exists = Mock(return_value=True)
|
|
|
|
upm.update_on_device = Mock(return_value=True)
|
|
|
|
upm.read_current_from_device = Mock(return_value=current)
|
2017-05-18 19:21:18 +00:00
|
|
|
|
2018-01-13 07:03:41 +00:00
|
|
|
mm = ModuleManager(module=module)
|
|
|
|
mm.is_version_less_than_13 = Mock(return_value=True)
|
|
|
|
mm.get_manager = Mock(return_value=upm)
|
|
|
|
|
2017-05-18 19:21:18 +00:00
|
|
|
msg = "Shell access is only available to 'admin' or " \
|
2018-11-02 18:25:18 +00:00
|
|
|
"'resource-admin' roles."
|
2017-05-18 19:21:18 +00:00
|
|
|
|
|
|
|
with pytest.raises(F5ModuleError) as ex:
|
2018-01-13 07:03:41 +00:00
|
|
|
mm.exec_module()
|
2017-05-18 19:21:18 +00:00
|
|
|
assert str(ex.value) == msg
|