From c97f5c718a4548c7796c2eb6eb6520c9931a222c Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Thu, 14 Feb 2013 01:15:57 +0000 Subject: [PATCH] First commit for python client test suite * Create a new top level directory for the tests: cli * Adds simple read only python-novaclient (compute) test Change-Id: I83e9171c119980951ee0866ec94847dd8c15f645 --- cli/__init__.py | 36 ++++++++++ cli/simple_read_only/README.txt | 1 + cli/simple_read_only/__init__.py | 0 cli/simple_read_only/test_compute.py | 104 +++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 cli/__init__.py create mode 100644 cli/simple_read_only/README.txt create mode 100644 cli/simple_read_only/__init__.py create mode 100644 cli/simple_read_only/test_compute.py diff --git a/cli/__init__.py b/cli/__init__.py new file mode 100644 index 0000000000..cea0b621fd --- /dev/null +++ b/cli/__init__.py @@ -0,0 +1,36 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# +# 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 + +from tempest.openstack.common import cfg + +LOG = logging.getLogger(__name__) + +cli_opts = [ + cfg.BoolOpt('enabled', + default=True, + help="enable cli tests"), + cfg.StrOpt('cli_dir', + default='/usr/local/bin/', + help="directory where python client binaries are located"), +] + +CONF = cfg.CONF +cli_group = cfg.OptGroup(name='cli', title="cli Configuration Options") +CONF.register_group(cli_group) +CONF.register_opts(cli_opts, group=cli_group) diff --git a/cli/simple_read_only/README.txt b/cli/simple_read_only/README.txt new file mode 100644 index 0000000000..ca5fa2f6f2 --- /dev/null +++ b/cli/simple_read_only/README.txt @@ -0,0 +1 @@ +This directory consists of simple read only python client tests. diff --git a/cli/simple_read_only/__init__.py b/cli/simple_read_only/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cli/simple_read_only/test_compute.py b/cli/simple_read_only/test_compute.py new file mode 100644 index 0000000000..742b5a4310 --- /dev/null +++ b/cli/simple_read_only/test_compute.py @@ -0,0 +1,104 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# +# 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 shlex +import subprocess + +import testtools + +import cli + +from tempest import config +from tempest.openstack.common import cfg + + +CONF = cfg.CONF + + +LOG = logging.getLogger(__name__) + + +class SimpleReadOnlyNovaCLientTest(testtools.TestCase): + + """ + This is a first pass at a simple read only python-novaclient test. This + only exercises client commands that are read only. + + This should test commands: + * as a regular user + * as a admin user + * with and without optional parameters + * initially just check return codes, and later test command outputs + + """ + + @classmethod + def setUpClass(cls): + if not CONF.cli.enabled: + msg = "cli testing disabled" + raise cls.skipException(msg) + cls.identity = config.TempestConfig().identity + super(SimpleReadOnlyNovaCLientTest, cls).setUpClass() + + def nova(self, action, flags='', params='', admin=True, fail_ok=False): + """Executes nova command for the given action.""" + #TODO(jogo) make admin=False work + creds = ('--os-username %s --os-tenant-name %s --os-password %s ' + '--os-auth-url %s ' % (self.identity.admin_username, + self.identity.admin_tenant_name, self.identity.admin_password, + self.identity.uri)) + flags = creds + ' ' + flags + cmd = ' '.join([CONF.cli.cli_dir + 'nova', flags, action, params]) + LOG.info("running: '%s'" % cmd) + cmd = shlex.split(cmd) + result = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + return result + + def test_admin_version(self): + self.nova('', flags='--version') + + def test_admin_timing(self): + self.nova('list', flags='--timing') + + def test_admin_timeout(self): + self.nova('list', flags='--timeout 2') + + def test_admin_debug_list(self): + self.nova('list', flags='--debug') + + def test_admin_fake_action(self): + self.assertRaises(subprocess.CalledProcessError, + self.nova, + 'this-does-nova-exist') + + def test_admin_aggregate_list(self): + self.nova('aggregate-list') + + def test_admin_cloudpipe_list(self): + self.nova('cloudpipe-list') + + def test_admin_image_list(self): + self.nova('image-list') + + def test_admin_dns_domains(self): + self.nova('dns-domains') + + def test_admin_flavor_list(self): + self.nova('flavor-list') + + #TODO(jogo) add more tests