def test_deleting_existing_fcmap(self, svc_authorize_mock, svc_run_command_mock, gd):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'absent',
            'username': '******',
            'password': '******',
            'name': 'test_name',
        })
        fdata = {
            "id": "45", "name": "test_name", "source_vdisk_id": "320", "source_vdisk_name": "Ans_n7",
            "target_vdisk_id": "323", "target_vdisk_name": "target_vdisk", "group_id": "1", "group_name": "new_consistgrp",
            "status": "idle_or_copied", "progress": "0", "copy_rate": "100", "start_time": "",
            "dependent_mappings": "0", "autodelete": "off", "clean_progress": "100", "clean_rate": "0",
            "incremental": "off", "difference": "100", "grain_size": "64", "IO_group_id": "0",
            "IO_group_name": "io_grp_name", "partner_FC_id": "43", "partner_FC_name": "test_fcmap",
            "restoring": "no", "rc_controlled": "no", "keep_target": "no", "type": "generic",
            "restore_progress": "0", "fc_controlled": "no", "owner_id": "", "owner_name": ""
        }
        gd.return_value = [fdata, None, None, []]
        with pytest.raises(AnsibleExitJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]['changed'])
    def test_creating_fcmap(self, svc_authorize_mock, svc_run_command_mock, gd, tcm, fcm, rtttm):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'present',
            'username': '******',
            'password': '******',
            'name': 'test_name',
            'copytype': 'snapshot',
            'source': 'test_source',
            'target': 'test_target',
            'mdiskgrp': 'test_mdiskgrp',
            'consistgrp': 'test_consistgrp',
            'copyrate': 50,
            'grainsize': 64,
        })
        sdata = {
            "id": "500", "name": "test_source", "IO_group_id": "0", "IO_group_name": "io_grp0",
            "status": "online", "mdisk_grp_id": "1", "mdisk_grp_name": "AnsibleMaster",
            "capacity": "10737418240", "type": "striped", "FC_id": "", "FC_name": "", "RC_id": "500",
            "RC_name": "rcopy_8", "vdisk_UID": "60050768108101C7C0000000000009D0", "fc_map_count": "0",
            "copy_count": "1", "fast_write_state": "not_empty", "se_copy_count": "1", "RC_change": "no",
            "compressed_copy_count": "0", "parent_mdisk_grp_id": "1", "parent_mdisk_grp_name": "AnsibleMaster",
            "owner_id": "", "owner_name": "", "formatting": "no", "encrypt": "no", "volume_id": "500",
            "volume_name": "master_vol_8", "function": "master", "protocol": ""
        }
        gd.return_value = ({}, [sdata], None, [])
        with pytest.raises(AnsibleExitJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]['changed'])
    def test_updating_existing_fcmap(self, svc_authorize_mock, svc_run_command_mock, gd):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'present',
            'username': '******',
            'password': '******',
            'name': 'test_name',
            'copytype': 'snapshot',
            'source': 'test_source',
            'target': 'test_target',
            'mdiskgrp': 'test_mdiskgrp',
            'consistgrp': 'test_consistgrp',
            'copyrate': 50,
            'grainsize': 64,
        })
        fdata = {
            "id": "45", "name": "test_name", "source_vdisk_id": "320", "source_vdisk_name": "test_source",
            "target_vdisk_id": "323", "target_vdisk_name": "test_target", "group_id": "1", "group_name": "new_consistgrp",
            "status": "idle_or_copied", "progress": "0", "copy_rate": "100", "start_time": "",
            "dependent_mappings": "0", "autodelete": "off", "clean_progress": "100", "clean_rate": "0",
            "incremental": "off", "difference": "100", "grain_size": "64", "IO_group_id": "0",
            "IO_group_name": "io_grp_name", "partner_FC_id": "43", "partner_FC_name": "test_fcmap",
            "restoring": "no", "rc_controlled": "no", "keep_target": "no", "type": "generic",
            "restore_progress": "0", "fc_controlled": "no", "owner_id": "", "owner_name": ""
        }
        sdata = {
            "id": "500", "name": "test_source", "IO_group_id": "0", "IO_group_name": "io_grp0",
            "status": "online", "mdisk_grp_id": "1", "mdisk_grp_name": "AnsibleMaster",
            "capacity": "10737418240", "type": "striped", "FC_id": "", "FC_name": "", "RC_id": "500",
            "RC_name": "rcopy_8", "vdisk_UID": "60050768108101C7C0000000000009D0", "fc_map_count": "0",
            "copy_count": "1", "fast_write_state": "not_empty", "se_copy_count": "1", "RC_change": "no",
            "compressed_copy_count": "0", "parent_mdisk_grp_id": "1", "parent_mdisk_grp_name": "AnsibleMaster",
            "owner_id": "", "owner_name": "", "formatting": "no", "encrypt": "no", "volume_id": "500",
            "volume_name": "master_vol_8", "function": "master", "protocol": ""
        }
        tdata = {
            "id": "500", "name": "test_target", "IO_group_id": "0", "IO_group_name": "io_grp0",
            "status": "online", "mdisk_grp_id": "1", "mdisk_grp_name": "AnsibleMaster",
            "capacity": "10737418240", "type": "striped", "FC_id": "", "FC_name": "", "RC_id": "500",
            "RC_name": "rcopy_8", "vdisk_UID": "60050768108101C7C0000000000009D0", "fc_map_count": "0",
            "copy_count": "1", "fast_write_state": "not_empty", "se_copy_count": "1", "RC_change": "no",
            "compressed_copy_count": "0", "parent_mdisk_grp_id": "1", "parent_mdisk_grp_name": "AnsibleMaster",
            "owner_id": "", "owner_name": "", "formatting": "no", "encrypt": "no", "volume_id": "500",
            "volume_name": "master_vol_8", "function": "master", "protocol": ""
        }
        gd.return_value = (fdata, sdata, tdata, [])
        with pytest.raises(AnsibleExitJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]["changed"])
    def test_failure_create_with_missing_parameter(self, svc_authorize_mock):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'present',
            'username': '******',
            'password': '******',
            'name': 'test_name',
        })
        with pytest.raises(AnsibleFailJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]['failed'])
    def test_deleting_non_existing_fcmap(self, svc_authorize_mock, svc_run_command_mock, gd):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'absent',
            'username': '******',
            'password': '******',
            'name': 'test_name'
        })
        gd.return_value = [{}, None, None, []]
        with pytest.raises(AnsibleExitJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(False, exc.value.args[0]['changed'])
    def test_failure_with_copyrate_outside_range(self, svc_authorize_mock):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'absent',
            'username': '******',
            'password': '******',
            'name': 'test_name',
            'copytype': 'snapshot',
            'source': 'test_source',
            'target': 'test_target',
            'mdiskgrp': 'test_mdiskgrp',
            'consistgrp': 'test_consistgrp',
            'copyrate': 500,
            'grainsize': 64,
        })
        with pytest.raises(AnsibleFailJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]['failed'])
    def test_with_source_missing(self, svc_authorize_mock, svc_run_command_mock, gd):
        set_module_args({
            'clustername': 'clustername',
            'domain': 'domain',
            'state': 'present',
            'username': '******',
            'password': '******',
            'name': 'test_name',
            'copytype': 'snapshot',
            'source': 'test_source',
            'target': 'test_target',
            'mdiskgrp': 'test_mdiskgrp',
            'consistgrp': 'test_consistgrp',
            'copyrate': 50,
            'grainsize': 64,
        })
        gd.return_value = (None, None, None, [])
        with pytest.raises(AnsibleFailJson) as exc:
            obj = IBMSVCFlashcopy()
            data = obj.apply()

        self.assertEqual(True, exc.value.args[0]['failed'])