Example #1
0
 def test_get_existing_vdiskhostmap(self, svc_authorize_mock,
                                    svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'volname': 'volume0',
         'host': 'host4test',
     })
     mapping_ret = [{
         "id": "0",
         "name": "volume_Ansible_collections",
         "SCSI_id": "0",
         "host_id": "14",
         "host_name": "host_ansible_collects",
         "vdisk_UID": "6005076810CA0166C00000000000019F",
         "IO_group_id": "0",
         "IO_group_name": "io_grp0",
         "mapping_type": "private",
         "host_cluster_id": "",
         "host_cluster_name": "",
         "protocol": "scsi"
     }]
     svc_obj_info_mock.return_value = mapping_ret
     host_mapping_data = IBMSVCvdiskhostmap().get_existing_vdiskhostmap()
     for host_mapping in host_mapping_data:
         self.assertEqual('volume_Ansible_collections',
                          host_mapping['name'])
         self.assertEqual('0', host_mapping['id'])
Example #2
0
 def test_delete_hostcluster_mapping_successfully(
         self, svc_authorize_mock, host_delete_mock,
         get_existing_vdiskhostmap_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'absent',
         'username': '******',
         'password': '******',
         'volname': 'volume0',
         'hostcluster': 'hostcluster4test',
     })
     mapping_ret = [{
         "id": "0",
         "name": "volume_Ansible_collections",
         "SCSI_id": "0",
         "host_id": "",
         "host_name": "",
         "vdisk_UID": "6005076810CA0166C00000000000019F",
         "IO_group_id": "0",
         "IO_group_name": "io_grp0",
         "mapping_type": "private",
         "host_cluster_id": "1",
         "host_cluster_name": "hostcluster4test",
         "protocol": "scsi"
     }]
     get_existing_vdiskhostmap_mock.return_value = mapping_ret
     host_mapping_deleted = IBMSVCvdiskhostmap()
     with pytest.raises(AnsibleExitJson) as exc:
         host_mapping_deleted.apply()
     self.assertTrue(exc.value.args[0]['changed'])
     get_existing_vdiskhostmap_mock.assert_called_with()
Example #3
0
 def test_delete_hostcluster_mapping_not_exist(
         self, svc_authorize_mock, get_existing_vdiskhostmap_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'absent',
         'username': '******',
         'password': '******',
         'volname': 'volume0',
         'hostcluster': 'hostcluster4test',
     })
     get_existing_vdiskhostmap_mock.return_value = []
     host_mapping_deleted = IBMSVCvdiskhostmap()
     with pytest.raises(AnsibleExitJson) as exc:
         host_mapping_deleted.apply()
     self.assertFalse(exc.value.args[0]['changed'])
     get_existing_vdiskhostmap_mock.assert_called_with()
Example #4
0
 def test_create_hostcluster_mapping_but_mapping_exist(
         self, svc_authorize_mock, vdiskhostclustermap_create_mock,
         get_existing_vdiskhostmap_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'volname': 'volume0',
         'hostcluster': 'hostcluster4test',
     })
     host_mapping = {
         u'message': u'Volume to Host Cluster map, id [0], '
         u'successfully created',
         u'id': u'0'
     }
     vdiskhostclustermap_create_mock.return_value = host_mapping
     get_existing_vdiskhostmap_mock.return_value = []
     host_mapping_created = IBMSVCvdiskhostmap()
     with pytest.raises(AnsibleExitJson) as exc:
         host_mapping_created.apply()
     self.assertTrue(exc.value.args[0]['changed'])
     get_existing_vdiskhostmap_mock.assert_called_with()
Example #5
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({})
         IBMSVCvdiskhostmap()
     print('Info: %s' % exc.value.args[0]['msg'])