aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-08-12 01:36:45 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-08-12 01:36:45 +0900
commit6f38e14866421cef83b91b5b982ae7ae3e06d823 (patch)
treee043e8aace3df5f862d0e919947404b1297c4ff7
parentremoved build_livepatch from client as already doing automatically when (diff)
downloadelivepatch-6f38e14866421cef83b91b5b982ae7ae3e06d823.tar.gz
elivepatch-6f38e14866421cef83b91b5b982ae7ae3e06d823.tar.bz2
elivepatch-6f38e14866421cef83b91b5b982ae7ae3e06d823.zip
removed buildlivepatch and merged with GetFiles and modified for manage
incremental patches
-rw-r--r--elivepatch_server/elivepatch5
-rw-r--r--elivepatch_server/resources/dispatcher.py86
2 files changed, 38 insertions, 53 deletions
diff --git a/elivepatch_server/elivepatch b/elivepatch_server/elivepatch
index 21f0106..cd14f75 100644
--- a/elivepatch_server/elivepatch
+++ b/elivepatch_server/elivepatch
@@ -26,11 +26,6 @@ def create_app():
api.add_resource(AgentInfo.AgentAPI, '/elivepatch/api/v1.0/agent',
endpoint='agent')
- # where to start the livepatch build
- api.add_resource(dispatcher.BuildLivePatch,
- '/elivepatch/api/v1.0/build_livepatch',
- endpoint='build_livepatch')
-
# where to retrieve the live patch when ready
api.add_resource(dispatcher.SendLivePatch,
'/elivepatch/api/v1.0/send_livepatch',
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index 3b67a95..dbe9af4 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -49,48 +49,6 @@ def get_uuid_dir(uuid):
return os.path.join('/tmp/', 'elivepatch-' + uuid)
-class BuildLivePatch(Resource):
-
- def __init__(self):
- self.reqparse = reqparse.RequestParser()
- self.reqparse.add_argument('KernelVersion', type=str, required=False,
- help='No task title provided',
- location='json')
- self.reqparse.add_argument('UUID', type=str, required=False,
- help='No task title provided',
- location='json')
- super(BuildLivePatch, self).__init__()
- pass
-
- def get(self):
- return {'packs': [marshal(pack, pack_fields) for pack in packs]}
-
- def post(self):
- lpatch = PaTch()
- args = self.reqparse.parse_args()
- args['UUID'] = check_uuid(args['UUID'])
- if args['KernelVersion']:
- print("build livepatch: " + str(args))
- # check vmlinux presence if not rebuild the kernel
- kernel_sources_status = lpatch.get_kernel_sources(args['UUID'], args['KernelVersion'])
- if not kernel_sources_status:
- return make_response(jsonify({'message': 'gentoo-sources not available'}), 403)
- lpatch.build_livepatch(args['UUID'], 'vmlinux')
- pack = {
- 'id': packs['id'] + 1,
- 'KernelVersion': args['KernelVersion'],
- 'UUID' : args['UUID']
- }
- return {'build_livepatch': marshal(pack, pack_fields)}, 201
-
- @staticmethod
- def build_kernel_path(uuid, kernel_version):
- kernel_absolute_path = 'linux-' + str(kernel_version) + '-gentoo'
- kernel_path = os.path.join('/tmp/', 'elivepatch-' + uuid, 'usr',
- 'src', kernel_absolute_path)
- return kernel_path
-
-
class SendLivePatch(Resource):
def __init__(self):
@@ -149,17 +107,19 @@ class GetFiles(Resource):
parse = reqparse.RequestParser()
parse.add_argument('patch', action='append', type=werkzeug.datastructures.FileStorage,
location='files')
+ parse.add_argument('main_patch', action='append', type=werkzeug.datastructures.FileStorage,
+ location='files')
parse.add_argument('config', type=werkzeug.datastructures.FileStorage,
location='files')
file_args = parse.parse_args()
+
+ lpatch = PaTch()
+
print("file get config: " + str(file_args))
configFile = file_args['config']
configFile_name = file_args['config'].filename
- for patch in file_args['patch']:
- patchfile = patch
- patchfile_name = patch.filename
-
+ # saving config file
configFile_name = os.path.join('/tmp','elivepatch-' + args['UUID'], configFile_name)
if os.path.exists('/tmp/elivepatch-' + args['UUID']):
print('the folder: "/tmp/elivepatch-' + args['UUID'] + '" is already present')
@@ -170,8 +130,38 @@ class GetFiles(Resource):
configFile.save(configFile_name)
- patch_fulldir_name = os.path.join('/tmp','elivepatch-' + args['UUID'], patchfile_name)
- patchfile.save(patch_fulldir_name)
+
+ # saving incremental patches
+ incremental_patches_directory = os.path.join('/tmp', 'elivepatch-' + args['UUID'], 'etc', 'portage', 'patches',
+ 'sys-kernel', 'gentoo-sources')
+ if os.path.exists(incremental_patches_directory):
+ print('the folder: "/tmp/elivepatch-' + args['UUID'] + '" is already present')
+ return {'the request with ' + args['UUID'] + ' is already present'}, 201
+ else:
+ print('creating: '+incremental_patches_directory)
+ os.makedirs(incremental_patches_directory)
+ try:
+ for patch in file_args['patch']:
+ print(str(patch))
+ patchfile = patch
+ patchfile_name = patch.filename
+ patch_fulldir_name = os.path.join(incremental_patches_directory, patchfile_name)
+ patchfile.save(patch_fulldir_name)
+ except:
+ print('no incremental patches')
+
+ # saving main patch
+ print(str(file_args['main_patch']))
+ main_patchfile = file_args['main_patch'][0]
+ main_patchfile_name = main_patchfile.filename
+ main_patch_fulldir_name = os.path.join('/tmp','elivepatch-' + args['UUID'], main_patchfile_name)
+ main_patchfile.save(main_patch_fulldir_name)
+
+ # check vmlinux presence if not rebuild the kernel
+ kernel_sources_status = lpatch.get_kernel_sources(args['UUID'], args['KernelVersion'])
+ if not kernel_sources_status:
+ return make_response(jsonify({'message': 'gentoo-sources not available'}), 403)
+ lpatch.build_livepatch(args['UUID'], 'vmlinux')
pack = {
'id': packs['id'] + 1,