summaryrefslogtreecommitdiffstats
path: root/testsuites/vstf/vstf_scripts/vstf/common
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/vstf/vstf_scripts/vstf/common')
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/__init__.py1
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/candy_text.py4
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/cfgparser.py1
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/cliutil.py3
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/cmds.py4
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/daemon.py32
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/decorator.py11
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/log.py5
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/pyhtml.py133
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/rsync.py93
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/saltstack.py50
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/ssh.py33
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/test_func.py2
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/unix.py34
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/utils.py16
-rw-r--r--testsuites/vstf/vstf_scripts/vstf/common/vstfcli.py13
16 files changed, 320 insertions, 115 deletions
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/__init__.py b/testsuites/vstf/vstf_scripts/vstf/common/__init__.py
index df7d24d0..83b8d15d 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/__init__.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/__init__.py
@@ -6,4 +6,3 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/candy_text.py b/testsuites/vstf/vstf_scripts/vstf/common/candy_text.py
index 818ae767..306d9124 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/candy_text.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/candy_text.py
@@ -36,7 +36,7 @@ def dict2text(info):
def text2dict(candy):
- tmp = candy.replace("##","#").split("#")
+ tmp = candy.replace("##", "#").split("#")
result = {
"sn": int(tmp[0]),
"node": tmp[1],
@@ -49,7 +49,7 @@ def text2dict(candy):
def text2tuple(candy):
- tmp = candy.replace("##","#").split("#")
+ tmp = candy.replace("##", "#").split("#")
sn = int(tmp[0])
node = tmp[1]
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/cfgparser.py b/testsuites/vstf/vstf_scripts/vstf/common/cfgparser.py
index 9de5a2cd..802cb214 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/cfgparser.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/cfgparser.py
@@ -12,6 +12,7 @@ from oslo.config import cfg
class CfgParser(object):
+
def __init__(self, config_file):
super(CfgParser, self).__init__()
if os.path.isfile(config_file) is False:
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/cliutil.py b/testsuites/vstf/vstf_scripts/vstf/common/cliutil.py
index 541bba7b..8997cd6a 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/cliutil.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/cliutil.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
def arg(*args, **kwargs):
"""Decorator for CLI args.
@@ -33,4 +34,4 @@ def add_arg(func, *args, **kwargs):
if (args, kwargs) not in func.arguments:
# Because of the semantics of decorator composition if we just append
# to the options list positional options will appear to be backwards.
- func.arguments.insert(0, (args, kwargs)) \ No newline at end of file
+ func.arguments.insert(0, (args, kwargs))
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/cmds.py b/testsuites/vstf/vstf_scripts/vstf/common/cmds.py
index 2952be2c..f348a804 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/cmds.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/cmds.py
@@ -20,7 +20,9 @@ def execute(cmd=None, care_result=True):
try:
(status, ret) = commands.getstatusoutput(cmd)
if care_result and 0 != status:
- LOG.error('CMD<%(cmd)s> \nSTDOUT:\n%(ret)s.', {'cmd':cmd, 'ret':ret})
+ LOG.error(
+ 'CMD<%(cmd)s> \nSTDOUT:\n%(ret)s.', {
+ 'cmd': cmd, 'ret': ret})
return None
else:
return ret
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/daemon.py b/testsuites/vstf/vstf_scripts/vstf/common/daemon.py
index 35933dad..46087493 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/daemon.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/daemon.py
@@ -7,7 +7,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import sys, os, time, atexit
+import sys
+import os
+import time
+import atexit
import logging
from signal import SIGTERM
@@ -17,11 +20,16 @@ LOG = logging.getLogger(__name__)
class Daemon(object):
"""
A generic daemon class.
-
+
Usage: subclass the Daemon class and override the run() method
"""
- def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
+ def __init__(
+ self,
+ pidfile,
+ stdin='/dev/null',
+ stdout='/dev/null',
+ stderr='/dev/null'):
super(Daemon, self).__init__()
self.stdin = stdin
self.stdout = stdout
@@ -30,7 +38,7 @@ class Daemon(object):
def daemonize(self):
"""
- do the UNIX double-fork magic, see Stevens' "Advanced
+ do the UNIX double-fork magic, see Stevens' "Advanced
Programming in the UNIX Environment" for details (ISBN 0201563177)
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
"""
@@ -38,7 +46,7 @@ class Daemon(object):
pid = os.fork()
if pid > 0:
sys.exit(0)
- except OSError, e:
+ except OSError as e:
LOG.error("fork #1 failed: %(errno)s, %(strerror)s",
{'errno': e.errno, 'strerror': e.strerror})
sys.exit(1)
@@ -54,7 +62,7 @@ class Daemon(object):
if pid > 0:
# exit from second parent
sys.exit(0)
- except OSError, e:
+ except OSError as e:
LOG.error("fork #1 failed: %(errno)s, %(strerror)s",
{'errno': e.errno, 'strerror': e.strerror})
sys.exit(1)
@@ -116,12 +124,12 @@ class Daemon(object):
sys.stderr.write(message % self.pidfile)
return # not an error in a restart
- # Try killing the daemon process
+ # Try killing the daemon process
try:
- while 1:
+ while True:
os.kill(pid, SIGTERM)
time.sleep(0.1)
- except OSError, err:
+ except OSError as err:
err = str(err)
if err.find("No such process") > 0:
if os.path.exists(self.pidfile):
@@ -139,16 +147,16 @@ class Daemon(object):
def run(self):
"""
- You should override this method when you subclass Daemon.
+ You should override this method when you subclass Daemon.
It will be called after the process has been
daemonized by start() or restart().
-
+
"""
pass
def daemon_die(self):
"""You should override this method when you shutdown daemon
this func will be call by stop() before kill the process
-
+
"""
pass
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/decorator.py b/testsuites/vstf/vstf_scripts/vstf/common/decorator.py
index 98d539f1..ed910556 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/decorator.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/decorator.py
@@ -17,7 +17,9 @@ def check(key, choices=[], defaults=_DEFAULTS):
if defaults != _DEFAULTS:
kwargs[key] = defaults
else:
- raise Exception("Error: '%s' is needed in %s" % (key, func))
+ raise Exception(
+ "Error: '%s' is needed in %s" %
+ (key, func))
if choices and kwargs[key] not in choices:
raise Exception("Error: %s :%s" % (key, kwargs[key]))
@@ -40,7 +42,9 @@ def dcheck(key, choices=[]):
values = None
if isinstance(values, dict):
if key not in values:
- raise Exception("Error: '%s' is needed in %s" % (key, func))
+ raise Exception(
+ "Error: '%s' is needed in %s" %
+ (key, func))
if choices and values[key] not in choices:
raise Exception("Error: %s :%s" % (key, values[key]))
ret = func(*args)
@@ -84,7 +88,8 @@ def namespace():
ret = func(*args, **kwargs)
nspace = kwargs.get("namespace", None)
if nspace:
- ret = "ip netns exec %(namespace)s " % {"namespace": nspace} + ret
+ ret = "ip netns exec %(namespace)s " % {
+ "namespace": nspace} + ret
return ret
return __deco
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/log.py b/testsuites/vstf/vstf_scripts/vstf/common/log.py
index 415b003a..b8b64888 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/log.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/log.py
@@ -34,7 +34,10 @@ def _init_log(log_file, level=logging.INFO, clevel=logging.INFO):
return file_handler, console
-def setup_logging(level=logging.INFO, log_file="/var/log/esp_test.log", clevel=logging.WARNING):
+def setup_logging(
+ level=logging.INFO,
+ log_file="/var/log/esp_test.log",
+ clevel=logging.WARNING):
log = logging.getLogger()
log.setLevel(level)
file_handler, console = _init_log(log_file, level, clevel)
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/pyhtml.py b/testsuites/vstf/vstf_scripts/vstf/common/pyhtml.py
index f3adee8d..b2162290 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/pyhtml.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/pyhtml.py
@@ -14,22 +14,124 @@ doc_type = '<!DOCTYPE HTML>\n'
default_title = "Html Page"
charset = '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n'
-html4_tags = {'a', 'abbr', 'acronym', 'address', 'area', 'b', 'base', 'bdo', 'big',
- 'blockquote', 'body', 'br', 'button', 'caption', 'cite', 'code', 'col',
- 'colgroup', 'dd', 'del', 'div', 'dfn', 'dl', 'dt', 'em', 'fieldset',
- 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head',
- 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd',
- 'label', 'legend', 'li', 'link', 'map', 'menu', 'menuitem', 'meta',
- 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'p',
- 'param', 'pre', 'q', 'samp', 'script', 'select', 'small', 'span', 'strong',
- 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th',
- 'thead', 'title', 'tr', 'tt', 'ul', 'var'}
+html4_tags = {
+ 'a',
+ 'abbr',
+ 'acronym',
+ 'address',
+ 'area',
+ 'b',
+ 'base',
+ 'bdo',
+ 'big',
+ 'blockquote',
+ 'body',
+ 'br',
+ 'button',
+ 'caption',
+ 'cite',
+ 'code',
+ 'col',
+ 'colgroup',
+ 'dd',
+ 'del',
+ 'div',
+ 'dfn',
+ 'dl',
+ 'dt',
+ 'em',
+ 'fieldset',
+ 'form',
+ 'frame',
+ 'frameset',
+ 'h1',
+ 'h2',
+ 'h3',
+ 'h4',
+ 'h5',
+ 'h6',
+ 'head',
+ 'hr',
+ 'html',
+ 'i',
+ 'iframe',
+ 'img',
+ 'input',
+ 'ins',
+ 'kbd',
+ 'label',
+ 'legend',
+ 'li',
+ 'link',
+ 'map',
+ 'menu',
+ 'menuitem',
+ 'meta',
+ 'noframes',
+ 'noscript',
+ 'object',
+ 'ol',
+ 'optgroup',
+ 'option',
+ 'p',
+ 'param',
+ 'pre',
+ 'q',
+ 'samp',
+ 'script',
+ 'select',
+ 'small',
+ 'span',
+ 'strong',
+ 'style',
+ 'sub',
+ 'sup',
+ 'table',
+ 'tbody',
+ 'td',
+ 'textarea',
+ 'tfoot',
+ 'th',
+ 'thead',
+ 'title',
+ 'tr',
+ 'tt',
+ 'ul',
+ 'var'}
disused_tags = {'isindex', 'font', 'dir', 's', 'strike',
'u', 'center', 'basefont', 'applet', 'xmp'}
-html5_tags = {'article', 'aside', 'audio', 'bdi', 'canvas', 'command', 'datalist', 'details',
- 'dialog', 'embed', 'figcaption', 'figure', 'footer', 'header',
- 'keygen', 'mark', 'meter', 'nav', 'output', 'progress', 'rp', 'rt', 'ruby',
- 'section', 'source', 'summary', 'details', 'time', 'track', 'video', 'wbr'}
+html5_tags = {
+ 'article',
+ 'aside',
+ 'audio',
+ 'bdi',
+ 'canvas',
+ 'command',
+ 'datalist',
+ 'details',
+ 'dialog',
+ 'embed',
+ 'figcaption',
+ 'figure',
+ 'footer',
+ 'header',
+ 'keygen',
+ 'mark',
+ 'meter',
+ 'nav',
+ 'output',
+ 'progress',
+ 'rp',
+ 'rt',
+ 'ruby',
+ 'section',
+ 'source',
+ 'summary',
+ 'details',
+ 'time',
+ 'track',
+ 'video',
+ 'wbr'}
nl = '\n'
tags = html4_tags | disused_tags | html5_tags
@@ -105,7 +207,8 @@ class Tag(list):
result = ''
if self.tag_name:
result += '<%s%s%s>' % (self.tag_name,
- self._render_attr(), self._self_close() * ' /')
+ self._render_attr(),
+ self._self_close() * ' /')
if not self._self_close():
isnl = True
for c in self:
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/rsync.py b/testsuites/vstf/vstf_scripts/vstf/common/rsync.py
index 2209dfd3..03331368 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/rsync.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/rsync.py
@@ -10,7 +10,15 @@
# from __future__ import nested_scopes
-import os, os.path, shutil, glob, re, sys, getopt, stat, string
+import os
+import os.path
+import shutil
+import glob
+import re
+import sys
+import getopt
+import stat
+import string
try:
import win32file
@@ -19,6 +27,7 @@ except:
class Cookie:
+
def __init__(self):
self.sink_root = ""
self.target_root = ""
@@ -45,7 +54,7 @@ class Cookie:
def visit(cookie, dirname, names):
"""Copy files names from sink_root + (dirname - sink_root) to target_root + (dirname - sink_root)"""
if os.path.split(cookie.sink_root)[
- 1]: # Should be tested with (C:\Cvs -> C:\)! (C:\Archives\MyDatas\UltraEdit -> C:\Archives\MyDatas) (Cvs -> "")! (Archives\MyDatas\UltraEdit -> Archives\MyDatas) (\Cvs -> \)! (\Archives\MyDatas\UltraEdit -> Archives\MyDatas)
+ 1]: # Should be tested with (C:\Cvs -> C:\)! (C:\Archives\MyDatas\UltraEdit -> C:\Archives\MyDatas) (Cvs -> "")! (Archives\MyDatas\UltraEdit -> Archives\MyDatas) (\Cvs -> \)! (\Archives\MyDatas\UltraEdit -> Archives\MyDatas)
dirname = dirname[len(cookie.sink_root) + 1:]
else:
dirname = dirname[len(cookie.sink_root):]
@@ -81,7 +90,9 @@ def visit(cookie, dirname, names):
elif os.path.isdir(sink):
removeDir(cookie, sink)
else:
- logError("Sink %s is neither a file nor a folder (skip removal)" % sink)
+ logError(
+ "Sink %s is neither a file nor a folder (skip removal)" %
+ sink)
names_excluded += [names[name_index]]
del (names[name_index])
name_index = name_index - 1
@@ -95,7 +106,7 @@ def visit(cookie, dirname, names):
for name in os.listdir(target_dir):
if not cookie.delete_excluded and name in names_excluded:
continue
- if not name in names:
+ if name not in names:
target = os.path.join(target_dir, name)
if os.path.isfile(target):
removeFile(cookie, target)
@@ -122,7 +133,9 @@ def visit(cookie, dirname, names):
copyFile(cookie, sink, target)
else:
# file-???
- logError("Target %s is neither a file nor folder (skip update)" % sink)
+ logError(
+ "Target %s is neither a file nor folder (skip update)" %
+ sink)
elif os.path.isdir(sink):
if os.path.isfile(target):
@@ -131,7 +144,9 @@ def visit(cookie, dirname, names):
makeDir(cookie, target)
else:
# ???-xxx
- logError("Sink %s is neither a file nor a folder (skip update)" % sink)
+ logError(
+ "Sink %s is neither a file nor a folder (skip update)" %
+ sink)
elif not cookie.existing:
# When target dont exist:
@@ -142,7 +157,9 @@ def visit(cookie, dirname, names):
# folder
makeDir(cookie, target)
else:
- logError("Sink %s is neither a file nor a folder (skip update)" % sink)
+ logError(
+ "Sink %s is neither a file nor a folder (skip update)" %
+ sink)
def log(cookie, message):
@@ -166,7 +183,9 @@ def shouldUpdate(cookie, sink, target):
sink_sz = sink_st.st_size
sink_mt = sink_st.st_mtime
except:
- logError("Fail to retrieve information about sink %s (skip update)" % sink)
+ logError(
+ "Fail to retrieve information about sink %s (skip update)" %
+ sink)
return 0
try:
@@ -174,7 +193,9 @@ def shouldUpdate(cookie, sink, target):
target_sz = target_st.st_size
target_mt = target_st.st_mtime
except:
- logError("Fail to retrieve information about target %s (skip update)" % target)
+ logError(
+ "Fail to retrieve information about target %s (skip update)" %
+ target)
return 0
if cookie.update:
@@ -203,7 +224,7 @@ def copyFile(cookie, sink, target):
if cookie.time:
try:
s = os.stat(sink)
- os.utime(target, (s.st_atime, s.st_mtime));
+ os.utime(target, (s.st_atime, s.st_mtime))
except:
logError("Fail to copy timestamp of %s" % sink)
@@ -216,8 +237,9 @@ def updateFile(cookie, sink, target):
try:
if win32file:
filemode = win32file.GetFileAttributesW(target)
- win32file.SetFileAttributesW(target,
- filemode & ~win32file.FILE_ATTRIBUTE_READONLY & ~win32file.FILE_ATTRIBUTE_HIDDEN & ~win32file.FILE_ATTRIBUTE_SYSTEM)
+ win32file.SetFileAttributesW(
+ target,
+ filemode & ~win32file.FILE_ATTRIBUTE_READONLY & ~win32file.FILE_ATTRIBUTE_HIDDEN & ~win32file.FILE_ATTRIBUTE_SYSTEM)
else:
os.chmod(target, stat.S_IWUSR)
except:
@@ -228,10 +250,11 @@ def updateFile(cookie, sink, target):
if cookie.time:
try:
s = os.stat(sink)
- os.utime(target, (s.st_atime, s.st_mtime));
+ os.utime(target, (s.st_atime, s.st_mtime))
except:
- logError(
- "Fail to copy timestamp of %s" % sink) # The utime api of the 2.3 version of python is not unicode compliant.
+ # The utime api of the 2.3 version of python is not unicode
+ # compliant.
+ logError("Fail to copy timestamp of %s" % sink)
except:
logError("Fail to override %s" % sink)
@@ -242,8 +265,8 @@ def updateFile(cookie, sink, target):
def prepareRemoveFile(path):
if win32file:
filemode = win32file.GetFileAttributesW(path)
- win32file.SetFileAttributesW(path,
- filemode & ~win32file.FILE_ATTRIBUTE_READONLY & ~win32file.FILE_ATTRIBUTE_HIDDEN & ~win32file.FILE_ATTRIBUTE_SYSTEM)
+ win32file.SetFileAttributesW(path, filemode & ~win32file.FILE_ATTRIBUTE_READONLY &
+ ~win32file.FILE_ATTRIBUTE_HIDDEN & ~win32file.FILE_ATTRIBUTE_SYSTEM)
else:
os.chmod(path, stat.S_IWUSR)
@@ -305,7 +328,8 @@ def convertPath(path):
if separator != "/":
path = re.sub(re.escape(separator), "/", path)
- # Help file, folder pattern to express that it should match the all file or folder name.
+ # Help file, folder pattern to express that it should match the all file
+ # or folder name.
path = "/" + path
return path
@@ -360,7 +384,7 @@ def convertPatterns(path, sign):
"""Read the files for pattern and return a vector of filters"""
filters = []
f = open(path, "r")
- while 1:
+ while True:
pattern = f.readline()
if not pattern:
break
@@ -428,8 +452,8 @@ def main(args):
cookie.relative = 1
elif o in ["-n", "--dry-run"]:
cookie.dry_run = 1
- elif o in ["-t", "--times",
- "--time"]: # --time is there to guaranty backward compatibility with previous buggy version.
+ # --time is there to guaranty backward compatibility with previous buggy version.
+ elif o in ["-t", "--times", "--time"]:
cookie.time = 1
elif o in ["-u", "--update"]:
cookie.update = 1
@@ -474,7 +498,7 @@ def main(args):
target_root = args[1]
try: # In order to allow compatibility below 2.3.
pass
- if os.path.__dict__.has_key("supports_unicode_filenames") and os.path.supports_unicode_filenames:
+ if "supports_unicode_filenames" in os.path.__dict__ and os.path.supports_unicode_filenames:
target_root = unicode(target_root, sys.getfilesystemencoding())
finally:
cookie.target_root = target_root
@@ -486,7 +510,7 @@ def main(args):
sink_families = {}
for sink in sinks:
try: # In order to allow compatibility below 2.3.
- if os.path.__dict__.has_key("supports_unicode_filenames") and os.path.supports_unicode_filenames:
+ if "supports_unicode_filenames" in os.path.__dict__ and os.path.supports_unicode_filenames:
sink = unicode(sink, sys.getfilesystemencoding())
except:
pass
@@ -499,7 +523,7 @@ def main(args):
break
sink_root, sink_name = os.path.split(sink_root)
sink_root = sink_drive + sink_root
- if not sink_families.has_key(sink_root):
+ if sink_root not in sink_families:
sink_families[sink_root] = []
sink_families[sink_root] = sink_families[sink_root] + [sink_name]
@@ -509,15 +533,28 @@ def main(args):
else:
cookie.sink_root = sink_root
- global y # In order to allow compatibility below 2.1 (nested scope where used before).
+ # In order to allow compatibility below 2.1 (nested scope where used
+ # before).
+ global y
y = sink_root
- files = filter(lambda x: os.path.isfile(os.path.join(y, x)), sink_families[sink_root])
+ files = filter(
+ lambda x: os.path.isfile(
+ os.path.join(
+ y,
+ x)),
+ sink_families[sink_root])
if files:
visit(cookie, sink_root, files)
- # global y # In order to allow compatibility below 2.1 (nested scope where used before).
+ # global y # In order to allow compatibility below 2.1 (nested scope
+ # where used before).
y = sink_root
- folders = filter(lambda x: os.path.isdir(os.path.join(y, x)), sink_families[sink_root])
+ folders = filter(
+ lambda x: os.path.isdir(
+ os.path.join(
+ y,
+ x)),
+ sink_families[sink_root])
for folder in folders:
folder_path = os.path.join(sink_root, folder)
if not cookie.recursive:
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/saltstack.py b/testsuites/vstf/vstf_scripts/vstf/common/saltstack.py
index 030bef5d..96bdc911 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/saltstack.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/saltstack.py
@@ -32,14 +32,16 @@ class Mysalt(object):
cmds.execute("grep '^pillar_roots' \
/etc/salt/master -A 2 | sed 1,2d | awk '{print $2}'") + '/')
if self.pillar_path == "":
- log.warning("pillar path not found, make sure the pillar_roots configed")
+ log.warning(
+ "pillar path not found, make sure the pillar_roots configed")
else:
os.system("mkdir -p " + self.pillar_path)
self.state_path = str(cmds.execute("grep '^file_roots' \
/etc/salt/master -A 2 | sed 1,2d | awk '{print $2}'") + '/')
if self.state_path == "":
- log.warning("state path not found, make sure the file_roots configed")
+ log.warning(
+ "state path not found, make sure the file_roots configed")
else:
os.system("mkdir -p " + self.state_path)
@@ -72,7 +74,8 @@ class Mysalt(object):
elif flag == "state":
dst = self.state_path
else:
- log.error("this file or dir not pillar or state, can not support now.")
+ log.error(
+ "this file or dir not pillar or state, can not support now.")
return False
if self.IS_FILE == self.__is_dir_or_file(target):
@@ -125,20 +128,27 @@ class Mysalt(object):
num_s += 1
else:
num_f += 1
- msg = msg + self.__luxuriant_line("Failed %d:\n" % num_f, "red")
+ msg = msg + \
+ self.__luxuriant_line("Failed %d:\n" % num_f, "red")
msg = msg + "\t" + key + '\n'
- msg = msg + self.__luxuriant_line("\t%s\n" % ret[host][key]['comment'], "red")
- if True == ret[host][key]['changes'].has_key('retcode'):
- msg = msg + "RETCODE: %s\n" % (ret[host][key]['changes']['retcode'])
- if True == ret[host][key]['changes'].has_key('stderr'):
- msg = msg + "STDERR: %s\n" % (ret[host][key]['changes']['stderr'])
- if True == ret[host][key]['changes'].has_key('stdout'):
- msg = msg + "STDOUT: %s\n" % (ret[host][key]['changes']['stdout'])
- msg = msg + self.__luxuriant_line("total success: %d\n" % num_s, "green")
+ msg = msg + \
+ self.__luxuriant_line("\t%s\n" % ret[host][key]['comment'], "red")
+ if True == ('retcode' in ret[host][key]['changes']):
+ msg = msg + \
+ "RETCODE: %s\n" % (ret[host][key]['changes']['retcode'])
+ if True == ('stderr' in ret[host][key]['changes']):
+ msg = msg + \
+ "STDERR: %s\n" % (ret[host][key]['changes']['stderr'])
+ if True == ('stdout' in ret[host][key]['changes']):
+ msg = msg + \
+ "STDOUT: %s\n" % (ret[host][key]['changes']['stdout'])
+ msg = msg + \
+ self.__luxuriant_line("total success: %d\n" % num_s, "green")
msg = msg + self.__luxuriant_line("failed: %d\n" % num_f, "red")
except Exception as e:
- log.error("sorry, thy to check result happend error, <%(e)s>.\nret:%(ret)s",
- {'e': e, 'ret': ret})
+ log.error(
+ "sorry, thy to check result happend error, <%(e)s>.\nret:%(ret)s", {
+ 'e': e, 'ret': ret})
return -1
log.info(':\n' + msg)
return num_f
@@ -147,7 +157,9 @@ class Mysalt(object):
try:
log.info("salt " + host + " state.sls " +
fstate + ' pillar=\'' + str(ext_pillar) + '\'')
- ret = self.salt.cmd(host, 'state.sls', [fstate, 'pillar=' + str(ext_pillar)], 180, 'list')
+ ret = self.salt.cmd(
+ host, 'state.sls', [
+ fstate, 'pillar=' + str(ext_pillar)], 180, 'list')
except Exception as e:
log.error("try to init host %(host)s happend error: <%(e)s>.",
{'host': host, 'e': e})
@@ -170,7 +182,7 @@ class Mysalt(object):
return ret
def copy_by_state(self, host, src, state_cmd, **kwargs):
- '''the src must be a dir, and the state.sls
+ '''the src must be a dir, and the state.sls
must be the name of the dir name'''
if not self.slave_exists(host):
@@ -184,10 +196,12 @@ class Mysalt(object):
def get_master_ip(self, host=None):
if not host:
- ret = cmds.execute("grep '^interface:' /etc/salt/master | awk '{print $2}'").strip()
+ ret = cmds.execute(
+ "grep '^interface:' /etc/salt/master | awk '{print $2}'").strip()
return ret
try:
- ret = self.salt.cmd(host, "grains.item", ["master"])[host]['master']
+ ret = self.salt.cmd(host, "grains.item", ["master"])[
+ host]['master']
except Exception:
log.error("salt happened error when get master ip")
return ""
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/ssh.py b/testsuites/vstf/vstf_scripts/vstf/common/ssh.py
index 7b85e086..5cf196d4 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/ssh.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/ssh.py
@@ -19,6 +19,7 @@ LOG = logging.getLogger(__name__)
class SSHClientContext(paramiko.SSHClient):
+
def __init__(self, ip, user, passwd, port=22):
self.host = ip
self.user = user
@@ -31,11 +32,20 @@ class SSHClientContext(paramiko.SSHClient):
ret = stdout.channel.recv_exit_status()
out = stdout.read().strip()
err = stderr.read().strip()
- LOG.info("in %s,%s,return:%s,output:%s:error:%s" % (self.host, cmd, ret, out, err))
+ LOG.info(
+ "in %s,%s,return:%s,output:%s:error:%s" %
+ (self.host, cmd, ret, out, err))
return ret, out, err
def connect(self):
- super(SSHClientContext, self).connect(self.host, self.port, self.user, self.passwd, timeout=10)
+ super(
+ SSHClientContext,
+ self).connect(
+ self.host,
+ self.port,
+ self.user,
+ self.passwd,
+ timeout=10)
def __enter__(self):
self.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@@ -48,6 +58,7 @@ class SSHClientContext(paramiko.SSHClient):
class SFTPClientContext(object):
+
def __init__(self, ip, user, passwd, port=22):
self.host = ip
self.passwd = passwd
@@ -97,7 +108,9 @@ def upload_dir(host, user, passwd, local_dir, remote_dir):
remote_dir = os.path.join(remote_dir, os.path.basename(local_dir))
ret, _, _ = run_cmd(host, user, passwd, "sudo rm -rf %s" % remote_dir)
if ret != 0 and ret != 1:
- LOG.error("somehow failed in rm -rf %s on host:%s,return:%s" % (remote_dir, host, ret))
+ LOG.error(
+ "somehow failed in rm -rf %s on host:%s,return:%s" %
+ (remote_dir, host, ret))
exit(1)
with SFTPClientContext(host, user, passwd) as sftp:
sftp.connect()
@@ -117,7 +130,7 @@ def upload_dir(host, user, passwd, local_dir, remote_dir):
try:
sftp.mkdir(remote_path)
LOG.info("mkdir path %s" % remote_path)
- except Exception, e:
+ except Exception as e:
raise
return remote_dir
@@ -177,7 +190,9 @@ def download_dir(host, user, passwd, remote_path, local_path):
dest_path = local_path
else:
raise Exception('path:%s is not exists' % dir_name)
- LOG.info("download_dir from host:%s:%s to dest:%s" % (host, remote_path, dest_path))
+ LOG.info(
+ "download_dir from host:%s:%s to dest:%s" %
+ (host, remote_path, dest_path))
transport = paramiko.Transport((host, 22))
transport.connect(username=user, password=passwd)
sftp = paramiko.SFTPClient.from_transport(transport)
@@ -189,7 +204,8 @@ def download_dir(host, user, passwd, remote_path, local_path):
path = q.get()
st = sftp.lstat(path).st_mode
relative_path = path[len(remote_path):]
- if relative_path.startswith('/'): relative_path = relative_path[1:]
+ if relative_path.startswith('/'):
+ relative_path = relative_path[1:]
local = os.path.join(dest_path, relative_path)
if os.path.exists(local):
shutil.rmtree(local)
@@ -206,7 +222,9 @@ def download_dir(host, user, passwd, remote_path, local_path):
sftp.get(fullpath, dest)
os.chmod(dest, st)
else:
- raise Exception('path:%s:%s not exists or is not a dir' % (host, remote_path))
+ raise Exception(
+ 'path:%s:%s not exists or is not a dir' %
+ (host, remote_path))
return dest_path
@@ -218,6 +236,7 @@ def run_cmd(host, user, passwd, cmd):
class SshFileTransfer(object):
+
def __init__(self, ip, user, passwd):
self.ip, self.user, self.passwd = ip, user, passwd
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/test_func.py b/testsuites/vstf/vstf_scripts/vstf/common/test_func.py
index 2a9a4c0d..3fa23cdc 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/test_func.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/test_func.py
@@ -20,4 +20,4 @@ from vstf.common import cliutil as util
help="a params of test-xx")
def do_test_xx(args):
"""this is a help doc"""
- print "run test01 " + args.test + args.xx \ No newline at end of file
+ print "run test01 " + args.test + args.xx
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/unix.py b/testsuites/vstf/vstf_scripts/vstf/common/unix.py
index 97582c74..ac3c9b72 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/unix.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/unix.py
@@ -14,49 +14,51 @@ from vstf.common import message
class UdpServer(object):
+
def __init__(self):
super(UdpServer, self).__init__()
try:
os.unlink(constants.sockaddr)
except OSError:
if os.path.exists(constants.sockaddr):
- raise Exception("socket not found %s" % constants.sockaddr)
- self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-
- def listen(self,backlog=5):
+ raise Exception("socket not found %s" % constants.sockaddr)
+ self.conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+
+ def listen(self, backlog=5):
self.conn.listen(backlog)
-
+
def accept(self):
return self.conn.accept()
-
+
def bind(self, addr=constants.sockaddr):
return self.conn.bind(addr)
-
+
# def send(self, data, addr):
# return message.sendto(self.conn.sendto, data, addr)
-
+
# def recv(self, size=constants.buff_size):
# return message.recv(self.conn.recvfrom)
-
+
def close(self):
self.conn.close()
class UdpClient(object):
+
def __init__(self):
super(UdpClient, self).__init__()
if not os.path.exists(constants.sockaddr):
- raise Exception("socket not found %s" % constants.sockaddr)
- self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-
+ raise Exception("socket not found %s" % constants.sockaddr)
+ self.conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+
def connect(self, addr=constants.sockaddr):
return self.conn.connect(addr)
-
+
def send(self, data):
message.send(self.conn.send, data)
-
+
def recv(self):
return message.recv(self.conn.recv)
-
+
def close(self):
- self.conn.close() \ No newline at end of file
+ self.conn.close()
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/utils.py b/testsuites/vstf/vstf_scripts/vstf/common/utils.py
index f2e14096..e9ee2791 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/utils.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/utils.py
@@ -82,7 +82,7 @@ def my_mkdir(filepath):
try:
LOG.info("mkdir -p %s" % filepath)
os.makedirs(filepath)
- except OSError, e:
+ except OSError as e:
if e.errno == 17:
LOG.info("! %s already exists" % filepath)
else:
@@ -107,7 +107,9 @@ def check_and_kill(process):
def list_mods():
- return check_output("lsmod | sed 1,1d | awk '{print $1}'", shell=True).split()
+ return check_output(
+ "lsmod | sed 1,1d | awk '{print $1}'",
+ shell=True).split()
def check_and_rmmod(mod):
@@ -144,6 +146,7 @@ def randomMAC():
class IPCommandHelper(object):
+
def __init__(self, ns=None):
self.devices = []
self.macs = []
@@ -174,7 +177,10 @@ class IPCommandHelper(object):
cmd = "ip netns exec %s " % ns + cmd
for device in self.devices:
buf = check_output(cmd % device, shell=True)
- bdfs = re.findall(r'^bus-info: \d{4}:(\d{2}:\d{2}\.\d*)$', buf, re.MULTILINE)
+ bdfs = re.findall(
+ r'^bus-info: \d{4}:(\d{2}:\d{2}\.\d*)$',
+ buf,
+ re.MULTILINE)
if bdfs:
self.bdf_device_map[bdfs[0]] = device
self.device_bdf_map[device] = bdfs[0]
@@ -188,7 +194,9 @@ class IPCommandHelper(object):
if ns:
cmd = "ip netns exec %s " % ns + cmd
buf = check_output(cmd, shell=True)
- macs = re.compile(r"[A-F0-9]{2}(?::[A-F0-9]{2}){5}", re.IGNORECASE | re.MULTILINE)
+ macs = re.compile(
+ r"[A-F0-9]{2}(?::[A-F0-9]{2}){5}",
+ re.IGNORECASE | re.MULTILINE)
for mac in macs.findall(buf):
if mac.lower() not in ('00:00:00:00:00:00', 'ff:ff:ff:ff:ff:ff'):
return mac
diff --git a/testsuites/vstf/vstf_scripts/vstf/common/vstfcli.py b/testsuites/vstf/vstf_scripts/vstf/common/vstfcli.py
index 896bb1d6..ae4fecfb 100644
--- a/testsuites/vstf/vstf_scripts/vstf/common/vstfcli.py
+++ b/testsuites/vstf/vstf_scripts/vstf/common/vstfcli.py
@@ -12,6 +12,7 @@ import sys
class VstfHelpFormatter(argparse.HelpFormatter):
+
def start_section(self, heading):
# Title-case the headings
heading = '%s%s' % (heading[0].upper(), heading[1:])
@@ -19,6 +20,7 @@ class VstfHelpFormatter(argparse.HelpFormatter):
class VstfParser(argparse.ArgumentParser):
+
def __init__(self,
prog='vstf',
description="",
@@ -41,11 +43,12 @@ class VstfParser(argparse.ArgumentParser):
desc = callback.__doc__ or ''
action_help = desc.strip()
arguments = getattr(callback, 'arguments', [])
- subparser = subparsers.add_parser(command,
- help=action_help,
- description=desc,
- add_help=False,
- formatter_class=VstfHelpFormatter)
+ subparser = subparsers.add_parser(
+ command,
+ help=action_help,
+ description=desc,
+ add_help=False,
+ formatter_class=VstfHelpFormatter)
subparser.add_argument('-h', '--help',
action='help',
help=argparse.SUPPRESS)