Move CLI tests under sahara_tempest_plugin

They are in fact Tempest-based tests. Moving them under sahara_tempest_plugin
- removes the need of an additional entry point, which would be complicated
  if not impossibile to handle;
- allows tests to be run like other Tempest tests;
- allows us to share code (like generic templates when certain plugins are
  enabled).

The handling of test initializations does not rely on pre- or post- scripts
as before:
- image upload is handled by devstack (URL specified in the pre- script);
- the special flavor is created on demand by the test which requires it.

There are also few code fixes.

TODO: remove hardcoded values in favor of tempest configuration (image name
and user, plugin options).

Change-Id: Ibcc30c81f94e300001ffa409635cba5c5677cb19
This commit is contained in:
Luigi Toscano 2016-08-02 10:18:11 +02:00
parent 1409bc4e1d
commit 12872a59c2
17 changed files with 57 additions and 111 deletions

View File

@ -1,21 +0,0 @@
================
Sahara CLI Tests
================
This directory contains tests to cover CLI commands of saharaclient.
To run these tests, you need export the next variables:
- OS_USERNAME
- OS_TENANT_NAME
- OS_PASSWORD
- OS_AUTH_URL
Also you need to install saharaclient on env, and Sahara should be correctly
configured and be working.
After this, you just run tests with the command:
.. sourcecode:: console
$ tox -e cli-tests
..

View File

@ -13,6 +13,7 @@
import os
from tempest.lib.cli import base
from tempest.test import BaseTestCase
class ClientTestBase(base.ClientTestBase):
@ -23,15 +24,26 @@ class ClientTestBase(base.ClientTestBase):
"""
def _get_clients(self):
cli_dir = os.environ.get(
'OS_SAHARA_TESTS_DIR',
os.path.join(os.path.abspath('.'), '.tox/cli-tests/bin'))
cli_dir = os.environ.get('OS_SAHARA_TESTS_DIR', '')
if not cli_dir:
# if this is executed in a virtualenv, the command installed there
# will be the first one.
paths = os.environ.get('PATH').split(':')
for path in paths:
client_candidate = os.path.join(path, 'openstack')
if os.path.isfile(client_candidate) and os.access(
client_candidate, os.X_OK):
cli_dir = path
break
self.client_manager_admin = BaseTestCase.get_client_manager('admin')
auth_provider = self.client_manager_admin.auth_provider
return base.CLIClient(
username=os.environ.get('OS_USERNAME'),
password=os.environ.get('OS_PASSWORD'),
tenant_name=os.environ.get('OS_TENANT_NAME'),
uri=os.environ.get('OS_AUTH_URL'),
username=auth_provider.credentials.get('username'),
password=auth_provider.credentials.get('password'),
tenant_name=auth_provider.credentials.get('tenant_name'),
uri=auth_provider.base_url({'service': 'identity'}),
cli_dir=cli_dir)
def openstack(self, *args, **kwargs):
@ -56,8 +68,10 @@ class ClientTestBase(base.ClientTestBase):
params=name)
result = ('''\
%s "%s" has been removed successfully.
''' % command % name)
self.assertEqual(delete_cmd, result)
''' % (command, name))
# lower() is required because "command" in the result string could
# have the first letter capitalized.
self.assertEqual(delete_cmd.lower(), result.lower())
def find_fake_plugin(self):
found_plugin = None

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
from tempest.lib.common.utils import data_utils

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
from tempest.lib.common.utils import data_utils

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaDataSourceCLITest(base.ClientTestBase):

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaImageCLITest(base.ClientTestBase):
@ -30,7 +30,7 @@ class SaharaImageCLITest(base.ClientTestBase):
flag = None
for image_name in images_name:
if image_name == name_to_register:
flag = ''.join([' --username fedora ', image_name])
flag = ''.join([' --username ubuntu ', image_name])
if flag is None:
raise self.skipException('No available image for testing')
self.assertTableStruct(
@ -48,7 +48,7 @@ class SaharaImageCLITest(base.ClientTestBase):
])
def openstack_image_tags_add(self, image_name):
flag = ''.join([image_name, ' --tags test'])
flag = ''.join([image_name, ' --tags fake 0.1'])
self.assertTableStruct(
self.listing_result(''.join(['image tags add ', flag])), [
'Field',

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaJobBinaryCLITest(base.ClientTestBase):

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaJobTemplateCLITest(base.ClientTestBase):

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaJobTypeCLITest(base.ClientTestBase):

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaJobCLITest(base.ClientTestBase):

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
from tempest.lib.common.utils import data_utils

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import base
from sahara_tempest_plugin.tests.cli import base
class SaharaPluginCLITest(base.ClientTestBase):

View File

@ -10,16 +10,18 @@
# License for the specific language governing permissions and limitations
# under the License.
from sahara_cli_tests import clusters
from sahara_cli_tests import cluster_templates
from sahara_cli_tests import images
from sahara_cli_tests import node_group_templates
from sahara_cli_tests import plugins
from sahara_cli_tests import job_binaries
from sahara_cli_tests import jobs
from sahara_cli_tests import job_templates
from sahara_cli_tests import data_sources
from sahara_cli_tests import job_types
import time
from sahara_tempest_plugin.tests.cli import clusters
from sahara_tempest_plugin.tests.cli import cluster_templates
from sahara_tempest_plugin.tests.cli import images
from sahara_tempest_plugin.tests.cli import node_group_templates
from sahara_tempest_plugin.tests.cli import plugins
from sahara_tempest_plugin.tests.cli import job_binaries
from sahara_tempest_plugin.tests.cli import jobs
from sahara_tempest_plugin.tests.cli import job_templates
from sahara_tempest_plugin.tests.cli import data_sources
from sahara_tempest_plugin.tests.cli import job_types
from tempest.test import BaseTestCase
class Scenario(images.SaharaImageCLITest,
@ -61,10 +63,17 @@ class Scenario(images.SaharaImageCLITest,
self.openstack_node_group_template_delete(ng_worker)
def test_cluster_cli(self):
image_name = self.openstack_image_register('fedora-heat-test-image')
image_name = self.openstack_image_register(
'xenial-server-cloudimg-amd64-disk1')
self.openstack_image_tags_add(image_name)
self.openstack_image_show(image_name)
self.openstack_image_list()
flavors_client = self.client_manager_admin.flavors_client
flavor_ref = flavors_client.create_flavor(name='sahara-flavor',
ram=512, vcpus=1, disk=4,
id=20)['flavor']
self.addCleanup(flavors_client.delete_flavor, flavor_ref['id'])
ng_master = self.openstack_node_group_template_create('cli-cluster'
'-master',
'sahara-flavor')
@ -78,6 +87,8 @@ class Scenario(images.SaharaImageCLITest,
self.openstack_cluster_list()
self.openstack_cluster_show(cluster_name)
self.openstack_cluster_delete(cluster_name)
# FIXME: this should be replaced by a proper busy waiting
time.sleep(300)
self.openstack_cluster_template_delete(cluster_template_name)
self.openstack_node_group_template_delete(ng_master)
self.openstack_node_group_template_delete(ng_worker)

View File

@ -23,13 +23,3 @@ export SAHARA_TESTS_DIR=${SAHARA_TESTS_DIR:-$DEST/sahara-tests}
export LOCALRC_PATH=$DEVSTACK_DIR/localrc
export LOCALCONF_PATH=$DEVSTACK_DIR/local.conf
function sahara_prepare_fake_plugin_image {
openstack --os-url $GLANCE_SERVICE_PROTOCOL://$GLANCE_HOSTPORT --os-image-api-version 1 image set \
$SAHARA_FAKE_PLUGIN_IMAGE_NAME --public
}
function sahara_register_flavor {
nova flavor-create $SAHARA_FLAVOR_NAME $SAHARA_FLAVOR_ID $SAHARA_FLAVOR_RAM \
$SAHARA_FLAVOR_DISK $SAHARA_FLAVOR_VCPUS
}

View File

@ -1,42 +0,0 @@
#!/bin/bash -xe
# 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.
# This script is executed inside post_test_hook function in devstack gate.
source commons $@
export DEST=${DEST:-$BASE/new}
export DEVSTACK_DIR=${DEVSTACK_DIR:-$DEST/devstack}
export SAHARA_TESTS_DIR="$BASE/new/sahara-tests"
# Get admin credentials
set +x
source $DEVSTACK_DIR/stackrc
source $DEVSTACK_DIR/openrc admin admin
set -x
# Prepare image for Sahara
sahara_prepare_fake_plugin_image
# Register sahara specific flavor for gate
sahara_register_flavor
# Go to the sahara-tests dir
sudo chown -R jenkins:stack $SAHARA_TESTS_DIR
cd $SAHARA_TESTS_DIR
# Run sahara cli tests
echo "Running sahara cli test suite"
sudo -E -H -u jenkins tox -e cli-tests

View File

@ -33,12 +33,6 @@ commands =
whitelist_externals =
rm
[testenv:cli-tests]
passenv = OS_*
setenv =
DISCOVER_DIRECTORY=sahara_cli_tests
commands = ostestr {posargs}
[tox:jenkins]
downloadcache = ~/cache/pip