diff options
author | Alice Ferrazzi <alicef@gentoo.org> | 2017-07-20 17:46:19 +0900 |
---|---|---|
committer | Alice Ferrazzi <alicef@gentoo.org> | 2017-07-20 17:46:19 +0900 |
commit | 7ad5d20f0e29ac3d3c6595afdfb5d9701387de3d (patch) | |
tree | fecf290231b627e8774be97247d225ef3037951b | |
parent | Static patch and config filename on send (diff) | |
download | elivepatch-7ad5d20f0e29ac3d3c6595afdfb5d9701387de3d.tar.gz elivepatch-7ad5d20f0e29ac3d3c6595afdfb5d9701387de3d.tar.bz2 elivepatch-7ad5d20f0e29ac3d3c6595afdfb5d9701387de3d.zip |
Removed livepatchStatus and lpatch class configurations.
Because we need a request to only be identified by is own UUID,
for isolating the transaction.
-rw-r--r-- | elivepatch_server/resources/dispatcher.py | 37 | ||||
-rw-r--r-- | elivepatch_server/resources/livepatch.py | 70 |
2 files changed, 11 insertions, 96 deletions
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py index f095e02..f87f6e4 100644 --- a/elivepatch_server/resources/dispatcher.py +++ b/elivepatch_server/resources/dispatcher.py @@ -16,7 +16,6 @@ from elivepatch_server.resources.livepatch import PaTch pack_fields = { 'KernelVersion': fields.String, - 'LivepatchStatus': fields.String, 'UUID': fields.String } @@ -24,7 +23,6 @@ pack_fields = { packs = { 'id': 1, 'KernelVersion': None, - 'LivepatchStatus': None, 'UUID': None } @@ -50,10 +48,6 @@ def check_uuid(uuid): def get_uuid_dir(uuid): return os.path.join('/tmp/', 'elivepatch-' + uuid) -# TODO: move lpatch to per request scope instead of global scope -lpatch = PaTch() -kernel_dir = lpatch.get_kernel_dir() - class BuildLivePatch(Resource): @@ -62,9 +56,6 @@ class BuildLivePatch(Resource): self.reqparse.add_argument('KernelVersion', type=str, required=False, help='No task title provided', location='json') - self.reqparse.add_argument('LivepatchStatus', 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') @@ -72,27 +63,20 @@ class BuildLivePatch(Resource): pass def get(self): - # lpatch.build_livepatch(kernel_dir, kernel_dir + '/vmlinux') 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']: - lpatch.set_kernel_dir(BuildLivePatch.build_kernel_path(args['UUID'], - args['KernelVersion'])) - kernel_config = lpatch.get_config() - kernel_patch = lpatch.get_patch() - if kernel_config and kernel_patch: - lpatch.set_lp_status('working') - print("build livepatch: " + str(args)) - # check vmlinux presence if not rebuild the kernel - lpatch.get_kernel_sources(args['UUID'], args['KernelVersion']) - lpatch.build_livepatch(args['UUID'], 'vmlinux') + print("build livepatch: " + str(args)) + # check vmlinux presence if not rebuild the kernel + lpatch.get_kernel_sources(args['UUID'], args['KernelVersion']) + lpatch.build_livepatch(args['UUID'], 'vmlinux') pack = { 'id': packs['id'] + 1, 'KernelVersion': args['KernelVersion'], - 'LivepatchStatus': lpatch.livepatch_status, 'UUID' : args['UUID'] } return {'build_livepatch': marshal(pack, pack_fields)}, 201 @@ -124,14 +108,8 @@ class SendLivePatch(Resource): # check if is a valid UUID request args['UUID'] = check_uuid(args['UUID']) uuid_dir = get_uuid_dir(args['UUID']) - 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 - livepatch_full_path = os.path.join(uuid_dir, 'kpatch-'+livepatch_name) + livepatch_full_path = os.path.join(uuid_dir, 'kpatch-'+ str(args['UUID']) + '-livepatch.ko') try: with open(livepatch_full_path, 'rb') as fp: response = make_response(fp.read()) @@ -189,12 +167,9 @@ class GetFiles(Resource): os.makedirs('/tmp/elivepatch-' + args['UUID']) configFile.save(configFile_name) - lpatch.set_config(configFile_name) patch_fulldir_name = os.path.join('/tmp','elivepatch-' + args['UUID'], patchfile_name) patchfile.save(patch_fulldir_name) - lpatch.set_patch(patch_fulldir_name) - lpatch.set_patch_filename(patchfile_name) pack = { 'id': packs['id'] + 1, diff --git a/elivepatch_server/resources/livepatch.py b/elivepatch_server/resources/livepatch.py index ecad33e..038b1e6 100644 --- a/elivepatch_server/resources/livepatch.py +++ b/elivepatch_server/resources/livepatch.py @@ -11,70 +11,8 @@ import os 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 - - def set_kernel_dir(self, kernel_dir): - self.kernel_dir = kernel_dir - - def get_kernel_dir(self): - return self.kernel_dir - - def set_lp_status(self, livepatch_status): - self.livepatch_status = livepatch_status - - def get_lp_status(self): - return self.livepatch_status - - def update_lp_status(self, livepatch): - if os.path.isfile(livepatch): - self.livepatch_status = 'done' - return self.livepatch_status - - def set_kernel_version(self, kernel_version): - self.kernel_version = kernel_version - - def get_kernel_version(self): - return self.kernel_version - - def get_config(self): - return self.config_file - - def set_config(self, config_file): - self.config_file = config_file - - 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 - - def kernel_version(self): pass - def compare_kernel_config(self): - pass - - def recompile_kernel(self): - pass - - def search_kernel_source_path(self): - pass - - def get_kernel_source_path(self): - self.kernel_path = '' - return self.kernel_path - # kpatch-build/kpatch-build -s /usr/src/linux-4.9.16-gentoo/ # -v /usr/src/linux-4.9.16-gentoo/vmlinux examples/test.patch # -c ../elivepatch/elivepatch_server/config --skip-gcc-check @@ -96,8 +34,8 @@ class PaTch(object): bashCommand = ['kpatch-build'] bashCommand.extend(['-s',kernel_source]) bashCommand.extend(['-v',vmlinux_source]) - bashCommand.extend(['-c',self.config_file]) - bashCommand.extend([self.patch_file]) + bashCommand.extend(['-c','config']) + bashCommand.extend(['01.patch']) bashCommand.extend(['--skip-gcc-check']) if debug: bashCommand.extend(['--skip-cleanup']) @@ -125,11 +63,13 @@ class PaTch(object): def build_kernel(self, uuid_dir): kernel_source_dir = '/tmp/elivepatch-' + uuid_dir + '/usr/src/linux/' command(['sudo','cp','/tmp/elivepatch-' + uuid_dir + '/config',kernel_source_dir + '.config']) - command(['sudo','make','oldconfig'], kernel_source_dir) + # olddefconfig default everything that is new from the configuration file + command(['sudo','make','olddefconfig'], kernel_source_dir) command(['sudo','make'], kernel_source_dir) command(['sudo','make', 'modules'], kernel_source_dir) command(['sudo','make', 'modules_install'], kernel_source_dir) + def command(bashCommand, kernel_source_dir=None): """ Popen override function |