def test_detach_rollback(self, mock_decrease, mock_remove_disk, mock_increase, mock_add_disk, mock_check, mock_fcp_info): connection_info = {'platform': 'x86_64', 'ip': '1.2.3.4', 'os_version': 'rhel7', 'multipath': 'False', 'target_wwpn': ['20076D8500005182'], 'target_lun': '2222', 'zvm_fcp': ['f83c'], 'mount_point': '/dev/sdz', 'assigner_id': 'user1'} fcp_list = ['opnstk1: FCP device number: F83C', 'opnstk1: Status: Free', 'opnstk1: NPIV world wide port number: ' '20076D8500005182', 'opnstk1: Channel path ID: 59', 'opnstk1: Physical world wide port number: ' '20076D8500005181'] mock_fcp_info.return_value = fcp_list # this return does not matter mock_check.return_value = True mock_decrease.return_value = 0 results = {'rs': 0, 'errno': 0, 'strError': '', 'overallRC': 1, 'logEntries': [], 'rc': 0, 'response': ['fake response']} mock_remove_disk.side_effect = exception.SDKSMTRequestFailed( results, 'fake error') self.assertRaises(exception.SDKBaseException, self.volumeops.detach, connection_info)
def set_hostname(self, userid, hostname, os_version): """Punch a script that used to set the hostname of the guest. :param str guest: the user id of the guest :param str hostname: the hostname of the guest :param str os_version: version of guest operation system """ tmp_path = self._pathutils.get_guest_temp_path(userid) if not os.path.exists(tmp_path): os.makedirs(tmp_path) tmp_file = tmp_path + '/hostname.sh' lnxdist = self._dist_manager.get_linux_dist(os_version)() lines = lnxdist.generate_set_hostname_script(hostname) with open(tmp_file, 'w') as f: f.writelines(lines) requestData = "ChangeVM " + userid + " punchfile " + \ tmp_file + " --class x" LOG.debug("Punch script to guest %s to set hostname" % userid) try: self._smtclient._request(requestData) except exception.SDKSMTRequestFailed as err: msg = ("Failed to punch set_hostname script to userid '%s'. SMT " "error: %s" % (userid, err.format_message())) LOG.error(msg) raise exception.SDKSMTRequestFailed(err.results, msg) finally: self._pathutils.clean_temp_folder(tmp_path)
def test_attach_rollback(self, mock_fcp_assigner, mock_dedicate, mock_rollback, mock_check, mock_fcp_info): connection_info = {'platform': 'x86_64', 'ip': '1.2.3.4', 'os_version': 'rhel7', 'multipath': 'false', 'target_wwpn': ['20076D8500005182'], 'target_lun': '2222', 'zvm_fcp': ['e83c'], 'mount_point': '/dev/sdz', 'assigner_id': 'user1'} fcp_list = ['opnstk1: FCP device number: E83C', 'opnstk1: Status: Free', 'opnstk1: NPIV world wide port number: ' '20076D8500005182', 'opnstk1: Channel path ID: 59', 'opnstk1: Physical world wide port number: ' '20076D8500005181'] mock_fcp_info.return_value = fcp_list mock_check.return_value = True mock_fcp_assigner.return_value = True results = {'rs': 0, 'errno': 0, 'strError': '', 'overallRC': 1, 'logEntries': [], 'rc': 0, 'response': ['fake response']} mock_dedicate.side_effect = exception.SDKSMTRequestFailed( results, 'fake error') self.assertRaises(exception.SDKBaseException, self.volumeops.attach, connection_info) calls = [mock.call(['e83c'], 'USER1'), mock.call([], 'USER1', all_fcp_list=['e83c'])] mock_rollback.assert_has_calls(calls)
def test_detach_rollback(self, mock_decrease, mock_remove_disk, mock_increase, mock_add_disk, mock_check): connection_info = { 'platform': 'x86_64', 'ip': '1.2.3.4', 'os_version': 'rhel7', 'multipath': False, 'target_wwpn': '1111', 'target_lun': '2222', 'zvm_fcp': 'b83c', 'mount_point': '/dev/sdz', 'assigner_id': 'user1' } # this return does not matter mock_check.return_value = True mock_decrease.return_value = 0 results = { 'rs': 0, 'errno': 0, 'strError': '', 'overallRC': 1, 'logEntries': [], 'rc': 0, 'response': ['fake response'] } mock_remove_disk.side_effect = exception.SDKSMTRequestFailed( results, 'fake error') self.assertRaises(exception.SDKBaseException, self.volumeops.detach, connection_info) mock_increase.assert_called_once_with('b83c', 'USER1') mock_add_disk.assert_called_once_with('b83c', 'USER1', '1111', '2222', False, 'rhel7', '/dev/sdz')
def test_check_IUCV_is_ready_not_ready(self, execute_cmd): # case: not ready, but can continue assigner_id = 'fakeid' results = {'rs': 0, 'errno': 0, 'strError': '', 'overallRC': 1, 'logEntries': [], 'rc': 0, 'response': ['fake response']} execute_cmd.side_effect = exception.SDKSMTRequestFailed( results, 'fake error contains other things') ret = self.configurator.check_IUCV_is_ready(assigner_id) execute_cmd.assert_called_once_with(assigner_id, 'pwd') self.assertEqual(ret, False)
def test_check_IUCV_is_ready_raise_excetion(self, execute_cmd): # case: not ready, must raise exception assigner_id = 'fakeid' results = {'rs': 0, 'errno': 0, 'strError': '', 'overallRC': 1, 'logEntries': [], 'rc': 0, 'response': ['fake response']} execute_cmd.side_effect = exception.SDKSMTRequestFailed( results, 'fake error contains UNAUTHORIZED_ERROR') self.assertRaises(exception.SDKVolumeOperationError, self.configurator.check_IUCV_is_ready, assigner_id)
def log_and_reraise_smt_request_failed(action=None): """Catch SDK base exception and print error log before reraise exception. msg: the error message to be logged. """ try: yield except exception.SDKSMTRequestFailed as err: msg = '' if action is not None: msg = "Failed to %s. " % action msg += "SMT error: %s" % err.format_message() LOG.error(msg) raise exception.SDKSMTRequestFailed(err.results, msg)