diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2020-06-05 14:51:01 +0200 |
---|---|---|
committer | Krystian Kedron <k.kedron@partner.samsung.com> | 2020-06-24 09:21:00 +0000 |
commit | 16fe29ac226610f79c8da1f691437ec7fe6e79c4 (patch) | |
tree | 5b73d8f1724c561609c05fd2802ad80b7acfb4c0 /catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py | |
parent | fca8a0b1af32083b8ea025135b120091aec9714f (diff) |
Improvement sdc-BE-init python scripts
- Implemented retries when request fail
- Moved configuration variables to the Properties file
- Extended sdcBeProxy
- Implemented script to run import/update (should fix deployment glitch)
- Updated the import_Normatives recipes to use new script
Issue-ID: SDC-2784
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: I83fab898783ad8d3b3d532af43d75bc54d033c33
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py')
-rwxr-xr-x | catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py index 6fea657fab..d9aa260b80 100755 --- a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py +++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py @@ -12,6 +12,9 @@ def get_url(ip, port, protocol): class SdcBeProxy: + BODY_SEPARATOR = "\r\n\r\n" + CHARTSET = 'UTF-8' + def __init__(self, be_ip, be_port, scheme, user_id="jh0003", debug=False, connector=None): if not check_arguments_not_none(be_ip, be_port, scheme, user_id): @@ -45,9 +48,20 @@ class SdcBeProxy: 'consumerPassword': password })) + def get_normatives(self): + return self.con.get("/sdc2/rest/v1/screen", with_buffer=True) + def post_file(self, path, multi_part_form_data): return self.con.post_file(path, multi_part_form_data) + def get_response_from_buffer(self): + value = self.con.buffer.getvalue() + self.con.buffer.truncate(0) + self.con.buffer.seek(0) + + response = value.decode(self.CHARTSET).split(self.BODY_SEPARATOR) + return response[1] if len(response) == 2 else response[0] + class CurlConnector: CONTENT_TYPE_HEADER = "Content-Type: application/json" @@ -71,13 +85,17 @@ class CurlConnector: self.url = url self._check_schema(scheme) - def get(self, path): + def get(self, path, buffer=None, with_buffer=False): try: self.c.setopt(pycurl.URL, self.url + path) self.c.setopt(pycurl.HTTPHEADER, [self.user_header, CurlConnector.CONTENT_TYPE_HEADER, CurlConnector.ACCEPT_HEADER]) + if with_buffer: + write = self.buffer.write if not buffer else buffer.write + self.c.setopt(pycurl.WRITEFUNCTION, write) + self.c.perform() return self.c.getinfo(pycurl.RESPONSE_CODE) except pycurl.error: |