aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-13 13:36:59 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-13 13:36:59 +0900
commit43b5741604c2431930073fc8db49d5edcf695521 (patch)
tree3482bbefa270eeef2c02f09e8da7efeeb67d9ce6
parentRemoved client check for system kernel version. (diff)
downloadelivepatch-43b5741604c2431930073fc8db49d5edcf695521.tar.gz
elivepatch-43b5741604c2431930073fc8db49d5edcf695521.tar.bz2
elivepatch-43b5741604c2431930073fc8db49d5edcf695521.zip
Build and get livepatch under the uuid temporary folder [for multi-threading]
added new helper function some fixes
-rw-r--r--elivepatch_server/resources/dispatcher.py63
-rw-r--r--elivepatch_server/resources/livepatch.py10
2 files changed, 49 insertions, 24 deletions
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index d16975d..c7804ab 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -29,14 +29,33 @@ packs = {
}
-def set_kernel_dir(uuid, kernel_ID):
- kernel_absolute_path = 'linux-' + str(kernel_ID) + '-gentoo'
+def id_generate():
+ UserID = str(uuid.uuid4())
+ return UserID
+
+
+def check_uuid(uuid):
+ if not uuid:
+ print('Generating new uuid')
+ return id_generate()
+ else:
+ print('UserID: ' + str(uuid))
+ return uuid
+
+
+def get_uuid_dir(uuid):
+ return os.path.join('/tmp/', 'elivepatch-' + uuid)
+
+
+def set_kernel_dir(uuid, kernel_version):
+ kernel_absolute_path = 'linux-' + str(kernel_version) + '-gentoo'
kernel_path = os.path.join('/tmp/', 'elivepatch-' + uuid, 'usr', 'src', kernel_absolute_path)
lpatch.set_kernel_dir(kernel_path)
lpatch = PaTch()
kernel_dir = lpatch.get_kernel_dir()
+
class BuildLivePatch(Resource):
def __init__(self):
@@ -59,10 +78,7 @@ class BuildLivePatch(Resource):
def post(self):
args = self.reqparse.parse_args()
- if not args['UserID']:
- args['UserID'] = id_generate()
- else:
- print('UserID: ' + str(args['UserID']))
+ args['UserID'] = check_uuid(args['UserID'])
if args['KernelVersion']:
set_kernel_dir(args['UserID'], args['KernelVersion'])
kernel_config = lpatch.get_config()
@@ -99,12 +115,17 @@ class SendLivePatch(Resource):
args = self.reqparse.parse_args()
print("get livepatch: " + str(args))
# check if is a new user
- if not args['UserID']:
- args['UserID'] = id_generate()
- else:
- print('UserID: ' + str(args['UserID']))
+ args['UserID'] = check_uuid(args['UserID'])
+ uuid_dir = get_uuid_dir(args['UserID'])
+ patch_name = lpatch.get_patch_filename()
+
+ # change patch extension to .ko
+ base = os.path.splitext(patch_name)[0]
+ livepatch_name = base + ".ko"
+
# Getting livepatch build status
- with open('kpatch-1.ko', 'rb') as fp:
+ livepatch_full_path = os.path.join(uuid_dir, 'kpatch-'+livepatch_name)
+ with open(livepatch_full_path, 'rb') as fp:
response = make_response(fp.read())
response.headers['content-type'] = 'application/octet-stream'
return response
@@ -133,10 +154,7 @@ class GetFiles(Resource):
def post(self):
args = self.reqparse.parse_args()
- if not args['UserID']:
- args['UserID'] = str(id_generate())
- else:
- print('UserID: ' + str(args['UserID']))
+ args['UserID'] = check_uuid(args['UserID'])
parse = reqparse.RequestParser()
parse.add_argument('patch', type=werkzeug.datastructures.FileStorage,
location='files')
@@ -147,8 +165,8 @@ class GetFiles(Resource):
configFile = file_args['config']
configFile_name = file_args['config'].filename
- patchFile = file_args['patch']
- patchFile_name = file_args['patch'].filename
+ patchfile = file_args['patch']
+ patchfile_name = file_args['patch'].filename
configFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], configFile_name)
if not os.path.exists('/tmp/elivepatch-' + args['UserID']):
@@ -156,11 +174,12 @@ class GetFiles(Resource):
configFile.save(configFile_name)
lpatch.set_config(configFile_name)
- patchFile_name = os.path.join('/tmp','elivepatch-' + args['UserID'], patchFile_name)
+ patch_fulldir_name = os.path.join('/tmp','elivepatch-' + args['UserID'], patchfile_name)
if not os.path.exists('/tmp/elivepatch-' + args['UserID']):
os.makedirs('/tmp/elivepatch-' + args['UserID'])
- patchFile.save(patchFile_name)
- lpatch.set_patch(patchFile_name)
+ patchfile.save(patch_fulldir_name)
+ lpatch.set_patch(patch_fulldir_name)
+ lpatch.set_patch_filename(patchfile_name)
pack = {
'id': packs['id'] + 1,
@@ -189,6 +208,4 @@ class GetID(Resource):
print("get ID: " + str(args))
-def id_generate():
- UserID = uuid.uuid4()
- return UserID
+
diff --git a/elivepatch_server/resources/livepatch.py b/elivepatch_server/resources/livepatch.py
index a315b92..11762ea 100644
--- a/elivepatch_server/resources/livepatch.py
+++ b/elivepatch_server/resources/livepatch.py
@@ -13,6 +13,7 @@ class PaTch(object):
def __init__(self):
self.config_file = None
self.patch_file = None
+ self.patch_filename = None
self.kernel_version = None
self.livepatch_status = "Not started"
self.kernel_dir = None
@@ -49,6 +50,12 @@ class PaTch(object):
def set_patch(self, patch_file):
self.patch_file = patch_file
+ def set_patch_filename(self, patch_filename):
+ self.patch_filename = patch_filename
+
+ def get_patch_filename(self):
+ return self.patch_filename
+
def get_patch(self):
return self.patch_file
@@ -80,6 +87,7 @@ class PaTch(object):
:return: void
"""
kernel_source = os.path.join('/tmp/','elivepatch-' + uuid, 'usr/src/linux/')
+ uuid_dir = os.path.join('/tmp/','elivepatch-' + uuid)
vmlinux_source = os.path.join(kernel_source, vmlinux)
if not os.path.isfile(vmlinux_source):
self.build_kernel(uuid)
@@ -93,7 +101,7 @@ class PaTch(object):
if debug:
bashCommand.extend(['--skip-cleanup'])
bashCommand.extend(['--debug'])
- command(bashCommand)
+ command(bashCommand, uuid_dir)
def get_kernel_sources(self, uuid_dir, kernel_version):
"""