Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sync bind for searching, needed by MS AD #1194

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install:
- sed -e 's/username = guest/username = unittest/' -e 's/password = guest/password = gottatest/' nipap-cli/nipaprc > ~/.nipaprc
- chmod 0600 ~/.nipaprc
# install postgresql + ip4r + contrib
- sudo apt-get install -qq -y postgresql-9.1 postgresql-9.1-ip4r postgresql-contrib-9.1
- sudo apt-get install -qq -y postgresql-9.2 postgresql-9.2-ip4r postgresql-contrib-9.2

# -- virtualenv build ------------------------------------------------------
# install nipap dependencies
Expand All @@ -54,7 +54,7 @@ install:
- if [ "$INSTALL" == "apt" ]; then wget -O - https://spritelink.github.io/NIPAP/nipap.gpg.key | sudo apt-key add -; fi
- if [ "$INSTALL" == "apt" ]; then sudo apt-get update -qq; fi
# install dependencies for installing & running nipap
- if [ "$INSTALL" == "apt" ]; then sudo apt-get install -qq -y --force-yes python-pysqlite2 python-psycopg2 python-ipy python3-ipy python-docutils postgresql-9.1 postgresql-9.1-ip4r python-tornado python-flask python-flask-xml-rpc python-flask-compress python-parsedatetime python-pylons python-tz python-dateutil python-psutil python-pyparsing; fi
- if [ "$INSTALL" == "apt" ]; then sudo apt-get install -qq -y --force-yes python-pysqlite2 python-psycopg2 python-ipy python3-ipy python-docutils postgresql-9.2 postgresql-9.2-ip4r python-tornado python-flask python-flask-xml-rpc python-flask-compress python-parsedatetime python-pylons python-tz python-dateutil python-psutil python-pyparsing; fi
# if we are testing the upgrade, first install NIPAP packages from official repo
- if [ "$INSTALL" == "apt" ] && [ "$UPGRADE" == "true" ]; then sudo apt-get install -qq nipapd nipap-www nipap-cli; fi
# bump version so that we know we are upgrading beyond what is installed
Expand Down
2 changes: 1 addition & 1 deletion nipap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ clean:
find . -name '*.pyc' -delete

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
DB_VER := $(shell grep "COMMENT ON DATABASE nipap IS" sql/ip_net.plsql | sed 's/.*version: \([0-9]\+\).*/\1/')
DB_VER := $(shell grep "COMMENT ON DATABASE %s IS" sql/ip_net.plsql | sed 's/.*version: \([0-9]\+\).*/\1/')
bumpversion:
# update debian package nipapd's config and postinst script with current db
# version
Expand Down
14 changes: 7 additions & 7 deletions nipap/nipap/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def _connect_db(self):
if re.search("hstore type not found in the database", unicode(exc)):
# automatically install if auto-install is enabled
if self._auto_install_db:
self._db_install()
self._db_install(db_args['database'])
continue
raise NipapDatabaseMissingExtensionError("hstore extension not found in the database")

Expand All @@ -800,7 +800,7 @@ def _connect_db(self):
# empty...
if self._auto_install_db:
# automatically install schema?
self._db_install()
self._db_install(db_args['database'])
continue
raise exc
except NipapError as exc:
Expand All @@ -809,7 +809,7 @@ def _connect_db(self):

if current_db_version != nipap.__db_version__:
if self._auto_upgrade_db:
self._db_upgrade()
self._db_upgrade(db_args['database'])
continue
raise NipapDatabaseWrongVersionError("NIPAP PostgreSQL database is outdated. Schema version %s is required to run but you are using %s" % (nipap.__db_version__, current_db_version))

Expand Down Expand Up @@ -1117,25 +1117,25 @@ def _get_db_version(self):



def _db_install(self):
def _db_install(self, db_name):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (3)

""" Install nipap database schema
"""
self._logger.info("Installing NIPAP database schemas into db")
self._execute(db_schema.ip_net)
self._execute(db_schema.ip_net % (db_name))
self._execute(db_schema.functions)
self._execute(db_schema.triggers)



def _db_upgrade(self):
def _db_upgrade(self, db_name):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (3)

""" Upgrade nipap database schema
"""
current_db_version = self._get_db_version()
self._execute(db_schema.functions)
for i in range(current_db_version, nipap.__db_version__):
self._logger.info("Upgrading DB schema:", i, "to", i+1)
upgrade_sql = db_schema.upgrade[i-1] # 0 count on array
self._execute(upgrade_sql)
self._execute(upgrade_sql % (db_name))
self._execute(db_schema.triggers)


Expand Down
12 changes: 6 additions & 6 deletions nipap/nipap/db_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@
--
--------------------------------------------

COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 6';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 6';

CREATE EXTENSION IF NOT EXISTS ip4r;
CREATE EXTENSION IF NOT EXISTS hstore;
Expand Down Expand Up @@ -1807,7 +1807,7 @@
UPDATE ip_net_plan inp SET added = (SELECT timestamp FROM ip_net_log inl WHERE inl.prefix_id = inp.id ORDER BY inl.timestamp DESC LIMIT 1);

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 2';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 2';
""",
"""
--
Expand All @@ -1819,7 +1819,7 @@
COMMENT ON COLUMN ip_net_plan.customer_id IS 'Customer Identifier';

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 3';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 3';

CREATE OR REPLACE FUNCTION update_children() RETURNS boolean AS $_$
DECLARE
Expand Down Expand Up @@ -1943,7 +1943,7 @@
CREATE INDEX ip_net_plan__pool_id__index ON ip_net_plan (pool_id);

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 4';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 4';
""",
"""
--
Expand Down Expand Up @@ -2014,7 +2014,7 @@
ALTER TABLE ip_net_plan ADD COLUMN expires timestamp with time zone DEFAULT 'infinity';

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 5';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 5';
""",
"""
--
Expand All @@ -2032,6 +2032,6 @@
CREATE UNIQUE INDEX ip_net_pool__name__index ON ip_net_pool (lower(name));

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 6';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 6';
""",
]
2 changes: 1 addition & 1 deletion nipap/sql/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ db:


tables:
PGPASSWORD=$(DB_PASS) psql -q -h localhost -U $(DB_USER) -d $(DB_NAME) < ip_net.plsql
PGPASSWORD=$(DB_PASS) cat ip_net.plsql | sed -e 's/%s/$(DB_NAME)/' | psql -q -h localhost -U $(DB_USER) -d $(DB_NAME)
PGPASSWORD=$(DB_PASS) psql -q -h localhost -U $(DB_USER) -d $(DB_NAME) < functions.plsql
PGPASSWORD=$(DB_PASS) psql -q -h localhost -U $(DB_USER) -d $(DB_NAME) < triggers.plsql

Expand Down
2 changes: 1 addition & 1 deletion nipap/sql/ip_net.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--
--------------------------------------------

COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 6';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 6';

CREATE EXTENSION IF NOT EXISTS ip4r;
CREATE EXTENSION IF NOT EXISTS hstore;
Expand Down
2 changes: 1 addition & 1 deletion nipap/sql/upgrade-1-2.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ COMMENT ON COLUMN ip_net_plan.last_modified IS 'The date and time when the prefi
UPDATE ip_net_plan inp SET added = (SELECT timestamp FROM ip_net_log inl WHERE inl.prefix_id = inp.id ORDER BY inl.timestamp DESC LIMIT 1);

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 2';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 2';
2 changes: 1 addition & 1 deletion nipap/sql/upgrade-2-3.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ALTER TABLE ip_net_plan ADD COLUMN customer_id text;
COMMENT ON COLUMN ip_net_plan.customer_id IS 'Customer Identifier';

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 3';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 3';

CREATE OR REPLACE FUNCTION update_children() RETURNS boolean AS $_$
DECLARE
Expand Down
2 changes: 1 addition & 1 deletion nipap/sql/upgrade-3-4.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ UPDATE ip_net_pool SET free_addresses_v6 = COALESCE((SELECT SUM(free_addresses)
CREATE INDEX ip_net_plan__pool_id__index ON ip_net_plan (pool_id);

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 4';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 4';
2 changes: 1 addition & 1 deletion nipap/sql/upgrade-4-5.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ ALTER TABLE ip_net_pool ADD COLUMN avps hstore NOT NULL DEFAULT '';
ALTER TABLE ip_net_plan ADD COLUMN expires timestamp with time zone DEFAULT 'infinity';

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 5';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 5';
2 changes: 1 addition & 1 deletion nipap/sql/upgrade-5-6.plsql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ALTER TABLE ip_net_pool DROP CONSTRAINT ip_net_pool_name_key;
CREATE UNIQUE INDEX ip_net_pool__name__index ON ip_net_pool (lower(name));

-- update database schema version
COMMENT ON DATABASE nipap IS 'NIPAP database - schema version: 6';
COMMENT ON DATABASE %s IS 'NIPAP database - schema version: 6';