[CRIU] [PATCH 5/6] p.haul: remove E302 linter warning from ignore list
Nikita Spiridonov
nspiridonov at odin.com
Mon Nov 9 07:40:25 PST 2015
Remove E302 linter warning (expected 2 blank lines, found 1) from
ignore list.
It is hard to read code with single blank line between classes and
global functions since there is no braces in python. 2 blank lines
much better.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
p.haul | 7 +++++--
p.haul-service | 18 +++++++++++-------
p.haul-wrap | 3 +++
phaul/connection.py | 2 ++
phaul/criu_api.py | 6 ++++++
phaul/criu_cr.py | 1 +
phaul/criu_req.py | 12 ++++++++++++
phaul/fs_haul_ploop.py | 2 ++
phaul/fs_haul_shared.py | 1 +
phaul/fs_haul_subtree.py | 1 +
phaul/htype.py | 5 +++++
phaul/images.py | 4 ++++
phaul/iters.py | 1 +
phaul/mstats.py | 2 ++
phaul/p_haul_docker.py | 2 ++
phaul/p_haul_lxc.py | 2 ++
phaul/p_haul_pid.py | 1 +
phaul/p_haul_vz.py | 4 ++++
phaul/service.py | 1 +
phaul/util.py | 8 ++++++++
phaul/xem_rpc.py | 4 ++++
phaul/xem_rpc_client.py | 2 ++
test/flake8.cfg | 3 +--
23 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/p.haul b/p.haul
index 478e1c7..940c819 100755
--- a/p.haul
+++ b/p.haul
@@ -23,6 +23,11 @@ import phaul.htype
# p.haul lxc myct --fdrpc 3 --fdmem 4 --fdfs 5
#
+
+def log_uncaught_exception(type, value, traceback):
+ logging.error(value, exc_info=(type, value, traceback))
+
+
parser = argparse.ArgumentParser("Process HAULer")
parser.add_argument("type", choices=phaul.htype.get_haul_names(),
help="Type of hat to haul, e.g. vz, lxc, or docker")
@@ -62,8 +67,6 @@ logging.basicConfig(filename=args.log_file, filemode="w", level=logging.INFO,
format="%(asctime)s.%(msecs)03d: %(message)s", datefmt="%H:%M:%S")
# Setup hook to log uncaught exceptions
-def log_uncaught_exception(type, value, traceback):
- logging.error(value, exc_info=(type, value, traceback))
sys.excepthook = log_uncaught_exception
logging.info("Starting p.haul")
diff --git a/p.haul-service b/p.haul-service
index 451311c..b838c1c 100755
--- a/p.haul-service
+++ b/p.haul-service
@@ -8,6 +8,17 @@ import phaul.xem_rpc
import phaul.service
import phaul.connection
+
+def log_uncaught_exception(type, value, traceback):
+ logging.error(value, exc_info=(type, value, traceback))
+
+
+def fin(foo, bar):
+ global stop_fd
+ logging.info("Stop by %d", foo)
+ stop_fd.close()
+
+
parser = argparse.ArgumentParser("Process HAULer service server")
parser.add_argument("--fdrpc", help="File descriptor of rpc socket", type=int, required=True)
parser.add_argument("--fdmem", help="File descriptor of memory socket", type=int, required=True)
@@ -21,15 +32,8 @@ logging.basicConfig(filename=args.log_file, filemode="w", level=logging.INFO,
format="%(asctime)s.%(msecs)03d: %(message)s", datefmt="%H:%M:%S")
# Setup hook to log uncaught exceptions
-def log_uncaught_exception(type, value, traceback):
- logging.error(value, exc_info=(type, value, traceback))
sys.excepthook = log_uncaught_exception
-stop_fd = None
-def fin(foo, bar):
- logging.info("Stop by %d", foo)
- stop_fd.close()
-
logging.info("Starting p.haul service")
# Establish connection
diff --git a/p.haul-wrap b/p.haul-wrap
index acf7604..bdaff49 100755
--- a/p.haul-wrap
+++ b/p.haul-wrap
@@ -19,9 +19,11 @@ import thread
# p.haul-wrap client 10.0.0.1 vz 100
#
+
default_rpc_port = 12345
default_service_bind_addr = "0.0.0.0"
+
def start_web_gui(partner, rpc_port):
"""Start web gui if requested"""
import webgui.p_haul_web_gui
@@ -90,6 +92,7 @@ def run_phaul_client(args, unknown_args):
print "Exec p.haul: {0}".format(" ".join(target_args))
os.system(" ".join(target_args))
+
# Initialize arguments parser
parser = argparse.ArgumentParser("Process HAULer wrap")
subparsers = parser.add_subparsers(title="Subcommands")
diff --git a/phaul/connection.py b/phaul/connection.py
index 48b962a..33da9fd 100644
--- a/phaul/connection.py
+++ b/phaul/connection.py
@@ -7,6 +7,7 @@ import logging
import socket
import util
+
class connection:
"""p.haul connection
@@ -25,6 +26,7 @@ class connection:
self.mem_sk.close()
self.fs_sk.close()
+
def establish(fdrpc, fdmem, fdfs):
"""Construct required socket objects from file descriptors
diff --git a/phaul/criu_api.py b/phaul/criu_api.py
index 0fcc618..2da304a 100644
--- a/phaul/criu_api.py
+++ b/phaul/criu_api.py
@@ -17,10 +17,12 @@ cpuinfo_img_name = "cpuinfo.img"
def_verb = 2
+
#
# Connection to CRIU service
#
+
class criu_conn:
def __init__(self, mem_sk):
self._iter = 0
@@ -82,10 +84,12 @@ class criu_conn:
def shell_job(self, value):
self._shell_job = value
+
#
# Helper to read CRIU-generated statistics
#
+
def criu_get_stats(img, file_name):
with open(os.path.join(img.work_dir(), file_name)) as f:
stats_dict = pycriu.images.load(f)
@@ -93,10 +97,12 @@ def criu_get_stats(img, file_name):
pycriu.images.pb2dict.dict2pb(stats_dict['entries'][0], stats)
return stats
+
def criu_get_dstats(img):
stats = criu_get_stats(img, "stats-dump")
return stats.dump
+
def criu_get_rstats(img):
stats = criu_get_stats(img, "stats-restore")
return stats.restore
diff --git a/phaul/criu_cr.py b/phaul/criu_cr.py
index b97f8e1..d402ce1 100644
--- a/phaul/criu_cr.py
+++ b/phaul/criu_cr.py
@@ -6,6 +6,7 @@ import logging
import pycriu.rpc
import criu_req
+
def criu_dump(htype, pid, img, criu_connection, fs):
req = criu_req.make_dump_req(pid, htype, img, criu_connection, fs)
resp = criu_connection.send_req(req)
diff --git a/phaul/criu_req.py b/phaul/criu_req.py
index bd843cd..a5bb01c 100644
--- a/phaul/criu_req.py
+++ b/phaul/criu_req.py
@@ -4,6 +4,7 @@
import pycriu.rpc
+
def _build_names(name_strings):
names = {}
for key, value in name_strings.items():
@@ -11,6 +12,7 @@ def _build_names(name_strings):
names[getattr(pycriu.rpc, key)] = value
return names
+
_name_strings = {
"DUMP": "dump",
"PRE_DUMP": "pre_dump",
@@ -23,10 +25,12 @@ _name_strings = {
_names = _build_names(_name_strings)
+
def get_name(req_type):
"""Return printable request name"""
return _names[req_type]
+
def _make_req(typ, htype = None):
"""Prepare generic criu request"""
req = pycriu.rpc.criu_req()
@@ -35,6 +39,7 @@ def _make_req(typ, htype = None):
htype.adjust_criu_req(req)
return req
+
def make_cpuinfo_dump_req(img):
"""Prepare cpuinfo dump criu request (source side)"""
req = _make_req(pycriu.rpc.CPUINFO_DUMP)
@@ -42,6 +47,7 @@ def make_cpuinfo_dump_req(img):
req.keep_open = True
return req
+
def _make_common_dump_req(typ, pid, htype, img, connection, fs):
"""Prepare common criu request for pre-dump or dump (source side)"""
@@ -59,11 +65,13 @@ def _make_common_dump_req(typ, pid, htype, img, connection, fs):
return req
+
def make_predump_req(pid, img, connection, fs):
"""Prepare pre-dump criu request (source side)"""
return _make_common_dump_req(
pycriu.rpc.PRE_DUMP, pid, None, img, connection, fs)
+
def make_dump_req(pid, htype, img, connection, fs):
"""Prepare dump criu request (source side)"""
req = _make_common_dump_req(
@@ -76,6 +84,7 @@ def make_dump_req(pid, htype, img, connection, fs):
req.opts.tcp_established = True
return req
+
def make_page_server_req(img, connection):
"""Prepare page server criu request (destination side)"""
@@ -91,6 +100,7 @@ def make_page_server_req(img, connection):
return req
+
def make_cpuinfo_check_req(img):
"""Prepare cpuinfo check criu request (destination side)"""
req = _make_req(pycriu.rpc.CPUINFO_CHECK)
@@ -98,6 +108,7 @@ def make_cpuinfo_check_req(img):
req.opts.images_dir_fd = img.work_dir_fd()
return req
+
def make_restore_req(htype, img, nroot):
"""Prepare restore criu request (destination side)"""
@@ -117,6 +128,7 @@ def make_restore_req(htype, img, nroot):
return req
+
def make_dirty_tracking_req(img):
"""Check if dirty memory tracking is supported."""
req = _make_req(pycriu.rpc.FEATURE_CHECK)
diff --git a/phaul/fs_haul_ploop.py b/phaul/fs_haul_ploop.py
index b70edff..abfb052 100644
--- a/phaul/fs_haul_ploop.py
+++ b/phaul/fs_haul_ploop.py
@@ -6,6 +6,7 @@ import logging
import threading
import libploop
+
class p_haul_fs:
def __init__(self, ddxml_path, fs_sk):
"""Initialize ploop disk hauler
@@ -36,6 +37,7 @@ class p_haul_fs:
"""Inode numbers do not change during ploop disk migration"""
return True
+
class p_haul_fs_receiver(threading.Thread):
def __init__(self, fname_path, fs_sk):
"""Initialize ploop disk receiver
diff --git a/phaul/fs_haul_shared.py b/phaul/fs_haul_shared.py
index 2212e0e..9e373a5 100644
--- a/phaul/fs_haul_shared.py
+++ b/phaul/fs_haul_shared.py
@@ -4,6 +4,7 @@
import logging
+
class p_haul_fs:
def __init__(self):
logging.info("Initilized shared FS hauler")
diff --git a/phaul/fs_haul_subtree.py b/phaul/fs_haul_subtree.py
index 32334cb..405f840 100644
--- a/phaul/fs_haul_subtree.py
+++ b/phaul/fs_haul_subtree.py
@@ -10,6 +10,7 @@ import logging
rsync_log_file = "rsync.log"
+
class p_haul_fs:
def __init__(self, subtree_paths):
self.__roots = []
diff --git a/phaul/htype.py b/phaul/htype.py
index bee49b4..77a7e32 100644
--- a/phaul/htype.py
+++ b/phaul/htype.py
@@ -7,6 +7,7 @@
import logging
import importlib
+
__haul_modules = {
"vz": "p_haul_vz",
"pid": "p_haul_pid",
@@ -14,6 +15,7 @@ __haul_modules = {
"docker": "p_haul_docker",
}
+
def __get(id):
hauler_name, haulee_id = id[0], id[1]
if hauler_name not in __haul_modules:
@@ -28,15 +30,18 @@ def __get(id):
return hauler_module.p_haul_type(haulee_id)
+
def get_haul_names():
"""Return list of available haulers"""
return __haul_modules.keys()
+
def get_src(id):
ht = __get(id)
ht.init_src()
return ht
+
def get_dst(id):
ht = __get(id)
ht.init_dst()
diff --git a/phaul/images.py b/phaul/images.py
index 57dca59..a67b569 100644
--- a/phaul/images.py
+++ b/phaul/images.py
@@ -14,6 +14,7 @@ import criu_api
def_path = "/var/local/p.haul-fs/"
+
class opendir:
def __init__(self, path):
self._dirname = path
@@ -31,6 +32,7 @@ class opendir:
def fileno(self):
return self._dirfd
+
class untar_thread(threading.Thread):
def __init__(self, sk, tdir):
threading.Thread.__init__(self)
@@ -45,6 +47,7 @@ class untar_thread(threading.Thread):
except:
logging.exception("Exception in untar_thread")
+
class img_tar:
def __init__(self, sk, dirname):
self.__tf = tarfile.open(mode="w|", fileobj=util.fileobj_wrap(sk))
@@ -59,6 +62,7 @@ class img_tar:
def close(self):
self.__tf.close()
+
class phaul_images:
WDIR = 1
IMGDIR = 2
diff --git a/phaul/iters.py b/phaul/iters.py
index eedec7d..c3edca2 100644
--- a/phaul/iters.py
+++ b/phaul/iters.py
@@ -26,6 +26,7 @@ phaul_iter_min_size = 64
# this % more than previous
phaul_iter_grow_max = 10
+
class phaul_iter_worker:
def __init__(self, p_type, connection):
self.connection = connection
diff --git a/phaul/mstats.py b/phaul/mstats.py
index 00ec6f1..a10bdaf 100644
--- a/phaul/mstats.py
+++ b/phaul/mstats.py
@@ -1,9 +1,11 @@
import time
import logging
+
def usec2sec(usec):
return usec / 1000000.
+
class migration_stats:
def __init__(self):
self._iter_fr_times = []
diff --git a/phaul/p_haul_docker.py b/phaul/p_haul_docker.py
index 1259c5c..b07ce2c 100644
--- a/phaul/p_haul_docker.py
+++ b/phaul/p_haul_docker.py
@@ -14,11 +14,13 @@ from subprocess import PIPE
# TODO use docker-py
# import docker
+
# Some constants for docker
docker_bin = "/usr/bin/docker-1.9.0-dev"
docker_dir = "/var/lib/docker/"
docker_run_meta_dir = "/var/run/docker/execdriver/native"
+
class p_haul_type:
def __init__(self, ctid):
diff --git a/phaul/p_haul_lxc.py b/phaul/p_haul_lxc.py
index 577a1bc..e7d6553 100644
--- a/phaul/p_haul_lxc.py
+++ b/phaul/p_haul_lxc.py
@@ -10,9 +10,11 @@ import util
import fs_haul_shared
from subprocess import Popen, PIPE
+
lxc_dir = "/var/lib/lxc/"
lxc_rootfs_dir = "/usr/lib64/lxc/rootfs"
+
class p_haul_type:
def __init__(self, name):
self._ctname = name
diff --git a/phaul/p_haul_pid.py b/phaul/p_haul_pid.py
index 55f85da..bc9c0cc 100644
--- a/phaul/p_haul_pid.py
+++ b/phaul/p_haul_pid.py
@@ -6,6 +6,7 @@ import logging
import criu_cr
import fs_haul_shared
+
class p_haul_type:
def __init__(self, id):
self.pid = int(id)
diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index 0646e6f..48f5e69 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -12,10 +12,12 @@ import fs_haul_shared
import fs_haul_ploop
import pycriu.rpc
+
vz_global_conf = "/etc/vz/vz.conf"
vz_conf_dir = "/etc/vz/conf/"
vzctl_bin = "vzctl"
+
class p_haul_type:
def __init__(self, ctid):
self._ctid = ctid
@@ -251,6 +253,7 @@ class p_haul_type:
def dump_need_ps(self):
return True
+
def parse_vz_config(body):
"""Parse shell-like virtuozzo config file"""
@@ -260,6 +263,7 @@ def parse_vz_config(body):
config_values[name] = value
return config_values
+
def expand_veid_var(value, ctid):
"""Replace shell-like VEID variable with actual container id"""
return value.replace("$VEID", ctid).replace("${VEID}", ctid)
diff --git a/phaul/service.py b/phaul/service.py
index 305f729..248c9fa 100644
--- a/phaul/service.py
+++ b/phaul/service.py
@@ -8,6 +8,7 @@ import criu_api
import criu_req
import htype
+
class phaul_service:
def __init__(self, connection):
self.criu_connection = None
diff --git a/phaul/util.py b/phaul/util.py
index 2a66de4..bb9a8ac 100644
--- a/phaul/util.py
+++ b/phaul/util.py
@@ -3,6 +3,7 @@ import fcntl
import errno
import logging
+
class fileobj_wrap:
"""Helper class provides read/write interface for socket object
@@ -21,12 +22,14 @@ class fileobj_wrap:
def write(self, str):
self.__sk.send(str)
+
class net_dev:
def __init__(self, name=None, pair=None, link=None):
self.name = name
self.pair = pair
self.link = link
+
def path_to_fs(path):
dev = os.stat(path)
dev_str = "%d:%d" % (os.major(dev.st_dev), os.minor(dev.st_dev))
@@ -38,22 +41,27 @@ def path_to_fs(path):
return None
+
def ifup(ifname):
logging.info("\t\tUpping %s", ifname)
os.system("ip link set %s up" % ifname)
+
def ifdown(ifname):
logging.info("\t\tDowning %s", ifname)
os.system("ip link set %s down" % ifname)
+
def bridge_add(ifname, brname):
logging.info("\t\tAdd %s to %s", ifname, brname)
os.system("brctl addif %s %s" % (brname, ifname))
+
def set_cloexec(sk):
flags = fcntl.fcntl(sk, fcntl.F_GETFD)
fcntl.fcntl(sk, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
+
def makedirs(dirpath):
try:
os.makedirs(dirpath)
diff --git a/phaul/xem_rpc.py b/phaul/xem_rpc.py
index 529400d..ac070d4 100644
--- a/phaul/xem_rpc.py
+++ b/phaul/xem_rpc.py
@@ -16,6 +16,7 @@ RPC_CALL = 2
RPC_RESP = 1
RPC_EXC = 2
+
class _rpc_server_sk:
def __init__(self, sk):
self._sk = sk
@@ -56,6 +57,7 @@ class _rpc_server_sk:
self._master = mgr.make_master()
self._master.on_connect(*args)
+
class _rpc_stop_fd:
def __init__(self, fd):
self._fd = fd
@@ -66,6 +68,7 @@ class _rpc_stop_fd:
def work(self, mgr):
mgr.stop()
+
class _rpc_server_manager:
def __init__(self, srv_class, connection):
self._srv_class = srv_class
@@ -98,6 +101,7 @@ class _rpc_server_manager:
logging.info("RPC Service stops")
+
class rpc_threaded_srv(threading.Thread):
def __init__(self, srv_class, connection):
threading.Thread.__init__(self)
diff --git a/phaul/xem_rpc_client.py b/phaul/xem_rpc_client.py
index 073521f..df6b7be 100644
--- a/phaul/xem_rpc_client.py
+++ b/phaul/xem_rpc_client.py
@@ -5,6 +5,7 @@
import logging
import xem_rpc
+
class _rpc_proxy_caller:
def __init__(self, sk, typ, fname):
self._rpc_sk = sk
@@ -26,6 +27,7 @@ class _rpc_proxy_caller:
else:
raise Exception("Proto resp error")
+
class rpc_proxy:
def __init__(self, sk, *args):
self._rpc_sk = sk
diff --git a/test/flake8.cfg b/test/flake8.cfg
index a88807c..8b4560c 100644
--- a/test/flake8.cfg
+++ b/test/flake8.cfg
@@ -1,8 +1,7 @@
[flake8]
# W191 indentation contains tabs
# E128 continuation line under-indented for visual indent
-# E302 expected 2 blank lines, found 1
# E501 line too long
# E251 unexpected spaces around keyword / parameter equals
# E101 indentation contains mixed spaces and tabs
-ignore = W191,E128,E302,E501,E251,E101
+ignore = W191,E128,E501,E251,E101
--
1.7.1
More information about the CRIU
mailing list