aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorpaweldenst <pawel.denst@external.t-mobile.pl>2022-10-25 11:37:03 +0000
committerpaweldenst <pawel.denst@external.t-mobile.pl>2022-11-25 08:14:07 +0000
commit1b6a93d93fe6ac41eb221dc59c2171e9bdd578e3 (patch)
tree426764fe83cf6313f7b04e94afdc892ff1056df4 /src
parent25cafb994c9ba3b874cd973a1e1d440fb0b98bf0 (diff)
Run Python 3.11 tests
This commit deletes unnecessary comments Issue-ID: INT-2168 Signed-off-by: paweldenst <pawel.denst@external.t-mobile.pl> Change-Id: I08b738d3a9aebbdf5d305a118a4d7b7e64d686a5
Diffstat (limited to 'src')
-rw-r--r--src/onapsdk/sdc/service.py17
-rw-r--r--src/onapsdk/utils/configuration.py5
-rw-r--r--src/onapsdk/utils/headers_creator.py2
-rw-r--r--src/onapsdk/utils/tosca_file_handler.py4
4 files changed, 11 insertions, 17 deletions
diff --git a/src/onapsdk/sdc/service.py b/src/onapsdk/sdc/service.py
index c866fa4..9bd92f0 100644
--- a/src/onapsdk/sdc/service.py
+++ b/src/onapsdk/sdc/service.py
@@ -31,8 +31,7 @@ from onapsdk.exceptions import (ParameterError, RequestError, ResourceNotFound,
from onapsdk.sdc.category_management import ServiceCategory
from onapsdk.sdc.properties import NestedInput, Property
from onapsdk.sdc.sdc_resource import SdcResource
-from onapsdk.utils.configuration import (components_needing_distribution,
- tosca_path)
+from onapsdk.utils.configuration import components_needing_distribution
from onapsdk.utils.headers_creator import headers_sdc_creator, headers_sdc_artifact_upload
from onapsdk.utils.jinja import jinja_env
@@ -591,7 +590,7 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too
const.DISTRIBUTE,
headers=headers)
- def get_tosca(self) -> None:
+ def get_tosca(self, paths) -> None:
"""Get Service tosca files and save it."""
url = "{}/services/{}/toscaModel".format(self._base_url(),
self.identifier)
@@ -603,17 +602,17 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too
url,
headers=headers)
if result:
- self._create_tosca_file(result)
+ self._create_tosca_file(paths, result)
- def _create_tosca_file(self, result: Response) -> None:
+ def _create_tosca_file(self, paths, result: Response) -> None:
"""Create Service Tosca files from HTTP response."""
csar_filename = "service-{}-csar.csar".format(self.name)
- makedirs(tosca_path(), exist_ok=True)
- with open((tosca_path() + csar_filename), 'wb') as csar_file:
+ makedirs(paths, exist_ok=True)
+ with open((paths + csar_filename), 'wb') as csar_file:
for chunk in result.iter_content(chunk_size=128):
csar_file.write(chunk)
try:
- self._unzip_csar_file(tosca_path() + csar_filename,
+ self._unzip_csar_file(paths + csar_filename,
self._write_csar_file)
except BadZipFile as exc:
self._logger.exception(exc)
@@ -795,7 +794,7 @@ class Service(SdcResource): # pylint: disable=too-many-instance-attributes, too
def _write_csar_file(service_template: str,
template_file: TextIOWrapper) -> None:
"""Write service temple into a file."""
- with open(tosca_path() + service_template[12:], 'wb') as file:
+ with open(service_template[12:], 'wb') as file:
file.write(template_file.read())
# _service_template is not used but function generation is generic
diff --git a/src/onapsdk/utils/configuration.py b/src/onapsdk/utils/configuration.py
index 89bee5a..487a472 100644
--- a/src/onapsdk/utils/configuration.py
+++ b/src/onapsdk/utils/configuration.py
@@ -15,11 +15,6 @@
from typing import List
-def tosca_path() -> str:
- """Return tosca file paths."""
- return '/tmp/tosca_files/'
-
-
def components_needing_distribution() -> List[str]:
"""Return the list of components needing distribution."""
return ["SO", "sdnc", "aai"]
diff --git a/src/onapsdk/utils/headers_creator.py b/src/onapsdk/utils/headers_creator.py
index adb0609..ae03a38 100644
--- a/src/onapsdk/utils/headers_creator.py
+++ b/src/onapsdk/utils/headers_creator.py
@@ -223,7 +223,7 @@ def headers_sdc_artifact_upload(base_header: Dict[str, str], data: str):
headers["Accept"] = "application/json, text/plain, */*"
headers["Accept-Encoding"] = "gzip, deflate, br"
headers["Content-Type"] = "application/json; charset=UTF-8"
- md5_content = hashlib.md5(data.encode('UTF-8')).hexdigest()
+ md5_content = hashlib.new('md5', data.encode('UTF-8'), usedforsecurity=False).hexdigest()
content = base64.b64encode(md5_content.encode('ascii')).decode('UTF-8')
headers["Content-MD5"] = content
return headers
diff --git a/src/onapsdk/utils/tosca_file_handler.py b/src/onapsdk/utils/tosca_file_handler.py
index 921b868..1d1918b 100644
--- a/src/onapsdk/utils/tosca_file_handler.py
+++ b/src/onapsdk/utils/tosca_file_handler.py
@@ -14,7 +14,7 @@
# limitations under the License.
import json
import string
-import random
+import secrets
from typing import Dict, List
from onapsdk.exceptions import ValidationError
@@ -103,4 +103,4 @@ def random_string_generator(size=6,
str: a sequence of random characters
"""
- return ''.join(random.choice(chars) for _ in range(size))
+ return ''.join(secrets.choice(chars) for _ in range(size))