From 1a87ebfcce7be6e10bed23b64f87a0110e76a22b Mon Sep 17 00:00:00 2001 From: Josh Gachnang Date: Thu, 3 Apr 2014 14:02:53 -0700 Subject: [PATCH] Adding oslotest to improve debugging oslotest includes things like showing log messages/stdout on test errors, which makes debugging much easier. Also moved mock to second group in imports, as it's a 3rd party library. Change-Id: I016ae0a376d42dec28085687ea7194df4cd44eda --- ironic_python_agent/tests/__init__.py | 15 --------------- ironic_python_agent/tests/agent.py | 14 ++++++++------ ironic_python_agent/tests/api.py | 7 ++++--- ironic_python_agent/tests/configdrive.py | 6 ++++-- ironic_python_agent/tests/decom.py | 6 +++--- ironic_python_agent/tests/hardware.py | 5 +++-- ironic_python_agent/tests/ironic_api_client.py | 9 +++++---- ironic_python_agent/tests/standby.py | 5 +++-- openstack-common.conf | 1 + requirements.txt | 1 + 10 files changed, 32 insertions(+), 37 deletions(-) diff --git a/ironic_python_agent/tests/__init__.py b/ironic_python_agent/tests/__init__.py index 13e76de9f..e69de29bb 100644 --- a/ironic_python_agent/tests/__init__.py +++ b/ironic_python_agent/tests/__init__.py @@ -1,15 +0,0 @@ -""" -Copyright 2013 Rackspace, Inc. - -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. -""" diff --git a/ironic_python_agent/tests/agent.py b/ironic_python_agent/tests/agent.py index ee8437d20..3a25cd707 100644 --- a/ironic_python_agent/tests/agent.py +++ b/ironic_python_agent/tests/agent.py @@ -16,9 +16,9 @@ limitations under the License. import json import time -import unittest import mock +from oslotest import base as test_base import pkg_resources from stevedore import extension from wsgiref import simple_server @@ -45,8 +45,9 @@ class FakeExtension(base.BaseAgentExtension): super(FakeExtension, self).__init__('FAKE') -class TestHeartbeater(unittest.TestCase): +class TestHeartbeater(test_base.BaseTestCase): def setUp(self): + super(TestHeartbeater, self).setUp() self.mock_agent = mock.Mock() self.heartbeater = agent.IronicPythonAgentHeartbeater(self.mock_agent) self.heartbeater.api = mock.Mock() @@ -118,8 +119,9 @@ class TestHeartbeater(unittest.TestCase): self.assertEqual(self.heartbeater.error_delay, 2.7) -class TestBaseAgent(unittest.TestCase): +class TestBaseAgent(test_base.BaseTestCase): def setUp(self): + super(TestBaseAgent, self).setUp() self.encoder = encoding.RESTJSONEncoder(indent=4) self.agent = agent.IronicPythonAgent('https://fake_api.example.' 'org:8081/', @@ -244,9 +246,10 @@ class TestBaseAgent(unittest.TestCase): self.assertEqualEncoded(result, expected_result) -class TestAgentCmd(unittest.TestCase): +class TestAgentCmd(test_base.BaseTestCase): + @mock.patch('ironic_python_agent.openstack.common.log.getLogger') @mock.patch('__builtin__.open') - def test__get_kernel_params_fail(self, open_mock): + def test__get_kernel_params_fail(self, logger_mock, open_mock): open_mock.side_effect = Exception params = agent_cmd._get_kernel_params() self.assertEqual(params, {}) @@ -258,7 +261,6 @@ class TestAgentCmd(unittest.TestCase): open_mock.return_value.__exit__ = mock.Mock() read_mock = open_mock.return_value.read read_mock.return_value = kernel_line - params = agent_cmd._get_kernel_params() self.assertEqual(params['api-url'], 'http://localhost:9999') self.assertEqual(params['foo'], 'bar') diff --git a/ironic_python_agent/tests/api.py b/ironic_python_agent/tests/api.py index f4e253457..f6425a9fc 100644 --- a/ironic_python_agent/tests/api.py +++ b/ironic_python_agent/tests/api.py @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. """ -import mock import time -import unittest +import mock +from oslotest import base as test_base import pecan import pecan.testing @@ -28,7 +28,7 @@ from ironic_python_agent import base PATH_PREFIX = '/v1' -class TestIronicAPI(unittest.TestCase): +class TestIronicAPI(test_base.BaseTestCase): def setUp(self): super(TestIronicAPI, self).setUp() @@ -36,6 +36,7 @@ class TestIronicAPI(unittest.TestCase): self.app = self._make_app(self.mock_agent) def tearDown(self): + super(TestIronicAPI, self).tearDown() pecan.set_config({}, overwrite=True) def _make_app(self, enable_acl=False): diff --git a/ironic_python_agent/tests/configdrive.py b/ironic_python_agent/tests/configdrive.py index fffedbebf..209b078ee 100644 --- a/ironic_python_agent/tests/configdrive.py +++ b/ironic_python_agent/tests/configdrive.py @@ -18,15 +18,17 @@ from __future__ import unicode_literals import base64 import json + import mock -import unittest +from oslotest import base as test_base from ironic_python_agent import configdrive from ironic_python_agent import utils -class ConfigDriveWriterTestCase(unittest.TestCase): +class ConfigDriveWriterTestCase(test_base.BaseTestCase): def setUp(self): + super(ConfigDriveWriterTestCase, self).setUp() self.writer = configdrive.ConfigDriveWriter() self.maxDiff = None diff --git a/ironic_python_agent/tests/decom.py b/ironic_python_agent/tests/decom.py index 737cd7971..11f68d822 100644 --- a/ironic_python_agent/tests/decom.py +++ b/ironic_python_agent/tests/decom.py @@ -13,14 +13,14 @@ 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 unittest +from oslotest import base as test_base from ironic_python_agent import decom -class TestDecomExtension(unittest.TestCase): +class TestDecomExtension(test_base.BaseTestCase): def setUp(self): + super(TestDecomExtension, self).setUp() self.agent_extension = decom.DecomExtension() def test_decom_extension(self): diff --git a/ironic_python_agent/tests/hardware.py b/ironic_python_agent/tests/hardware.py index 4db844cf6..ad02d9b07 100644 --- a/ironic_python_agent/tests/hardware.py +++ b/ironic_python_agent/tests/hardware.py @@ -15,13 +15,14 @@ limitations under the License. """ import mock -import unittest +from oslotest import base as test_base from ironic_python_agent import hardware -class TestGenericHardwareManager(unittest.TestCase): +class TestGenericHardwareManager(test_base.BaseTestCase): def setUp(self): + super(TestGenericHardwareManager, self).setUp() self.hardware = hardware.GenericHardwareManager() @mock.patch('os.listdir') diff --git a/ironic_python_agent/tests/ironic_api_client.py b/ironic_python_agent/tests/ironic_api_client.py index 888e3db83..08593a4ca 100644 --- a/ironic_python_agent/tests/ironic_api_client.py +++ b/ironic_python_agent/tests/ironic_api_client.py @@ -15,16 +15,16 @@ limitations under the License. """ import json -import mock import time -import unittest + +import mock +from oslotest import base as test_base from ironic_python_agent import errors from ironic_python_agent import hardware from ironic_python_agent import ironic_api_client from ironic_python_agent.openstack.common import loopingcall - API_URL = 'http://agent-api.ironic.example.org/' @@ -36,8 +36,9 @@ class FakeResponse(object): self.headers = headers or {} -class TestBaseIronicPythonAgent(unittest.TestCase): +class TestBaseIronicPythonAgent(test_base.BaseTestCase): def setUp(self): + super(TestBaseIronicPythonAgent, self).setUp() self.api_client = ironic_api_client.APIClient(API_URL) self.hardware_info = [ hardware.HardwareInfo(hardware.HardwareType.MAC_ADDRESS, diff --git a/ironic_python_agent/tests/standby.py b/ironic_python_agent/tests/standby.py index c88ccf4a8..0a2248af2 100644 --- a/ironic_python_agent/tests/standby.py +++ b/ironic_python_agent/tests/standby.py @@ -15,14 +15,15 @@ limitations under the License. """ import mock -import unittest +from oslotest import base as test_base from ironic_python_agent import errors from ironic_python_agent import standby -class TestStandbyExtension(unittest.TestCase): +class TestStandbyExtension(test_base.BaseTestCase): def setUp(self): + super(TestStandbyExtension, self).setUp() self.agent_extension = standby.StandbyExtension() def test_standby_extension(self): diff --git a/openstack-common.conf b/openstack-common.conf index a33869d3e..7295fadb9 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -6,5 +6,6 @@ module=gettextutils module=log module=loopingcall module=processutils + # The base module to hold the copy of openstack.common base=ironic_python_agent diff --git a/requirements.txt b/requirements.txt index ab13e7701..6c69480cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ eventlet>=0.13.0 oslo.config>=1.2.0 Babel>=1.3 iso8601>=0.1.9 +oslotest==1.0 \ No newline at end of file