diff --git a/ironic_python_agent/tests/functional/__init__.py b/ironic_python_agent/tests/functional/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ironic_python_agent/tests/functional/base.py b/ironic_python_agent/tests/functional/base.py new file mode 100644 index 000000000..7e2f5990f --- /dev/null +++ b/ironic_python_agent/tests/functional/base.py @@ -0,0 +1,58 @@ +# Copyright 2015 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. + +import logging +import multiprocessing +import os +import time + +from oslotest import base as test_base +import requests + +from ironic_python_agent import agent + + +class FunctionalBase(test_base.BaseTestCase): + def setUp(self): + """Start the agent and wait for it to start""" + super(FunctionalBase, self).setUp() + mpl = multiprocessing.log_to_stderr() + mpl.setLevel(logging.INFO) + test_port = os.environ.get('TEST_PORT', '9999') + # Build a basic standalone agent using the config option defaults. + # 127.0.0.1:6835 is the fake Ironic client. + self.agent = agent.IronicPythonAgent( + 'http://127.0.0.1:6835', 'localhost', ('0.0.0.0', + int(test_port)), 3, 10, None, 300, 1, + 'agent_ipmitool', True) + self.process = multiprocessing.Process( + target=self.agent.run) + self.process.start() + + # Wait for process to start, otherwise we have a race for tests + tries = 0 + max_tries = os.environ.get('IPA_WAIT_TIME', '2') + while tries < int(max_tries): + try: + return requests.get('http://localhost:%s/v1/commands' % + test_port) + except requests.ConnectionError: + time.sleep(.1) + tries += 1 + + raise IOError('Agent did not start after %s seconds.' % max_tries) + + def tearDown(self): + super(FunctionalBase, self).tearDown() + self.process.terminate() diff --git a/ironic_python_agent/tests/functional/test_commands.py b/ironic_python_agent/tests/functional/test_commands.py new file mode 100644 index 000000000..797485bdc --- /dev/null +++ b/ironic_python_agent/tests/functional/test_commands.py @@ -0,0 +1,26 @@ +# Copyright 2015 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. + +import os +import requests + +from ironic_python_agent.tests.functional import base + + +class TestCommands(base.FunctionalBase): + def test_empty_commands(self): + commands = requests.get('http://localhost:%s/v1/commands' % + os.environ.get('TEST_PORT', '9999')) + self.assertEqual(200, commands.status_code) + self.assertEqual({'commands': []}, commands.json()) diff --git a/ironic_python_agent/tests/unit/__init__.py b/ironic_python_agent/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ironic_python_agent/tests/agent.py b/ironic_python_agent/tests/unit/test_agent.py similarity index 100% rename from ironic_python_agent/tests/agent.py rename to ironic_python_agent/tests/unit/test_agent.py diff --git a/ironic_python_agent/tests/api.py b/ironic_python_agent/tests/unit/test_api.py similarity index 100% rename from ironic_python_agent/tests/api.py rename to ironic_python_agent/tests/unit/test_api.py diff --git a/ironic_python_agent/tests/backoff.py b/ironic_python_agent/tests/unit/test_backoff.py similarity index 100% rename from ironic_python_agent/tests/backoff.py rename to ironic_python_agent/tests/unit/test_backoff.py diff --git a/ironic_python_agent/tests/errors.py b/ironic_python_agent/tests/unit/test_errors.py similarity index 100% rename from ironic_python_agent/tests/errors.py rename to ironic_python_agent/tests/unit/test_errors.py diff --git a/ironic_python_agent/tests/hardware.py b/ironic_python_agent/tests/unit/test_hardware.py similarity index 100% rename from ironic_python_agent/tests/hardware.py rename to ironic_python_agent/tests/unit/test_hardware.py diff --git a/ironic_python_agent/tests/ironic_api_client.py b/ironic_python_agent/tests/unit/test_ironic_api_client.py similarity index 100% rename from ironic_python_agent/tests/ironic_api_client.py rename to ironic_python_agent/tests/unit/test_ironic_api_client.py diff --git a/ironic_python_agent/tests/multi_hardware.py b/ironic_python_agent/tests/unit/test_multi_hardware.py similarity index 100% rename from ironic_python_agent/tests/multi_hardware.py rename to ironic_python_agent/tests/unit/test_multi_hardware.py diff --git a/ironic_python_agent/tests/netutils.py b/ironic_python_agent/tests/unit/test_netutils.py similarity index 100% rename from ironic_python_agent/tests/netutils.py rename to ironic_python_agent/tests/unit/test_netutils.py diff --git a/ironic_python_agent/tests/utils.py b/ironic_python_agent/tests/unit/utils.py similarity index 100% rename from ironic_python_agent/tests/utils.py rename to ironic_python_agent/tests/unit/utils.py diff --git a/tox.ini b/tox.ini index 5928a3d42..70665912f 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,12 @@ envlist = py27,py34,pep8 [testenv] usedevelop = True install_command = pip install --allow-external -U {opts} {packages} -setenv = VIRTUAL_ENV={envdir} +# Define virtualenv directory, port to use for functional testing, and number +# of seconds to wait for the agent to come alive during functional testing. +setenv = + VIRTUAL_ENV={envdir} + TEST_PORT=9999 + IPA_WAIT_TIME=2 deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands =