def test_create_mdisk_successfully(self, svc_authorize_mock, mdisk_create_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_create_mdisk_successfully', 'level': 'raid0', 'drive': '5:6', 'encrypt': 'no', 'mdiskgrp': 'Pool' }) mdisk = { u'message': u'Mdisk, id [0],' u'successfully created', u'id': u'0' } mdisk_create_mock.return_value = mdisk get_existing_mdisk_mock.return_value = [] mdisk_created = IBMSVCmdisk() with pytest.raises(AnsibleExitJson) as exc: mdisk_created.apply() self.assertTrue(exc.value.args[0]['changed']) get_existing_mdisk_mock.assert_called_with()
def test_mdisk_create_get_existing_mdisk_called(self, svc_authorize_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_mdisk_create_get_existing_mdisk_called', 'mdiskgrp': 'Pool' }) mdisk_created = IBMSVCmdisk() with pytest.raises(AnsibleExitJson) as exc: mdisk_created.apply() get_existing_mdisk_mock.assert_called_with()
def test_delete_mdisk_but_mdisk_not_existed(self, svc_authorize_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'absent', 'username': '******', 'password': '******', 'name': 'test_delete_mdisk_but_mdisk_not_existed', 'mdiskgrp': 'Pool' }) get_existing_mdisk_mock.return_value = [] mdisk_deleted = IBMSVCmdisk() with pytest.raises(AnsibleExitJson) as exc: mdisk_deleted.apply() self.assertFalse(exc.value.args[0]['changed']) get_existing_mdisk_mock.assert_called_with()
def test_create_mdisk_failed_since_missed_required_param( self, svc_authorize_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_create_mdisk_failed_since_missed_required_param', 'mdiskgrp': 'Pool' }) get_existing_mdisk_mock.return_value = [] mdisk_created = IBMSVCmdisk() with pytest.raises(AnsibleFailJson) as exc: mdisk_created.apply() self.assertTrue(exc.value.args[0]['failed']) get_existing_mdisk_mock.assert_called_with()
def test_create_mdisk_failed_since_no_message_in_result( self, svc_authorize_mock, svc_run_command_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_create_mdisk_successfully', 'level': 'raid0', 'drive': '5:6', 'encrypt': 'no', 'mdiskgrp': 'Pool' }) mdisk = {u'id': u'0'} svc_run_command_mock.return_value = mdisk get_existing_mdisk_mock.return_value = [] mdisk_created = IBMSVCmdisk() with pytest.raises(AnsibleFailJson) as exc: mdisk_created.apply() get_existing_mdisk_mock.assert_called_with()
def test_create_mdisk_but_mdisk_existed(self, svc_authorize_mock, mdisk_probe_mock, get_existing_mdisk_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_create_mdisk_but_mdisk_existed', 'mdiskgrp': 'Pool' }) mdisk_ret = [{ "id": "0", "name": "mdisk_Ansible_collections", "status": "online", "mode": "array", "mdisk_grp_id": "0", "mdisk_grp_name": "Pool_Ansible_collections", "capacity": "5.2TB", "ctrl_LUN_#": "", "controller_name": "", "UID": "", "tier": "tier0_flash", "encrypt": "no", "site_id": "", "site_name": "", "distributed": "no", "dedupe": "no", "over_provisioned": "no", "supports_unmap": "yes" }] get_existing_mdisk_mock.return_value = mdisk_ret mdisk_probe_mock.return_value = [] mdisk_created = IBMSVCmdisk() with pytest.raises(AnsibleExitJson) as exc: mdisk_created.apply() self.assertFalse(exc.value.args[0]['changed']) get_existing_mdisk_mock.assert_called_with()