aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-29 11:55:31 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-29 11:55:31 +0900
commit5a76d9780076455729b36eef8fab5832eb98488f (patch)
treec13b570e6f431c66bd10bb4e68df21ade9ac6a28
parentremoved constants file as dead code (diff)
downloadelivepatch-5a76d9780076455729b36eef8fab5832eb98488f.tar.gz
elivepatch-5a76d9780076455729b36eef8fab5832eb98488f.tar.bz2
elivepatch-5a76d9780076455729b36eef8fab5832eb98488f.zip
catching client errors
-rw-r--r--elivepatch_client/client/restful.py51
1 files changed, 34 insertions, 17 deletions
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index fa6c583..f5b78cd 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -8,6 +8,8 @@ import requests
import os
import shutil
+import sys
+
class ManaGer(object):
"""
@@ -43,6 +45,7 @@ class ManaGer(object):
# The server is dividing user by UUID
# UUID is generated with python UUID
# TODO: add the UUID in the json location instead of headers
+ response_dict = None
headers = {
'KernelVersion' : self.kernel_version,
'UUID': self.uuid
@@ -52,10 +55,16 @@ class ManaGer(object):
'config': ('config', open(temporary_config.name, 'rb'), 'multipart/form-data', {'Expires': '0'})}
print(str(files))
temporary_config.close()
- r = requests.post(url, files=files, headers=headers)
- print('send file: ' + str(r.json()))
- r_dict = r.json()
- return r_dict
+ try:
+ response = requests.post(url, files=files, headers=headers)
+ print('send file: ' + str(response.json()))
+ response_dict = response.json()
+ except requests.exceptions.ConnectionError as e:
+ print('connection error: %s' % e)
+ except:
+ e = sys.exc_info()[0]
+ print( "Error: %s" % e )
+ return response_dict
def build_livepatch(self):
url = self.server_url+'/elivepatch/api/v1.0/build_livepatch'
@@ -63,8 +72,12 @@ class ManaGer(object):
'KernelVersion': self.kernel_version,
'UUID' : self.uuid
}
- r = requests.post(url, json=payload)
- print(r.json())
+ try:
+ response = requests.post(url, json=payload)
+ print(response.json())
+ except:
+ e = sys.exc_info()[0]
+ print( "Error build_livepatch: %s" % e )
def get_livepatch(self):
from io import BytesIO
@@ -73,17 +86,21 @@ class ManaGer(object):
'KernelVersion': self.kernel_version,
'UUID' : self.uuid
}
- r = requests.get(url, json=payload)
- if r.status_code == requests.codes.ok: # livepatch returned ok
- 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()
+ try:
+ r = requests.get(url, json=payload)
+ if r.status_code == requests.codes.ok: # livepatch returned ok
+ 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()
+ except:
+ e = sys.exc_info()[0]
+ print( "Error get livepatch: %s" % e )
if os.path.exists('myfile.ko'):
elivepatch_uuid_dir = os.path.join('..', 'elivepatch-'+ self.uuid)