diff --git a/nova/test.py b/nova/test.py index ef6d5b737..45e701571 100644 --- a/nova/test.py +++ b/nova/test.py @@ -54,8 +54,8 @@ from nova.openstack.common import log as nova_logging from nova import paths from nova import rpc from nova import service -from nova.tests import conf_fixture -from nova.tests import policy_fixture +from nova.tests.unit import conf_fixture +from nova.tests.unit import policy_fixture from nova import utils diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index a40a66648..e69de29bb 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -1,49 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# 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. - -""" -:mod:`nova.tests` -- Nova Unittests -===================================================== - -.. automodule:: nova.tests - :platform: Unix -""" - -# TODO(mikal): move eventlet imports to nova.__init__ once we move to PBR -import os -import sys -import traceback - - -# NOTE(mikal): All of this is because if dnspython is present in your -# environment then eventlet monkeypatches socket.getaddrinfo() with an -# implementation which doesn't work for IPv6. What we're checking here is -# that the magic environment variable was set when the import happened. -# NOTE(dims): Prevent this code from kicking in under docs generation -# as it leads to spurious errors/warning. -stack = traceback.extract_stack() -if ('eventlet' in sys.modules and - os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes' and - (len(stack) < 2 or 'sphinx' not in stack[-2][0])): - raise ImportError('eventlet imported before nova/cmd/__init__ ' - '(env var set to %s)' - % os.environ.get('EVENTLET_NO_GREENDNS')) - -os.environ['EVENTLET_NO_GREENDNS'] = 'yes' - -import eventlet - -eventlet.monkey_patch(os=False) diff --git a/nova/tests/functional/__init__.py b/nova/tests/functional/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/nova/tests/README.rst b/nova/tests/unit/README.rst similarity index 100% rename from nova/tests/README.rst rename to nova/tests/unit/README.rst diff --git a/nova/tests/unit/__init__.py b/nova/tests/unit/__init__.py new file mode 100644 index 000000000..31822c151 --- /dev/null +++ b/nova/tests/unit/__init__.py @@ -0,0 +1,49 @@ +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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. + +""" +:mod:`nova.tests.unit` -- Nova Unittests +===================================================== + +.. automodule:: nova.tests.unit + :platform: Unix +""" + +# TODO(mikal): move eventlet imports to nova.__init__ once we move to PBR +import os +import sys +import traceback + + +# NOTE(mikal): All of this is because if dnspython is present in your +# environment then eventlet monkeypatches socket.getaddrinfo() with an +# implementation which doesn't work for IPv6. What we're checking here is +# that the magic environment variable was set when the import happened. +# NOTE(dims): Prevent this code from kicking in under docs generation +# as it leads to spurious errors/warning. +stack = traceback.extract_stack() +if ('eventlet' in sys.modules and + os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes' and + (len(stack) < 2 or 'sphinx' not in stack[-2][0])): + raise ImportError('eventlet imported before nova/cmd/__init__ ' + '(env var set to %s)' + % os.environ.get('EVENTLET_NO_GREENDNS')) + +os.environ['EVENTLET_NO_GREENDNS'] = 'yes' + +import eventlet + +eventlet.monkey_patch(os=False) diff --git a/nova/tests/api/openstack/compute/contrib/test_aggregates.py b/nova/tests/unit/api/openstack/compute/contrib/test_aggregates.py similarity index 99% rename from nova/tests/api/openstack/compute/contrib/test_aggregates.py rename to nova/tests/unit/api/openstack/compute/contrib/test_aggregates.py index e1df95248..9b52146fa 100644 --- a/nova/tests/api/openstack/compute/contrib/test_aggregates.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_aggregates.py @@ -23,8 +23,8 @@ from nova.api.openstack.compute.plugins.v3 import aggregates as aggregates_v21 from nova import context from nova import exception from nova import test -from nova.tests.api.openstack import fakes -from nova.tests import matchers +from nova.tests.unit.api.openstack import fakes +from nova.tests.unit import matchers AGGREGATE_LIST = [ {"name": "aggregate1", "id": "1", "availability_zone": "nova1"}, diff --git a/nova/tests/integrated/api_samples/README.rst b/nova/tests/unit/integrated/api_samples/README.rst similarity index 94% rename from nova/tests/integrated/api_samples/README.rst rename to nova/tests/unit/integrated/api_samples/README.rst index 6395f4887..a08cac3a4 100644 --- a/nova/tests/integrated/api_samples/README.rst +++ b/nova/tests/unit/integrated/api_samples/README.rst @@ -11,7 +11,7 @@ for your tests. There should be both JSON and XML tests included. Then run the following command: - GENERATE_SAMPLES=True tox -epy27 nova.tests.integrated + GENERATE_SAMPLES=True tox -epy27 nova.tests.unit.integrated Which will create the files on doc/api_samples. diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-add-host-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-metadata-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-post-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-remove-host-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregate-update-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregate-update-post-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-add-host-post-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-get-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-get-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-get-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-get-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-get-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-get-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-get-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-get-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-list-get-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-list-get-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-list-get-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-list-get-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-metadata-post-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/aggregates-remove-host-post-resp.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/server-post-req.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/server-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/server-post-req.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/server-post-req.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/server-post-req.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/server-post-req.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/server-post-req.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/server-post-req.xml.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/server-post-resp.json.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/server-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/server-post-resp.json.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/server-post-resp.json.tpl diff --git a/nova/tests/integrated/api_samples/os-aggregates/server-post-resp.xml.tpl b/nova/tests/unit/integrated/api_samples/os-aggregates/server-post-resp.xml.tpl similarity index 100% rename from nova/tests/integrated/api_samples/os-aggregates/server-post-resp.xml.tpl rename to nova/tests/unit/integrated/api_samples/os-aggregates/server-post-resp.xml.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-add-host-post-req.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-metadata-post-req.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-post-req.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-post-req.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-post-req.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-post-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-post-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-post-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-remove-host-post-req.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-update-post-req.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-update-post-req.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-update-post-req.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-update-post-req.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregate-update-post-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-add-host-post-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-get-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-get-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-get-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-get-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-list-get-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-metadata-post-resp.json.tpl diff --git a/nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl b/nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl similarity index 100% rename from nova/tests/integrated/v3/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl rename to nova/tests/unit/integrated/v3/api_samples/os-aggregates/aggregates-remove-host-post-resp.json.tpl diff --git a/nova/tests/integrated/v3/test_aggregates.py b/nova/tests/unit/integrated/v3/test_aggregates.py similarity index 98% rename from nova/tests/integrated/v3/test_aggregates.py rename to nova/tests/unit/integrated/v3/test_aggregates.py index 819cf3447..6e29ea040 100644 --- a/nova/tests/integrated/v3/test_aggregates.py +++ b/nova/tests/unit/integrated/v3/test_aggregates.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova.tests.integrated.v3 import api_sample_base +from nova.tests.unit.integrated.v3 import api_sample_base class AggregatesSampleJsonTest(api_sample_base.ApiSampleTestBaseV3): diff --git a/nova/tests/objects/test_aggregate.py b/nova/tests/unit/objects/test_aggregate.py similarity index 98% rename from nova/tests/objects/test_aggregate.py rename to nova/tests/unit/objects/test_aggregate.py index 9492b26cf..67ea514bc 100644 --- a/nova/tests/objects/test_aggregate.py +++ b/nova/tests/unit/objects/test_aggregate.py @@ -18,8 +18,8 @@ from oslo.utils import timeutils from nova import db from nova import exception from nova.objects import aggregate -from nova.tests import fake_notifier -from nova.tests.objects import test_objects +from nova.tests.unit import fake_notifier +from nova.tests.unit.objects import test_objects NOW = timeutils.utcnow().replace(microsecond=0) diff --git a/nova/tests/unit/policy_fixture.py b/nova/tests/unit/policy_fixture.py new file mode 100644 index 000000000..cf2887524 --- /dev/null +++ b/nova/tests/unit/policy_fixture.py @@ -0,0 +1,73 @@ +# Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# 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 fixtures +from oslo.config import cfg +from oslo.serialization import jsonutils + +from nova.openstack.common import policy as common_policy +import nova.policy +from nova.tests.unit import fake_policy + +CONF = cfg.CONF + + +class PolicyFixture(fixtures.Fixture): + + def setUp(self): + super(PolicyFixture, self).setUp() + self.policy_dir = self.useFixture(fixtures.TempDir()) + self.policy_file_name = os.path.join(self.policy_dir.path, + 'policy.json') + with open(self.policy_file_name, 'w') as policy_file: + policy_file.write(fake_policy.policy_data) + CONF.set_override('policy_file', self.policy_file_name) + nova.policy.reset() + nova.policy.init() + self.addCleanup(nova.policy.reset) + + def set_rules(self, rules): + policy = nova.policy._ENFORCER + policy.set_rules(dict((k, common_policy.parse_rule(v)) + for k, v in rules.items())) + + +class RoleBasedPolicyFixture(fixtures.Fixture): + + def __init__(self, role="admin", *args, **kwargs): + super(RoleBasedPolicyFixture, self).__init__(*args, **kwargs) + self.role = role + + def setUp(self): + """Copy live policy.json file and convert all actions to + allow users of the specified role only + """ + super(RoleBasedPolicyFixture, self).setUp() + policy = jsonutils.load(open(CONF.policy_file)) + + # Convert all actions to require specified role + for action, rule in policy.iteritems(): + policy[action] = 'role:%s' % self.role + + self.policy_dir = self.useFixture(fixtures.TempDir()) + self.policy_file_name = os.path.join(self.policy_dir.path, + 'policy.json') + with open(self.policy_file_name, 'w') as policy_file: + jsonutils.dump(policy, policy_file) + CONF.set_override('policy_file', self.policy_file_name) + nova.policy.reset() + nova.policy.init() + self.addCleanup(nova.policy.reset) diff --git a/nova/tests/scheduler/filters/test_aggregate_image_properties_isolation_filters.py b/nova/tests/unit/scheduler/filters/test_aggregate_image_properties_isolation_filters.py similarity index 99% rename from nova/tests/scheduler/filters/test_aggregate_image_properties_isolation_filters.py rename to nova/tests/unit/scheduler/filters/test_aggregate_image_properties_isolation_filters.py index b574350f0..b4eacf321 100644 --- a/nova/tests/scheduler/filters/test_aggregate_image_properties_isolation_filters.py +++ b/nova/tests/unit/scheduler/filters/test_aggregate_image_properties_isolation_filters.py @@ -14,7 +14,7 @@ import mock from nova.scheduler.filters import aggregate_image_properties_isolation as aipi from nova import test -from nova.tests.scheduler import fakes +from nova.tests.unit.scheduler import fakes @mock.patch('nova.db.aggregate_metadata_get_by_host') diff --git a/nova/tests/scheduler/filters/test_aggregate_instance_extra_specs_filters.py b/nova/tests/unit/scheduler/filters/test_aggregate_instance_extra_specs_filters.py similarity index 98% rename from nova/tests/scheduler/filters/test_aggregate_instance_extra_specs_filters.py rename to nova/tests/unit/scheduler/filters/test_aggregate_instance_extra_specs_filters.py index c534b6c3f..451284106 100644 --- a/nova/tests/scheduler/filters/test_aggregate_instance_extra_specs_filters.py +++ b/nova/tests/unit/scheduler/filters/test_aggregate_instance_extra_specs_filters.py @@ -14,7 +14,7 @@ import mock from nova.scheduler.filters import aggregate_instance_extra_specs as agg_specs from nova import test -from nova.tests.scheduler import fakes +from nova.tests.unit.scheduler import fakes @mock.patch('nova.db.aggregate_metadata_get_by_host') diff --git a/nova/tests/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py b/nova/tests/unit/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py similarity index 98% rename from nova/tests/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py rename to nova/tests/unit/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py index 5691f40a2..70fe5e2d4 100644 --- a/nova/tests/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py +++ b/nova/tests/unit/scheduler/filters/test_aggregate_multitenancy_isolation_filters.py @@ -14,7 +14,7 @@ import mock from nova.scheduler.filters import aggregate_multitenancy_isolation as ami from nova import test -from nova.tests.scheduler import fakes +from nova.tests.unit.scheduler import fakes @mock.patch('nova.db.aggregate_metadata_get_by_host') diff --git a/nova/tests/volume/encryptors/test_cryptsetup.py b/nova/tests/unit/volume/encryptors/test_cryptsetup.py similarity index 98% rename from nova/tests/volume/encryptors/test_cryptsetup.py rename to nova/tests/unit/volume/encryptors/test_cryptsetup.py index 5ed64217f..ab84d17d9 100644 --- a/nova/tests/volume/encryptors/test_cryptsetup.py +++ b/nova/tests/unit/volume/encryptors/test_cryptsetup.py @@ -18,7 +18,7 @@ import array import os from nova.keymgr import key -from nova.tests.volume.encryptors import test_base +from nova.tests.unit.volume.encryptors import test_base from nova import utils from nova.volume.encryptors import cryptsetup diff --git a/tox.ini b/tox.ini index 0624819d9..484e47977 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ install_command = pip install -U --force-reinstall {opts} {packages} # random hash seed successfully. setenv = VIRTUAL_ENV={envdir} PYTHONHASHSEED=0 + OS_TEST_PATH=./nova/tests/unit deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands =