@ -18,8 +18,7 @@ if sys.version_info < (2, 7):
from ansible . compat . tests import unittest
from ansible . compat . tests . mock import Mock
from ansible . compat . tests . mock import patch
from ansible . module_utils . f5_utils import AnsibleF5Client
from ansible . module_utils . f5_utils import F5ModuleError
from ansible . module_utils . basic import AnsibleModule
try :
from library . bigip_user import Parameters
@ -27,7 +26,8 @@ try:
from library . bigip_user import ArgumentSpec
from library . bigip_user import UnparitionedManager
from library . bigip_user import PartitionedManager
from ansible . module_utils . f5_utils import iControlUnexpectedHTTPError
from library . module_utils . network . f5 . common import F5ModuleError
from library . module_utils . network . f5 . common import iControlUnexpectedHTTPError
from test . unit . modules . utils import set_module_args
except ImportError :
try :
@ -36,7 +36,8 @@ except ImportError:
from ansible . modules . network . f5 . bigip_user import ArgumentSpec
from ansible . modules . network . f5 . bigip_user import UnparitionedManager
from ansible . modules . network . f5 . bigip_user import PartitionedManager
from ansible . module_utils . f5_utils import iControlUnexpectedHTTPError
from ansible . module_utils . network . f5 . common import F5ModuleError
from ansible . module_utils . network . f5 . common import iControlUnexpectedHTTPError
from units . modules . utils import set_module_args
except ImportError :
raise SkipTest ( " F5 Ansible modules require the f5-sdk Python library " )
@ -74,7 +75,7 @@ class TestParameters(unittest.TestCase):
update_password = ' always '
)
p = Parameters ( args)
p = Parameters ( params= args)
assert p . username_credential == ' someuser '
assert p . password_credential == ' testpass '
assert p . full_name == ' Fake Person '
@ -91,7 +92,7 @@ class TestParameters(unittest.TestCase):
shell = ' none '
)
p = Parameters ( args)
p = Parameters ( params= args)
assert p . name == ' someuser '
assert p . password == ' testpass '
assert p . full_name == ' Fake Person '
@ -99,8 +100,6 @@ class TestParameters(unittest.TestCase):
assert p . shell == ' none '
@patch ( ' ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root ' ,
return_value = True )
class TestManager ( unittest . TestCase ) :
def setUp ( self ) :
@ -118,21 +117,21 @@ class TestManager(unittest.TestCase):
update_password = ' on_create '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -147,21 +146,21 @@ class TestManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -177,26 +176,26 @@ class TestManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = False )
mm . get_manager = Mock ( return_value = pm )
msg = " The ' update_password ' option " \
" needs to be set to ' on_create ' when creating " \
" a resource with a password. "
with pytest . raises ( F5ModuleError ) as ex :
p m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_create_user_partition_access_raises ( self , * args ) :
@ -207,25 +206,25 @@ class TestManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = False )
mm . get_manager = Mock ( return_value = pm )
msg = " The ' partition_access ' option " \
" is required when creating a resource. "
with pytest . raises ( F5ModuleError ) as ex :
p m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_create_user_shell_bash ( self , * args ) :
@ -241,21 +240,21 @@ class TestManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -273,25 +272,25 @@ class TestManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . create_on_device = Mock ( return_value = True )
pm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = False )
mm . get_manager = Mock ( return_value = pm )
msg = " Shell access is only available to ' admin ' or " \
" ' resource-admin ' roles "
with pytest . raises ( F5ModuleError ) as ex :
p m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_update_user_password_no_pass ( self , * args ) :
@ -303,26 +302,26 @@ class TestManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
current = Parameters ( load_fixture( ' load_auth_user_no_pass.json ' ) )
current = Parameters ( params= load_fixture( ' load_auth_user_no_pass.json ' ) )
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . exists = Mock ( return_value = True )
pm . update_on_device = Mock ( return_value = True )
pm . read_current_from_device = Mock ( return_value = current )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
@ -335,26 +334,26 @@ class TestManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
current = Parameters ( load_fixture( ' load_auth_user_with_pass.json ' ) )
current = Parameters ( params= load_fixture( ' load_auth_user_with_pass.json ' ) )
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . exists = Mock ( return_value = True )
pm . update_on_device = Mock ( return_value = True )
pm . read_current_from_device = Mock ( return_value = current )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
@ -367,31 +366,31 @@ class TestManager(unittest.TestCase):
shell = ' none '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh '
)
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . exists = Mock ( return_value = True )
pm . update_on_device = Mock ( return_value = True )
pm . read_current_from_device = Mock ( return_value = current )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' shell ' ] == ' none '
@ -405,32 +404,32 @@ class TestManager(unittest.TestCase):
shell = ' none '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
access = [ { ' name ' : ' Common ' , ' role ' : ' guest ' } ]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
partition_access = access
)
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = False )
pm = PartitionedManager ( client )
pm = PartitionedManager ( module = module , params = module . params )
pm . exists = Mock ( return_value = True )
pm . update_on_device = Mock ( return_value = True )
pm . read_current_from_device = Mock ( return_value = current )
results = pm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is False
assert not hasattr ( results , ' shell ' )
@ -444,17 +443,16 @@ class TestManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
access = [ { ' name ' : ' all ' , ' role ' : ' admin ' } ]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh ' ,
partition_access = access
@ -462,15 +460,16 @@ class TestManager(unittest.TestCase):
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' shell ' ] == ' bash '
@ -484,10 +483,9 @@ class TestManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
@ -497,7 +495,7 @@ class TestManager(unittest.TestCase):
{ ' name ' : ' all ' , ' role ' : ' guest ' }
]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh ' ,
partition_access = access
@ -505,24 +503,23 @@ class TestManager(unittest.TestCase):
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = True )
mm . get_manager = Mock ( return_value = upm )
msg = " Shell access is only available to ' admin ' or " \
" ' resource-admin ' roles "
with pytest . raises ( F5ModuleError ) as ex :
up m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
@patch ( ' ansible.module_utils.f5_utils.AnsibleF5Client._get_mgmt_root ' ,
return_value = True )
class TestLegacyManager ( unittest . TestCase ) :
def setUp ( self ) :
@ -540,21 +537,21 @@ class TestLegacyManager(unittest.TestCase):
update_password = ' on_create '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -569,21 +566,21 @@ class TestLegacyManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -599,26 +596,26 @@ class TestLegacyManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = True )
mm . get_manager = Mock ( return_value = upm )
msg = " The ' update_password ' option " \
" needs to be set to ' on_create ' when creating " \
" a resource with a password. "
with pytest . raises ( F5ModuleError ) as ex :
up m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_create_user_partition_access_raises ( self , * args ) :
@ -629,25 +626,25 @@ class TestLegacyManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = True )
mm . get_manager = Mock ( return_value = upm )
msg = " The ' partition_access ' option " \
" is required when creating a resource. "
with pytest . raises ( F5ModuleError ) as ex :
up m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_create_user_shell_bash ( self , * args ) :
@ -663,21 +660,21 @@ class TestLegacyManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' partition_access ' ] == access
@ -695,25 +692,25 @@ class TestLegacyManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . create_on_device = Mock ( return_value = True )
upm . exists = Mock ( return_value = False )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = True )
mm . get_manager = Mock ( return_value = upm )
msg = " Shell access is only available to ' admin ' or " \
" ' resource-admin ' roles "
with pytest . raises ( F5ModuleError ) as ex :
up m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg
def test_update_user_password ( self , * args ) :
@ -725,32 +722,32 @@ class TestLegacyManager(unittest.TestCase):
user = ' admin '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
access = [ { ' name ' : ' Common ' , ' role ' : ' guest ' } ]
current = Parameters (
dict (
params = dict (
shell = ' tmsh ' ,
partition_access = access
)
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
@ -763,31 +760,31 @@ class TestLegacyManager(unittest.TestCase):
shell = ' none '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh '
)
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' shell ' ] == ' none '
@ -801,32 +798,32 @@ class TestLegacyManager(unittest.TestCase):
shell = ' none '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
access = [ { ' name ' : ' Common ' , ' role ' : ' guest ' } ]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
partition_access = access
)
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is False
assert not hasattr ( results , ' shell ' )
@ -840,17 +837,16 @@ class TestLegacyManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
# remote device
access = [ { ' name ' : ' all ' , ' role ' : ' admin ' } ]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh ' ,
partition_access = access
@ -858,15 +854,16 @@ class TestLegacyManager(unittest.TestCase):
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
results = upm . exec_module ( )
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 ( )
assert results [ ' changed ' ] is True
assert results [ ' shell ' ] == ' bash '
@ -880,10 +877,9 @@ class TestLegacyManager(unittest.TestCase):
shell = ' bash '
) )
client = AnsibleF5Client (
module = AnsibleModule (
argument_spec = self . spec . argument_spec ,
supports_check_mode = self . spec . supports_check_mode ,
f5_product_name = self . spec . f5_product_name
supports_check_mode = self . spec . supports_check_mode
)
# Configure the parameters that would be returned by querying the
@ -893,7 +889,7 @@ class TestLegacyManager(unittest.TestCase):
{ ' name ' : ' all ' , ' role ' : ' guest ' }
]
current = Parameters (
dict (
params = dict (
user = ' admin ' ,
shell = ' tmsh ' ,
partition_access = access
@ -901,17 +897,18 @@ class TestLegacyManager(unittest.TestCase):
)
# Override methods to force specific logic in the module to happen
mm = ModuleManager ( client )
mm . is_version_less_than_13 = Mock ( return_value = True )
upm = UnparitionedManager ( client )
upm = UnparitionedManager ( module = module , params = module . params )
upm . exists = Mock ( return_value = True )
upm . update_on_device = Mock ( return_value = True )
upm . read_current_from_device = Mock ( return_value = current )
mm = ModuleManager ( module = module )
mm . is_version_less_than_13 = Mock ( return_value = True )
mm . get_manager = Mock ( return_value = upm )
msg = " Shell access is only available to ' admin ' or " \
" ' resource-admin ' roles "
with pytest . raises ( F5ModuleError ) as ex :
up m. exec_module ( )
m m. exec_module ( )
assert str ( ex . value ) == msg