Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 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'])
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
 def test_get_existing_host(self, svc_authorize_mock, svc_obj_info_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'state': 'present',
         'username': '******',
         'password': '******',
         'name': 'test_get_existing_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
     host = IBMSVChost().get_existing_host()
     self.assertEqual('ansible_host', host['name'])
     self.assertEqual('1', host['id'])
Exemplo n.º 6
0
 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()
Exemplo n.º 7
0
 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'])
Exemplo n.º 8
0
 def test_host_fcwwpn_update(self, svc_authorize_mock,
                             svc_run_command_mock):
     set_module_args({
         'clustername': 'clustername',
         'domain': 'domain',
         'username': '******',
         'password': '******',
         'name': 'test',
         'state': 'present',
         'fcwwpn': '1000001AA0570264:1000001AA0570265:1000001AA0570266',
         'protocol': 'scsi',
         'type': 'generic'
     })
     obj = IBMSVChost()
     obj.existing_fcwwpn = [
         '1000001AA0570262', '1000001AA0570263', '1000001AA0570264'
     ]
     obj.input_fcwwpn = [
         '1000001AA0570264', '1000001AA0570265', '1000001AA0570266'
     ]
     self.assertEqual(obj.host_fcwwpn_update(), None)
Exemplo n.º 9
0
 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()
Exemplo n.º 10
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({})
         IBMSVChost()
     print('Info: %s' % exc.value.args[0]['msg'])