def test_fcwwpn_update_when_new_added(self, svc_authorize_mock, get_existing_host_mock, host_fcwwpn_update_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'username': '******', 'password': '******', 'name': 'test', 'state': 'present', 'fcwwpn': '1000001AA0570260:1000001AA0570261:1000001AA0570262:1000001AA0570264', 'protocol': 'scsi', 'type': 'generic' }) lshost_data = { 'id': '24', 'name': 'test', 'port_count': '5', 'type': 'generic', 'mask': '1111111', 'iogrp_count': '4', 'status': 'offline', 'site_id': '', 'site_name': '', 'host_cluster_id': '', 'host_cluster_name': '', 'protocol': 'scsi', 'nodes': [{ 'WWPN': '1000001AA0570260', 'node_logged_in_count': '0', 'state': 'online' }, { 'WWPN': '1000001AA0570261', 'node_logged_in_count': '0', 'state': 'online' }, { 'WWPN': '1000001AA0570262', 'node_logged_in_count': '0', 'state': 'online' }] } get_existing_host_mock.return_value = lshost_data host_created = IBMSVChost() with pytest.raises(AnsibleExitJson) as exc: host_created.apply() self.assertTrue(exc.value.args[0]['changed']) get_existing_host_mock.assert_called_with()
def test_delete_host_successfully(self, svc_authorize_mock, host_delete_mock, get_existing_host_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'absent', 'username': '******', 'password': '******', 'name': 'ansible_host', }) host_ret = [{ "id": "1", "name": "ansible_host", "port_count": "1", "iogrp_count": "4", "status": "offline", "site_id": "", "site_name": "", "host_cluster_id": "", "host_cluster_name": "", "protocol": "nvme", "owner_id": "", "owner_name": "" }] get_existing_host_mock.return_value = host_ret host_deleted = IBMSVChost() with pytest.raises(AnsibleExitJson) as exc: host_deleted.apply() self.assertTrue(exc.value.args[0]['changed']) get_existing_host_mock.assert_called_with()
def test_host_hostcluster_update(self, svc_authorize_mock, svc_obj_info_mock, src): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'username': '******', 'password': '******', 'name': 'test', 'state': 'present', 'protocol': 'scsi', 'type': 'generic', 'site': 'site1', 'hostcluster': 'hostcluster0' }) svc_obj_info_mock.return_value = { 'id': '24', 'name': 'test', 'port_count': '5', 'type': 'generic', 'mask': '1111111', 'iogrp_count': '4', 'status': 'offline', 'site_id': '', 'site_name': 'site2', 'host_cluster_id': '1', 'host_cluster_name': 'hostcluster0' } with pytest.raises(AnsibleExitJson) as exc: obj = IBMSVChost() obj.apply() self.assertEqual(True, exc.value.args[0]['changed'])
def test_host_create_get_existing_host_called(self, svc_authorize_mock, get_existing_host_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'test_host_create_get_existing_host_called', }) host_created = IBMSVChost() with pytest.raises(AnsibleExitJson) as exc: host_created.apply() self.assertFalse(exc.value.args[0]['changed']) get_existing_host_mock.assert_called_with()
def test_create_host_failed_since_missed_required_param( self, svc_authorize_mock, get_existing_host_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'ansible_host', }) get_existing_host_mock.return_value = [] host_created = IBMSVChost() with pytest.raises(AnsibleFailJson) as exc: host_created.apply() self.assertTrue(exc.value.args[0]['failed']) get_existing_host_mock.assert_called_with()
def test_duplicate_checker(self, svc_authorize_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'username': '******', 'password': '******', 'name': 'test', 'state': 'present', 'fcwwpn': '1000001AA0570260:1000001AA0570260:1000001AA0570260', 'protocol': 'scsi', 'type': 'generic', 'site': 'site1' }) with pytest.raises(AnsibleFailJson) as exc: obj = IBMSVChost() obj.apply() self.assertEqual(True, exc.value.args[0]['failed'])
def test_create_host_successfully(self, svc_authorize_mock, host_create_mock, get_existing_host_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'present', 'username': '******', 'password': '******', 'name': 'ansible_host', 'fcwwpn': '100000109B570216' }) host = { u'message': u'Host, id [14], ' u'successfully created', u'id': u'14' } host_create_mock.return_value = host get_existing_host_mock.return_value = [] host_created = IBMSVChost() with pytest.raises(AnsibleExitJson) as exc: host_created.apply() self.assertTrue(exc.value.args[0]['changed']) get_existing_host_mock.assert_called_with()