Fix relative import path in source tree
This patch fixes the relative import path to use congress as the base to be consistant with other openstack projects. In addition, this commit removes the the run_congress_server script and replaces that with bin/congress-server and the run_test script. Unit tests can now be successfully be run by issuing: make tox -epy27 (once the tox.ini enables tests again). Closes-bug: 1338840 Change-Id: I371192e9573a7f1ca4ea8e1d6a707e265e8f8dc9
This commit is contained in:
parent
75ce78e592
commit
fa43a63f9f
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (c) 2013 VMware, Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# If ../congress/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(__file__),
|
||||
os.pardir,
|
||||
os.pardir))
|
||||
if os.path.exists(os.path.join(possible_topdir,
|
||||
'congress',
|
||||
'__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
|
||||
from congress.server import congress_server
|
||||
|
||||
if __name__ == '__main__':
|
||||
congress_server.main()
|
|
@ -18,13 +18,12 @@ import traceback
|
|||
import webob
|
||||
import webob.dec
|
||||
|
||||
from openstack.common.gettextutils import _
|
||||
|
||||
from api.webservice import CollectionHandler
|
||||
from api.webservice import ElementHandler
|
||||
from api.webservice import INTERNAL_ERROR_RESPONSE
|
||||
from api.webservice import NOT_SUPPORTED_RESPONSE
|
||||
from api.webservice import SimpleDataModel
|
||||
from congress.api.webservice import CollectionHandler
|
||||
from congress.api.webservice import ElementHandler
|
||||
from congress.api.webservice import INTERNAL_ERROR_RESPONSE
|
||||
from congress.api.webservice import NOT_SUPPORTED_RESPONSE
|
||||
from congress.api.webservice import SimpleDataModel
|
||||
from congress.openstack.common.gettextutils import _
|
||||
from congress.openstack.common import log as logging
|
||||
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import dse.deepsix
|
||||
import policy.compile
|
||||
import policy.runtime
|
||||
from congress.dse import deepsix
|
||||
from congress.policy import compile
|
||||
from congress.policy import runtime
|
||||
|
||||
|
||||
class DataSourceDriver(dse.deepsix.deepSix):
|
||||
class DataSourceDriver(deepsix.deepSix):
|
||||
def __init__(self, name, keys, inbox=None, datapath=None,
|
||||
poll_time=None, **creds):
|
||||
if poll_time is None:
|
||||
|
@ -125,12 +125,12 @@ class DataSourceDriver(dse.deepsix.deepSix):
|
|||
self.log("to_add: " + str(to_add))
|
||||
self.log("to_del: " + str(to_del))
|
||||
# create Events
|
||||
to_add = [policy.runtime.Event(
|
||||
formula=policy.compile.Literal.create_from_table_tuple(
|
||||
to_add = [runtime.Event(
|
||||
formula=compile.Literal.create_from_table_tuple(
|
||||
dataindex, x), insert=True)
|
||||
for x in to_add]
|
||||
to_del = [policy.runtime.Event(
|
||||
formula=policy.compile.Literal.create_from_table_tuple(
|
||||
to_del = [runtime.Event(
|
||||
formula=compile.Literal.create_from_table_tuple(
|
||||
dataindex, x), insert=False)
|
||||
for x in to_del]
|
||||
result = to_add + to_del
|
||||
|
@ -141,7 +141,7 @@ class DataSourceDriver(dse.deepsix.deepSix):
|
|||
result = None
|
||||
text = "None"
|
||||
else:
|
||||
text = policy.runtime.iterstr(result)
|
||||
text = runtime.iterstr(result)
|
||||
self.log("prepush_processor for <{}> returning: {}".format(self.name,
|
||||
dataindex, text))
|
||||
return result
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from datasources.datasource_driver import DataSourceDriver
|
||||
from congress.datasources.datasource_driver import DataSourceDriver
|
||||
import datetime
|
||||
import logging
|
||||
import novaclient.client
|
||||
from datasources.settings import OS_USERNAME, \
|
||||
from congress.datasources.settings import OS_USERNAME, \
|
||||
OS_PASSWORD, OS_AUTH_URL, OS_TENANT_NAME
|
||||
|
||||
|
||||
|
|
|
@ -17,18 +17,13 @@ import logging
|
|||
import mock
|
||||
import mox
|
||||
import neutronclient.v2_0.client
|
||||
|
||||
import congress.tests.helper as helper
|
||||
from datasources.neutron_driver import NeutronDriver
|
||||
import dse.d6cage
|
||||
# do not add 'congress' at the beginning of the import. Causes isinstance
|
||||
# failures.
|
||||
# TODO(thinrichs): look into why this happens--seems that Python is importing
|
||||
# the same module more than once, which causes odd things to happen with
|
||||
# isinstance. Maybe force all imports to start with 'congress'
|
||||
import policy.compile as compile
|
||||
import unittest
|
||||
|
||||
from congress.datasources.neutron_driver import NeutronDriver
|
||||
import congress.dse.d6cage
|
||||
import congress.policy.compile as compile
|
||||
import congress.tests.helper as helper
|
||||
|
||||
|
||||
class TestNeutronDriver(unittest.TestCase):
|
||||
|
||||
|
@ -235,7 +230,7 @@ class TestNeutronDriver(unittest.TestCase):
|
|||
|
||||
def setup_polling(self, debug_mode=False):
|
||||
"""Setup polling tests."""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
|
|
@ -18,10 +18,10 @@ from mock import patch
|
|||
import novaclient
|
||||
import unittest
|
||||
|
||||
from congress.datasources.nova_driver import NovaDriver
|
||||
from congress.datasources.tests.unit import fakes
|
||||
import congress.dse.d6cage
|
||||
import congress.tests.helper as helper
|
||||
from datasources.nova_driver import NovaDriver
|
||||
from datasources.tests.unit import fakes
|
||||
import dse.d6cage
|
||||
|
||||
|
||||
class TestNovaDriver(unittest.TestCase):
|
||||
|
@ -174,7 +174,7 @@ class TestNovaDriver(unittest.TestCase):
|
|||
"""Test the module's ability to be loaded into the DSE
|
||||
by checking its ability to communicate on the message bus.
|
||||
"""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import congress.tests.helper as helper
|
||||
import dse.d6cage
|
||||
import policy.compile as compile
|
||||
import policy.runtime as runtime
|
||||
import unittest
|
||||
|
||||
import congress.dse.d6cage
|
||||
import congress.policy.compile as compile
|
||||
import congress.policy.runtime as runtime
|
||||
import congress.tests.helper as helper
|
||||
|
||||
|
||||
class TestDSE(unittest.TestCase):
|
||||
|
||||
|
@ -27,7 +28,7 @@ class TestDSE(unittest.TestCase):
|
|||
|
||||
def test_cage(self):
|
||||
"""Test basic DSE functionality."""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
@ -56,7 +57,7 @@ class TestDSE(unittest.TestCase):
|
|||
|
||||
def test_policy(self):
|
||||
"""Test basic DSE functionality with policy engine."""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
@ -75,7 +76,7 @@ class TestDSE(unittest.TestCase):
|
|||
|
||||
def test_policy_data(self):
|
||||
"""Test policy properly inserts data and processes it normally."""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
@ -97,7 +98,7 @@ class TestDSE(unittest.TestCase):
|
|||
|
||||
def test_policy_tables(self):
|
||||
"""Test basic DSE functionality with policy engine and the API."""
|
||||
cage = dse.d6cage.d6Cage()
|
||||
cage = congress.dse.d6cage.d6Cage()
|
||||
# so that we exit once test finishes; all other threads are forced
|
||||
# to be daemons
|
||||
cage.daemon = True
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
import dse.deepsix as deepsix
|
||||
import policy.compile as compile
|
||||
import policy.runtime as runtime
|
||||
import congress.dse.deepsix as deepsix
|
||||
import congress.policy.compile as compile
|
||||
import congress.policy.runtime as runtime
|
||||
|
||||
|
||||
class PolicyServiceMismatch (Exception):
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
#
|
||||
|
||||
import collections
|
||||
import compile
|
||||
import logging
|
||||
import os
|
||||
|
||||
#FIXME there is a circular import here because compile.py imports runtime.py
|
||||
import compile
|
||||
import unify
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,10 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
from policy import compile
|
||||
import unittest
|
||||
|
||||
from congress.policy import compile
|
||||
|
||||
|
||||
class TestCompiler(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
import logging
|
||||
import uuid
|
||||
|
||||
#FIXME there is a circular import here because compile.py imports unify.py
|
||||
import compile
|
||||
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ import os.path
|
|||
from oslo.config import cfg
|
||||
import sys
|
||||
|
||||
import api.application
|
||||
import api.wsgi
|
||||
from congress.api import application
|
||||
from congress.api import wsgi
|
||||
from congress.common import config
|
||||
import congress.dse.d6cage
|
||||
from congress.openstack.common import log as logging
|
||||
import dse.d6cage
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -52,7 +52,7 @@ class EventLoop(object):
|
|||
fpath = os.path.dirname(os.path.realpath(__file__))
|
||||
module_dir = os.path.dirname(fpath)
|
||||
self.module_dir = module_dir
|
||||
self.cage = dse.d6cage.d6Cage()
|
||||
self.cage = congress.dse.d6cage.d6Cage()
|
||||
|
||||
self.pool = eventlet.GreenPool(pool_size)
|
||||
|
||||
|
@ -94,10 +94,10 @@ def main():
|
|||
# API resource runtime encapsulation:
|
||||
# event loop -> wsgi server -> webapp -> resource manager
|
||||
|
||||
wsgi_server = api.wsgi.Server("Congress API Broker", pool=loop.pool)
|
||||
api_resource_mgr = api.application.ResourceManager()
|
||||
api.application.initialize_resources(api_resource_mgr)
|
||||
api_webapp = api.application.ApiApplication(api_resource_mgr)
|
||||
wsgi_server = wsgi.Server("Congress API Broker", pool=loop.pool)
|
||||
api_resource_mgr = application.ResourceManager()
|
||||
application.initialize_resources(api_resource_mgr)
|
||||
api_webapp = application.ApiApplication(api_resource_mgr)
|
||||
# TODO(pballand): start this inside d6cage(?)
|
||||
wsgi_server.start(api_webapp, cfg.CONF.bind_port,
|
||||
cfg.CONF.bind_host)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
import dse.deepsix as deepsix
|
||||
import congress.dse.deepsix as deepsix
|
||||
|
||||
|
||||
def d6service(name, keys, inbox, datapath, args):
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
#
|
||||
|
||||
import os.path
|
||||
import policy.runtime as runtime
|
||||
import time
|
||||
|
||||
import congress.policy.runtime as runtime
|
||||
|
||||
|
||||
def source_path():
|
||||
x = os.path.realpath(__file__)
|
||||
|
|
|
@ -24,13 +24,13 @@ import mox
|
|||
import neutronclient.v2_0
|
||||
import os
|
||||
|
||||
from congress.datasources.neutron_driver import NeutronDriver
|
||||
import congress.datasources.tests.unit.test_neutron_driver as test_neutron
|
||||
from congress import main
|
||||
import congress.policy.compile as compile
|
||||
import congress.policy.runtime as runtime
|
||||
from congress.tests import base
|
||||
import congress.tests.helper as helper
|
||||
from datasources.neutron_driver import NeutronDriver
|
||||
import datasources.tests.unit.test_neutron_driver as test_neutron
|
||||
import main
|
||||
import policy.compile as compile
|
||||
import policy.runtime as runtime
|
||||
|
||||
|
||||
class TestCongress(base.TestCase):
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 VMware, Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
SRCSCRIPT=`readlink -f $0`
|
||||
SCRIPTDIR=`dirname $SRCSCRIPT`
|
||||
ROOTDIR=`dirname $SCRIPTDIR`
|
||||
PYSRCDIR=$ROOTDIR/congress
|
||||
SERVERDIR=$PYSRCDIR/server
|
||||
THIRDPARTYDIR=$ROOTDIR/thirdparty
|
||||
|
||||
export PYTHONPATH=$PYSRCDIR:$THIRDPARTYDIR:$ROOTDIR
|
||||
|
||||
ARGS="$@"
|
||||
cd $SERVERDIR
|
||||
python congress_server.py $ARGS
|
|
@ -1,37 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Copyright (c) 2013 VMware, Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
# Usage: run_tests
|
||||
|
||||
# TODO(pjb): Run from a build (rather than source) dir
|
||||
# SRCSCRIPT=`readlink -f $0`
|
||||
SRCSCRIPT=`python -c 'import os,sys;print os.path.realpath(sys.argv[1])' $0`
|
||||
SCRIPTDIR=`dirname $SRCSCRIPT`
|
||||
ROOTDIR=`dirname $SCRIPTDIR`
|
||||
|
||||
SRCDIR=$ROOTDIR/congress
|
||||
THIRDPARTYDIR=$ROOTDIR/thirdparty
|
||||
TESTDIR=$ROOTDIR/congress/tests
|
||||
export PYTHONPATH=$SRCDIR:$THIRDPARTYDIR
|
||||
|
||||
# Use nosetests to find all unitests in tree
|
||||
ARGS="$@"
|
||||
cd $ROOTDIR
|
||||
nosetests $ARGS
|
||||
|
||||
#cd $ROOTDIR/congress/tests
|
||||
#nosetests functional/test_api.py
|
||||
|
Loading…
Reference in New Issue