def test_stop_existsting_fc_consistgrp_with_force(self, svc_authorize_mock,
                                                   gef, sc):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_name',
         'state': 'stopped',
         'force': True
     })
     gef.return_value = {
         'id': '4',
         'name': 'test_group',
         'status': 'copying',
         'autodelete': 'off',
         'start_time': '210112113610',
         'owner_id': '0',
         'owner_name': 'test_ownershipgroup',
         'FC_mapping_id': '39',
         'FC_mapping_name': 'test_mapping'
     }
     sc.return_value = None
     with pytest.raises(AnsibleExitJson) as exc:
         obj = IBMSVCFlashcopyStartStop()
         obj.apply()
     self.assertEqual(True, exc.value.args[0]["changed"])
 def test_get_existing_fcmapping_isgroup(self, svc_authorize_mock,
                                         svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_group',
         'state': 'started',
         'isgroup': True
     })
     svc_obj_info_mock.return_value = {
         'id': '4',
         'name': 'test_group',
         'status': 'stopped',
         'autodelete': 'off',
         'start_time': '',
         'owner_id': '0',
         'owner_name': 'test_ownershipgroup',
         'FC_mapping_id': '39',
         'FC_mapping_name': 'test_mapping'
     }
     obj = IBMSVCFlashcopyStartStop()
     data = obj.get_existing_fcmapping()
     self.assertEqual('test_group', data['name'])
 def test_stop_fc(self, svc_authorize_mock, svc_run_command_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_name',
         'state': 'stopped',
     })
     svc_run_command_mock.return_value = None
     obj = IBMSVCFlashcopyStartStop()
     data = obj.stop_fc()
     self.assertEqual(None, data)
 def test_stop_existsting_fc_mappping_with_force(self, svc_authorize_mock,
                                                 gef, sc):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_name',
         'state': 'stopped',
         'force': True
     })
     gef.return_value = {
         "id": "39",
         "name": "test_mapping",
         "source_vdisk_id": "146",
         "source_vdisk_name": "test_source",
         "target_vdisk_id": "324",
         "target_vdisk_name": "test_target",
         "group_id": "4",
         "group_name": "test_group",
         "status": "copying",
         "progress": "0",
         "copy_rate": "41",
         "start_time": "210112113610",
         "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": ""
     }
     sc.return_value = None
     with pytest.raises(AnsibleExitJson) as exc:
         obj = IBMSVCFlashcopyStartStop()
         obj.apply()
     self.assertEqual(True, exc.value.args[0]["changed"])
 def test_stop_nonexiststing_fc_mappping(self, svc_authorize_mock, gef, sc):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_name',
         'state': 'stopped'
     })
     gef.return_value = {}
     sc.return_value = None
     with pytest.raises(AnsibleExitJson) as exc:
         obj = IBMSVCFlashcopyStartStop()
         obj.apply()
     self.assertEqual(False, exc.value.args[0]["changed"])
 def test_get_existing_fcmapping(self, svc_authorize_mock,
                                 svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test_name',
         'state': 'started'
     })
     svc_obj_info_mock.return_value = {
         "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": "test_group",
         "status": "idle_or_copied",
         "progress": "0",
         "copy_rate": "0",
         "start_time": "",
         "dependent_mappings": "0",
         "autodelete": "off",
         "clean_progress": "100",
         "clean_rate": "0",
         "incremental": "off",
         "difference": "100",
         "grain_size": "256",
         "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": ""
     }
     obj = IBMSVCFlashcopyStartStop()
     data = obj.get_existing_fcmapping()
     self.assertEqual('test_name', data['name'])
 def test_module_fail_when_required_args_missing(self):
     """ required arguments are reported as errors """
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         IBMSVCFlashcopyStartStop()
     print('Info: %s' % exc.value.args[0]['msg'])