move all tests to nova/tests/unit

As part of the split of functional and unit tests we need to isolate
the unit tests into a separate directory for having multiple test
targets in a sane way.

Part of bp:functional-tests-for-nova

Change-Id: Id42ba373c1bda6a312b673ab2b489ca56da8c628
This commit is contained in:
Sean Dague
2014-11-07 14:27:03 +01:00
parent 830608f371
commit 38e320474a
55 changed files with 135 additions and 61 deletions

View File

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

View File

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

View File

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

View File

@@ -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"},

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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