Пример #1
0
 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.SDKSMUTRequestFailed(
         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')
Пример #2
0
    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._smutclient._request(requestData)
        except exception.SDKSMUTRequestFailed as err:
            msg = ("Failed to punch set_hostname script to userid '%s'. SMUT "
                   "error: %s" % (userid, err.format_message()))
            LOG.error(msg)
            raise exception.SDKSMUTRequestFailed(err.results, msg)
        finally:
            self._pathutils.clean_temp_folder(tmp_path)
Пример #3
0
def log_and_reraise_smut_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.SDKSMUTRequestFailed as err:
        msg = ''
        if action is not None:
            msg = "Failed to %s. " % action
        msg += "SMUT error: %s" % err.format_message()
        LOG.error(msg)
        raise exception.SDKSMUTRequestFailed(err.results, msg)
Пример #4
0
 def test_config_volume_attach_active_rollback(self, check_module,
                                               online_device, zfcp_config,
                                               offline_device):
     fcp = '1fc5'
     assigner_id = 'fakeid'
     wwpn = '0x5005076812341234'
     lun = '0x0026000000000000'
     multipath = True
     mount_point = '/dev/sdz'
     zfcp_config.side_effect = exception.SDKSMUTRequestFailed({}, 'err')
     self.assertRaises(exception.SDKSMUTRequestFailed,
                       self.linux_dist.config_volume_attach_active, fcp,
                       assigner_id, wwpn, lun, multipath, mount_point)
     check_module.assert_called_once_with(assigner_id)
     online_device.assert_called_once_with(assigner_id, fcp)
     offline_device.assert_called_once_with(assigner_id, fcp, wwpn, lun,
                                            multipath)
Пример #5
0
 def test_attach_rollback(self, mock_increase, mock_decrease,
                          mock_dedicate, mock_undedicate):
     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'}
     mock_increase.return_value = True
     results = {'rs': 0, 'errno': 0, 'strError': '',
                'overallRC': 1, 'logEntries': [], 'rc': 0,
                'response': ['fake response']}
     mock_dedicate.side_effect = exception.SDKSMUTRequestFailed(
         results, 'fake error')
     # return value of decreate must bigger than 1
     mock_decrease.return_value = 0
     self.assertRaises(exception.SDKBaseException,
                       self.volumeops.attach,
                       connection_info)
     mock_undedicate.assert_called_once_with('b83c', 'user1')