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
This commit is contained in:
Rick Harris 2013-08-05 18:23:10 +00:00
parent 27ff32ad09
commit a134850886
2 changed files with 9 additions and 4 deletions

View File

@ -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)

View File

@ -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