aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-14 03:26:31 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-14 03:26:31 +0900
commitd6bf464dbdc63233bafdca04fd1db77ed6a232c7 (patch)
tree6ff76144eb2498305045f919c05f184ed6b579d8
parentdon't error exit the server but instead send back a error message if the live... (diff)
downloadelivepatch-d6bf464dbdc63233bafdca04fd1db77ed6a232c7.tar.gz
elivepatch-d6bf464dbdc63233bafdca04fd1db77ed6a232c7.tar.bz2
elivepatch-d6bf464dbdc63233bafdca04fd1db77ed6a232c7.zip
Changed UserID with UUID for clarity
The previous UserID variable was actually used as universally unique identifier for dividing tasks with multi-threading. Fixed for better understability.
-rw-r--r--elivepatch_client/client/checkers.py39
-rw-r--r--elivepatch_client/client/restful.py45
-rw-r--r--elivepatch_server/resources/dispatcher.py48
3 files changed, 68 insertions, 64 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py
index b3bad95..439e722 100644
--- a/elivepatch_client/client/checkers.py
+++ b/elivepatch_client/client/checkers.py
@@ -17,13 +17,13 @@ from elivepatch_client.client import restful
class Kernel(object):
- def __init__(self, url):
+ def __init__(self, restserver_url):
self.config = ''
self.patch = ''
- self.url = url
+ self.restserver_url = restserver_url
self.kernel_version = None
- self.rest_manager = restful.ManaGer(url, self.kernel_version)
- self.UserID = None
+ self.rest_manager = restful.ManaGer(self.restserver_url, self.kernel_version)
+ self.uuid = None
def set_config(self, config_path):
self.config = config_path
@@ -49,29 +49,32 @@ class Kernel(object):
path, patch_file = (os.path.split(self.patch))
- # check userID
- data_store = shelve.open('userid')
+ # check uuid
+ data_store = shelve.open('uuid')
- # get old userid if present
+ # get old uuid if present
try:
- old_userid = data_store['UserID']
+ old_uuid = data_store['UUID']
except:
- old_userid = None
- print('no UserID')
+ old_uuid = None
+ print('no UUID')
# send uncompressed config and patch files
replay = self.rest_manager.send_file(self.config, self.patch, file, patch_file, '/elivepatch/api/v1.0/get_files')
- # get userid returned from the server
- userid = replay['get_config']['UserID']
- self.rest_manager.set_user_id(userid)
+ # get uuid returned from the server
+ try:
+ uuid = replay['get_config']['UUID']
+ except:
+ uuid = None
+ self.rest_manager.set_uuid(uuid)
- # check if the userid is new
- if userid:
+ # check if the uuid is new
+ if uuid:
try:
- if userid != old_userid:
- print('new userid: ' + str(userid))
- data_store['UserID'] = userid
+ if uuid != old_uuid or not old_uuid:
+ print('new uuid: ' + str(uuid))
+ data_store['UUID'] = uuid
data_store.close()
except:
pass
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index e89d397..93bb0b4 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -15,10 +15,10 @@ class ManaGer(object):
def __init__(self, server_url, kernel_version):
self.server_url = server_url
self.kernel_version = kernel_version
- self.user_id = None
+ self.uuid = None
- def set_user_id(self, user_id):
- self.user_id = user_id
+ def set_uuid(self, uuid):
+ self.uuid = uuid
def set_kernel_version(self, kernel_version):
self.kernel_version = kernel_version
@@ -26,8 +26,8 @@ class ManaGer(object):
def get_kernel_version(self):
return self.kernel_version
- def get_user_id(self):
- return self.user_id
+ def get_uuid(self):
+ return self.uuid
def version(self):
url = self.server_url + '/elivepatch/api/v1.0/agent'
@@ -37,13 +37,13 @@ class ManaGer(object):
def send_file(self, config_send_file, patch_send_file, config_file_name, patch_file_name, api):
url = self.server_url+ api
- # we are sending the file and the UserID
- # The server is dividing user by UserID
- # UserID is generated with python UUID
- # TODO: add the UserID in the json location instead of headers
+ # we are sending the file and the UUID
+ # The server is dividing user by UUID
+ # UUID is generated with python UUID
+ # TODO: add the UUID in the json location instead of headers
headers = {
'KernelVersion' : self.kernel_version,
- 'UserID': self.user_id
+ 'UUID': self.uuid
}
files = {'patch': (patch_file_name, open(patch_send_file, 'rb'), 'multipart/form-data', {'Expires': '0'}),
'config': (config_file_name, open(config_send_file, 'rb'), 'multipart/form-data', {'Expires': '0'})}
@@ -58,7 +58,7 @@ class ManaGer(object):
url = self.server_url+'/elivepatch/api/v1.0/build_livepatch'
payload = {
'KernelVersion': self.kernel_version,
- 'UserID' : self.user_id
+ 'UUID' : self.uuid
}
r = requests.post(url, json=payload)
# print(r.text)
@@ -69,20 +69,21 @@ class ManaGer(object):
url = self.server_url+'/elivepatch/api/v1.0/send_livepatch'
payload = {
'KernelVersion': self.kernel_version,
- 'UserID' : self.user_id
+ 'UUID' : self.uuid
}
r = requests.get(url, json=payload)
if r.status_code == requests.codes.ok: # livepatch returned ok
- b= BytesIO(r.content)
- with open('myfile.ko', 'wb') as out:
- out.write(r.content)
- r.close()
- print(b)
- else:
- r.close()
- time.sleep(5)
- return self.get_livepatch() # try to get the livepatch again
- elivepatch_dir = os.path.join('..', 'elivepatch-'+ self.user_id)
+ try:
+ b= BytesIO(r.content)
+ with open('myfile.ko', 'wb') as out:
+ out.write(r.content)
+ r.close()
+ print(b)
+ except:
+ print('livepatch not found')
+ r.close()
+
+ elivepatch_dir = os.path.join('..', 'elivepatch-'+ self.uuid)
if not os.path.exists(elivepatch_dir):
os.makedirs(elivepatch_dir)
shutil.move("myfile.ko", os.path.join(elivepatch_dir, 'livepatch.ko'))
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index 56340ec..e55595b 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -17,7 +17,7 @@ from elivepatch_server.resources.livepatch import PaTch
pack_fields = {
'KernelVersion': fields.String,
'LivepatchStatus': fields.String,
- 'UserID': fields.String
+ 'UUID': fields.String
}
@@ -25,13 +25,13 @@ packs = {
'id': 1,
'KernelVersion': None,
'LivepatchStatus': None,
- 'UserID': None
+ 'UUID': None
}
def id_generate():
- UserID = str(uuid.uuid4())
- return UserID
+ UUID = str(uuid.uuid4())
+ return UUID
def check_uuid(uuid):
@@ -39,7 +39,7 @@ def check_uuid(uuid):
print('Generating new uuid')
return id_generate()
else:
- print('UserID: ' + str(uuid))
+ print('UUID: ' + str(uuid))
return uuid
@@ -66,7 +66,7 @@ class BuildLivePatch(Resource):
self.reqparse.add_argument('LivepatchStatus', type=str, required=False,
help='No task title provided',
location='json')
- self.reqparse.add_argument('UserID', type=str, required=False,
+ self.reqparse.add_argument('UUID', type=str, required=False,
help='No task title provided',
location='json')
super(BuildLivePatch, self).__init__()
@@ -78,22 +78,22 @@ class BuildLivePatch(Resource):
def post(self):
args = self.reqparse.parse_args()
- args['UserID'] = check_uuid(args['UserID'])
+ args['UUID'] = check_uuid(args['UUID'])
if args['KernelVersion']:
- set_kernel_dir(args['UserID'], args['KernelVersion'])
+ set_kernel_dir(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['UserID'], args['KernelVersion'])
- lpatch.build_livepatch(args['UserID'], 'vmlinux')
+ 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,
- 'UserID' : args['UserID']
+ 'UUID' : args['UUID']
}
return {'build_livepatch': marshal(pack, pack_fields)}, 201
@@ -105,7 +105,7 @@ class SendLivePatch(Resource):
self.reqparse.add_argument('KernelVersion', type=str, required=False,
help='No task title provided',
location='json')
- self.reqparse.add_argument('UserID', type=str, required=False,
+ self.reqparse.add_argument('UUID', type=str, required=False,
help='No task title provided',
location='json')
super(SendLivePatch, self).__init__()
@@ -115,8 +115,8 @@ class SendLivePatch(Resource):
args = self.reqparse.parse_args()
print("get livepatch: " + str(args))
# check if is a new user
- args['UserID'] = check_uuid(args['UserID'])
- uuid_dir = get_uuid_dir(args['UserID'])
+ args['UUID'] = check_uuid(args['UUID'])
+ uuid_dir = get_uuid_dir(args['UUID'])
patch_name = lpatch.get_patch_filename()
# change patch extension to .ko
@@ -146,7 +146,7 @@ class GetFiles(Resource):
self.reqparse.add_argument('KernelVersion', type=str, required=False,
help='No task title provided',
location='headers')
- self.reqparse.add_argument('UserID', type=str, required=False,
+ self.reqparse.add_argument('UUID', type=str, required=False,
help='No task title provided',
location='headers')
super(GetFiles, self).__init__()
@@ -158,7 +158,7 @@ class GetFiles(Resource):
def post(self):
args = self.reqparse.parse_args()
- args['UserID'] = check_uuid(args['UserID'])
+ args['UUID'] = check_uuid(args['UUID'])
parse = reqparse.RequestParser()
parse.add_argument('patch', type=werkzeug.datastructures.FileStorage,
location='files')
@@ -172,15 +172,15 @@ class GetFiles(Resource):
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']):
- os.makedirs('/tmp/elivepatch-' + args['UserID'])
+ configFile_name = os.path.join('/tmp','elivepatch-' + args['UUID'], configFile_name)
+ if not os.path.exists('/tmp/elivepatch-' + args['UUID']):
+ os.makedirs('/tmp/elivepatch-' + args['UUID'])
configFile.save(configFile_name)
lpatch.set_config(configFile_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'])
+ patch_fulldir_name = os.path.join('/tmp','elivepatch-' + args['UUID'], patchfile_name)
+ if not os.path.exists('/tmp/elivepatch-' + args['UUID']):
+ os.makedirs('/tmp/elivepatch-' + args['UUID'])
patchfile.save(patch_fulldir_name)
lpatch.set_patch(patch_fulldir_name)
lpatch.set_patch_filename(patchfile_name)
@@ -188,7 +188,7 @@ class GetFiles(Resource):
pack = {
'id': packs['id'] + 1,
'KernelVersion': None,
- 'UserID' : args['UserID']
+ 'UUID' : args['UUID']
}
return {'get_config': marshal(pack, pack_fields)}, 201
@@ -197,7 +197,7 @@ class GetID(Resource):
def __init__(self):
self.reqparse = reqparse.RequestParser()
- self.reqparse.add_argument('UserID', type=str, required=False,
+ self.reqparse.add_argument('UUID', type=str, required=False,
help='No task title provided',
location='json')
super(GetID, self).__init__()