當前位置: 首頁>>代碼示例>>Python>>正文


Python processutils.execute方法代碼示例

本文整理匯總了Python中oslo_concurrency.processutils.execute方法的典型用法代碼示例。如果您正苦於以下問題:Python processutils.execute方法的具體用法?Python processutils.execute怎麽用?Python processutils.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_concurrency.processutils的用法示例。


在下文中一共展示了processutils.execute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_deregister_image

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def test_deregister_image(self):
        self._setup_model()

        # normal flow
        resp = self.execute('DeregisterImage',
                            {'ImageId': fakes.ID_EC2_IMAGE_1})
        self.assertThat(resp, matchers.DictMatches({'return': True}))
        self.db_api.delete_item.assert_called_once_with(
            mock.ANY, fakes.ID_EC2_IMAGE_1)
        self.glance.images.delete.assert_called_once_with(
            fakes.ID_OS_IMAGE_1)

        # deregister image which failed on asynchronously creation
        self.glance.reset_mock()
        image_id = fakes.random_ec2_id('ami')
        self.add_mock_db_items({'id': image_id,
                                'os_id': None,
                                'state': 'failed'})
        resp = self.execute('DeregisterImage',
                            {'ImageId': image_id})
        self.assertThat(resp, matchers.DictMatches({'return': True}))
        self.db_api.delete_item.assert_called_with(mock.ANY, image_id)
        self.assertFalse(self.glance.images.delete.called) 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:25,代碼來源:test_image.py

示例2: ovs_appctl

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def ovs_appctl(self, action, *parameters):
        """Run 'ovs-appctl' with the specified action

         Its possible the command may fail due to timing if, for example,
         the command affects an interface and it the prior ifup command
         has not completed.  So retry the command and if a failures still
         occurs save the error for later handling.

         :param action: The ovs-appctl action.
         :param parameters: Parameters to pass to ovs-appctl.
         """
        msg = 'Running ovs-appctl %s %s' % (action, parameters)
        try:
            self.execute(msg, '/bin/ovs-appctl', action, *parameters,
                         delay_on_retry=True, attempts=5)
        except processutils.ProcessExecutionError as e:
            self.errors.append(e) 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:19,代碼來源:__init__.py

示例3: get_pci_address

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def get_pci_address(ifname, noop):
    # TODO(skramaja): Validate if the given interface supports dpdk
    if not noop:
        try:
            out, err = processutils.execute('ethtool', '-i', ifname)
            if not err:
                for item in out.split('\n'):
                    if 'bus-info' in item:
                        return item.split(' ')[1]
        except processutils.ProcessExecutionError:
            # If ifname is already bound, then ethtool will not be able to
            # list the device, in which case, binding is already done, proceed
            # with scripts generation.
            return

    else:
        logger.info('Fetch the PCI address of the interface %s using '
                    'ethtool' % ifname) 
開發者ID:openstack,項目名稱:os-net-config,代碼行數:20,代碼來源:utils.py

示例4: temporary_chown

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def temporary_chown(self, path):
        owner_uid = os.getuid()
        orig_uid = os.stat(path).st_uid

        if orig_uid != owner_uid:
            processutils.execute(
                'chown', owner_uid, path,
                run_as_root=True,
                root_helper=self.get_root_helper())
        try:
            yield
        finally:
            if orig_uid != owner_uid:
                processutils.execute(
                    'chown', orig_uid, path,
                    run_as_root=True,
                    root_helper=self.get_root_helper()) 
開發者ID:openstack,項目名稱:glance_store,代碼行數:19,代碼來源:cinder.py

示例5: _real_umount

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def _real_umount(self, mountpoint, rootwrap_helper):
        # Unmount and delete a mountpoint.
        # Return mount state after umount (i.e. True means still mounted)
        LOG.debug('Unmounting %(mountpoint)s', {'mountpoint': mountpoint})

        try:
            processutils.execute('umount', mountpoint, run_as_root=True,
                                 attempts=3, delay_on_retry=True,
                                 root_helper=rootwrap_helper)
        except processutils.ProcessExecutionError as ex:
            LOG.error(_LE("Couldn't unmount %(mountpoint)s: %(reason)s"),
                      {'mountpoint': mountpoint, 'reason': ex})

        if not os.path.ismount(mountpoint):
            try:
                os.rmdir(mountpoint)
            except Exception as ex:
                LOG.error(_LE("Couldn't remove directory %(mountpoint)s: "
                              "%(reason)s"),
                          {'mountpoint': mountpoint,
                           'reason': ex})
            return False

        return True 
開發者ID:openstack,項目名稱:glance_store,代碼行數:26,代碼來源:fs_mount.py

示例6: setUp

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def setUp(self):
        super(BrickLvmTestCase, self).setUp()
        if not hasattr(self, 'configuration'):
            self.configuration = mock.Mock()
            self.configuration.lvm_suppress_fd_warnings = False
        self.volume_group_name = 'fake-vg'

        # Stub processutils.execute for static methods
        self.mock_object(priv_rootwrap, 'execute',
                         self.fake_execute)
        self.vg = brick.LVM(
            self.volume_group_name,
            'sudo',
            create_vg=False,
            physical_volumes=None,
            lvm_type='default',
            executor=self.fake_execute,
            suppress_fd_warn=self.configuration.lvm_suppress_fd_warnings) 
開發者ID:openstack,項目名稱:os-brick,代碼行數:20,代碼來源:test_brick_lvm.py

示例7: create_tap_dev

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def create_tap_dev(dev, mac_address=None, multiqueue=False):
    if not device_exists(dev):
        try:
            # First, try with 'ip'
            cmd = ('ip', 'tuntap', 'add', dev, 'mode', 'tap')
            if multiqueue:
                cmd = cmd + ('multi_queue', )
            execute(*cmd, check_exit_code=[0, 2, 254])
        except processutils.ProcessExecutionError:
            if multiqueue:
                LOG.warning(
                    'Failed to create a tap device with ip tuntap. '
                    'tunctl does not support creation of multi-queue '
                    'enabled devices, skipping fallback.')
                raise

            # Second option: tunctl
            execute('tunctl', '-b', '-t', dev)
        if mac_address:
            execute('ip', 'link', 'set', dev, 'address', mac_address,
                    check_exit_code=[0, 2, 254])
        execute('ip', 'link', 'set', dev, 'up', check_exit_code=[0, 2, 254]) 
開發者ID:openstack,項目名稱:networking-midonet,代碼行數:24,代碼來源:linux_net.py

示例8: execute

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def execute(*cmd, **kwargs):
    """Convenience wrapper around oslo's execute() method.

    :param cmd: Passed to processutils.execute.
    :param use_standard_locale: True | False. Defaults to False. If set to
                                True, execute command with standard locale
                                added to environment variables.
    :returns: (stdout, stderr) from process execution
    :raises: UnknownArgumentError
    :raises: ProcessExecutionError
    """

    use_standard_locale = kwargs.pop('use_standard_locale', False)
    if use_standard_locale:
        env = kwargs.pop('env_variables', os.environ.copy())
        env['LC_ALL'] = 'C'
        kwargs['env_variables'] = env
    if kwargs.get('run_as_root') and 'root_helper' not in kwargs:
        kwargs['root_helper'] = _get_root_helper()
    result = processutils.execute(*cmd, **kwargs)
    LOG.debug('Execution completed, command line is "%s"',
              ' '.join(map(str, cmd)))
    LOG.debug('Command stdout is: "%s"', result[0])
    LOG.debug('Command stderr is: "%s"', result[1])
    return result 
開發者ID:openstack,項目名稱:magnum,代碼行數:27,代碼來源:utils.py

示例9: _update_info_from_rpm

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def _update_info_from_rpm(self):
        LOG.debug('Trying rpm command.')
        try:
            out, err = putils.execute("rpm", "-q", "--queryformat",
                                      "'%{version}\t%{release}\t%{vendor}'",
                                      self.PACKAGE_NAME)
            if not out:
                LOG.info('No rpm info found for %(pkg)s package.', {
                    'pkg': self.PACKAGE_NAME})
                return False
            parts = out.split()
            self._version = parts[0]
            self._release = parts[1]
            self._vendor = ' '.join(parts[2::])
            return True
        except Exception as e:
            LOG.info('Could not run rpm command: %(msg)s.', {
                'msg': e})
            return False

    # Ubuntu, Mirantis on Ubuntu. 
開發者ID:openstack,項目名稱:manila,代碼行數:23,代碼來源:utils.py

示例10: mount_share

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def mount_share(export_location, access_to):
    data = {
        'mount_point': os.path.join(CONF.zaqar.mount_dir,
                                    export_location.split('/')[-1]),
        'export_location': export_location,
    }
    if (rule_affects_me(access_to) and
            not is_share_mounted(data['mount_point'])):
        print_with_time(
            "Mounting '%(export_location)s' share to %(mount_point)s.")
        execute('sudo mkdir -p %(mount_point)s' % data)
        stdout, stderr = execute(
            'sudo mount.nfs %(export_location)s %(mount_point)s' % data)
        if stderr:
            print_with_time("Mount operation failed.")
        else:
            print_with_time("Mount operation went OK.") 
開發者ID:openstack,項目名稱:manila,代碼行數:19,代碼來源:zaqar_notification_example_consumer.py

示例11: test_execute_with_callback_and_errors

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def test_execute_with_callback_and_errors(self, mock_comm):
        on_execute_callback = mock.Mock()
        on_completion_callback = mock.Mock()

        def fake_communicate(*args, timeout=None):
            raise IOError("Broken pipe")

        mock_comm.side_effect = fake_communicate

        self.assertRaises(IOError,
                          processutils.execute,
                          TRUE_UTILITY,
                          on_execute=on_execute_callback,
                          on_completion=on_completion_callback)
        self.assertEqual(1, on_execute_callback.call_count)
        self.assertEqual(1, on_completion_callback.call_count) 
開發者ID:openstack,項目名稱:oslo.concurrency,代碼行數:18,代碼來源:test_processutils.py

示例12: custom_execute

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def custom_execute(*cmd, **kwargs):
    try:
        return processutils.execute(*cmd, **kwargs)
    except processutils.ProcessExecutionError as e:
        sanitized_cmd = strutils.mask_password(' '.join(cmd))
        raise exception.CommandError(cmd=sanitized_cmd,
                                     error=str(e)) 
開發者ID:openstack,項目名稱:zun,代碼行數:9,代碼來源:utils.py

示例13: execute

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def execute(*cmd, **kwargs):
    run_as_root = kwargs.pop('run_as_root', False)
    # NOTE(kiennt): Root_helper is unnecessary when use privsep,
    #               therefore pop it!
    kwargs.pop('root_helper', None)
    if run_as_root:
        return execute_root(*cmd, **kwargs)
    else:
        return custom_execute(*cmd, **kwargs) 
開發者ID:openstack,項目名稱:zun,代碼行數:11,代碼來源:utils.py

示例14: _s3_decrypt_image

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def _s3_decrypt_image(context, encrypted_filename, encrypted_key,
                      encrypted_iv, decrypted_filename):
    encrypted_key = binascii.a2b_hex(encrypted_key)
    encrypted_iv = binascii.a2b_hex(encrypted_iv)
    try:
        key = _decrypt_text(encrypted_key).decode()
    except Exception as exc:
        msg = _('Failed to decrypt private key: %s') % exc
        raise exception.EC2Exception(msg)
    try:
        iv = _decrypt_text(encrypted_iv).decode()
    except Exception as exc:
        msg = _('Failed to decrypt initialization vector: %s') % exc
        raise exception.EC2Exception(msg)

    try:
        processutils.execute('openssl', 'enc',
                             '-d', '-aes-128-cbc',
                             '-in', '%s' % (encrypted_filename,),
                             '-K', '%s' % (key,),
                             '-iv', '%s' % (iv,),
                             '-out', '%s' % (decrypted_filename,))
    except processutils.ProcessExecutionError as exc:
        raise exception.EC2Exception(_('Failed to decrypt image file '
                                       '%(image_file)s: %(err)s') %
                                     {'image_file': encrypted_filename,
                                      'err': exc.stdout}) 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:29,代碼來源:image.py

示例15: test_register_image_by_s3

# 需要導入模塊: from oslo_concurrency import processutils [as 別名]
# 或者: from oslo_concurrency.processutils import execute [as 別名]
def test_register_image_by_s3(self, s3_create):
        s3_create.return_value = fakes.OSImage(fakes.OS_IMAGE_1)
        self.db_api.add_item.side_effect = (
            tools.get_db_api_add_item(fakes.ID_EC2_IMAGE_1))

        resp = self.execute(
            'RegisterImage',
            {'ImageLocation': fakes.LOCATION_IMAGE_1})
        self.assertThat(resp, matchers.DictMatches(
            {'imageId': fakes.ID_EC2_IMAGE_1}))

        s3_create.assert_called_once_with(
            mock.ANY,
            {'name': fakes.LOCATION_IMAGE_1,
             'image_location': fakes.LOCATION_IMAGE_1})
        s3_create.reset_mock()

        resp = self.execute(
            'RegisterImage',
            {'ImageLocation': fakes.LOCATION_IMAGE_1,
             'Name': 'an image name'})
        self.assertThat(resp, matchers.DictMatches(
            {'imageId': fakes.ID_EC2_IMAGE_1}))

        s3_create.assert_called_once_with(
            mock.ANY,
            {'name': 'an image name',
             'image_location': fakes.LOCATION_IMAGE_1}) 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:30,代碼來源:test_image.py


注:本文中的oslo_concurrency.processutils.execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。