From b9a656aa30df3f7970705fc91fc0d9952390e960 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Mon, 2 Nov 2015 14:38:08 +0200 Subject: [PATCH 1/5] Add install-origin option. --- config.yaml | 9 +++++++++ hooks/odl_controller_hooks.py | 36 ++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 8ad6aa3..dbfb161 100644 --- a/config.yaml +++ b/config.yaml @@ -13,6 +13,15 @@ options: type: string default: "https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz" description: Web addressable location of OpenDayLight binaries to install + install-origin: + type: string + default: "" + description: | + Repository to install OpenDaylight binaries from. It can be a full APT + URL or a PPA. + + If not specified, the package is installed from the URL specified by the + 'install-url' option. http-proxy: type: string default: diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index ca563e8..1245641 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -21,12 +21,14 @@ from charmhelpers.core.host import ( service_start ) -from charmhelpers.fetch import apt_install, install_remote +from charmhelpers.fetch import ( + add_source, apt_update, apt_install, install_remote) from odl_controller_utils import write_mvn_config, process_odl_cmds from odl_controller_utils import PROFILES PACKAGES = ["default-jre-headless", "python-jinja2"] +KARAF_PACKAGE = "opendaylight-karaf" hooks = Hooks() config = config() @@ -50,20 +52,28 @@ def controller_api_joined(r_id=None): @hooks.hook() def install(): - # install dependencies + packages = PACKAGES.copy() + + install_origin = config["install-origin"] + if install_origin: + add_source(install_origin) + packages.append(KARAF_PACKAGE) + apt_update(fatal=True) + + # install packages apt_install(PACKAGES, fatal=True) - # install opendaylight - install_url = config["install-url"] - install_remote(install_url, dest="/opt") # this extracts the archive too - - # The extracted dirname. Look at what's on disk instead of mangling, so - # the distribution tar.gz's name doesn't matter. - name = [f for f in os.listdir("/opt") - if f.startswith("distribution-karaf")][0] - - if not os.path.exists("/opt/opendaylight-karaf"): - os.symlink(name, "/opt/opendaylight-karaf") + if not install_origin: + # install opendaylight from tarball + install_url = config["install-url"] + # this extracts the archive too + install_remote(install_url, dest="/opt") + # The extracted dirname. Look at what's on disk instead of mangling, so + # the distribution tar.gz's name doesn't matter. + name = [f for f in os.listdir("/opt") + if f.startswith("distribution-karaf")][0] + if not os.path.exists("/opt/opendaylight-karaf"): + os.symlink(name, "/opt/opendaylight-karaf") shutil.copy("files/odl-controller.conf", "/etc/init") adduser("opendaylight", system_user=True) From 80e9c5c6db314acf43b0d44e8e0b6d087b478780 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Mon, 2 Nov 2015 17:50:00 +0200 Subject: [PATCH 2/5] Fixes and cleanups. --- hooks/odl_controller_hooks.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index 1245641..757c56e 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -52,7 +52,7 @@ def controller_api_joined(r_id=None): @hooks.hook() def install(): - packages = PACKAGES.copy() + packages = PACKAGES[:] install_origin = config["install-origin"] if install_origin: @@ -61,7 +61,9 @@ def install(): apt_update(fatal=True) # install packages - apt_install(PACKAGES, fatal=True) + apt_install(packages, fatal=True) + + install_dir_name = "opendaylight-karaf" if not install_origin: # install opendaylight from tarball @@ -70,16 +72,19 @@ def install(): install_remote(install_url, dest="/opt") # The extracted dirname. Look at what's on disk instead of mangling, so # the distribution tar.gz's name doesn't matter. - name = [f for f in os.listdir("/opt") - if f.startswith("distribution-karaf")][0] + install_dir_name = [ + f for f in os.listdir("/opt") + if f.startswith("distribution-karaf")][0] if not os.path.exists("/opt/opendaylight-karaf"): - os.symlink(name, "/opt/opendaylight-karaf") + os.symlink(install_dir_name, "/opt/opendaylight-karaf") shutil.copy("files/odl-controller.conf", "/etc/init") adduser("opendaylight", system_user=True) mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755) - check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name]) + check_call( + ["chown", "-R", "opendaylight:opendaylight", + os.path.join("/opt", install_dir_name)]) mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755) From 7a5ccf1dfe474c893ea33243bb2afe28a3cb25da Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Wed, 4 Nov 2015 17:41:54 +0200 Subject: [PATCH 3/5] Address review comments. --- config.yaml | 16 ++++++++-------- hooks/odl_controller_hooks.py | 23 ++++++++++------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/config.yaml b/config.yaml index dbfb161..fd57211 100644 --- a/config.yaml +++ b/config.yaml @@ -12,16 +12,16 @@ options: install-url: type: string default: "https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz" - description: Web addressable location of OpenDayLight binaries to install - install-origin: - type: string - default: "" description: | - Repository to install OpenDaylight binaries from. It can be a full APT - URL or a PPA. + Web addressable location of OpenDayLight binaries to install. - If not specified, the package is installed from the URL specified by the - 'install-url' option. + If unset, the charm will install binaries from the opendaylight-karaf + package. + install-sources: + type: string + description: | + Package sources to install. Can be used to specify where to isntall the + opendaylight-karaf package from. http-proxy: type: string default: diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index 757c56e..916c475 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -22,7 +22,7 @@ from charmhelpers.core.host import ( ) from charmhelpers.fetch import ( - add_source, apt_update, apt_install, install_remote) + configure_sources, apt_install, install_remote) from odl_controller_utils import write_mvn_config, process_odl_cmds from odl_controller_utils import PROFILES @@ -52,22 +52,16 @@ def controller_api_joined(r_id=None): @hooks.hook() def install(): - packages = PACKAGES[:] - - install_origin = config["install-origin"] - if install_origin: - add_source(install_origin) - packages.append(KARAF_PACKAGE) - apt_update(fatal=True) + if config["install-sources"]: + configure_sources(update=True, install_key="install_sources") # install packages - apt_install(packages, fatal=True) + apt_install(PACKAGES, fatal=True) - install_dir_name = "opendaylight-karaf" - - if not install_origin: + install_url = config["install-url"] + if install_url: # install opendaylight from tarball - install_url = config["install-url"] + # this extracts the archive too install_remote(install_url, dest="/opt") # The extracted dirname. Look at what's on disk instead of mangling, so @@ -77,6 +71,9 @@ def install(): if f.startswith("distribution-karaf")][0] if not os.path.exists("/opt/opendaylight-karaf"): os.symlink(install_dir_name, "/opt/opendaylight-karaf") + else: + apt_install([KARAF_PACKAGE], fatal=True) + install_dir_name = "opendaylight-karaf" shutil.copy("files/odl-controller.conf", "/etc/init") adduser("opendaylight", system_user=True) From f852afd1663748ce88c1abe1f719259406557ee4 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Wed, 4 Nov 2015 18:08:32 +0200 Subject: [PATCH 4/5] Fix call. --- config.yaml | 7 +++++-- hooks/odl_controller_hooks.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index fd57211..e89628c 100644 --- a/config.yaml +++ b/config.yaml @@ -13,7 +13,7 @@ options: type: string default: "https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz" description: | - Web addressable location of OpenDayLight binaries to install. + Web addressable location of OpenDayLight binaries to install If unset, the charm will install binaries from the opendaylight-karaf package. @@ -21,7 +21,10 @@ options: type: string description: | Package sources to install. Can be used to specify where to isntall the - opendaylight-karaf package from. + opendaylight-karaf package from + install-keys: + type: string + description: Apt keys for package install sources http-proxy: type: string default: diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index 916c475..5c2aae9 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -53,7 +53,7 @@ def controller_api_joined(r_id=None): @hooks.hook() def install(): if config["install-sources"]: - configure_sources(update=True, install_key="install_sources") + configure_sources(update=True, sources_var="install_sources") # install packages apt_install(PACKAGES, fatal=True) From f9a0b4d3908f195a5f35de137843c3f3d2e0d342 Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Wed, 4 Nov 2015 19:21:24 +0200 Subject: [PATCH 5/5] Handle empty case. --- hooks/odl_controller_hooks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/odl_controller_hooks.py b/hooks/odl_controller_hooks.py index 5c2aae9..2ec1e1f 100755 --- a/hooks/odl_controller_hooks.py +++ b/hooks/odl_controller_hooks.py @@ -52,8 +52,8 @@ def controller_api_joined(r_id=None): @hooks.hook() def install(): - if config["install-sources"]: - configure_sources(update=True, sources_var="install_sources") + if config.get("install-sources"): + configure_sources(update=True, sources_var="install-sources") # install packages apt_install(PACKAGES, fatal=True)