def test_delete_fccg_successfully(self, svc_authorize_mock,
                                   fccg_delete_mock,
                                   get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'absent',
         'username': '******',
         'password': '******',
         'name': 'test_delete_fccg_successfully',
     })
     fccg_ret = [{
         "id": "1",
         "name": "fccstgrp0",
         "status": "empty",
         "start_time": "",
         "owner_id": "",
         "owner_name": ""
     }]
     get_existing_fccg_mock.return_value = fccg_ret
     host_deleted = IBMSVCFCCG()
     with pytest.raises(AnsibleExitJson) as exc:
         host_deleted.apply()
     self.assertTrue(exc.value.args[0]['changed'])
     get_existing_fccg_mock.assert_called_with()
 def test_fccg_create_get_existing_fccg_called(self, svc_authorize_mock,
                                               get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_fccg_create_get_existing_fccg_called',
     })
     fccg_created = IBMSVCFCCG()
     with pytest.raises(AnsibleFailJson) as exc:
         fccg_created.apply()
     get_existing_fccg_mock.assert_called_with()
 def test_delete_fccg_but_fccg_not_existed(self, svc_authorize_mock,
                                           get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'absent',
         'username': '******',
         'password': '******',
         'name': 'test_delete_fccg_but_fccg_not_existed',
     })
     get_existing_fccg_mock.return_value = []
     host_deleted = IBMSVCFCCG()
     with pytest.raises(AnsibleExitJson) as exc:
         host_deleted.apply()
     self.assertFalse(exc.value.args[0]['changed'])
     get_existing_fccg_mock.assert_called_with()
 def test_create_fccg_failed_since_missed_required_param(
         self, svc_authorize_mock, get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
     })
     get_existing_fccg_mock.return_value = []
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         IBMSVCFCCG()
     print('Info: %s' % exc.value.args[0]['msg'])
 def test_create_fccg_successfully(self, svc_authorize_mock,
                                   fccg_create_mock,
                                   get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_create_fccg_successfully',
     })
     fccg = {
         u'message': u'FlashCopy Consistency Group, id [35], '
         u'successfully created',
         u'id': u'35'
     }
     fccg_create_mock.return_value = fccg
     get_existing_fccg_mock.return_value = []
     fccg_created = IBMSVCFCCG()
     with pytest.raises(AnsibleExitJson) as exc:
         fccg_created.apply()
     self.assertTrue(exc.value.args[0]['changed'])
     get_existing_fccg_mock.assert_called_with()
 def test_get_existing_fccg(self, svc_authorize_mock, svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_get_existing_fccg',
     })
     fccg_ret = [{
         "id": "0",
         "name": "fccg4test",
         "status": "empty",
         "start_time": "",
         "owner_id": "",
         "owner_name": ""
     }]
     svc_obj_info_mock.return_value = fccg_ret
     fccg = IBMSVCFCCG().get_existing_fccg()
     self.assertEqual('fccg4test', fccg['name'])
     self.assertEqual('0', fccg['id'])
 def test_flashcopymap_probe(self, svc_authorize_mock,
                             get_existing_fccg_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'fccg4test',
         'autodelete': 'on'
     })
     fccg_ret = {
         'id': '1',
         'name': 'fccg4test',
         'status': 'empty',
         'autodelete': 'off',
         'start_time': '',
         'owner_id': '',
         'owner_name': ''
     }
     get_existing_fccg_mock.return_value = fccg_ret
     ret = IBMSVCFCCG().fccg_probe(fccg_ret)
     self.assertTrue(ret['autodelete'])
 def test_module_fail_when_required_args_missing(self):
     """ required arguments are reported as errors """
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         IBMSVCFCCG()
     print('Info: %s' % exc.value.args[0]['msg'])