Пример #1
0
    def _gpfs_ssh_execute(self, ssh, cmd, ignore_exit_code=None,
                          check_exit_code=True):
        sanitized_cmd = strutils.mask_password(cmd)
        LOG.debug('Running cmd (SSH): %s', sanitized_cmd)

        stdin_stream, stdout_stream, stderr_stream = ssh.exec_command(cmd)
        channel = stdout_stream.channel

        stdout = stdout_stream.read()
        sanitized_stdout = strutils.mask_password(stdout)
        stderr = stderr_stream.read()
        sanitized_stderr = strutils.mask_password(stderr)

        stdin_stream.close()

        exit_status = channel.recv_exit_status()

        # exit_status == -1 if no exit code was returned
        if exit_status != -1:
            LOG.debug('Result was %s' % exit_status)
            if ((check_exit_code and exit_status != 0)
                and
                (ignore_exit_code is None or
                 exit_status not in ignore_exit_code)):
                raise exception.ProcessExecutionError(exit_code=exit_status,
                                                      stdout=sanitized_stdout,
                                                      stderr=sanitized_stderr,
                                                      cmd=sanitized_cmd)

        return (sanitized_stdout, sanitized_stderr)
Пример #2
0
 def _execute(self, *cmd, **kwargs):
     for x in range(0, len(self.hosts)):
         try:
             check_exit_code = kwargs.pop('check_exit_code', True)
             host = self.hosts[x]
             if host in self.local_hosts:
                 cmd = self._as_user(cmd,
                                     self.configuration.maprfs_ssh_name)
                 out, err = utils.execute(*cmd,
                                          check_exit_code=check_exit_code)
             else:
                 out, err = self._run_ssh(host, cmd, check_exit_code)
             # move available cldb host to the beginning
             if x > 0:
                 self.hosts[0], self.hosts[x] = self.hosts[x], self.hosts[0]
             return out, err
         except exception.ProcessExecutionError as e:
             if self._check_error(e):
                 raise
             elif x < len(self.hosts) - 1:
                 msg = ('Error running SSH command. Trying another host')
                 LOG.error(msg)
             else:
                 raise
         except Exception as e:
             if x < len(self.hosts) - 1:
                 msg = ('Error running SSH command. Trying another host')
                 LOG.error(msg)
             else:
                 raise exception.ProcessExecutionError(six.text_type(e))
Пример #3
0
 def _get_gluster_vol_option(opt):
     if opt == 'auth.ssl-allow':
         return('some.common.name,' + access['access_to'])
     elif opt == 'dynamic-auth':
         if falseish == '!':
             raise exception.ProcessExecutionError(exit_code=1)
         return falseish
Пример #4
0
 def delete_volume(self, name):
     cmd = [self.maprcli_bin, 'volume', 'remove', '-name', name, '-force',
            'true']
     out, __ = self._execute(*cmd, check_exit_code=False)
     # if volume does not exist do not raise exception.ProcessExecutionError
     if self.ERROR_MSG in out and self.NOT_FOUND_MSG not in out:
         raise exception.ProcessExecutionError(out)
Пример #5
0
 def delete_snapshot(self, name, volume_name):
     cmd = [self.maprcli_bin, 'volume', 'snapshot', 'remove',
            '-snapshotname',
            name, '-volume', volume_name]
     out, __ = self._execute(*cmd, check_exit_code=False)
     # if snapshot does not exist do not raise ProcessExecutionError
     if self.ERROR_MSG in out and self.NOT_FOUND_MSG not in out:
         raise exception.ProcessExecutionError(out)
Пример #6
0
 def get_cluster_name(self):
     cmd = [self.maprcli_bin, 'dashboard', 'info', '-json']
     out, __ = self._execute(*cmd)
     try:
         return json.loads(out)['data'][0]['cluster']['name']
     except (IndexError, ValueError) as e:
         msg = (_("Failed to parse cluster name. Error: %s") % e)
         raise exception.ProcessExecutionError(msg)
Пример #7
0
 def fake_ovs_execute(*args, **kwargs):
     if len(args) == 3:
         return list_of_veths
     if len(args) == 4:
         return ('fake:manila_b5afb5c1_6011_43c4_8a37_29820e6951a7', '')
     if 'del-port' in args:
         raise exception.ProcessExecutionError()
     else:
         return 0
Пример #8
0
    def test_is_kernel_version_false(self):
        zfs_utils.utils.execute.reset_mock()
        zfs_utils.utils.execute.side_effect = (
            exception.ProcessExecutionError('Fake'))

        self.assertFalse(self.helper.is_kernel_version)

        zfs_utils.utils.execute.assert_has_calls([
            mock.call("modinfo", "zfs"),
        ])
Пример #9
0
 def test_get_valid_users_not_force_with_exc(self):
     self.mock_object(
         self._helper,
         '_ssh_exec',
         mock.Mock(side_effect=exception.ProcessExecutionError()))
     self.assertRaises(exception.ProcessExecutionError,
                       self._helper._get_valid_users, self.server_details,
                       self.share_name, const.ACCESS_LEVEL_RW, force=False)
     self._helper._ssh_exec.assert_called_once_with(
         self.server_details,
         ['sudo', 'net', 'conf', 'getparm', self.share_name, 'valid users'])
Пример #10
0
    def test_create_export_share_does_not_exist_exception(self):

        self.mock_object(
            self._helper, '_ssh_exec',
            mock.Mock(
                side_effect=[exception.ProcessExecutionError(),
                             Exception('')]))

        self.assertRaises(exception.ManilaException,
                          self._helper.create_exports, self.server_details,
                          self.share_name)
Пример #11
0
    def test_execute_with_retry(self):
        self.mock_object(time, 'sleep')
        self.mock_object(
            self.driver, 'execute',
            mock.Mock(
                side_effect=[exception.ProcessExecutionError('FAKE'), None]))
        self.driver.execute_with_retry('foo', 'bar')

        self.assertEqual(2, self.driver.execute.call_count)
        self.driver.execute.assert_has_calls(
            [mock.call('foo', 'bar'),
             mock.call('foo', 'bar')])
Пример #12
0
    def test_set_vol_option_error_relaxed(self):
        fake_obj = mock.Mock(
            side_effect=exception.ProcessExecutionError(exit_code=1))
        with mock.patch.object(common.ganesha_utils, 'RootExecutor',
                               mock.Mock(return_value=fake_obj)):
            gluster_manager = common.GlusterManager(
                '127.0.0.1:/testvol', self.fake_execf)

            gluster_manager.set_vol_option('an_option', "some_value",
                                           ignore_failure=True)

            self.assertTrue(fake_obj.called)
Пример #13
0
    def test_set_vol_option_error(self, kwargs):
        fake_obj = mock.Mock(
            side_effect=exception.ProcessExecutionError(exit_code=1))
        with mock.patch.object(common.ganesha_utils, 'RootExecutor',
                               mock.Mock(return_value=fake_obj)):
            gluster_manager = common.GlusterManager(
                '127.0.0.1:/testvol', self.fake_execf)

            self.assertRaises(exception.GlusterfsException,
                              gluster_manager.set_vol_option,
                              'an_option', "some_value", **kwargs)

            self.assertTrue(fake_obj.called)
Пример #14
0
    def test__unmount_device_with_retry_busy_device(self, retry_busy_device):
        execute_sideeffects = [
            exception.ProcessExecutionError(stderr='device is busy'),
            exception.ProcessExecutionError(
                stderr='target is busy'), None, None
        ] if retry_busy_device else [None, None]
        mount_path = self._get_mount_path(self.share)
        self._os.path.exists.return_value = True
        self.mock_object(self._driver, '_execute',
                         mock.Mock(side_effect=execute_sideeffects))

        self._driver._unmount_device(self.share,
                                     retry_busy_device=retry_busy_device)

        num_of_times_umount_is_called = 3 if retry_busy_device else 1

        self._os.path.exists.assert_called_with(mount_path)
        self._driver._execute.assert_has_calls(
            [
                mock.call('umount', '-f', mount_path, run_as_root=True),
            ] * num_of_times_umount_is_called +
            [mock.call('rmdir', mount_path, run_as_root=True)])
Пример #15
0
 def fs_capacity(self):
     cmd = [self.hadoop_bin, 'fs', '-df']
     out, err = self._execute(*cmd)
     lines = out.splitlines()
     try:
         fields = lines[1].split()
         total = int(fields[1])
         free = int(fields[3])
     except (IndexError, ValueError):
         msg = _('Failed to get MapR-FS capacity info.')
         LOG.exception(msg)
         raise exception.ProcessExecutionError(msg)
     return total, free
Пример #16
0
    def test_init_helper_log(self):

        # mocks
        self.mock_object(
            self._helper, '_ssh_exec',
            mock.Mock(side_effect=exception.ProcessExecutionError(
                stderr='fake')))

        # run
        self._helper.init_helper(self.server)

        # asserts
        self._helper._ssh_exec.assert_called_once_with(self.server,
                                                       ['sudo', 'exportfs'])
Пример #17
0
    def test_execute_with_retry_exceeded(self):
        self.mock_object(time, 'sleep')
        self.mock_object(
            self.driver, 'execute',
            mock.Mock(side_effect=exception.ProcessExecutionError('FAKE')))

        self.assertRaises(
            exception.ProcessExecutionError,
            self.driver.execute_with_retry,
            'foo',
            'bar',
        )

        self.assertEqual(36, self.driver.execute.call_count)
Пример #18
0
    def test_deny_access_force(self):
        self.mock_object(
            self._helper,
            '_get_allow_hosts',
            mock.Mock(side_effect=exception.ProcessExecutionError()),
        )
        self.mock_object(self._helper, '_set_allow_hosts')

        self._helper.deny_access(
            self.server_details, self.share_name, self.access, force=True)

        self._helper._get_allow_hosts.assert_called_once_with(
            self.server_details, self.share_name)
        self._helper._set_allow_hosts.assert_has_calls([])
    def test_ldap_retry_operation_invalid_credential(self):
        mock_cmd = ["command", "to", "be", "executed"]

        mock_execute = self.mock_object(
            self.security_service_helper, '_execute',
            mock.Mock(side_effect=exception.ProcessExecutionError(
                exit_code=49)))

        self.assertRaises(exception.ShareBackendException,
                          self.security_service_helper.ldap_retry_operation,
                          mock_cmd,
                          run_as_root=False)

        mock_execute.assert_called_once_with(*mock_cmd, run_as_root=False)
Пример #20
0
    def test_verify_setup_error_calling_exportfs(self):
        zfs_utils.utils.execute.reset_mock()
        zfs_utils.utils.execute.side_effect = [
            ('fake_out', ''),
            exception.ProcessExecutionError('Fake')
        ]

        self.assertRaises(exception.ProcessExecutionError,
                          self.helper.verify_setup)

        zfs_utils.utils.execute.assert_has_calls([
            mock.call("which", "exportfs"),
            mock.call("exportfs", run_as_root=True),
        ])
Пример #21
0
 def try_ldap_operation():
     try:
         self._execute(*cmd, run_as_root=run_as_root)
     except exception.ProcessExecutionError as e:
         if e.exit_code == LDAP_INVALID_CREDENTIALS:
             msg = _('LDAP credentials are invalid. '
                     'Aborting operation.')
             LOG.warning(msg)
             raise exception.ShareBackendException(msg=msg)
         else:
             msg = _('Command has returned execution error.'
                     ' Will retry the operation.'
                     ' Error details: %s') % e.stderr
             LOG.warning(msg)
             raise exception.ProcessExecutionError()
Пример #22
0
    def test_init_helper(self):

        # mocks
        self.mock_object(
            self._helper, '_ssh_exec',
            mock.Mock(side_effect=exception.ProcessExecutionError(
                stderr='command not found')))

        # run
        self.assertRaises(exception.ManilaException, self._helper.init_helper,
                          self.server)

        # asserts
        self._helper._ssh_exec.assert_called_once_with(self.server,
                                                       ['sudo', 'exportfs'])
Пример #23
0
    def test_update_access_exception(self):
        aces = {
            'volumeAces': {
                'readAce': 'p',
                'writeAce': 'p',
            }
        }
        self._driver._maprfs_util.get_volume_info = mock.Mock(
            return_value=aces)
        self._driver._maprfs_util.group_exists = mock.Mock(return_value=True)
        utils.execute = mock.Mock(side_effect=exception.ProcessExecutionError(
            stdout='ERROR'))

        self.assertRaises(exception.MapRFSException,
                          self._driver.update_access, self._context,
                          self.share, [self.access], [], [])
    def test_ldap_retry_operation_timeout(self):
        mock_cmd = ["command", "to", "be", "executed"]

        mock_execute = self.mock_object(
            self.security_service_helper, '_execute',
            mock.Mock(side_effect=exception.ProcessExecutionError(
                exit_code=1)))

        self.assertRaises(exception.ShareBackendException,
                          self.security_service_helper.ldap_retry_operation,
                          mock_cmd,
                          run_as_root=False,
                          timeout=10)

        mock_execute.assert_has_calls([
            mock.call(*mock_cmd, run_as_root=False),
            mock.call(*mock_cmd, run_as_root=False)
        ])
Пример #25
0
    def test_mount_device_exception_01(self):
        volume = {'mountpoint': 'fake_mount_point'}
        self._driver._ssh_exec.side_effect = [
            exception.ProcessExecutionError(stderr='already mounted'), None
        ]
        self.stubs.Set(self._driver, '_get_mount_path',
                       mock.Mock(return_value='fake_mount_path'))

        self._driver._mount_device(self._context, self.share, 'fake_server',
                                   volume)

        self._driver._ssh_exec.assert_has_calls([
            mock.call('fake_server', [
                'sudo', 'mkdir', '-p', 'fake_mount_path', ';', 'sudo', 'mount',
                volume['mountpoint'], 'fake_mount_path'
            ]),
            mock.call('fake_server',
                      ['sudo', 'chmod', '777', 'fake_mount_path'])
        ])
Пример #26
0
    def test_deny_access_force_exc(self, access):
        self.mock_object(
            self._helper,
            '_get_valid_users',
            mock.Mock(side_effect=exception.ProcessExecutionError()),
        )
        self.mock_object(self._helper, '_set_valid_users')

        self.assertRaises(exception.ProcessExecutionError,
                          self._helper.deny_access,
                          self.server_details,
                          self.share_name,
                          access,
                          force=True)
        self._helper._get_valid_users.assert_called_once_with(
            self.server_details,
            self.share_name,
            access['access_level'],
            force=True)
Пример #27
0
 def mock_return(*args, **kwargs):
     if args == test_args[0]:
         if mv_error:
             raise exception.ProcessExecutionError()
         else:
             return ('', '')
Пример #28
0
 def raise_exception(*args, **kwargs):
     if(args == test_args):
         raise exception.ProcessExecutionError()
Пример #29
0
 def fake_ssh_exec(*args, **kwargs):
     if delshare_command == args[1]:
         raise exception.ProcessExecutionError()
     else:
         return ('', '')
Пример #30
0
 def fake_ssh_exec(*args, **kwargs):
     if 'showshare' in args[1]:
         raise exception.ProcessExecutionError()
     else:
         return '', ''