From: David Garcia Date: Mon, 22 Mar 2021 11:56:16 +0000 (+0100) Subject: Add automatic build for ops charms X-Git-Tag: v9.0.0-dev~6 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=52424a2ae26db69c5a97d01e84454ffdd4d31228;p=osm%2Fosmclient.git Add automatic build for ops charms Added charmcraft dependency for building charms. For using this utility, place the src code of the charm under charms/ops, and the osmclient will build and place the charm code in the charms/ folder. Change-Id: Ib86d9ac966822131b2df3fc7621b42a49be7baba Signed-off-by: David Garcia --- diff --git a/osmclient/common/package_tool.py b/osmclient/common/package_tool.py index e792ce9..473ff3d 100644 --- a/osmclient/common/package_tool.py +++ b/osmclient/common/package_tool.py @@ -367,6 +367,8 @@ class PackageTool(object): print('Building charm {}/charms/layers/{}'.format(package_folder, charmName)) self.charm_build(package_folder, charmName) print('Charm built: {}'.format(charmName)) + elif os.path.isdir('{}/charms/ops/{}'.format(package_folder, charmName)): + self.charmcraft_build(package_folder, charmName) else: if not os.path.isdir('{}/charms/{}'.format(package_folder, charmName)): raise ClientException('The charm: {} referenced in the descriptor file ' @@ -431,6 +433,26 @@ class PackageTool(object): raise ClientException("failed to build the charm: {}".format(src_folder)) self._logger.verbose("charm {} built".format(src_folder)) + def charmcraft_build(self, package_folder, charm_name): + """ + Build the charms inside the package (new operator framework charms) + params: package_folder is the name of the folder where is the charms to compile. + build_name is the name of the layer or interface + """ + self._logger.debug("Building charm {}".format(charm_name)) + src_folder = f"{package_folder}/charms/ops/{charm_name}" + current_directory = os.getcwd() + os.chdir(src_folder) + try: + result = subprocess.run(["charmcraft", "build"]) + if result.returncode == 1: + raise ClientException("failed to build the charm: {}".format(src_folder)) + subprocess.run(["rm", "-rf", f"../../{charm_name}"]) + subprocess.run(["mv", "build", f"../../{charm_name}"]) + self._logger.verbose("charm {} built".format(src_folder)) + finally: + os.chdir(current_directory) + def build_tarfile(self, package_folder, charm_list=None): """ Creates a .tar.gz file given a package_folder @@ -556,17 +578,14 @@ class PackageTool(object): def _charms_search_on_vnfd_sol006_dict(self, sol006_dict): self._logger.debug("") charms_list = [] - for k1, v1 in sol006_dict.items(): - for k2, v2 in v1.items(): - if k2 == "df": - for df in v2: - lcm_ops = df.get("lcm-operations-configuration", {}) - ops_config = lcm_ops.get("operate-vnf-op-config", {}) - for day_12_config in ops_config.get("day1-2", []): - self._logger.debug("Execution environment found") - for ee in day_12_config.get("execution-environment-list", []): - if "juju" in ee: - charms_list.append((ee["juju"]['charm'])) + dfs = sol006_dict.get("vnfd", {}).get("df", []) + for df in dfs: + day_1_2s = df.get("lcm-operations-configuration", {}).get("operate-vnf-op-config", {}).get("day1-2") + for day_1_2 in day_1_2s: + exec_env_list = day_1_2.get("execution-environment-list", []) + for exec_env in exec_env_list: + if "juju" in exec_env and "charm" in exec_env["juju"]: + charms_list.append(exec_env["juju"]["charm"]) return charms_list def _charms_search_on_nsd_sol006_dict(self, sol006_dict): diff --git a/requirements.txt b/requirements.txt index f3cb782..ee434ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,11 +16,12 @@ Click prettytable<=1.0.1 -PyYAML +PyYAML==5.3.1 pycurl python-magic -jinja2 +jinja2==2.11.2 verboselogs packaging -requests +requests==2.24.0 +charmcraft git+https://osm.etsi.org/gerrit/osm/IM.git#egg=osm-im diff --git a/setup.py b/setup.py index 43ce3ee..22b5a54 100644 --- a/setup.py +++ b/setup.py @@ -28,8 +28,9 @@ setup( description=_description, license='Apache 2', install_requires=[ - 'Click', 'prettytable', 'pyyaml', 'pycurl', 'python-magic', - 'jinja2', 'osm-im', 'verboselogs', 'packaging', 'requests', + 'Click', 'prettytable', 'pyyaml==5.3.1', 'pycurl', 'python-magic', + 'jinja2==2.11.2', 'osm-im', 'verboselogs', 'packaging', + 'requests==2.24.0', 'charmcraft', ], setup_requires=['setuptools-version-command'], test_suite='nose.collector', diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 84635ae..e131f3b 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -37,7 +37,7 @@ apps: - home - ssh-public-keys environment: - PATH: $SNAP/usr/bin:$SNAP/bin/:$PATH + PATH: $SNAP/usr/bin:$SNAP/bin/:$PATH:$SNAP/usr/local/bin/ PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH MAGIC: $SNAP/usr/share/file/magic.mgc @@ -52,6 +52,8 @@ parts: - git - make - wget + - libcurl4-openssl-dev + - libssl-dev stage-packages: - libmagic1 - python3 @@ -70,6 +72,7 @@ parts: git checkout $BRANCH_OR_TAG $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install . cd ../ && rm -rf IM/ + $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install -r requirements.txt $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install . rm -rf .tox snapcraftctl build