本文整理汇总了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)
示例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)
示例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)
示例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())
示例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
示例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)
示例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])
示例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
示例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.
示例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.")
示例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)
示例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))
示例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)
示例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})
示例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})