Add basic functional tests

This patch add openstack client call, use openstack client
execute profile, policy, cluster, node, receiver, action,
event list operation.

Change-Id: I7f2a60c276f82ad9afab8130fea73fde078eff07
Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
Yuanbin.Chen 2018-01-18 09:56:28 +08:00
parent d509871913
commit cc62587035
19 changed files with 386 additions and 9 deletions

View File

@ -1,4 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_command=${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./senlinclient/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -52,13 +52,13 @@
fi
function pre_test_hook {
cd /opt/stack/new/python-senlinclient/senlinclient/tests/functional/
cd /opt/stack/new/python-senlinclient/senlinclient/tests/functional/hooks/
./pre_test_hook.sh
}
export -f pre_test_hook
function post_test_hook {
cd /opt/stack/new/python-senlinclient/senlinclient/tests/functional/
cd /opt/stack/new/python-senlinclient/senlinclient/tests/functional/hooks/
./post_test_hook.sh
}
export -f post_test_hook

View File

@ -0,0 +1,39 @@
# 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
from tempest.lib.cli import base
from tempest.lib.cli import output_parser
class OpenStackClientTestBase(base.ClientTestBase):
"""Command line client base functions."""
def setUp(self):
super(OpenStackClientTestBase, self).setUp()
self.parser = output_parser
def _get_clients(self):
cli_dir = os.environ.get(
'OS_SENLINCLIENT_EXEC_DIR',
os.path.join(os.path.abspath('.'), '.tox/functional/bin'))
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'),
cli_dir=cli_dir)
def openstack(self, *args, **kwargs):
return self.clients.openstack(*args, **kwargs)

View File

@ -16,17 +16,20 @@
export SENLINCLIENT_DIR="$BASE/new/python-senlinclient"
cd $BASE/new/devstack
source openrc admin admin
source $BASE/new/devstack/openrc admin admin
cd $SENLINCLIENT_DIR
sudo -E chown -R $USER:stack $SENLINCLIENT_DIR
# Run tests
echo "Running senlinclient functional test."
set +e
# TODO(Anyone): Running senlinclient functional test by running
# "tox -efunctional"
sudo -E -H -u $USER tox -efunctional
RESULT=$?
set -e
echo "Running senlinclient functional test succeeded."
echo "Completed running senlinclient functional test."
exit 0
exit $RESULT

View File

@ -0,0 +1,24 @@
# 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 senlinclient.tests.functional import base
class ActionTest(base.OpenStackClientTestBase):
"""Test for actions"""
def test_action_list(self):
result = self.openstack('cluster action list')
action_list = self.parser.listing(result)
self.assertTableStruct(action_list, ['id', 'name', 'action', 'status',
'target_id', 'depends_on',
'depended_by', 'created_at'])

View File

@ -0,0 +1,41 @@
# 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 senlinclient.tests.functional import base
class ClusterTest(base.OpenStackClientTestBase):
"""Test for clusters"""
def test_cluster_list(self):
result = self.openstack('cluster list')
cluster_list = self.parser.listing(result)
self.assertTableStruct(cluster_list, ['id', 'name', 'status',
'created_at', 'updated_at'])
def test_cluster_list_filters(self):
params = {'name': 'test1', 'status': 'ACTIVE'}
for k, v in params.items():
cmd = ('cluster list --filters %s=%s' % (k, v))
self.openstack(cmd)
def test_cluster_list_sort(self):
params = ['name', 'status', 'init_at', 'created_at', 'updated_at']
for param in params:
cmd = 'cluster list --sort %s' % param
self.openstack(cmd)
def test_cluster_full_id(self):
self.openstack('cluster list --full-id')
def test_cluster_limit(self):
self.openstack('cluster list --limit 1')

View File

@ -0,0 +1,24 @@
# 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 senlinclient.tests.functional import base
class EventTest(base.OpenStackClientTestBase):
"""Test for events"""
def test_event_list(self):
result = self.openstack('cluster event list')
event_list = self.parser.listing(result)
self.assertTableStruct(event_list, ['id', 'generated_at', 'obj_type',
'obj_id', 'obj_name', 'action',
'status', 'level', 'cluster_id'])

View File

@ -0,0 +1,22 @@
# 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 senlinclient.tests.functional import base
class HelpTest(base.OpenStackClientTestBase):
"""Test for help commands"""
def test_help_cmd(self):
help_text = self.openstack('help cluster list')
lines = help_text.split('\n')
self.assertFirstLineStartsWith(lines, 'usage: openstack cluster list')

View File

@ -0,0 +1,25 @@
# 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 senlinclient.tests.functional import base
class NodeTest(base.OpenStackClientTestBase):
"""Test for nodes"""
def test_node_list(self):
result = self.openstack('cluster node list')
node_list = self.parser.listing(result)
self.assertTableStruct(node_list, ['id', 'name', 'index', 'status',
'cluster_id', 'physical_id',
'profile_name', 'created_at',
'updated_at'])

View File

@ -0,0 +1,23 @@
# 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 senlinclient.tests.functional import base
class PolicyTest(base.OpenStackClientTestBase):
"""Test for policies"""
def test_policy_list(self):
result = self.openstack('cluster policy list')
policy_list = self.parser.listing(result)
self.assertTableStruct(policy_list, ['id', 'name', 'type',
'created_at'])

View File

@ -0,0 +1,35 @@
# 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 senlinclient.tests.functional import base
class PolicyTypeTest(base.OpenStackClientTestBase):
"""Test for policy types"""
def test_policy_type_list(self):
result = self.openstack('cluster policy type list')
policy_type = self.parser.listing(result)
self.assertTableStruct(policy_type, ['name', 'version',
'support_status'])
def test_policy_type_show(self):
params = ['senlin.policy.affinity-1.0',
'senlin.policy.batch-1.0',
'senlin.policy.deletion-1.0',
'senlin.policy.health-1.0',
'senlin.policy.loadbalance-1.1',
'senlin.policy.region_placement-1.0',
'senlin.policy.zone_placement-1.0']
for param in params:
cmd = 'cluster policy type show %s' % param
self.openstack(cmd)

View File

@ -0,0 +1,40 @@
# 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 senlinclient.tests.functional import base
class ProfileTypeTest(base.OpenStackClientTestBase):
"""Test for profile types
Basic smoke test for the Openstack CLI commands which do not require
creating or modifying.
"""
def test_profile_type_list(self):
result = self.openstack('cluster profile type list')
profile_type = self.parser.listing(result)
self.assertTableStruct(profile_type, ['name', 'version',
'support_status'])
def test_profile_list_debug(self):
self.openstack('cluster profile list', flags='--debug')
def test_profile_type_show(self):
params = ['container.dockerinc.docker-1.0',
'os.heat.stack-1.0',
'os.nova.server-1.0']
for param in params:
cmd = 'cluster profile type show %s' % param
self.openstack(cmd)
def test_profile_type_show_json(self):
self.openstack('cluster profile type show os.nova.server-1.0 -f json')

View File

@ -0,0 +1,23 @@
# 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 senlinclient.tests.functional import base
class ProfileTest(base.OpenStackClientTestBase):
"""Test for profiles"""
def test_profile_list(self):
result = self.openstack('cluster profile list')
profile_list = self.parser.listing(result)
self.assertTableStruct(profile_list, ['id', 'name', 'type',
'created_at'])

View File

@ -0,0 +1,24 @@
# 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 tempest.lib import exceptions
from senlinclient.tests.functional import base
class FakeTest(base.OpenStackClientTestBase):
"""Test if fake actions can be detected"""
def test_fake_action(self):
self.assertRaises(exceptions.CommandFailed,
self.openstack,
'this-does-not-exist')

View File

@ -0,0 +1,24 @@
# 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 senlinclient.tests.functional import base
class ReceiverTest(base.OpenStackClientTestBase):
"""Test for receivers"""
def test_receiver_list(self):
result = self.openstack('cluster receiver list')
receiver_list = self.parser.listing(result)
self.assertTableStruct(receiver_list, ['id', 'name', 'type',
'cluster_id', 'action',
'created_at'])

View File

@ -0,0 +1,20 @@
# 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 senlinclient.tests.functional import base
class VersionTest(base.OpenStackClientTestBase):
"""Test for versions"""
def test_openstack_version(self):
self.openstack('', flags='--version')

View File

@ -9,9 +9,11 @@ fixtures>=3.0.0 # Apache-2.0/BSD
requests-mock>=1.1.0 # Apache-2.0
mock>=2.0.0 # BSD
openstackdocstheme>=1.18.1 # Apache-2.0
python-openstackclient>=3.12.0 # Apache-2.0
oslotest>=3.2.0 # Apache-2.0
setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=16.0 # PSF/ZPL
sphinx!=1.6.6,>=1.6.2 # BSD
tempest>=17.1.0 # Apache-2.0
testrepository>=0.0.18 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=2.2.0 # MIT

View File

@ -4,6 +4,8 @@ minversion = 2.0
skipsdist = True
[testenv]
setenv = VIRTUAL_ENV={envdir}
CLIENT_NAME=python-senlinclient
usedevelop = True
install_command = pip install {opts} {packages}
deps =
@ -25,6 +27,12 @@ whitelist_externals = bash
[testenv:venv]
commands = {posargs}
[testenv:functional]
setenv =
{[testenv]setenv}
OS_TEST_PATH = ./senlinclient/tests/functional
passenv = OS_*
[testenv:cover]
commands =
python setup.py testr --coverage --testr-args='{posargs}'