From 738d215661c18aa3d37dd1262d6ca28045da5a7b Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 12 Mar 2015 17:18:36 +0100 Subject: [PATCH] Add initial compute functional tests to Shade Also, modified tox.ini to add a 'functional' stanza and the testenv now runs only unit tests. Change-Id: Id8a1193c829f7f3ab764c334b1f796f19f447fdd Depends-On: I1cf58e6a4cf728c5d2a32d602d9dfae1d4dfd62c --- .testr.conf | 4 +- shade/tests/functional/__init__.py | 0 .../tests/functional/hooks/post_test_hook.sh | 29 +++++++++ shade/tests/functional/test_compute.py | 59 +++++++++++++++++++ shade/tests/functional/util.py | 37 ++++++++++++ shade/tests/unit/__init__.py | 0 shade/tests/{ => unit}/test_meta.py | 0 shade/tests/{ => unit}/test_shade.py | 0 tox.ini | 4 ++ 9 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 shade/tests/functional/__init__.py create mode 100755 shade/tests/functional/hooks/post_test_hook.sh create mode 100644 shade/tests/functional/test_compute.py create mode 100644 shade/tests/functional/util.py create mode 100644 shade/tests/unit/__init__.py rename shade/tests/{ => unit}/test_meta.py (100%) rename shade/tests/{ => unit}/test_shade.py (100%) diff --git a/.testr.conf b/.testr.conf index fb622677a..3ce7ec2a9 100644 --- a/.testr.conf +++ b/.testr.conf @@ -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:-./shade/tests/unit} $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE -test_list_option=--list \ No newline at end of file +test_list_option=--list diff --git a/shade/tests/functional/__init__.py b/shade/tests/functional/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/shade/tests/functional/hooks/post_test_hook.sh b/shade/tests/functional/hooks/post_test_hook.sh new file mode 100755 index 000000000..ccf477455 --- /dev/null +++ b/shade/tests/functional/hooks/post_test_hook.sh @@ -0,0 +1,29 @@ +# -*- 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. + +export SHADE_DIR="$BASE/new/shade" + +cd $BASE/new/devstack +source openrc admin admin +unset OS_CACERT + +cd $SHADE_DIR +sudo chown -R jenkins:stack $SHADE_DIR +echo "Running shade functional test suite" +set +e +sudo -E -H -u jenkins tox -efunctional +EXIT_CODE=$? +set -e + +exit $EXIT_CODE diff --git a/shade/tests/functional/test_compute.py b/shade/tests/functional/test_compute.py new file mode 100644 index 000000000..6e456b1a8 --- /dev/null +++ b/shade/tests/functional/test_compute.py @@ -0,0 +1,59 @@ +# -*- 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_compute +---------------------------------- + +Functional tests for `shade` compute methods. +""" + +from novaclient.v2.servers import Server +from shade import openstack_cloud +from shade.tests import base +from shade.tests.functional.util import pick_flavor, pick_image + + +class TestCompute(base.TestCase): + def setUp(self): + super(TestCompute, self).setUp() + # Shell should have OS-* envvars from openrc, typically loaded by job + self.cloud = openstack_cloud() + self.nova = self.cloud.nova_client + self.flavor = pick_flavor(self.nova.flavors.list()) + if self.flavor is None: + self.addDetail('pick_flavor', 'no sensible flavor available') + self.image = pick_image(self.nova.images.list()) + if self.image is None: + self.addDetail('pick_image', 'no sensible image available') + self.addCleanup(self._cleanup_servers) + + def _cleanup_servers(self): + for i in self.nova.servers.list(): + if i.name.startswith('test'): + self.nova.servers.delete(i) + + def test_create_server(self): + server = self.cloud.create_server(name='test_create_server', + image=self.image, flavor=self.flavor) + self.assertIsInstance(server, Server) + self.assertEquals(server.name, 'test_create_server') + self.assertEquals(server.image['id'], self.image.id) + self.assertEquals(server.flavor['id'], self.flavor.id) + + def test_delete_server(self): + self.cloud.create_server(name='test_delete_server', + image=self.image, flavor=self.flavor) + server_deleted = self.cloud.delete_server('test_delete_server') + self.assertIsNone(server_deleted) diff --git a/shade/tests/functional/util.py b/shade/tests/functional/util.py new file mode 100644 index 000000000..bddb57f3e --- /dev/null +++ b/shade/tests/functional/util.py @@ -0,0 +1,37 @@ +# -*- 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. + +""" +util +-------------------------------- + +Util methods for functional tests +""" + + +def pick_flavor(flavors): + """Given a flavor list pick a reasonable one.""" + for flavor in flavors: + if flavor.name == 'm1.tiny': + return flavor + + for flavor in flavors: + if flavor.name == 'm1.small': + return flavor + + +def pick_image(images): + for image in images: + if image.name.startswith('cirros') and image.name.endswith('-uec'): + return image diff --git a/shade/tests/unit/__init__.py b/shade/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/shade/tests/test_meta.py b/shade/tests/unit/test_meta.py similarity index 100% rename from shade/tests/test_meta.py rename to shade/tests/unit/test_meta.py diff --git a/shade/tests/test_shade.py b/shade/tests/unit/test_shade.py similarity index 100% rename from shade/tests/test_shade.py rename to shade/tests/unit/test_shade.py diff --git a/tox.ini b/tox.ini index e0ff3d6e6..71cbd48c8 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,10 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = python setup.py testr --slowest --testr-args='{posargs}' +[testenv:functional] +setenv = + OS_TEST_PATH = ./shade/tests/functional + [testenv:pep8] commands = flake8