From a13485088674af672d1e8a30f05a483092878507 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Mon, 5 Aug 2013 18:23:10 +0000 Subject: [PATCH] Catch ldap ImportError Since the `ldap` module isn't a requirement, we need to guard against it not being present. One reason this is needed is that we generate sample configs by walking the module import tree. If a module isn't importable--because a depenency isn't met, for example--the module's configs are omitted from the sample config, requiring the developer to manually add them back. Fixes bug 1208560 Change-Id: Ie23b7fad118ecadabf7e36703934fa933f4e8c50 --- nova/network/ldapdns.py | 10 +++++++++- test-requirements.txt | 3 --- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/nova/network/ldapdns.py b/nova/network/ldapdns.py index c22885a4fed2..484918c4ba72 100644 --- a/nova/network/ldapdns.py +++ b/nova/network/ldapdns.py @@ -12,7 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import ldap +try: + import ldap +except ImportError: + # This module needs to be importable despite ldap not being a requirement + ldap = None + import time from oslo.config import cfg @@ -313,6 +318,9 @@ class LdapDNS(dns_driver.DNSDriver): """ def __init__(self): + if not ldap: + raise ImportError(_('ldap not installed')) + self.lobj = ldap.initialize(CONF.ldap_dns_url) self.lobj.simple_bind_s(CONF.ldap_dns_user, CONF.ldap_dns_password) diff --git a/test-requirements.txt b/test-requirements.txt index 15525ccc9214..2e5b14675e89 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,9 +7,6 @@ mox==0.5.3 MySQL-python psycopg2 pylint==0.25.2 -# Imported by ldapdns so required to generate -# the sample configuration file -python-ldap==2.3.13 python-subunit setuptools_git>=0.4 sphinx>=1.1.2