Start writing tests

Also, sync requirements with Neutron.

Partial-Bug: #1501792
Change-Id: Ib5f70646ddcbc807d45c8d352219029a8d9530d1
This commit is contained in:
YAMAMOTO Takashi 2015-10-02 01:49:11 +09:00
parent fe4e5cdcfa
commit 7dc7c7cdb0
10 changed files with 110 additions and 60 deletions

View File

@ -2,6 +2,6 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./neutron_taas/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 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.
from oslotest import base
class TestCase(base.BaseTestCase):
"""Test case base class for all unit tests."""

View File

@ -1,28 +0,0 @@
# -*- coding: utf-8 -*-
# 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.
"""
test_neutron_taas
----------------------------------
Tests for `neutron_taas` module.
"""
from neutron_taas.tests import base
class TestNeutron_taas(base.TestCase):
def test_something(self):
pass

View File

View File

@ -0,0 +1,96 @@
# Copyright (C) 2015 Midokura SARL.
# 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 mock
import testtools
from oslo_utils import uuidutils
import neutron.common.rpc as n_rpc
from neutron import context
from neutron.tests.unit import testlib_api
import neutron_taas.db.taas_db # noqa
import neutron_taas.extensions.taas as taas_ext
from neutron_taas.services.taas import taas_plugin
class TestTaasPlugin(testlib_api.SqlTestCaseLight):
def setUp(self):
super(TestTaasPlugin, self).setUp()
mock.patch.object(n_rpc, 'create_connection', auto_spec=True).start()
mock.patch.object(taas_plugin, 'TaasCallbacks', auto_spec=True).start()
mock.patch.object(taas_plugin, 'TaasAgentApi', auto_spec=True).start()
self._plugin = taas_plugin.TaasPlugin()
self._context = context.get_admin_context()
def test_create_tap_service(self):
tenant_id = 'tenant-X'
network_id = uuidutils.generate_uuid()
host_id = 'host-A'
port_id = uuidutils.generate_uuid()
port_details = {
'tenant_id': tenant_id,
'binding:host_id': host_id,
}
tap_service = {
'tenant_id': tenant_id,
'name': 'MyTap',
'description': 'This is my tap service',
'port_id': port_id,
'network_id': network_id,
}
req = {
'tap_service': tap_service,
}
with mock.patch.object(self._plugin, '_get_port_details',
return_value=port_details):
self._plugin.create_tap_service(self._context, req)
tap_service['id'] = mock.ANY
expected_msg = {
'tap_service': tap_service,
'taas_id': mock.ANY,
'port': port_details,
}
self.assertEqual(
[
mock.call.create_tap_service(self._context, expected_msg,
host_id)
], self._plugin.agent_rpc.mock_calls)
def test_create_tap_service_wrong_tenant_id(self):
tenant_id = 'tenant-X'
network_id = uuidutils.generate_uuid()
host_id = 'host-A'
port_id = uuidutils.generate_uuid()
port_details = {
'tenant_id': 'other-tenant',
'binding:host_id': host_id,
}
tap_service = {
'tenant_id': tenant_id,
'name': 'MyTap',
'description': 'This is my tap service',
'port_id': port_id,
'network_id': network_id,
}
req = {
'tap_service': tap_service,
}
with mock.patch.object(self._plugin, '_get_port_details',
return_value=port_details), \
testtools.ExpectedException(taas_ext.PortDoesNotBelongToTenant):
self._plugin.create_tap_service(self._context, req)
self.assertEqual([], self._plugin.agent_rpc.mock_calls)

View File

@ -2,5 +2,6 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
pbr>=0.6,!=0.7,<1.0
pbr>=1.6
Babel>=1.3
-e git://git.openstack.org/openstack/neutron.git@master#egg=neutron

View File

@ -6,9 +6,10 @@ hacking<0.11,>=0.10.0
coverage>=3.6
python-subunit>=0.0.18
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
oslosphinx>=2.2.0 # Apache-2.0
oslotest>=1.2.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.1.0
testrepository>=0.0.18
testscenarios>=0.4
testtools>=0.9.36,!=1.2.0

13
tox.ini
View File

@ -1,16 +1,19 @@
[tox]
minversion = 1.6
envlist = py27,pep8
envlist = docs,py27,py34,pep8
minversion = 1.8
skipsdist = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py test --slowest --testr-args='{posargs}'
commands = ostestr --regex '{posargs}'
[tox:jenkins]
sitepackages = True
downloadcache = ~/cache/pip
[testenv:pep8]
commands = flake8