Merge "Replace ' with " in rally/common"

This commit is contained in:
Jenkins 2015-01-23 18:54:43 +00:00 committed by Gerrit Code Review
commit 6de4598de1
5 changed files with 43 additions and 43 deletions

View File

@ -27,7 +27,7 @@ def _read_env_file(path, except_env=None):
"""
output = []
if os.path.exists(path):
with open(path, 'r') as env_file:
with open(path, "r") as env_file:
content = env_file.readlines()
for line in content:
if except_env is None or not line.startswith("%s=" %
@ -54,7 +54,7 @@ def _rewrite_env_file(path, initial_content):
:param path: the path of the file
:param initial_content: the original content of the file
"""
with open(path, 'w+') as env_file:
with open(path, "w+") as env_file:
for line in initial_content:
env_file.write(line)
@ -67,5 +67,5 @@ def update_env_file(path, env_key, env_value):
:param env_value: the value of the property to update
"""
output = _read_env_file(path, env_key)
output.append('%s=%s' % (env_key, env_value))
output.append("%s=%s" % (env_key, env_value))
_rewrite_env_file(path, output)

View File

@ -19,7 +19,7 @@ See http://docs.openstack.org/developer/oslo.i18n/usage.html .
from oslo import i18n
_translators = i18n.TranslatorFactory(domain='rally')
_translators = i18n.TranslatorFactory(domain="rally")
# The primary translation function using the well-known name "_"
_ = _translators.primary

View File

@ -20,32 +20,32 @@ Usage examples:
Execute command and get output:
ssh = sshclient.SSH('root', 'example.com', port=33)
status, stdout, stderr = ssh.execute('ps ax')
ssh = sshclient.SSH("root", "example.com", port=33)
status, stdout, stderr = ssh.execute("ps ax")
if status:
raise Exception('Command failed with non-zero status.')
raise Exception("Command failed with non-zero status.")
print stdout.splitlines()
Execute command with huge output:
class PseudoFile(object):
def write(chunk):
if 'error' in chunk:
if "error" in chunk:
email_admin(chunk)
ssh = sshclient.SSH('root', 'example.com')
ssh.run('tail -f /var/log/syslog', stdout=PseudoFile(), timeout=False)
ssh = sshclient.SSH("root", "example.com")
ssh.run("tail -f /var/log/syslog", stdout=PseudoFile(), timeout=False)
Execute local script on remote side:
ssh = sshclient.SSH('user', 'example.com')
status, out, err = ssh.execute('/bin/sh -s arg1 arg2',
stdin=open('~/myscript.sh', 'r'))
ssh = sshclient.SSH("user", "example.com")
status, out, err = ssh.execute("/bin/sh -s arg1 arg2",
stdin=open("~/myscript.sh", "r"))
Upload file:
ssh = sshclient.SSH('user', 'example.com')
ssh.run('cat > ~/upload/file.gz', stdin=open('/store/file.gz', 'rb'))
ssh = sshclient.SSH("user", "example.com")
ssh.run("cat > ~/upload/file.gz", stdin=open("/store/file.gz", "rb"))
Eventlet:
@ -111,7 +111,7 @@ class SSH(object):
return key_class.from_private_key(key)
except paramiko.SSHException as e:
errors.append(e)
raise SSHError('Invalid pkey: %s' % (errors))
raise SSHError("Invalid pkey: %s" % (errors))
def _get_client(self):
if self._client:
@ -128,8 +128,8 @@ class SSH(object):
message = _("Exception %(exception_type)s was raised "
"during connect. Exception value is: %(exception)r")
self._client = False
raise SSHError(message % {'exception': e,
'exception_type': type(e)})
raise SSHError(message % {"exception": e,
"exception_type": type(e)})
def close(self):
self._client.close()
@ -166,7 +166,7 @@ class SSH(object):
session.exec_command(cmd)
start_time = time.time()
data_to_send = ''
data_to_send = ""
stderr_data = None
# If we have data to be sent to stdin then `select' should also
@ -182,14 +182,14 @@ class SSH(object):
if session.recv_ready():
data = session.recv(4096)
LOG.debug('stdout: %r' % data)
LOG.debug("stdout: %r" % data)
if stdout is not None:
stdout.write(data)
continue
if session.recv_stderr_ready():
stderr_data = session.recv_stderr(4096)
LOG.debug('stderr: %r' % stderr_data)
LOG.debug("stderr: %r" % stderr_data)
if stderr is not None:
stderr.write(stderr_data)
continue
@ -204,25 +204,25 @@ class SSH(object):
writes = []
continue
sent_bytes = session.send(data_to_send)
LOG.debug('sent: %s' % data_to_send[:sent_bytes])
LOG.debug("sent: %s" % data_to_send[:sent_bytes])
data_to_send = data_to_send[sent_bytes:]
if session.exit_status_ready():
break
if timeout and (time.time() - timeout) > start_time:
args = {'cmd': cmd, 'host': self.host}
raise SSHTimeout(_('Timeout executing command '
'"%(cmd)s" on host %(host)s') % args)
args = {"cmd": cmd, "host": self.host}
raise SSHTimeout(_("Timeout executing command "
"'%(cmd)s' on host %(host)s") % args)
if e:
raise SSHError('Socket error.')
raise SSHError("Socket error.")
exit_status = session.recv_exit_status()
if 0 != exit_status and raise_on_error:
fmt = _('Command "%(cmd)s" failed with exit_status %(status)d.')
details = fmt % {'cmd': cmd, 'status': exit_status}
fmt = _("Command '%(cmd)s' failed with exit_status %(status)d.")
details = fmt % {"cmd": cmd, "status": exit_status}
if stderr_data:
details += _(' Last stderr data: "%s".') % stderr_data
details += _(" Last stderr data: '%s'.") % stderr_data
raise SSHError(details)
return exit_status
@ -250,9 +250,9 @@ class SSH(object):
start_time = time.time()
while True:
try:
return self.execute('uname')
return self.execute("uname")
except (socket.error, SSHError) as e:
LOG.debug('Ssh is still unavailable: %r' % e)
LOG.debug("Ssh is still unavailable: %r" % e)
time.sleep(interval)
if time.time() > (start_time + timeout):
raise SSHTimeout(_('Timeout waiting for "%s"') % self.host)
raise SSHTimeout(_("Timeout waiting for '%s'") % self.host)

View File

@ -51,7 +51,7 @@ class ImmutableMixin(object):
class EnumMixin(object):
def __iter__(self):
for k, v in moves.map(lambda x: (x, getattr(self, x)), dir(self)):
if not k.startswith('_'):
if not k.startswith("_"):
yield v
@ -143,8 +143,8 @@ def itersubclasses(cls, _seen=None):
"""Generator over all subclasses of a given class in depth first order."""
if not isinstance(cls, type):
raise TypeError(_('itersubclasses must be called with '
'new-style classes, not %.100r') % cls)
raise TypeError(_("itersubclasses must be called with "
"new-style classes, not %.100r") % cls)
_seen = _seen or set()
try:
subs = cls.__subclasses__()
@ -168,14 +168,14 @@ def import_modules_from_package(package):
:param: package - Full package name. For example: rally.deploy.engines
"""
path = [os.path.dirname(rally.__file__), '..'] + package.split('.')
path = [os.path.dirname(rally.__file__), ".."] + package.split(".")
path = os.path.join(*path)
for root, dirs, files in os.walk(path):
for filename in files:
if filename.startswith('__') or not filename.endswith('.py'):
if filename.startswith("__") or not filename.endswith(".py"):
continue
new_package = ".".join(root.split(os.sep)).split("....")[1]
module_name = '%s.%s' % (new_package, filename[:-3])
module_name = "%s.%s" % (new_package, filename[:-3])
try_append_module(module_name, sys.modules)
@ -191,7 +191,7 @@ def _log_wrapper(obj, log, msg, **kw):
[Method execution...]
"Task <Task UUID> | Completed: <Logging message>"
:param obj: task or deployment which must be attribute of 'self'
:param obj: task or deployment which must be attribute of "self"
:param log: Logging method to be used, e.g. LOG.info
:param msg: Text message (possibly parameterized) to be put to the log
:param **kw: Parameters for msg
@ -210,15 +210,15 @@ def _log_wrapper(obj, log, msg, **kw):
def log_task_wrapper(log, msg, **kw):
return _log_wrapper('task', log, msg, **kw)
return _log_wrapper("task", log, msg, **kw)
def log_deploy_wrapper(log, msg, **kw):
return _log_wrapper('deployment', log, msg, **kw)
return _log_wrapper("deployment", log, msg, **kw)
def log_verification_wrapper(log, msg, **kw):
return _log_wrapper('verification', log, msg, **kw)
return _log_wrapper("verification", log, msg, **kw)
def load_plugins(directory):

View File

@ -20,7 +20,7 @@ RALLY_PRODUCT = "OpenStack Rally"
RALLY_PACKAGE = None # OS distro package version suffix
loaded = False
version_info = pbr_version.VersionInfo('rally')
version_info = pbr_version.VersionInfo("rally")
def version_string():