From 7c9463d10e93b50796c882632e5725ed8adbeab5 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 22 Apr 2015 18:47:00 +0000 Subject: [PATCH 01/42] Sync charm-helpers --- .../contrib/openstack/amulet/deployment.py | 21 +++++++++++++------ hooks/charmhelpers/contrib/openstack/utils.py | 12 +++++++++-- hooks/charmhelpers/contrib/python/packages.py | 7 +++++-- tests/charmhelpers/contrib/amulet/utils.py | 9 +++++++- .../contrib/openstack/amulet/deployment.py | 21 +++++++++++++------ 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/amulet/deployment.py b/hooks/charmhelpers/contrib/openstack/amulet/deployment.py index 11d49a7c..461a702f 100644 --- a/hooks/charmhelpers/contrib/openstack/amulet/deployment.py +++ b/hooks/charmhelpers/contrib/openstack/amulet/deployment.py @@ -46,15 +46,22 @@ class OpenStackAmuletDeployment(AmuletDeployment): stable or next branches for the other_services.""" base_charms = ['mysql', 'mongodb'] + if self.series in ['precise', 'trusty']: + base_series = self.series + else: + base_series = self.current_next + if self.stable: for svc in other_services: - temp = 'lp:charms/{}' - svc['location'] = temp.format(svc['name']) + temp = 'lp:charms/{}/{}' + svc['location'] = temp.format(base_series, + svc['name']) else: for svc in other_services: if svc['name'] in base_charms: - temp = 'lp:charms/{}' - svc['location'] = temp.format(svc['name']) + temp = 'lp:charms/{}/{}' + svc['location'] = temp.format(base_series, + svc['name']) else: temp = 'lp:~openstack-charmers/charms/{}/{}/next' svc['location'] = temp.format(self.current_next, @@ -99,10 +106,12 @@ class OpenStackAmuletDeployment(AmuletDeployment): Return an integer representing the enum value of the openstack release. """ + # Must be ordered by OpenStack release (not by Ubuntu release): (self.precise_essex, self.precise_folsom, self.precise_grizzly, self.precise_havana, self.precise_icehouse, - self.trusty_icehouse, self.trusty_juno, self.trusty_kilo, - self.utopic_juno, self.vivid_kilo) = range(10) + self.trusty_icehouse, self.trusty_juno, self.utopic_juno, + self.trusty_kilo, self.vivid_kilo) = range(10) + releases = { ('precise', None): self.precise_essex, ('precise', 'cloud:precise-folsom'): self.precise_folsom, diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index f90a0289..f4824f99 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -517,6 +517,7 @@ def git_clone_and_install(projects_yaml, core_project): """ global requirements_dir parent_dir = '/mnt/openstack-git' + http_proxy = None if not projects_yaml: return @@ -527,6 +528,7 @@ def git_clone_and_install(projects_yaml, core_project): old_environ = dict(os.environ) if 'http_proxy' in projects.keys(): + http_proxy = projects['http_proxy'] os.environ['http_proxy'] = projects['http_proxy'] if 'https_proxy' in projects.keys(): os.environ['https_proxy'] = projects['https_proxy'] @@ -539,10 +541,12 @@ def git_clone_and_install(projects_yaml, core_project): branch = p['branch'] if p['name'] == 'requirements': repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, + http_proxy, update_requirements=False) requirements_dir = repo_dir else: repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, + http_proxy, update_requirements=True) os.environ = old_environ @@ -574,7 +578,8 @@ def _git_ensure_key_exists(key, keys): error_out('openstack-origin-git key \'{}\' is missing'.format(key)) -def _git_clone_and_install_single(repo, branch, parent_dir, update_requirements): +def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, + update_requirements): """ Clone and install a single git repository. """ @@ -598,7 +603,10 @@ def _git_clone_and_install_single(repo, branch, parent_dir, update_requirements) _git_update_requirements(repo_dir, requirements_dir) juju_log('Installing git repo from dir: {}'.format(repo_dir)) - pip_install(repo_dir) + if http_proxy: + pip_install(repo_dir, ignore=True, proxy=http_proxy) + else: + pip_install(repo_dir, ignore=True) return repo_dir diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index 8659516b..ceaa5971 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -51,17 +51,20 @@ def pip_install_requirements(requirements, **options): pip_execute(command) -def pip_install(package, fatal=False, upgrade=False, **options): +def pip_install(package, fatal=False, upgrade=False, ignore=False, **options): """Install a python package""" command = ["install"] - available_options = ('proxy', 'src', 'log', "index-url", ) + available_options = ('proxy', 'src', 'log', 'index-url', ) for option in parse_options(options, available_options): command.append(option) if upgrade: command.append('--upgrade') + if ignore: + command.append('--ignore-installed') + if isinstance(package, list): command.extend(package) else: diff --git a/tests/charmhelpers/contrib/amulet/utils.py b/tests/charmhelpers/contrib/amulet/utils.py index 5088b1d1..f61c2e8b 100644 --- a/tests/charmhelpers/contrib/amulet/utils.py +++ b/tests/charmhelpers/contrib/amulet/utils.py @@ -79,6 +79,9 @@ class AmuletUtils(object): for k, v in six.iteritems(commands): for cmd in v: output, code = k.run(cmd) + self.log.debug('{} `{}` returned ' + '{}'.format(k.info['unit_name'], + cmd, code)) if code != 0: return "command `{}` returned {}".format(cmd, str(code)) return None @@ -86,7 +89,11 @@ class AmuletUtils(object): def _get_config(self, unit, filename): """Get a ConfigParser object for parsing a unit's config file.""" file_contents = unit.file_contents(filename) - config = ConfigParser.ConfigParser() + + # NOTE(beisner): by default, ConfigParser does not handle options + # with no value, such as the flags used in the mysql my.cnf file. + # https://bugs.python.org/issue7005 + config = ConfigParser.ConfigParser(allow_no_value=True) config.readfp(io.StringIO(file_contents)) return config diff --git a/tests/charmhelpers/contrib/openstack/amulet/deployment.py b/tests/charmhelpers/contrib/openstack/amulet/deployment.py index 11d49a7c..461a702f 100644 --- a/tests/charmhelpers/contrib/openstack/amulet/deployment.py +++ b/tests/charmhelpers/contrib/openstack/amulet/deployment.py @@ -46,15 +46,22 @@ class OpenStackAmuletDeployment(AmuletDeployment): stable or next branches for the other_services.""" base_charms = ['mysql', 'mongodb'] + if self.series in ['precise', 'trusty']: + base_series = self.series + else: + base_series = self.current_next + if self.stable: for svc in other_services: - temp = 'lp:charms/{}' - svc['location'] = temp.format(svc['name']) + temp = 'lp:charms/{}/{}' + svc['location'] = temp.format(base_series, + svc['name']) else: for svc in other_services: if svc['name'] in base_charms: - temp = 'lp:charms/{}' - svc['location'] = temp.format(svc['name']) + temp = 'lp:charms/{}/{}' + svc['location'] = temp.format(base_series, + svc['name']) else: temp = 'lp:~openstack-charmers/charms/{}/{}/next' svc['location'] = temp.format(self.current_next, @@ -99,10 +106,12 @@ class OpenStackAmuletDeployment(AmuletDeployment): Return an integer representing the enum value of the openstack release. """ + # Must be ordered by OpenStack release (not by Ubuntu release): (self.precise_essex, self.precise_folsom, self.precise_grizzly, self.precise_havana, self.precise_icehouse, - self.trusty_icehouse, self.trusty_juno, self.trusty_kilo, - self.utopic_juno, self.vivid_kilo) = range(10) + self.trusty_icehouse, self.trusty_juno, self.utopic_juno, + self.trusty_kilo, self.vivid_kilo) = range(10) + releases = { ('precise', None): self.precise_essex, ('precise', 'cloud:precise-folsom'): self.precise_folsom, From e3a7f105a564497f0f7c32d520975545f828f7ae Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 22 Apr 2015 19:32:28 +0000 Subject: [PATCH 02/42] Add libffi-dev, libssl-dev, and libyaml-dev to base git install packages --- hooks/glance_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 37de5682..2f20d9ab 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -60,8 +60,11 @@ PACKAGES = [ "python-psycopg2", "python-keystone", "python-six", "uuid", "haproxy", ] BASE_GIT_PACKAGES = [ + 'libffi-dev', + 'libssl-dev', 'libxml2-dev', 'libxslt1-dev', + 'libyaml-dev', 'python-dev', 'python-pip', 'python-setuptools', From c3d29dd0ab29d89d15ab178c3e41a41b2c26ae36 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 01:16:12 +0000 Subject: [PATCH 03/42] Unit test update --- unit_tests/test_glance_relations.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index e41abdd1..db28f8e0 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -131,9 +131,11 @@ class GlanceRelationTests(CharmTestCase): self.apt_install.assert_called_with(['haproxy', 'python-setuptools', 'python-six', 'uuid', 'python-mysqldb', 'python-pip', + 'libssl-dev', 'libffi-dev', 'apache2', 'libxslt1-dev', - 'python-psycopg2', 'zlib1g-dev', - 'python-dev', 'libxml2-dev'], + 'libyaml-dev', 'python-psycopg2', + 'zlib1g-dev', 'python-dev', + 'libxml2-dev'], fatal=True) self.git_install.assert_called_with(projects_yaml) From 5c5c588fdcc6cf8cfbc693f7bb598d86e45e3fed Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 11:55:31 +0000 Subject: [PATCH 04/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 4 ++-- hooks/charmhelpers/contrib/python/packages.py | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index f4824f99..0460e076 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -604,9 +604,9 @@ def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, juju_log('Installing git repo from dir: {}'.format(repo_dir)) if http_proxy: - pip_install(repo_dir, ignore=True, proxy=http_proxy) + pip_install(repo_dir, proxy=http_proxy) else: - pip_install(repo_dir, ignore=True) + pip_install(repo_dir) return repo_dir diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index ceaa5971..3f1fb09d 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -51,7 +51,7 @@ def pip_install_requirements(requirements, **options): pip_execute(command) -def pip_install(package, fatal=False, upgrade=False, ignore=False, **options): +def pip_install(package, fatal=False, upgrade=False, **options): """Install a python package""" command = ["install"] @@ -62,9 +62,6 @@ def pip_install(package, fatal=False, upgrade=False, ignore=False, **options): if upgrade: command.append('--upgrade') - if ignore: - command.append('--ignore-installed') - if isinstance(package, list): command.extend(package) else: From 81a34324dc867a286b65e2801ac36077d9da7402 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 13:01:33 +0000 Subject: [PATCH 05/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 0460e076..86bf91f5 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -604,9 +604,9 @@ def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, juju_log('Installing git repo from dir: {}'.format(repo_dir)) if http_proxy: - pip_install(repo_dir, proxy=http_proxy) + pip_install(repo_dir, upgrade=True, proxy=http_proxy) else: - pip_install(repo_dir) + pip_install(repo_dir, upgrade=True) return repo_dir From 8ddae35f8a4eefbcde48e742d18e85578177cce7 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 14:43:26 +0000 Subject: [PATCH 06/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 86bf91f5..0460e076 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -604,9 +604,9 @@ def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, juju_log('Installing git repo from dir: {}'.format(repo_dir)) if http_proxy: - pip_install(repo_dir, upgrade=True, proxy=http_proxy) + pip_install(repo_dir, proxy=http_proxy) else: - pip_install(repo_dir, upgrade=True) + pip_install(repo_dir) return repo_dir From aa3bb166f10fcda0991cb59b352b09c354ee9057 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 15:58:08 +0000 Subject: [PATCH 07/42] Drop added packages --- hooks/glance_utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 2f20d9ab..37de5682 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -60,11 +60,8 @@ PACKAGES = [ "python-psycopg2", "python-keystone", "python-six", "uuid", "haproxy", ] BASE_GIT_PACKAGES = [ - 'libffi-dev', - 'libssl-dev', 'libxml2-dev', 'libxslt1-dev', - 'libyaml-dev', 'python-dev', 'python-pip', 'python-setuptools', From d0f9094d93cf9ebd7ced673f0ae4c81d2085bddc Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 23 Apr 2015 16:00:33 +0000 Subject: [PATCH 08/42] Fix unit test --- unit_tests/test_glance_relations.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index db28f8e0..8f3d3025 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -131,9 +131,8 @@ class GlanceRelationTests(CharmTestCase): self.apt_install.assert_called_with(['haproxy', 'python-setuptools', 'python-six', 'uuid', 'python-mysqldb', 'python-pip', - 'libssl-dev', 'libffi-dev', 'apache2', 'libxslt1-dev', - 'libyaml-dev', 'python-psycopg2', + 'python-psycopg2', 'zlib1g-dev', 'python-dev', 'libxml2-dev'], fatal=True) From 54843f316185febfd63aff2bdfce8afd37bdae26 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 28 Apr 2015 19:04:25 +0000 Subject: [PATCH 09/42] Sync charm-helpers --- hooks/charmhelpers/fetch/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hooks/charmhelpers/fetch/__init__.py b/hooks/charmhelpers/fetch/__init__.py index 792e629a..57a179b8 100644 --- a/hooks/charmhelpers/fetch/__init__.py +++ b/hooks/charmhelpers/fetch/__init__.py @@ -367,13 +367,15 @@ def install_remote(source, *args, **kwargs): # explaining why it can't handle a given source. handlers = [h for h in plugins() if h.can_handle(source) is True] installed_to = None - for handler in handlers: - try: - installed_to = handler.install(source, *args, **kwargs) - except UnhandledSource: - pass - if not installed_to: - raise UnhandledSource("No handler found for source {}".format(source)) + while not installed_to: + for handler in handlers: + try: + installed_to = handler.install(source, *args, **kwargs) + except UnhandledSource: + pass + log("CB: install loop - installed_to = |%s|".format(installed_to)) + #if not installed_to: + # raise UnhandledSource("No handler found for source {}".format(source)) return installed_to From 7b270ed148f9817e7fb4f257a085cc6ee24c82e0 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 1 May 2015 14:56:06 +0000 Subject: [PATCH 10/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 15 ++++++++------- hooks/charmhelpers/fetch/__init__.py | 16 +++++++--------- hooks/charmhelpers/fetch/giturl.py | 11 +++++++---- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 0460e076..b47ed937 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -497,7 +497,7 @@ def git_install_requested(): requirements_dir = None -def git_clone_and_install(projects_yaml, core_project): +def git_clone_and_install(projects_yaml, core_project, depth=1): """ Clone/install all specified OpenStack repositories. @@ -540,13 +540,13 @@ def git_clone_and_install(projects_yaml, core_project): repo = p['repository'] branch = p['branch'] if p['name'] == 'requirements': - repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, - http_proxy, + repo_dir = _git_clone_and_install_single(repo, branch, depth, + parent_dir, http_proxy, update_requirements=False) requirements_dir = repo_dir else: - repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, - http_proxy, + repo_dir = _git_clone_and_install_single(repo, branch, depth, + parent_dir, http_proxy, update_requirements=True) os.environ = old_environ @@ -578,7 +578,7 @@ def _git_ensure_key_exists(key, keys): error_out('openstack-origin-git key \'{}\' is missing'.format(key)) -def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, +def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy, update_requirements): """ Clone and install a single git repository. @@ -592,7 +592,8 @@ def _git_clone_and_install_single(repo, branch, parent_dir, http_proxy, if not os.path.exists(dest_dir): juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) - repo_dir = install_remote(repo, dest=parent_dir, branch=branch) + repo_dir = install_remote(repo, dest=parent_dir, branch=branch, + depth=depth) else: repo_dir = dest_dir diff --git a/hooks/charmhelpers/fetch/__init__.py b/hooks/charmhelpers/fetch/__init__.py index 57a179b8..792e629a 100644 --- a/hooks/charmhelpers/fetch/__init__.py +++ b/hooks/charmhelpers/fetch/__init__.py @@ -367,15 +367,13 @@ def install_remote(source, *args, **kwargs): # explaining why it can't handle a given source. handlers = [h for h in plugins() if h.can_handle(source) is True] installed_to = None - while not installed_to: - for handler in handlers: - try: - installed_to = handler.install(source, *args, **kwargs) - except UnhandledSource: - pass - log("CB: install loop - installed_to = |%s|".format(installed_to)) - #if not installed_to: - # raise UnhandledSource("No handler found for source {}".format(source)) + for handler in handlers: + try: + installed_to = handler.install(source, *args, **kwargs) + except UnhandledSource: + pass + if not installed_to: + raise UnhandledSource("No handler found for source {}".format(source)) return installed_to diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py index 93aae87b..06b0e767 100644 --- a/hooks/charmhelpers/fetch/giturl.py +++ b/hooks/charmhelpers/fetch/giturl.py @@ -45,14 +45,17 @@ class GitUrlFetchHandler(BaseFetchHandler): else: return True - def clone(self, source, dest, branch): + def clone(self, source, dest, branch, depth): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) - repo = Repo.clone_from(source, dest) + if depth: + repo = Repo.clone_from(source, dest, depth) + else: + repo = Repo.clone_from(source, dest) repo.git.checkout(branch) - def install(self, source, branch="master", dest=None): + def install(self, source, branch="master", dest=None, depth=None): url_parts = self.parse_url(source) branch_name = url_parts.path.strip("/").split("/")[-1] if dest: @@ -63,7 +66,7 @@ class GitUrlFetchHandler(BaseFetchHandler): if not os.path.exists(dest_dir): mkdir(dest_dir, perms=0o755) try: - self.clone(source, dest_dir, branch) + self.clone(source, dest_dir, branch, depth) except GitCommandError as e: raise UnhandledSource(e.message) except OSError as e: From 387cdffb707181360a8b71b84e37b1b60f05a38d Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Sat, 2 May 2015 18:33:09 +0000 Subject: [PATCH 11/42] Sync charm-helpers --- hooks/charmhelpers/fetch/giturl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py index 06b0e767..742cf319 100644 --- a/hooks/charmhelpers/fetch/giturl.py +++ b/hooks/charmhelpers/fetch/giturl.py @@ -50,7 +50,7 @@ class GitUrlFetchHandler(BaseFetchHandler): raise UnhandledSource("Cannot handle {}".format(source)) if depth: - repo = Repo.clone_from(source, dest, depth) + repo = Repo.clone_from(source, dest, depth=depth) else: repo = Repo.clone_from(source, dest) repo.git.checkout(branch) From a7bec7ca086d47af1bc061da61c6db01d534e081 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Sat, 2 May 2015 20:09:37 +0000 Subject: [PATCH 12/42] Sync charm-helpers --- hooks/charmhelpers/fetch/giturl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py index 742cf319..4e05c08a 100644 --- a/hooks/charmhelpers/fetch/giturl.py +++ b/hooks/charmhelpers/fetch/giturl.py @@ -50,10 +50,9 @@ class GitUrlFetchHandler(BaseFetchHandler): raise UnhandledSource("Cannot handle {}".format(source)) if depth: - repo = Repo.clone_from(source, dest, depth=depth) + repo = Repo.clone_from(source, dest, branch=branch, depth=depth) else: - repo = Repo.clone_from(source, dest) - repo.git.checkout(branch) + repo = Repo.clone_from(source, dest, branch=branch) def install(self, source, branch="master", dest=None, depth=None): url_parts = self.parse_url(source) From b2d7c408aaca3b7bae5705b7bd7b6eacbec78244 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 5 May 2015 19:17:34 +0000 Subject: [PATCH 13/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 8 +++++++- hooks/charmhelpers/contrib/python/packages.py | 19 ++++++++++++++++++- hooks/charmhelpers/fetch/giturl.py | 4 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index b47ed937..ce8c8213 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -53,9 +53,13 @@ from charmhelpers.contrib.network.ip import ( get_ipv6_addr ) +from charmhelpers.contrib.python.packages import ( + pip_create_virtualenv, + pip_install, +) + from charmhelpers.core.host import lsb_release, mounts, umount from charmhelpers.fetch import apt_install, apt_cache, install_remote -from charmhelpers.contrib.python.packages import pip_install from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device @@ -536,6 +540,8 @@ def git_clone_and_install(projects_yaml, core_project, depth=1): if 'directory' in projects.keys(): parent_dir = projects['directory'] + pip_create_virtualenv(proxy=http_proxy) + for p in projects['repositories']: repo = p['repository'] branch = p['branch'] diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index 3f1fb09d..e62240b4 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -17,8 +17,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with charm-helpers. If not, see . +import os +import subprocess + from charmhelpers.fetch import apt_install, apt_update -from charmhelpers.core.hookenv import log +from charmhelpers.core.hookenv import charm_dir, log try: from pip import main as pip_execute @@ -94,3 +97,17 @@ def pip_list(): """Returns the list of current python installed packages """ return pip_execute(["list"]) + + +def pip_create_virtualenv(parent_dir=charm_dir(), proxy=None): + """Create and activate an isolated Python environment (virtualenv).""" + if proxy: + pip_install('virtualenv', proxy=proxy) + else: + pip_install('virtualenv') + + venv_dir = os.path.join(parent_dir, 'venv') + subprocess.check_call(['virtualenv', '--no-site-packages', venv_dir]) + + venv_activate = os.path.join(venv_dir, 'bin/activate') + subprocess.check_call(['.', venv_activate], shell=True) diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py index 4e05c08a..7d842d49 100644 --- a/hooks/charmhelpers/fetch/giturl.py +++ b/hooks/charmhelpers/fetch/giturl.py @@ -50,9 +50,9 @@ class GitUrlFetchHandler(BaseFetchHandler): raise UnhandledSource("Cannot handle {}".format(source)) if depth: - repo = Repo.clone_from(source, dest, branch=branch, depth=depth) + Repo.clone_from(source, dest, branch=branch, depth=depth) else: - repo = Repo.clone_from(source, dest, branch=branch) + Repo.clone_from(source, dest, branch=branch) def install(self, source, branch="master", dest=None, depth=None): url_parts = self.parse_url(source) From 7182ebd3baffe7a18602957c5ea2b3912dc6a356 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 5 May 2015 19:20:32 +0000 Subject: [PATCH 14/42] Point upstart scripts at venv binaries --- hooks/glance_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 37de5682..9279c005 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -350,13 +350,14 @@ def git_post_install(projects_yaml): shutil.rmtree(configs['dest']) shutil.copytree(configs['src'], configs['dest']) + bin_dir = os.path.join(charm_dir(), 'venv/bin') glance_api_context = { 'service_description': 'Glance API server', 'service_name': 'Glance', 'user_name': 'glance', 'start_dir': '/var/lib/glance', 'process_name': 'glance-api', - 'executable_name': '/usr/local/bin/glance-api', + 'executable_name': os.path.join(bin_dir, 'glance-api'), 'config_files': ['/etc/glance/glance-api.conf'], 'log_file': '/var/log/glance/api.log', } @@ -367,7 +368,7 @@ def git_post_install(projects_yaml): 'user_name': 'glance', 'start_dir': '/var/lib/glance', 'process_name': 'glance-registry', - 'executable_name': '/usr/local/bin/glance-registry', + 'executable_name': os.path.join(bin_dir, 'glance-registry'), 'config_files': ['/etc/glance/glance-registry.conf'], 'log_file': '/var/log/glance/registry.log', } From a09481fb0cc16da866a69361312419cad12285e6 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 5 May 2015 19:53:50 +0000 Subject: [PATCH 15/42] Update unit tests --- unit_tests/test_glance_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index 2ac4518e..2bbe1950 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -255,7 +255,7 @@ class TestGlanceUtils(CharmTestCase): 'user_name': 'glance', 'start_dir': '/var/lib/glance', 'process_name': 'glance-api', - 'executable_name': '/usr/local/bin/glance-api', + 'executable_name': 'joined-string', 'config_files': ['/etc/glance/glance-api.conf'], 'log_file': '/var/log/glance/api.log', } @@ -265,7 +265,7 @@ class TestGlanceUtils(CharmTestCase): 'user_name': 'glance', 'start_dir': '/var/lib/glance', 'process_name': 'glance-registry', - 'executable_name': '/usr/local/bin/glance-registry', + 'executable_name': 'joined-string', 'config_files': ['/etc/glance/glance-registry.conf'], 'log_file': '/var/log/glance/registry.log', } From 362a052df2ec8715fae3cb738f8521764b400f61 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 6 May 2015 15:59:57 +0000 Subject: [PATCH 16/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 6 ++-- hooks/charmhelpers/contrib/python/packages.py | 29 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index ce8c8213..5909b0f5 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -540,7 +540,7 @@ def git_clone_and_install(projects_yaml, core_project, depth=1): if 'directory' in projects.keys(): parent_dir = projects['directory'] - pip_create_virtualenv(proxy=http_proxy) + pip_create_virtualenv() for p in projects['repositories']: repo = p['repository'] @@ -611,9 +611,9 @@ def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy, juju_log('Installing git repo from dir: {}'.format(repo_dir)) if http_proxy: - pip_install(repo_dir, proxy=http_proxy) + pip_install(repo_dir, proxy=http_proxy, venv=True) else: - pip_install(repo_dir) + pip_install(repo_dir, venv=True) return repo_dir diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index e62240b4..740eaa51 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -54,9 +54,13 @@ def pip_install_requirements(requirements, **options): pip_execute(command) -def pip_install(package, fatal=False, upgrade=False, **options): +def pip_install(package, fatal=False, upgrade=False, venv=False, **options): """Install a python package""" - command = ["install"] + if venv: + venv_python = os.path.join(charm_dir(), 'venv/bin/pip') + command = [venv_python, "install"] + else: + command = ["install"] available_options = ('proxy', 'src', 'log', 'index-url', ) for option in parse_options(options, available_options): @@ -72,7 +76,10 @@ def pip_install(package, fatal=False, upgrade=False, **options): log("Installing {} package with options: {}".format(package, command)) - pip_execute(command) + if venv: + subprocess.check_call(command) + else: + pip_execute(command) def pip_uninstall(package, **options): @@ -99,15 +106,7 @@ def pip_list(): return pip_execute(["list"]) -def pip_create_virtualenv(parent_dir=charm_dir(), proxy=None): - """Create and activate an isolated Python environment (virtualenv).""" - if proxy: - pip_install('virtualenv', proxy=proxy) - else: - pip_install('virtualenv') - - venv_dir = os.path.join(parent_dir, 'venv') - subprocess.check_call(['virtualenv', '--no-site-packages', venv_dir]) - - venv_activate = os.path.join(venv_dir, 'bin/activate') - subprocess.check_call(['.', venv_activate], shell=True) +def pip_create_virtualenv(): + """Create an isolated Python environment.""" + apt_install('python-virtualenv') + subprocess.check_call(['virtualenv', os.path.join(charm_dir(), 'venv')]) From f3eca49ccec73f7a9987c555e8c6f8d32fdff45d Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 6 May 2015 16:14:38 +0000 Subject: [PATCH 17/42] Add libssl-dev to base git install packages --- hooks/glance_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 9279c005..b27f0578 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -62,6 +62,7 @@ PACKAGES = [ BASE_GIT_PACKAGES = [ 'libxml2-dev', 'libxslt1-dev', + 'libssl-dev', 'python-dev', 'python-pip', 'python-setuptools', From 61de31282282e49f579a58937f567b86f3aa03ef Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 6 May 2015 19:11:29 +0000 Subject: [PATCH 18/42] Symlink glance-manage to /usr/local/bin/glance-manage for 'glance-manage db_sync' --- hooks/glance_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index b27f0578..6b8fc3af 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -351,6 +351,16 @@ def git_post_install(projects_yaml): shutil.rmtree(configs['dest']) shutil.copytree(configs['src'], configs['dest']) + symlinks = [ + {'src': os.path.join(charm_dir(), 'venv/bin/glance-manage'), + 'link': '/usr/local/bin/glance-manage'}, + ] + + for s in symlinks: + if os.path.lexists(s['link']): + os.remove(s['link']) + os.symlink(s['src'], s['link']) + bin_dir = os.path.join(charm_dir(), 'venv/bin') glance_api_context = { 'service_description': 'Glance API server', From f838110b6c35fee0013c50bd3e9fb48e280f8289 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 6 May 2015 19:46:56 +0000 Subject: [PATCH 19/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 5909b0f5..6d91490e 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -655,3 +655,18 @@ def git_src_dir(projects_yaml, project): return os.path.join(parent_dir, os.path.basename(p['repository'])) return None + + +def git_http_proxy(projects_yaml): + """ + Return the http_proxy value if it is specified in projects_yaml. + """ + if not projects_yaml: + return + + projects = yaml.load(projects_yaml) + + if 'http_proxy' in projects.keys(): + return projects['http_proxy'] + + return None From 85f1c1dd37b51a4bd0e46dcc3825a619906dbdc3 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 6 May 2015 20:02:26 +0000 Subject: [PATCH 20/42] Install mysql client/interface packages --- hooks/glance_utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 6b8fc3af..51d66746 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -14,6 +14,10 @@ from charmhelpers.fetch import ( apt_install, add_source) +from charmhelpers.contrib.python.packages import ( + pip_install, +) + from charmhelpers.core.hookenv import ( charm_dir, config, @@ -47,6 +51,7 @@ from charmhelpers.contrib.openstack.utils import ( git_install_requested, git_clone_and_install, git_src_dir, + git_http_proxy, configure_installation_source, os_release, ) @@ -60,6 +65,7 @@ PACKAGES = [ "python-psycopg2", "python-keystone", "python-six", "uuid", "haproxy", ] BASE_GIT_PACKAGES = [ + 'libmysqlclient-dev', 'libxml2-dev', 'libxslt1-dev', 'libssl-dev', @@ -341,6 +347,12 @@ def git_pre_install(): def git_post_install(projects_yaml): """Perform glance post-install setup.""" + http_proxy = git_http_proxy(projects_yaml) + if http_proxy: + pip_install('mysql-python', proxy=http_proxy, venv=True) + else: + pip_install('mysql-python', venv=True) + src_etc = os.path.join(git_src_dir(projects_yaml, 'glance'), 'etc') configs = { 'src': src_etc, From 28fac908176b40454018efb898cb0820932c3f0b Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 12:44:03 +0000 Subject: [PATCH 21/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 12 +++++------ hooks/charmhelpers/contrib/python/packages.py | 20 ++++++++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 6d91490e..29ac7b78 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -540,7 +540,7 @@ def git_clone_and_install(projects_yaml, core_project, depth=1): if 'directory' in projects.keys(): parent_dir = projects['directory'] - pip_create_virtualenv() + pip_create_virtualenv(os.path.join(parent_dir, 'venv')) for p in projects['repositories']: repo = p['repository'] @@ -657,16 +657,16 @@ def git_src_dir(projects_yaml, project): return None -def git_http_proxy(projects_yaml): +def git_yaml_value(projects_yaml, key): """ - Return the http_proxy value if it is specified in projects_yaml. + Return the value in projects_yaml for the specified key. """ if not projects_yaml: - return + return None projects = yaml.load(projects_yaml) - if 'http_proxy' in projects.keys(): - return projects['http_proxy'] + if key in projects.keys(): + return projects[key] return None diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index 740eaa51..12838d24 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -30,6 +30,8 @@ except ImportError: apt_install('python-pip') from pip import main as pip_execute +pip_venv_path = None + __author__ = "Jorge Niedbalski " @@ -57,7 +59,7 @@ def pip_install_requirements(requirements, **options): def pip_install(package, fatal=False, upgrade=False, venv=False, **options): """Install a python package""" if venv: - venv_python = os.path.join(charm_dir(), 'venv/bin/pip') + venv_python = os.path.join(pip_venv_path, 'bin/pip') command = [venv_python, "install"] else: command = ["install"] @@ -106,7 +108,19 @@ def pip_list(): return pip_execute(["list"]) -def pip_create_virtualenv(): +def pip_create_virtualenv(path=None): """Create an isolated Python environment.""" + global pip_venv_path + apt_install('python-virtualenv') - subprocess.check_call(['virtualenv', os.path.join(charm_dir(), 'venv')]) + + if path: + pip_venv_path = path + else: + pip_venv_path = os.path.join(charm_dir(), 'venv') + + subprocess.check_call(['virtualenv', pip_venv_path]) + + +def pip_get_virtualenv_path(): + return pip_venv_path From db0f3994ba5f1b189f7cfd853b2f88e4161a6711 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 12:47:05 +0000 Subject: [PATCH 22/42] Use function to get pip venv path --- hooks/glance_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 51d66746..ac221278 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -16,6 +16,7 @@ from charmhelpers.fetch import ( from charmhelpers.contrib.python.packages import ( pip_install, + pip_get_virtualenv_path, ) from charmhelpers.core.hookenv import ( @@ -51,7 +52,7 @@ from charmhelpers.contrib.openstack.utils import ( git_install_requested, git_clone_and_install, git_src_dir, - git_http_proxy, + git_yaml_value, configure_installation_source, os_release, ) @@ -347,7 +348,7 @@ def git_pre_install(): def git_post_install(projects_yaml): """Perform glance post-install setup.""" - http_proxy = git_http_proxy(projects_yaml) + http_proxy = git_yaml_value(projects_yaml, 'http_proxy') if http_proxy: pip_install('mysql-python', proxy=http_proxy, venv=True) else: @@ -364,7 +365,7 @@ def git_post_install(projects_yaml): shutil.copytree(configs['src'], configs['dest']) symlinks = [ - {'src': os.path.join(charm_dir(), 'venv/bin/glance-manage'), + {'src': os.path.join(pip_get_virtualenv_path(), 'bin/glance-manage'), 'link': '/usr/local/bin/glance-manage'}, ] @@ -373,7 +374,7 @@ def git_post_install(projects_yaml): os.remove(s['link']) os.symlink(s['src'], s['link']) - bin_dir = os.path.join(charm_dir(), 'venv/bin') + bin_dir = os.path.join(pip_get_virtualenv_path(), 'bin') glance_api_context = { 'service_description': 'Glance API server', 'service_name': 'Glance', From dc7adfc781f2ca4c35fc2171224a5dbf6beffaee Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 14:39:48 +0000 Subject: [PATCH 23/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 23 +++++++++++++++++-- hooks/charmhelpers/contrib/python/packages.py | 18 ++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 29ac7b78..c5e08ec2 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -611,9 +611,11 @@ def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy, juju_log('Installing git repo from dir: {}'.format(repo_dir)) if http_proxy: - pip_install(repo_dir, proxy=http_proxy, venv=True) + pip_install(repo_dir, proxy=http_proxy, + venv=os.path.join(parent_dir, 'venv')) else: - pip_install(repo_dir, venv=True) + pip_install(repo_dir, + venv=os.path.join(parent_dir, 'venv')) return repo_dir @@ -636,6 +638,23 @@ def _git_update_requirements(package_dir, reqs_dir): os.chdir(orig_dir) +def git_pip_venv_dir(projects_yaml): + """ + Return the pip virtualenv path. + """ + parent_dir = '/mnt/openstack-git' + + if not projects_yaml: + return + + projects = yaml.load(projects_yaml) + + if 'directory' in projects.keys(): + parent_dir = projects['directory'] + + return os.path.join(parent_dir, 'venv') + + def git_src_dir(projects_yaml, project): """ Return the directory where the specified project's source is located. diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index 12838d24..88c8887d 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -30,8 +30,6 @@ except ImportError: apt_install('python-pip') from pip import main as pip_execute -pip_venv_path = None - __author__ = "Jorge Niedbalski " @@ -56,10 +54,10 @@ def pip_install_requirements(requirements, **options): pip_execute(command) -def pip_install(package, fatal=False, upgrade=False, venv=False, **options): +def pip_install(package, fatal=False, upgrade=False, venv=None, **options): """Install a python package""" if venv: - venv_python = os.path.join(pip_venv_path, 'bin/pip') + venv_python = os.path.join(venv, 'bin/pip') command = [venv_python, "install"] else: command = ["install"] @@ -110,17 +108,11 @@ def pip_list(): def pip_create_virtualenv(path=None): """Create an isolated Python environment.""" - global pip_venv_path - apt_install('python-virtualenv') if path: - pip_venv_path = path + venv_path = path else: - pip_venv_path = os.path.join(charm_dir(), 'venv') + venv_path = os.path.join(charm_dir(), 'venv') - subprocess.check_call(['virtualenv', pip_venv_path]) - - -def pip_get_virtualenv_path(): - return pip_venv_path + subprocess.check_call(['virtualenv', venv_path]) From d2b89104b5bd1909afddbfc13eed7f9438cee44a Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 14:51:42 +0000 Subject: [PATCH 24/42] Use git_pip_venv_dir to get venv path --- hooks/glance_utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index ac221278..49b31e1f 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -16,7 +16,6 @@ from charmhelpers.fetch import ( from charmhelpers.contrib.python.packages import ( pip_install, - pip_get_virtualenv_path, ) from charmhelpers.core.hookenv import ( @@ -53,6 +52,7 @@ from charmhelpers.contrib.openstack.utils import ( git_clone_and_install, git_src_dir, git_yaml_value, + git_pip_venv_dir, configure_installation_source, os_release, ) @@ -350,9 +350,11 @@ def git_post_install(projects_yaml): """Perform glance post-install setup.""" http_proxy = git_yaml_value(projects_yaml, 'http_proxy') if http_proxy: - pip_install('mysql-python', proxy=http_proxy, venv=True) + pip_install('mysql-python', proxy=http_proxy, + venv=git_pip_venv_dir(projects_yaml)) else: - pip_install('mysql-python', venv=True) + pip_install('mysql-python', + venv=git_pip_venv_dir(projects_yaml)) src_etc = os.path.join(git_src_dir(projects_yaml, 'glance'), 'etc') configs = { @@ -365,7 +367,7 @@ def git_post_install(projects_yaml): shutil.copytree(configs['src'], configs['dest']) symlinks = [ - {'src': os.path.join(pip_get_virtualenv_path(), 'bin/glance-manage'), + {'src': os.path.join(git_pip_venv_dir(), 'bin/glance-manage'), 'link': '/usr/local/bin/glance-manage'}, ] @@ -374,7 +376,7 @@ def git_post_install(projects_yaml): os.remove(s['link']) os.symlink(s['src'], s['link']) - bin_dir = os.path.join(pip_get_virtualenv_path(), 'bin') + bin_dir = os.path.join(git_pip_venv_dir(), 'bin') glance_api_context = { 'service_description': 'Glance API server', 'service_name': 'Glance', From da398c91d19bb4970bcc7e06290a52f41d360b9b Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 15:09:40 +0000 Subject: [PATCH 25/42] Add missing params --- hooks/glance_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 49b31e1f..00b0949a 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -367,7 +367,8 @@ def git_post_install(projects_yaml): shutil.copytree(configs['src'], configs['dest']) symlinks = [ - {'src': os.path.join(git_pip_venv_dir(), 'bin/glance-manage'), + {'src': os.path.join(git_pip_venv_dir(projects_yaml), + 'bin/glance-manage'), 'link': '/usr/local/bin/glance-manage'}, ] @@ -376,7 +377,7 @@ def git_post_install(projects_yaml): os.remove(s['link']) os.symlink(s['src'], s['link']) - bin_dir = os.path.join(git_pip_venv_dir(), 'bin') + bin_dir = os.path.join(git_pip_venv_dir(projects_yaml), 'bin') glance_api_context = { 'service_description': 'Glance API server', 'service_name': 'Glance', From 7eed7de5e2c4832ae0a8cf0ab65ff7d23cae35e8 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 15:36:57 +0000 Subject: [PATCH 26/42] Unit test updates --- unit_tests/test_glance_relations.py | 6 ++++-- unit_tests/test_glance_utils.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 8f3d3025..38cba25d 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -130,8 +130,10 @@ class GlanceRelationTests(CharmTestCase): self.apt_update.assert_called_with(fatal=True) self.apt_install.assert_called_with(['haproxy', 'python-setuptools', 'python-six', 'uuid', - 'python-mysqldb', 'python-pip', - 'apache2', 'libxslt1-dev', + 'python-mysqldb', + 'libmysqlclient-dev', + 'libssl-dev', 'apache2', + 'python-pip', 'libxslt1-dev', 'python-psycopg2', 'zlib1g-dev', 'python-dev', 'libxml2-dev'], diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index 2bbe1950..87b0699c 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -236,19 +236,28 @@ class TestGlanceUtils(CharmTestCase): @patch.object(utils, 'git_src_dir') @patch.object(utils, 'service_restart') @patch.object(utils, 'render') + @patch.object(utils, 'git_pip_venv_dir') @patch('os.path.join') @patch('os.path.exists') + @patch('os.symlink') @patch('shutil.copytree') @patch('shutil.rmtree') - def test_git_post_install(self, rmtree, copytree, exists, join, render, - service_restart, git_src_dir): + @patch('subprocess.check_call') + def test_git_post_install(self, check_call, rmtree, copytree, symlink, + exists, join, venv, render, service_restart, + git_src_dir): projects_yaml = openstack_origin_git join.return_value = 'joined-string' + venv.return_value = '/mnt/openstack-git/venv' utils.git_post_install(projects_yaml) expected = [ call('joined-string', '/etc/glance'), ] copytree.assert_has_calls(expected) + expected = [ + call('joined-string', '/usr/local/bin/glance-manage'), + ] + symlink.assert_has_calls(expected, any_order=True) glance_api_context = { 'service_description': 'Glance API server', 'service_name': 'Glance', From 432271a6d3b194106d9ca1b72b11c891280c80f0 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 18:53:55 +0000 Subject: [PATCH 27/42] Sync charm-helpers --- hooks/charmhelpers/contrib/python/packages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/charmhelpers/contrib/python/packages.py b/hooks/charmhelpers/contrib/python/packages.py index 88c8887d..07b0c1d7 100644 --- a/hooks/charmhelpers/contrib/python/packages.py +++ b/hooks/charmhelpers/contrib/python/packages.py @@ -115,4 +115,5 @@ def pip_create_virtualenv(path=None): else: venv_path = os.path.join(charm_dir(), 'venv') - subprocess.check_call(['virtualenv', venv_path]) + if not os.path.exists(venv_path): + subprocess.check_call(['virtualenv', venv_path]) From 1670dc7bb909a0df072fc54a10cd71916b4b5903 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Thu, 7 May 2015 20:11:27 +0000 Subject: [PATCH 28/42] Add symlinks to rbd.py and rados.py --- hooks/glance_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 00b0949a..d77a1598 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -370,6 +370,14 @@ def git_post_install(projects_yaml): {'src': os.path.join(git_pip_venv_dir(projects_yaml), 'bin/glance-manage'), 'link': '/usr/local/bin/glance-manage'}, + # NOTE(coreycb): This is ugly but couldn't find pypi package that + # installs rbd.py and rados.py. + {'src': '/usr/lib/python2.7/dist-packages/rbd.py', + 'link': os.path.join(git_pip_venv_dir(projects_yaml), + 'lib/python2.7/site-packages/rbd.py')}, + {'src': '/usr/lib/python2.7/dist-packages/rados.py', + 'link': os.path.join(git_pip_venv_dir(projects_yaml), + 'lib/python2.7/site-packages/rados.py')}, ] for s in symlinks: From 5b6c75682b6ac60b39c94e9880153079c49e24a5 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 8 May 2015 12:35:25 +0000 Subject: [PATCH 29/42] Patch out pip_install --- unit_tests/test_glance_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index 87b0699c..70016473 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -23,6 +23,7 @@ TO_PATCH = [ 'apt_install', 'mkdir', 'os_release', + 'pip_install', 'service_start', 'service_stop', 'service_name', From 6994528576284763819f5c5f06e99c424dc6fe72 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 8 May 2015 14:08:43 +0000 Subject: [PATCH 30/42] Add libffi-dev to base git pkgs --- hooks/glance_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index d77a1598..c7e13325 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -66,6 +66,7 @@ PACKAGES = [ "python-psycopg2", "python-keystone", "python-six", "uuid", "haproxy", ] BASE_GIT_PACKAGES = [ + 'libffi-dev', 'libmysqlclient-dev', 'libxml2-dev', 'libxslt1-dev', From 77f2a5d506cc9792b844016592bc903935d84828 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Fri, 8 May 2015 14:10:19 +0000 Subject: [PATCH 31/42] Update unit tests --- unit_tests/test_glance_relations.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 38cba25d..9c2e29cc 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -132,8 +132,9 @@ class GlanceRelationTests(CharmTestCase): 'python-six', 'uuid', 'python-mysqldb', 'libmysqlclient-dev', - 'libssl-dev', 'apache2', - 'python-pip', 'libxslt1-dev', + 'libssl-dev', 'libffi-dev', + 'apache2', 'python-pip', + 'libxslt1-dev', 'python-psycopg2', 'zlib1g-dev', 'python-dev', 'libxml2-dev'], From 8ba86398c84e225230970d262dcd904f33bd3be3 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Mon, 11 May 2015 12:32:28 +0000 Subject: [PATCH 32/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index c5e08ec2..774eaba1 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -501,6 +501,16 @@ def git_install_requested(): requirements_dir = None +def _git_yaml_load(projects_yaml): + """ + Load the specified yaml into a dictionary. + """ + if not projects_yaml: + return None + + projects = yaml.load(projects_yaml) + + def git_clone_and_install(projects_yaml, core_project, depth=1): """ Clone/install all specified OpenStack repositories. @@ -523,10 +533,7 @@ def git_clone_and_install(projects_yaml, core_project, depth=1): parent_dir = '/mnt/openstack-git' http_proxy = None - if not projects_yaml: - return - - projects = yaml.load(projects_yaml) + projects = _git_yaml_load(projects_yaml) _git_validate_projects_yaml(projects, core_project) old_environ = dict(os.environ) @@ -644,10 +651,7 @@ def git_pip_venv_dir(projects_yaml): """ parent_dir = '/mnt/openstack-git' - if not projects_yaml: - return - - projects = yaml.load(projects_yaml) + projects = _git_yaml_load(projects_yaml) if 'directory' in projects.keys(): parent_dir = projects['directory'] @@ -661,10 +665,7 @@ def git_src_dir(projects_yaml, project): """ parent_dir = '/mnt/openstack-git' - if not projects_yaml: - return - - projects = yaml.load(projects_yaml) + projects = _git_yaml_load(projects_yaml) if 'directory' in projects.keys(): parent_dir = projects['directory'] @@ -680,10 +681,7 @@ def git_yaml_value(projects_yaml, key): """ Return the value in projects_yaml for the specified key. """ - if not projects_yaml: - return None - - projects = yaml.load(projects_yaml) + projects = _git_yaml_load(projects_yaml) if key in projects.keys(): return projects[key] From a86c379b97f96634119dd0da73f157755adaf52f Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Mon, 11 May 2015 12:36:06 +0000 Subject: [PATCH 33/42] Add comment to fix bin symlinks --- hooks/glance_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index c7e13325..70111df0 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -368,6 +368,7 @@ def git_post_install(projects_yaml): shutil.copytree(configs['src'], configs['dest']) symlinks = [ + # NOTE(coreycb): Need to find better solution than bin symlinks. {'src': os.path.join(git_pip_venv_dir(projects_yaml), 'bin/glance-manage'), 'link': '/usr/local/bin/glance-manage'}, From 50ef62b9c5ef50f5f1525b644bb8fee1376d4ea4 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Mon, 11 May 2015 12:45:37 +0000 Subject: [PATCH 34/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 774eaba1..8bd2356e 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -508,7 +508,7 @@ def _git_yaml_load(projects_yaml): if not projects_yaml: return None - projects = yaml.load(projects_yaml) + return yaml.load(projects_yaml) def git_clone_and_install(projects_yaml, core_project, depth=1): From f805b0e6cb862aa5a6ec658ff9e577e988447846 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 12 May 2015 14:24:12 +0000 Subject: [PATCH 35/42] Sync charm-helpers --- hooks/charmhelpers/contrib/openstack/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/charmhelpers/contrib/openstack/utils.py b/hooks/charmhelpers/contrib/openstack/utils.py index 8bd2356e..d795a358 100644 --- a/hooks/charmhelpers/contrib/openstack/utils.py +++ b/hooks/charmhelpers/contrib/openstack/utils.py @@ -524,8 +524,8 @@ def git_clone_and_install(projects_yaml, core_project, depth=1): repository: 'git://git.openstack.org/openstack/requirements.git', branch: 'stable/icehouse'} directory: /mnt/openstack-git - http_proxy: http://squid.internal:3128 - https_proxy: https://squid.internal:3128 + http_proxy: squid-proxy-url + https_proxy: squid-proxy-url The directory, http_proxy, and https_proxy keys are optional. """ From d3cab63d04029e7a4b3e83fccdc16e38d5c721fe Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 12 May 2015 14:49:27 +0000 Subject: [PATCH 36/42] Clone from github in deploy from source amulet tests --- tests/basic_deployment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index 1b1fcb13..d0a8db8e 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -66,10 +66,10 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): openstack_origin_git = { 'repositories': [ {'name': 'requirements', - 'repository': 'git://git.openstack.org/openstack/requirements', + 'repository': 'git://github.com/openstack/requirements', 'branch': branch}, {'name': 'glance', - 'repository': 'git://git.openstack.org/openstack/glance', + 'repository': 'git://github.com/openstack/glance', 'branch': branch}, ], 'directory': '/mnt/openstack-git', From 885d0a5496764addc4198edf1f710af454c7fcf6 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Tue, 12 May 2015 19:46:43 +0000 Subject: [PATCH 37/42] Add libyaml-dev as base git package --- hooks/glance_utils.py | 1 + unit_tests/test_glance_relations.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 70111df0..a39f7985 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -71,6 +71,7 @@ BASE_GIT_PACKAGES = [ 'libxml2-dev', 'libxslt1-dev', 'libssl-dev', + 'libyaml-dev', 'python-dev', 'python-pip', 'python-setuptools', diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 9c2e29cc..4da7ba32 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -134,7 +134,7 @@ class GlanceRelationTests(CharmTestCase): 'libmysqlclient-dev', 'libssl-dev', 'libffi-dev', 'apache2', 'python-pip', - 'libxslt1-dev', + 'libxslt1-dev', 'libyaml-dev', 'python-psycopg2', 'zlib1g-dev', 'python-dev', 'libxml2-dev'], From 67e9a9636dddaeb988fc940b800b70efa3b0d8b6 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 27 May 2015 13:01:32 +0000 Subject: [PATCH 38/42] Sync charm-helpers --- hooks/charmhelpers/fetch/giturl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/charmhelpers/fetch/giturl.py b/hooks/charmhelpers/fetch/giturl.py index 7d842d49..ddc25b7e 100644 --- a/hooks/charmhelpers/fetch/giturl.py +++ b/hooks/charmhelpers/fetch/giturl.py @@ -45,7 +45,7 @@ class GitUrlFetchHandler(BaseFetchHandler): else: return True - def clone(self, source, dest, branch, depth): + def clone(self, source, dest, branch, depth=None): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) From fbe257b54228554ab737aebe7b373ef6a07bab46 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 2 Jun 2015 18:25:25 +0100 Subject: [PATCH 39/42] Sort out problem with sectional configuration of glance_store --- templates/kilo/glance-api.conf | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/templates/kilo/glance-api.conf b/templates/kilo/glance-api.conf index 6448de6e..f06fac23 100644 --- a/templates/kilo/glance-api.conf +++ b/templates/kilo/glance-api.conf @@ -40,6 +40,22 @@ registry_client_protocol = http notification_driver = rabbit {% endif -%} +delayed_delete = False +scrub_time = 43200 +scrubber_datadir = /var/lib/glance/scrubber +image_cache_dir = /var/lib/glance/image-cache/ +db_enforce_mysql_charset = False + +[glance_store] +known_stores = {{ known_stores }} +{% if rbd_pool -%} +default_store = rbd +{% elif swift_store -%} +default_store = swift +{% else -%} +default_store = file +{% endif -%} + {% if swift_store -%} swift_store_auth_version = 2 swift_store_auth_address = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v2.0/ @@ -59,15 +75,6 @@ rbd_store_pool = {{ rbd_pool }} rbd_store_chunk_size = 8 {% endif -%} -delayed_delete = False -scrub_time = 43200 -scrubber_datadir = /var/lib/glance/scrubber -image_cache_dir = /var/lib/glance/image-cache/ -db_enforce_mysql_charset = False - -[glance_store] -filesystem_store_datadir = /var/lib/glance/images/ - [image_format] disk_formats=ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar From 5a4597fdc7322685c54a1d3f830ea2dd0f8d8b42 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 2 Jun 2015 18:30:30 +0100 Subject: [PATCH 40/42] Restore filesystem_store_datadir option --- templates/kilo/glance-api.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/kilo/glance-api.conf b/templates/kilo/glance-api.conf index f06fac23..b7e26e7c 100644 --- a/templates/kilo/glance-api.conf +++ b/templates/kilo/glance-api.conf @@ -47,6 +47,7 @@ image_cache_dir = /var/lib/glance/image-cache/ db_enforce_mysql_charset = False [glance_store] +filesystem_store_datadir = /var/lib/glance/images/ known_stores = {{ known_stores }} {% if rbd_pool -%} default_store = rbd From 18a0a1ee12bde8be5dfd53fe46930bdeb73172d6 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 2 Jun 2015 18:33:25 +0100 Subject: [PATCH 41/42] Remove duplicate store config --- templates/kilo/glance-api.conf | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/templates/kilo/glance-api.conf b/templates/kilo/glance-api.conf index b7e26e7c..49b33885 100644 --- a/templates/kilo/glance-api.conf +++ b/templates/kilo/glance-api.conf @@ -3,16 +3,6 @@ verbose = {{ verbose }} use_syslog = {{ use_syslog }} debug = {{ debug }} workers = {{ workers }} - -known_stores = {{ known_stores }} -{% if rbd_pool -%} -default_store = rbd -{% elif swift_store -%} -default_store = swift -{% else -%} -default_store = file -{% endif -%} - bind_host = {{ bind_host }} {% if ext -%} From 16a30a3d2ef831dd4741aada7b91321c964526df Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 2 Jun 2015 19:29:59 +0100 Subject: [PATCH 42/42] Fixup key name --- templates/kilo/glance-api.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/kilo/glance-api.conf b/templates/kilo/glance-api.conf index 49b33885..d383244a 100644 --- a/templates/kilo/glance-api.conf +++ b/templates/kilo/glance-api.conf @@ -38,7 +38,7 @@ db_enforce_mysql_charset = False [glance_store] filesystem_store_datadir = /var/lib/glance/images/ -known_stores = {{ known_stores }} +stores = {{ known_stores }} {% if rbd_pool -%} default_store = rbd {% elif swift_store -%}