Fix 1219. Adding juju-bundles parsing 26/10026/11
authorsousaedu <eduardo.sousa@canonical.com>
Tue, 24 Nov 2020 23:53:59 +0000 (23:53 +0000)
committersousaedu <eduardo.sousa@canonical.com>
Wed, 25 Nov 2020 18:17:25 +0000 (18:17 +0000)
Change-Id: I9e19e8adc4e5ceaf1f32b4f1bf5d038bb336fe93
Signed-off-by: sousaedu <eduardo.sousa@canonical.com>
osmclient/common/package_tool.py
requirements.txt
setup.py

index 19b1386..ec0a6d4 100644 (file)
@@ -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
 
index a2a4e5c..26adb57 100644 (file)
@@ -15,7 +15,7 @@
 #    under the License.
 
 Click
-prettytable
+prettytable<=1.0.1
 PyYAML
 pycurl
 python-magic
index f5b9e15..6bf023e 100644 (file)
--- 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'
     ],