summaryrefslogtreecommitdiff
path: root/test/units
diff options
context:
space:
mode:
Diffstat (limited to 'test/units')
-rw-r--r--test/units/modules/storage/netapp/test_na_elementsw_access_group.py175
-rw-r--r--test/units/modules/storage/netapp/test_na_elementsw_cluster_config.py159
-rw-r--r--test/units/modules/storage/netapp/test_na_elementsw_cluster_snmp.py178
-rw-r--r--test/units/modules/storage/netapp/test_na_elementsw_initiators.py176
4 files changed, 0 insertions, 688 deletions
diff --git a/test/units/modules/storage/netapp/test_na_elementsw_access_group.py b/test/units/modules/storage/netapp/test_na_elementsw_access_group.py
deleted file mode 100644
index b14f7e6df9..0000000000
--- a/test/units/modules/storage/netapp/test_na_elementsw_access_group.py
+++ /dev/null
@@ -1,175 +0,0 @@
-''' unit test for Ansible module: na_elementsw_account.py '''
-
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
-
-import json
-import pytest
-
-from units.compat import unittest
-from units.compat.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
-import ansible.module_utils.netapp as netapp_utils
-
-if not netapp_utils.has_sf_sdk():
- pytestmark = pytest.mark.skip('skipping as missing required SolidFire Python SDK')
-
-from ansible.modules.storage.netapp.na_elementsw_access_group \
- import ElementSWAccessGroup as my_module # module under test
-
-
-def set_module_args(args):
- """prepare arguments so that they will be picked up during module creation"""
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args) # pylint: disable=protected-access
-
-
-class AnsibleExitJson(Exception):
- """Exception class to be raised by module.exit_json and caught by the test case"""
- pass
-
-
-class AnsibleFailJson(Exception):
- """Exception class to be raised by module.fail_json and caught by the test case"""
- pass
-
-
-def exit_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over exit_json; package return data into an exception"""
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
-
-def fail_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over fail_json; package return data into an exception"""
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
-
-ADD_ERROR = 'some_error_in_add_access_group'
-
-
-class MockSFConnection(object):
- ''' mock connection to ElementSW host '''
-
- class Bunch(object): # pylint: disable=too-few-public-methods
- ''' create object with arbitrary attributes '''
- def __init__(self, **kw):
- ''' called with (k1=v1, k2=v2), creates obj.k1, obj.k2 with values v1, v2 '''
- setattr(self, '__dict__', kw)
-
- def __init__(self, force_error=False, where=None):
- ''' save arguments '''
- self.force_error = force_error
- self.where = where
-
- def list_volume_access_groups(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' build access_group list: access_groups.name, access_groups.account_id '''
- access_groups = list()
- access_group_list = self.Bunch(volume_access_groups=access_groups)
- return access_group_list
-
- def create_volume_access_group(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' We don't check the return code, but could force an exception '''
- if self.force_error and 'add' in self.where:
- # The module does not check for a specific exception :(
- raise OSError(ADD_ERROR)
-
- def get_account_by_name(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' returns account_id '''
- if self.force_error and 'account_id' in self.where:
- account_id = None
- else:
- account_id = 1
- print('account_id', account_id)
- account = self.Bunch(account_id=account_id)
- result = self.Bunch(account=account)
- return result
-
-
-class TestMyModule(unittest.TestCase):
- ''' a group of related Unit Tests '''
-
- def setUp(self):
- self.mock_module_helper = patch.multiple(basic.AnsibleModule,
- exit_json=exit_json,
- fail_json=fail_json)
- self.mock_module_helper.start()
- self.addCleanup(self.mock_module_helper.stop)
-
- def test_module_fail_when_required_args_missing(self):
- ''' required arguments are reported as errors '''
- with pytest.raises(AnsibleFailJson) as exc:
- set_module_args({})
- my_module()
- print('Info: %s' % exc.value.args[0]['msg'])
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_command_called(self, mock_create_sf_connection):
- ''' a more interesting test '''
- set_module_args({
- 'state': 'present',
- 'name': 'element_groupname',
- 'account_id': 'element_account_id',
- 'hostname': 'hostname',
- 'username': 'username',
- 'password': 'password',
- })
- # my_obj.sfe will be assigned a MockSFConnection object:
- mock_create_sf_connection.return_value = MockSFConnection()
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- # It may not be a good idea to start with apply
- # More atomic methods can be easier to mock
- my_obj.apply()
- print(exc.value.args[0])
- assert exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_check_error_reporting_on_add_exception(self, mock_create_sf_connection):
- ''' a more interesting test '''
- set_module_args({
- 'state': 'present',
- 'name': 'element_groupname',
- 'account_id': 'element_account_id',
- 'hostname': 'hostname',
- 'username': 'username',
- 'password': 'password',
- })
- # my_obj.sfe will be assigned a MockSFConnection object:
- mock_create_sf_connection.return_value = MockSFConnection(force_error=True, where=['add'])
- my_obj = my_module()
- with pytest.raises(AnsibleFailJson) as exc:
- # It may not be a good idea to start with apply
- # More atomic methods can be easier to mock
- # apply() is calling list_accounts() and add_account()
- my_obj.apply()
- print(exc.value.args[0])
- message = 'Error creating volume access group element_groupname: %s' % ADD_ERROR
- assert exc.value.args[0]['msg'] == message
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_check_error_reporting_on_invalid_account_id(self, mock_create_sf_connection):
- ''' a more interesting test '''
- set_module_args({
- 'state': 'present',
- 'name': 'element_groupname',
- 'account_id': 'element_account_id',
- 'volumes': ['volume1'],
- 'hostname': 'hostname',
- 'username': 'username',
- 'password': 'password',
- })
- # my_obj.sfe will be assigned a MockSFConnection object:
- mock_create_sf_connection.return_value = MockSFConnection(force_error=True, where=['account_id'])
- my_obj = my_module()
- with pytest.raises(AnsibleFailJson) as exc:
- # It may not be a good idea to start with apply
- # More atomic methods can be easier to mock
- # apply() is calling list_accounts() and add_account()
- my_obj.apply()
- print(exc.value.args[0])
- message = 'Error: Specified account id "%s" does not exist.' % 'element_account_id'
- assert exc.value.args[0]['msg'] == message
diff --git a/test/units/modules/storage/netapp/test_na_elementsw_cluster_config.py b/test/units/modules/storage/netapp/test_na_elementsw_cluster_config.py
deleted file mode 100644
index bebdc72d88..0000000000
--- a/test/units/modules/storage/netapp/test_na_elementsw_cluster_config.py
+++ /dev/null
@@ -1,159 +0,0 @@
-# (c) 2019, NetApp, Inc
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-''' unit test for Ansible module: na_elementsw_cluster_config.py '''
-
-from __future__ import print_function
-import json
-import pytest
-
-from units.compat import unittest
-from units.compat.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
-import ansible.module_utils.netapp as netapp_utils
-
-if not netapp_utils.has_sf_sdk():
- pytestmark = pytest.mark.skip('skipping as missing required SolidFire Python SDK')
-
-from ansible.modules.storage.netapp.na_elementsw_cluster_config \
- import ElementSWClusterConfig as my_module # module under test
-
-
-def set_module_args(args):
- """prepare arguments so that they will be picked up during module creation"""
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args) # pylint: disable=protected-access
-
-
-class AnsibleExitJson(Exception):
- """Exception class to be raised by module.exit_json and caught by the test case"""
- pass
-
-
-class AnsibleFailJson(Exception):
- """Exception class to be raised by module.fail_json and caught by the test case"""
- pass
-
-
-def exit_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over exit_json; package return data into an exception"""
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
-
-def fail_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over fail_json; package return data into an exception"""
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
-
-GET_ERROR = 'some_error_in_get_ntp_info'
-
-
-class MockSFConnection(object):
- ''' mock connection to ElementSW host '''
-
- class Bunch(object): # pylint: disable=too-few-public-methods
- ''' create object with arbitrary attributes '''
-
- def __init__(self, **kw):
- ''' called with (k1=v1, k2=v2), creates obj.k1, obj.k2 with values v1, v2 '''
- setattr(self, '__dict__', kw)
-
- def __init__(self, force_error=False, where=None):
- ''' save arguments '''
- self.force_error = force_error
- self.where = where
-
-
-class TestMyModule(unittest.TestCase):
- ''' a group of related Unit Tests '''
-
- def setUp(self):
- self.mock_module_helper = patch.multiple(basic.AnsibleModule,
- exit_json=exit_json,
- fail_json=fail_json)
- self.mock_module_helper.start()
- self.addCleanup(self.mock_module_helper.stop)
-
- def set_default_args(self):
- return dict({
- 'hostname': '10.253.168.129',
- 'username': 'namburu',
- 'password': 'SFlab1234',
- })
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_module_fail_when_required_args_missing(self, mock_create_sf_connection):
- ''' required arguments are reported as errors '''
- with pytest.raises(AnsibleFailJson) as exc:
- set_module_args({})
- my_module()
- print('Info: %s' % exc.value.args[0]['msg'])
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_setup_ntp_info_called(self, mock_create_sf_connection):
- ''' test if setup_ntp_info is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- ntp_dict = {'set_ntp_info': {'broadcastclient': None,
- 'ntp_servers': ['1.1.1.1']}}
- module_args.update(ntp_dict)
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_setup_ntp_info: %s' % repr(exc.value))
- assert exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_set_encryption_at_rest_called(self, mock_create_sf_connection):
- ''' test if set_encryption_at_rest is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'encryption_at_rest': 'present'})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_set_encryption_at_rest enable: %s' % repr(exc.value))
- assert not exc.value.args[0]['changed']
- module_args.update({'encryption_at_rest': 'absent'})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_set_encryption_at_rest disable: %s' % repr(exc.value))
- assert not exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_enable_feature_called(self, mock_create_sf_connection):
- ''' test if enable_feature for vvols is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'enable_virtual_volumes': True})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_enable_feature: %s' % repr(exc.value))
- assert not exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_set_cluster_full_threshold_called(self, mock_create_sf_connection):
- ''' test if set_cluster_full threshold is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- cluster_mod_dict = \
- {'modify_cluster_full_threshold': {'stage2_aware_threshold': 2,
- 'stage3_block_threshold_percent': 2,
- 'max_metadata_over_provision_factor': 2}}
- module_args.update(cluster_mod_dict)
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_set_cluster_full_threshold: %s' % repr(exc.value))
- assert exc.value.args[0]['changed']
diff --git a/test/units/modules/storage/netapp/test_na_elementsw_cluster_snmp.py b/test/units/modules/storage/netapp/test_na_elementsw_cluster_snmp.py
deleted file mode 100644
index 50f90a6cec..0000000000
--- a/test/units/modules/storage/netapp/test_na_elementsw_cluster_snmp.py
+++ /dev/null
@@ -1,178 +0,0 @@
-# (c) 2019, NetApp, Inc
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-''' unit test for Ansible module: na_elementsw_cluster_snmp.py '''
-
-from __future__ import print_function
-import json
-import pytest
-
-from units.compat import unittest
-from units.compat.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
-import ansible.module_utils.netapp as netapp_utils
-
-if not netapp_utils.has_sf_sdk():
- pytestmark = pytest.mark.skip('skipping as missing required SolidFire Python SDK')
-
-from ansible.modules.storage.netapp.na_elementsw_cluster_snmp \
- import ElementSWClusterSnmp as my_module # module under test
-
-
-def set_module_args(args):
- """prepare arguments so that they will be picked up during module creation"""
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args) # pylint: disable=protected-access
-
-
-class AnsibleExitJson(Exception):
- """Exception class to be raised by module.exit_json and caught by the test case"""
- pass
-
-
-class AnsibleFailJson(Exception):
- """Exception class to be raised by module.fail_json and caught by the test case"""
- pass
-
-
-def exit_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over exit_json; package return data into an exception"""
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
-
-def fail_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over fail_json; package return data into an exception"""
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
-
-GET_ERROR = 'some_error_in_get_snmp_info'
-
-
-class MockSFConnection(object):
- ''' mock connection to ElementSW host '''
-
- class Bunch(object): # pylint: disable=too-few-public-methods
- ''' create object with arbitrary attributes '''
- def __init__(self, **kw):
- ''' called with (k1=v1, k2=v2), creates obj.k1, obj.k2 with values v1, v2 '''
- setattr(self, '__dict__', kw)
-
- def __init__(self, force_error=False, where=None):
- ''' save arguments '''
- self.force_error = force_error
- self.where = where
-
-
-class TestMyModule(unittest.TestCase):
- ''' a group of related Unit Tests '''
-
- def setUp(self):
- self.mock_module_helper = patch.multiple(basic.AnsibleModule,
- exit_json=exit_json,
- fail_json=fail_json)
- self.mock_module_helper.start()
- self.addCleanup(self.mock_module_helper.stop)
-
- def set_default_args(self):
- return dict({
- 'hostname': '10.117.78.131',
- 'username': 'admin',
- 'password': 'netapp1!',
- })
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_module_fail_when_required_args_missing(self, mock_create_sf_connection):
- ''' required arguments are reported as errors '''
- with pytest.raises(AnsibleFailJson) as exc:
- set_module_args({})
- my_module()
- print('Info: %s' % exc.value)
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_enable_snmp_called(self, mock_create_sf_connection):
- ''' test if enable_snmp is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'snmp_v3_enabled': True,
- 'state': 'present'})
- module_args.update({'usm_users': {'access': 'rouser',
- 'name': 'TestUser',
- 'password': 'ChangeMe@123',
- 'passphrase': 'ChangeMe@123',
- 'secLevel': 'auth', }})
-
- module_args.update({'networks': {'access': 'ro',
- 'cidr': 24,
- 'community': 'TestNetwork',
- 'network': '192.168.0.1', }})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_if_enable_snmp_called: %s' % repr(exc.value))
- assert exc.value
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_configure_snmp_from_version_3_TO_version_2_called(self, mock_create_sf_connection):
- ''' test if configure snmp from version_3 to version_2'''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'snmp_v3_enabled': False,
- 'state': 'present'})
- module_args.update({'usm_users': {'access': 'rouser',
- 'name': 'TestUser',
- 'password': 'ChangeMe@123',
- 'passphrase': 'ChangeMe@123',
- 'secLevel': 'auth', }})
-
- module_args.update({'networks': {'access': 'ro',
- 'cidr': 24,
- 'community': 'TestNetwork',
- 'network': '192.168.0.1', }})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_ensure_configure_snmp_from_version_3_TO_version_2_called: %s' % repr(exc.value))
- assert exc.value
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_configure_snmp_from_version_2_TO_version_3_called(self, mock_create_sf_connection):
- ''' test if configure snmp from version_2 to version_3'''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'snmp_v3_enabled': True,
- 'state': 'present'})
- module_args.update({'usm_users': {'access': 'rouser',
- 'name': 'TestUser_sample',
- 'password': 'ChangeMe@123',
- 'passphrase': 'ChangeMe@123',
- 'secLevel': 'auth', }})
-
- module_args.update({'networks': {'access': 'ro',
- 'cidr': 24,
- 'community': 'TestNetwork',
- 'network': '192.168.0.1', }})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_ensure_configure_snmp_from_version_2_TO_version_3_called: %s' % repr(exc.value))
- assert exc.value
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_ensure_disable_snmp_called(self, mock_create_sf_connection):
- ''' test if disable_snmp is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- module_args.update({'state': 'absent'})
- set_module_args(module_args)
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_if_disable_snmp_called: %s' % repr(exc.value))
- assert exc.value
diff --git a/test/units/modules/storage/netapp/test_na_elementsw_initiators.py b/test/units/modules/storage/netapp/test_na_elementsw_initiators.py
deleted file mode 100644
index 91972ae43b..0000000000
--- a/test/units/modules/storage/netapp/test_na_elementsw_initiators.py
+++ /dev/null
@@ -1,176 +0,0 @@
-# (c) 2019, NetApp, Inc
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-''' unit test for Ansible module: na_elementsw_initiators.py '''
-
-from __future__ import print_function
-import json
-import pytest
-
-from units.compat import unittest
-from units.compat.mock import patch
-from ansible.module_utils import basic
-from ansible.module_utils._text import to_bytes
-import ansible.module_utils.netapp as netapp_utils
-
-if not netapp_utils.has_sf_sdk():
- pytestmark = pytest.mark.skip('skipping as missing required SolidFire Python SDK')
-
-from ansible.modules.storage.netapp.na_elementsw_initiators \
- import ElementSWInitiators as my_module # module under test
-
-
-def set_module_args(args):
- """prepare arguments so that they will be picked up during module creation"""
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args) # pylint: disable=protected-access
-
-
-class AnsibleExitJson(Exception):
- """Exception class to be raised by module.exit_json and caught by the test case"""
- pass
-
-
-class AnsibleFailJson(Exception):
- """Exception class to be raised by module.fail_json and caught by the test case"""
- pass
-
-
-def exit_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over exit_json; package return data into an exception"""
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
-
-def fail_json(*args, **kwargs): # pylint: disable=unused-argument
- """function to patch over fail_json; package return data into an exception"""
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
-
-
-class MockSFConnection(object):
- ''' mock connection to ElementSW host '''
-
- class Bunch(object): # pylint: disable=too-few-public-methods
- ''' create object with arbitrary attributes '''
- def __init__(self, **kw):
- ''' called with (k1=v1, k2=v2), creates obj.k1, obj.k2 with values v1, v2 '''
- setattr(self, '__dict__', kw)
-
- class Initiator(object):
- def __init__(self, entries):
- self.__dict__.update(entries)
-
- def list_initiators(self):
- ''' build initiator Obj '''
- all_initiators = {
- "initiators": [{
- "initiator_name": "a",
- "initiator_id": 13,
- "alias": "a2",
- "attributes": {"key": "value"}
- }]
- }
- return json.loads(json.dumps(all_initiators), object_hook=self.Initiator)
-
- def create_initiators(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' mock method '''
- pass
-
- def delete_initiators(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' mock method '''
- pass
-
- def modify_initiators(self, *args, **kwargs): # pylint: disable=unused-argument
- ''' mock method '''
- pass
-
-
-class TestMyModule(unittest.TestCase):
- ''' a group of related Unit Tests '''
-
- def setUp(self):
- self.mock_module_helper = patch.multiple(basic.AnsibleModule,
- exit_json=exit_json,
- fail_json=fail_json)
- self.mock_module_helper.start()
- self.addCleanup(self.mock_module_helper.stop)
-
- def set_default_args(self):
- return dict({
- 'hostname': '10.253.168.129',
- 'username': 'namburu',
- 'password': 'SFlab1234',
- })
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_module_fail_when_required_args_missing(self, mock_create_sf_connection):
- ''' required arguments are reported as errors '''
- with pytest.raises(AnsibleFailJson) as exc:
- set_module_args({})
- my_module()
- print('Info: %s' % exc.value.args[0]['msg'])
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_create_initiators(self, mock_create_sf_connection):
- ''' test if create initiator is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- initiator_dict = {
- "state": "present",
- "initiators": [{
- "name": "newinitiator1",
- "alias": "newinitiator1alias",
- "attributes": {"key1": "value1"}
- }]
- }
- module_args.update(initiator_dict)
- set_module_args(module_args)
- mock_create_sf_connection.return_value = MockSFConnection()
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_create_initiators: %s' % repr(exc.value))
- assert exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_delete_initiators(self, mock_create_sf_connection):
- ''' test if delete initiator is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- initiator_dict = {
- "state": "absent",
- "initiators": [{
- "name": "a"
- }]
- }
- module_args.update(initiator_dict)
- set_module_args(module_args)
- mock_create_sf_connection.return_value = MockSFConnection()
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_delete_initiators: %s' % repr(exc.value))
- assert exc.value.args[0]['changed']
-
- @patch('ansible.module_utils.netapp.create_sf_connection')
- def test_modify_initiators(self, mock_create_sf_connection):
- ''' test if modify initiator is called '''
- module_args = {}
- module_args.update(self.set_default_args())
- initiator_dict = {
- "state": "present",
- "initiators": [{
- "initiator_name": "a",
- "alias": "a3",
- "attributes": {"key": "value"}
- }]
- }
- module_args.update(initiator_dict)
- set_module_args(module_args)
- mock_create_sf_connection.return_value = MockSFConnection()
- my_obj = my_module()
- with pytest.raises(AnsibleExitJson) as exc:
- my_obj.apply()
- print('Info: test_modify_initiators: %s' % repr(exc.value))
- assert exc.value.args[0]['changed']