def test_the_host_result_by_gather_info(self, svc_authorize_mock, svc_obj_info_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'state': 'info', 'name': 'test_get_host_list_called', 'username': '******', 'password': '******', 'gather_subset': '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": "" }] svc_obj_info_mock.return_value = host_ret with pytest.raises(AnsibleExitJson) as exc: IBMSVCGatherInfo().apply() self.assertFalse(exc.value.args[0]['changed']) self.assertDictEqual(exc.value.args[0]['Hosts'][0], host_ret[0])
def test_get_host_list_called(self, mock_svc_authorize, get_hosts_list_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'username': '******', 'password': '******', 'gather_subset': 'host', }) with pytest.raises(AnsibleExitJson) as exc: IBMSVCGatherInfo().apply() self.assertFalse(exc.value.args[0]['changed']) get_hosts_list_mock.assert_called_with()
def test_the_host_and_vol_result_by_gather_info(self, svc_authorize_mock, svc_obj_info_mock): set_module_args({ 'clustername': 'clustername', 'domain': 'domain', 'username': '******', 'password': '******', 'gather_subset': 'host,vol', }) 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": ""}] 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.side_effect = [vol_ret, host_ret] with pytest.raises(AnsibleExitJson) as exc: IBMSVCGatherInfo().apply() self.assertFalse(exc.value.args[0]['changed']) self.assertDictEqual(exc.value.args[0]['Host'][0], host_ret[0]) self.assertDictEqual(exc.value.args[0]['Volume'][0], vol_ret[0])
def test_module_fail_when_required_args_missing(self): """ required arguments are reported as errors """ with pytest.raises(AnsibleFailJson) as exc: set_module_args({}) IBMSVCGatherInfo() print('Info: %s' % exc.value.args[0]['msg'])