def test_create_fcmap_but_fcmap_existed(self, svc_authorize_mock,
                                         flashcopymap_probe_mock,
                                         get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'vol_clone_fcmapping',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     fcmap_ret = [{
         'id': '0',
         'name': 'vol_clone_fcmapping',
         'source_vdisk_id': '0',
         'source_vdisk_name': 'volume_Ansible_collections',
         'target_vdisk_id': '1',
         'target_vdisk_name': 'volume_Ansible_clone',
         'group_id': '',
         'group_name': '',
         'status': 'idle_or_copied',
         'progress': '0',
         'copy_rate': '0',
         'start_time': '',
         'dependent_mappings': '0',
         'autodelete': 'off',
         'clean_progress': '100',
         'clean_rate': '50',
         'incremental': 'off',
         'difference': '100',
         'grain_size': '256',
         'IO_group_id': '0',
         'IO_group_name': 'io_grp0',
         'partner_FC_id': '',
         'partner_FC_name': '',
         'restoring': 'no',
         'rc_controlled': 'no',
         'keep_target': 'no',
         'type': 'generic',
         'restore_progress': '0',
         'fc_controlled': 'no',
         'owner_id': '',
         'owner_name': ''
     }]
     get_fc_mapping_mock.return_value = fcmap_ret
     flashcopymap_probe_mock.return_value = []
     volume_created = IBMSVCClone()
     with pytest.raises(AnsibleExitJson) as exc:
         volume_created.apply()
     self.assertFalse(exc.value.args[0]['changed'])
     get_fc_mapping_mock.assert_called_with()
 def test_create_clone_successfully(self, svc_authorize_mock,
                                    flashcopymap_create_mock,
                                    get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'volume_Ansible_collections',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     fcmap = {
         u'message': u'Flash Copy mapping, id [0], '
         u'successfully created',
         u'id': u'0'
     }
     flashcopymap_create_mock.return_value = fcmap
     get_fc_mapping_mock.return_value = []
     with pytest.raises(AnsibleExitJson) as exc:
         IBMSVCClone().apply()
     self.assertTrue(exc.value.args[0]['changed'])
     get_fc_mapping_mock.assert_called_with()
 def test_get_existing_clone(self, svc_authorize_mock, svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_get_existing_clone',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     vol_ret = [{"id": "0", "name": "volume_Ansible_collections",
                 "IO_group_id": "0", "IO_group_name": "io_grp0",
                 "status": "online", "mdisk_grp_id": "0",
                 "mdisk_grp_name": "Pool_Ansible_collections",
                 "capacity": "4.00GB", "type": "striped", "FC_id": "",
                 "FC_name": "", "RC_id": "", "RC_name": "",
                 "vdisk_UID": "6005076810CA0166C00000000000019F",
                 "fc_map_count": "0", "copy_count": "1",
                 "fast_write_state": "empty", "se_copy_count": "0",
                 "RC_change": "no", "compressed_copy_count": "0",
                 "parent_mdisk_grp_id": "0",
                 "parent_mdisk_grp_name": "Pool_Ansible_collections",
                 "owner_id": "", "owner_name": "", "formatting": "no",
                 "encrypt": "no", "volume_id": "0",
                 "volume_name": "volume_Ansible_collections",
                 "function": "", "protocol": "scsi"}]
     svc_obj_info_mock.return_value = vol_ret
     vol = IBMSVCClone().get_existing_clone()
     self.assertEqual('volume_Ansible_collections', vol['name'])
     self.assertEqual('0', vol['id'])
 def test_flashcopymap_probe(self, svc_authorize_mock, get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'vol_clone_fcmapping',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol',
         'copyrate': '50'
     })
     fcmap_ret = [{'id': '0', 'name': 'vol_clone_fcmapping',
                   'source_vdisk_id': '0',
                   'source_vdisk_name': 'volume_Ansible_collections',
                   'target_vdisk_id': '1',
                   'target_vdisk_name': 'volume_Ansible_clone',
                   'group_id': '', 'group_name': '',
                   'status': 'idle_or_copied', 'progress': '0',
                   'copy_rate': '0', 'start_time': '',
                   'dependent_mappings': '0', 'autodelete': 'off',
                   'clean_progress': '100', 'clean_rate': '50',
                   'incremental': 'off', 'difference': '100',
                   'grain_size': '256', 'IO_group_id': '0',
                   'IO_group_name': 'io_grp0', 'partner_FC_id': '',
                   'partner_FC_name': '', 'restoring': 'no',
                   'rc_controlled': 'no', 'keep_target': 'no',
                   'type': 'generic', 'restore_progress': '0',
                   'fc_controlled': 'no', 'owner_id': '', 'owner_name': ''}]
     get_fc_mapping_mock.return_value = fcmap_ret
     ret = IBMSVCClone().flashcopymap_probe(fcmap_ret[0])
     print('Info: %s' % ret['copyrate'])
     self.assertEqual('50', ret['copyrate'])
 def test_fcmap_create_get_fc_mapping_called(self, svc_authorize_mock,
                                             mock_flashcopymap_probe,
                                             get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_get_existing_clone',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     fcmap_created = IBMSVCClone()
     mock_flashcopymap_probe.return_value = []
     with pytest.raises(AnsibleExitJson) as exc:
         fcmap_created.apply()
     self.assertFalse(exc.value.args[0]['changed'])
     get_fc_mapping_mock.assert_called_with()
 def test_create_fcmap_for_clone_failed_since_missed_required_param(
         self, svc_authorize_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_get_existing_clone',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol'
     })
     with pytest.raises(AnsibleFailJson) as exc:
         IBMSVCClone().apply()
     self.assertTrue(exc.value.args[0]['failed'])
 def test_delete_fcmap_but_fcmap_not_existed(self, svc_authorize_mock,
                                             get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'absent',
         'username': '******',
         'password': '******',
         'name': 'volume_Ansible_collections',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     get_fc_mapping_mock.return_value = []
     with pytest.raises(AnsibleExitJson) as exc:
         IBMSVCClone().apply()
     self.assertFalse(exc.value.args[0]['changed'])
     get_fc_mapping_mock.assert_called_with()
 def test_create_clone_failed_since_no_message_in_result(
         self, svc_authorize_mock, svc_run_command_mock,
         get_fc_mapping_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'volume_Ansible_collections',
         'mdiskgrp': 'Ansible-Pool',
         'volume': 'source-vol',
         'clone': 'clone-vol'
     })
     clone = {u'id': u'0'}
     svc_run_command_mock.return_value = clone
     get_fc_mapping_mock.return_value = []
     with pytest.raises(AnsibleFailJson) as exc:
         IBMSVCClone().apply()
     get_fc_mapping_mock.assert_called_with()
 def test_module_fail_when_required_args_missing(self):
     """ required arguments are reported as errors """
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         IBMSVCClone()
     print('Info: %s' % exc.value.args[0]['msg'])