Merge pull request #9079 from s0undt3ch/develop

Fix lint issues.
This commit is contained in:
Joseph Hall 2013-12-06 06:05:00 -08:00
commit 77c128a254
6 changed files with 61 additions and 56 deletions

View File

@ -19,16 +19,17 @@ except ImportError:
log = logging.getLogger(__name__)
def _connect(host, port):
'''
Returns a tuple of (user, host, port) with config, pillar, or default
values assigned to missing values.
'''
if not host:
user = __salt__['config.option']('memcache.host')
host = __salt__['config.option']('memcache.host')
if not port:
port = __salt__['config.option']('memcache.port')
if not HAS_MEMCACHE:
raise SaltException('Error: python-memcached is not installed.')
else:
@ -62,6 +63,7 @@ def status(host, port):
return ret
def get(host, port, key):
'''
get key from memcache server
@ -79,6 +81,7 @@ def get(host, port, key):
else:
return conn.get(key)
def set(host, port, key, val, time=0, min_compress_len=0):
'''
insert key to memcache server
@ -97,6 +100,7 @@ def set(host, port, key, val, time=0, min_compress_len=0):
ret = conn.set(key, val, time, min_compress_len)
return ret
def delete(host, port, key, time=0):
'''
delete key from memcache server
@ -105,7 +109,7 @@ def delete(host, port, key, time=0):
.. code-block:: bash
salt '*' memcache.delete <host> <port> <key>
salt '*' memcache.delete <host> <port> <key>
'''
conn = _connect(host, port)
status = conn.get_stats()
@ -139,7 +143,7 @@ def add(host, port, key, val, time=0, min_compress_len=0):
def incr(host, port, key, delta=1):
'''
incr key
incr key
CLI Example:
@ -161,7 +165,7 @@ def incr(host, port, key, delta=1):
def decr(host, port, key, delta=1):
'''
decr key
decr key
CLI Example:
@ -197,4 +201,3 @@ def replace(host, port, key, val, time=0, min_compress_len=0):
raise SaltException('Error: memcache server is down or not exists.')
else:
return conn.replace(key, val, time=0, min_compress_len=0)

View File

@ -500,7 +500,7 @@ def install(name=None, refresh=False, pkgs=None, saltenv='base', **kwargs):
if pkgs is None and len(pkg_params) == 1:
# Only use the 'version' param if 'name' was not specified as a
# comma-separated list
pkg_params = {name:
pkg_params = {name:
{
'version': kwargs.get('version'),
'extra_install_flags': kwargs.get('extra_install_flags')}}

View File

@ -89,15 +89,15 @@ class GitPillar(object):
'''
Try to initilize the Git repo object
'''
self.br = branch
self.branch = branch
self.rp_location = repo_location
self.opts = opts
self.envs = set()
self._envs = set()
self.working_dir = ''
self.repo = None
for idx, opts_dict in enumerate(self.opts['ext_pillar']):
if opts_dict.get('git', '') == '{0} {1}'.format(self.br,
if opts_dict.get('git', '') == '{0} {1}'.format(self.branch,
self.rp_location):
rp_ = os.path.join(self.opts['cachedir'],
'pillar_gitfs', str(idx))
@ -107,10 +107,11 @@ class GitPillar(object):
try:
self.repo = git.Repo.init(rp_)
except Exception as e:
except (git.exc.NoSuchPathError,
git.exc.InvalidGitRepositoryError) as exc:
log.error('GitPython exception caught while '
'initializing the repo: {0}. Maybe '
'git is not available.'.format(e))
'git is not available.'.format(exc))
# Git directory we are working on
# Should be the same as self.repo.working_dir
@ -126,15 +127,15 @@ class GitPillar(object):
else:
self.repo.git.config('http.sslVerify', 'false')
except os.error:
# This exception occurs when two processes are trying to write
# to the git config at once, go ahead and pass over it since
# this is the only write
# This should place a lock down
# This exception occurs when two processes are
# trying to write to the git config at once, go
# ahead and pass over it since this is the only
# write.
# This should place a lock down.
pass
break
def update(self):
'''
Ensure you are following the latest changes on the remote
@ -144,21 +145,20 @@ class GitPillar(object):
try:
log.debug('Updating fileserver for git_pillar module')
self.repo.git.fetch()
except git.exc.GitCommandError as e:
except git.exc.GitCommandError as exc:
log.error('Unable to fetch the latest changes from remote '
'{0}: {1}'.format(self.rp_location, e))
'{0}: {1}'.format(self.rp_location, exc))
return False
try:
self.repo.git.checkout("origin/" + self.br)
except git.exc.GitCommandError as e:
self.repo.git.checkout('origin/{0}'.format(self.branch))
except git.exc.GitCommandError as exc:
logging.error('Unable to checkout branch '
'{0}: {1}'.format(self.br, e))
'{0}: {1}'.format(self.branch, exc))
return False
return True
def envs(self):
'''
Return a list of refs that can be used as environments
@ -173,11 +173,11 @@ class GitPillar(object):
if short == 'master':
short = 'base'
if ref not in remote.stale_refs:
self.envs.add(short)
self._envs.add(short)
elif isinstance(ref, git.Tag):
self.envs.add(short)
self._envs.add(short)
return list(self.envs)
return list(self._envs)
def update(branch, repo_location):

View File

@ -722,7 +722,7 @@ def symlink(
backupname is set, when it will be renamed
backupname
If the target of the symlink exists and is not a symlink, it will be
If the target of the symlink exists and is not a symlink, it will be
renamed to the backupname. If the backupname already
exists and force is False, the state will fail. Otherwise, the
backupname will be removed first.
@ -818,7 +818,7 @@ def symlink(
# Make a backup first
if os.path.lexists(backupname):
if not force:
return _error(ret,
return _error(ret,
('File exists where the backup target {0} should go'
.format(backupname)))
elif os.path.isfile(backupname):
@ -826,7 +826,7 @@ def symlink(
elif os.path.isdir(backupname):
shutil.rmtree(backupname)
else:
return _error(ret,
return _error(ret,
('Something exists where the backup target {0} should go'
.format(backupname)))
os.rename(name, backupname)
@ -839,14 +839,14 @@ def symlink(
else:
# Otherwise throw an error
if os.path.isfile(name):
return _error(ret,
return _error(ret,
('File exists where the symlink {0} should be'
.format(name)))
else:
return _error(ret,
return _error(ret,
('Directory exists where the symlink {0} should be'
.format(name)))
if not os.path.exists(name):
# The link is not present, make it
try:

View File

@ -7,6 +7,7 @@ Management of Memcached Server.
This module is used to manage memcached server.
'''
def set(name,
host=None,
port=None,
@ -52,9 +53,10 @@ def set(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
def get(name,
host=None,
port=None):
@ -93,7 +95,7 @@ def get(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
@ -137,7 +139,7 @@ def delete(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
@ -156,7 +158,7 @@ def add(name,
port
The memcached server port
val
The value
@ -189,7 +191,7 @@ def add(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
@ -208,7 +210,7 @@ def incr(name,
port
The memcached server port
delta
The default value is 1
@ -236,7 +238,7 @@ def incr(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
@ -255,7 +257,7 @@ def decr(name,
port
The memcached server port
delta
The default value is 1
@ -283,11 +285,10 @@ def decr(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret
def replace(name,
host=None,
port=None,
@ -303,7 +304,7 @@ def replace(name,
port
The memcached server port
Val
The value
@ -331,7 +332,7 @@ def replace(name,
return ret
ret['comment'] = ('memcached server {0}:{1} is down or not exists.'
).format(host,port)
).format(host, port)
return ret

View File

@ -619,7 +619,7 @@ def local_port_tcp(port):
if iret[sl]['local_port'] == port:
ret.add(iret[sl]['remote_addr'])
return ret
else: # Fallback to use 'lsof' if /proc not available
else: # Fallback to use 'lsof' if /proc not available
ret = remotes_on_local_tcp_port(port)
return ret
@ -640,13 +640,14 @@ def _parse_tcp_line(line):
ret[sl]['remote_port'] = int(r_port, 16)
return ret
def remotes_on_local_tcp_port(port):
'''
Returns set of ipv4 host addresses of remote established connections
on local tcp port port.
Parses output of shell 'lsof' to get connections
Parses output of shell 'lsof' to get connections
$ sudo lsof -i4TCP:4505 -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Python 9971 root 35u IPv4 0x18a8464a29ca329d 0t0 TCP *:4505 (LISTEN)
@ -656,33 +657,33 @@ def remotes_on_local_tcp_port(port):
'''
port = int(port)
remotes = set()
try:
data = subprocess.check_output(['lsof', '-i4TCP:{0:d}'.format(port), '-n'])
except subprocess.CalledProcessError as ex:
log.error('Failed "lsof" with returncode = {0}'.format(ex.returncode))
return remotes
lines = data.split('\n')
for line in lines:
chunks = line.split()
if not chunks:
continue
# ['Python', '9971', 'root', '37u', 'IPv4', '0x18a8464a29b2b29d', '0t0',
# ['Python', '9971', 'root', '37u', 'IPv4', '0x18a8464a29b2b29d', '0t0',
# 'TCP', '127.0.0.1:4505->127.0.0.1:55703', '(ESTABLISHED)']
#print chunks
if 'COMMAND' in chunks[0]:
continue # ignore header
continue # ignore header
if 'ESTABLISHED' not in chunks[-1]:
continue # ignore if not ESTABLISHED
continue # ignore if not ESTABLISHED
# '127.0.0.1:4505->127.0.0.1:55703'
local, remote = chunks[8].split('->')
lhost, lport = local.split(':')
if not (int(lport) == port): #ignore if local port not port
if not (int(lport) == port): # ignore if local port not port
continue
rhost, rport = remote.split(':')
remotes.add(rhost)
remotes.add(rhost)
return remotes