From 60c9220d34b8e3a123837909999f88490ea5b561 Mon Sep 17 00:00:00 2001 From: sousaedu Date: Tue, 24 Nov 2020 23:53:59 +0000 Subject: [PATCH] Fix 1219. Adding juju-bundles parsing Change-Id: I9e19e8adc4e5ceaf1f32b4f1bf5d038bb336fe93 Signed-off-by: sousaedu --- osmclient/common/package_tool.py | 54 ++++++++++++++++++++++---------- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/osmclient/common/package_tool.py b/osmclient/common/package_tool.py index 19b1386..ec0a6d4 100644 --- a/osmclient/common/package_tool.py +++ b/osmclient/common/package_tool.py @@ -27,6 +27,8 @@ import subprocess import shutil import yaml import logging +import pathlib + class PackageTool(object): def __init__(self, client=None): @@ -438,24 +440,42 @@ class PackageTool(object): def charms_search(self, descriptor_file, desc_type): self._logger.debug("") - dict = {} - list = [] + + descriptor_dict = {} + charm_list = [] + bundle_list = [] + with open("{}".format(descriptor_file)) as yaml_desc: - dict = yaml.safe_load(yaml_desc) - for k1, v1 in dict.items(): - for k2, v2 in v1.items(): + descriptor_dict = yaml.safe_load(yaml_desc) + for _, v1 in descriptor_dict.items(): + for _, v2 in v1.items(): for entry in v2: - if '{}-configuration'.format(desc_type) in entry: - name = entry['{}-configuration'.format(desc_type)] - for k3, v3 in name.items(): - if 'charm' in v3: - list.append((v3['charm'])) - if 'vdu' in entry: - name = entry['vdu'] + if "{}-configuration".format(desc_type) in entry: + name = entry["{}-configuration".format(desc_type)] + for _, v3 in name.items(): + if "charm" in v3: + charm_list.append((v3["charm"])) + if "vdu" in entry: + name = entry["vdu"] for vdu in name: - if 'vdu-configuration' in vdu: - for k4, v4 in vdu['vdu-configuration'].items(): - if 'charm' in v4: - list.append((v4['charm'])) - return list + if "vdu-configuration" in vdu: + for _, v4 in vdu["vdu-configuration"].items(): + if "charm" in v4: + charm_list.append((v4["charm"])) + if "kdu" in entry: + name = entry["kdu"] + for kdu in name: + if "juju-bundle" in kdu: + bundle_list.append(kdu["juju-bundle"]) + + path = pathlib.Path(descriptor_file).parent + for bundle in bundle_list: + descriptor_dict = {} + with open("{}/juju-bundles/{}".format(path, bundle)) as yaml_desc: + descriptor_dict = yaml.safe_load(yaml_desc) + if "applications" in descriptor_dict: + for _, v in descriptor_dict["applications"].items(): + charm_list.append(pathlib.Path(v["charm"]).name) + + return charm_list diff --git a/requirements.txt b/requirements.txt index a2a4e5c..26adb57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ # under the License. Click -prettytable +prettytable<=1.0.1 PyYAML pycurl python-magic diff --git a/setup.py b/setup.py index f5b9e15..6bf023e 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( description=_description, license='Apache 2', install_requires=[ - 'Click', 'prettytable', 'pyyaml', 'pycurl', 'python-magic', + 'Click', 'prettytable<=1.0.1', 'pyyaml', 'pycurl', 'python-magic', 'jinja2', 'osm-im', 'verboselogs', 'packaging', 'ruamel.yaml', 'requests' ], -- 2.17.1