Functional tests for flavors with public and non-public access

The added tests check granting access actions for public and
non-public flavors

The test for microversion 2.7 checks that the appropriate
error is returned when attempting to grant an access
to a public flavor for the given tenant

The base TenantTest class has been added to avoid code
duplication in test_keypairs and test_flavor_access tests

Also, test_keypairs code has been modified in accordance with
TenantTestBase class usage

Change-Id: Icf21d8aceaa191aee8b8ffc7c52e97ebe9509b3d
This commit is contained in:
Anna Babich 2015-12-21 17:53:08 +02:00
parent 7c3ce18e4d
commit f6e0dcd34c
4 changed files with 139 additions and 29 deletions

View File

@ -285,3 +285,41 @@ class ClientTestBase(testtools.TestCase):
return line.split("|")[1:-1][column_index].strip()
raise ValueError("Unable to find value for column '%s'.")
class TenantTestBase(ClientTestBase):
"""Base test class for additional tenant and user creation which
could be required in various test scenarios
"""
def setUp(self):
super(TenantTestBase, self).setUp()
tenant = self.cli_clients.keystone(
'tenant-create --name %s --enabled True' %
self.name_generate('v' + self.COMPUTE_API_VERSION))
self.tenant_name = self._get_value_from_the_table(tenant, "name")
self.tenant_id = self._get_value_from_the_table(
self.cli_clients.keystone(
'tenant-get %s' % self.tenant_name), 'id')
self.addCleanup(self.cli_clients.keystone,
"tenant-delete %s" % self.tenant_name)
user_name = self.name_generate('v' + self.COMPUTE_API_VERSION)
password = 'password'
user = self.cli_clients.keystone(
"user-create --name %(name)s --pass %(pass)s --tenant %(tenant)s" %
{"name": user_name, "pass": password, "tenant": self.tenant_name})
self.user_id = self._get_value_from_the_table(user, "id")
self.addCleanup(self.cli_clients.keystone,
"user-delete %s" % self.user_id)
self.cli_clients_2 = tempest_lib.cli.base.CLIClient(
username=user_name,
password=password,
tenant_name=self.tenant_name,
uri=self.cli_clients.uri,
cli_dir=self.cli_clients.cli_dir)
def another_nova(self, action, flags='', params='', fail_ok=False,
endpoint_type='publicURL', merge_stderr=False):
flags += " --os-compute-api-version %s " % self.COMPUTE_API_VERSION
return self.cli_clients_2.nova(action, flags, params, fail_ok,
endpoint_type, merge_stderr)

View File

@ -0,0 +1,66 @@
# 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 novaclient.tests.functional import base
class TestFlvAccessNovaClient(base.TenantTestBase):
"""Functional tests for flavors with public and non-public access"""
COMPUTE_API_VERSION = "2.1"
def test_public_flavor_list(self):
# Check that flavors with public access are available for both admin
# and non-admin tenants
flavor_list1 = self.nova('flavor-list')
flavor_list2 = self.another_nova('flavor-list')
self.assertEqual(flavor_list1, flavor_list2)
def test_non_public_flavor_list(self):
# Check that non-public flavor appears in flavor list
# only for admin tenant and only with --all attribute
# and doesn't appear for non-admin tenant
flv_name = self.name_generate(prefix='flv')
self.nova('flavor-create --is-public false %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
flavor_list1 = self.nova('flavor-list')
self.assertNotIn(flv_name, flavor_list1)
flavor_list2 = self.nova('flavor-list --all')
flavor_list3 = self.another_nova('flavor-list --all')
self.assertIn(flv_name, flavor_list2)
self.assertNotIn(flv_name, flavor_list3)
def test_add_access_non_public_flavor(self):
# Check that it's allowed to grant an access to non-public flavor for
# the given tenant
flv_name = self.name_generate(prefix='flv')
self.nova('flavor-create --is-public false %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
self.nova('flavor-access-add', params="%s %s" %
(flv_name, self.tenant_id))
self.assertIn(self.tenant_id,
self.nova('flavor-access-list --flavor %s' % flv_name))
def test_add_access_public_flavor(self):
# For microversion < 2.7 the 'flavor-access-add' operation is executed
# successfully for public flavor, but the next operation,
# 'flavor-access-list --flavor %(name_of_public_flavor)' returns
# CommandError: Failed to get access list for public flavor type.
flv_name = self.name_generate(prefix='flv')
self.nova('flavor-create %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
self.nova('flavor-access-add %s %s' % (flv_name, self.tenant_id))
output = self.nova('flavor-access-list --flavor %s' % flv_name,
fail_ok=True, merge_stderr=True)
self.assertIn("ERROR (CommandError): "
"Failed to get access list for public flavor type.\n",
output)

View File

@ -0,0 +1,33 @@
# 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 novaclient.tests.functional.v2.legacy import test_flavor_access
class TestFlvAccessNovaClientV27(test_flavor_access.TestFlvAccessNovaClient):
"""Check that an attempt to grant an access to a public flavor
for the given tenant fails with Conflict error in accordance with
2.7 microversion REST API History
"""
COMPUTE_API_VERSION = "2.7"
def test_add_access_public_flavor(self):
flv_name = self.name_generate('v' + self.COMPUTE_API_VERSION)
self.nova('flavor-create %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
output = self.nova('flavor-access-add %s %s' %
(flv_name, self.tenant_id),
fail_ok=True, merge_stderr=True)
self.assertIn("ERROR (Conflict): "
"Can not add access to a public flavor. (HTTP 409) ",
output)

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import tempest_lib.cli.base
from novaclient.tests.functional import base
from novaclient.tests.functional.v2 import fake_crypto
from novaclient.tests.functional.v2.legacy import test_keypairs
@ -46,36 +44,11 @@ class TestKeypairsNovaClientV22(test_keypairs.TestKeypairsNovaClient):
self.assertIn('x509', keypair)
class TestKeypairsNovaClientV210(base.ClientTestBase):
"""Keypairs functional tests for v2.10 nova-api microversion.
"""
class TestKeypairsNovaClientV210(base.TenantTestBase):
"""Keypairs functional tests for v2.10 nova-api microversion."""
COMPUTE_API_VERSION = "2.10"
def setUp(self):
super(TestKeypairsNovaClientV210, self).setUp()
user_name = self.name_generate("v2.10")
password = "password"
user = self.cli_clients.keystone(
"user-create --name %(name)s --pass %(pass)s --tenant %(tenant)s" %
{"name": user_name, "pass": password,
"tenant": self.cli_clients.tenant_name})
self.user_id = self._get_value_from_the_table(user, "id")
self.addCleanup(self.cli_clients.keystone,
"user-delete %s" % self.user_id)
self.cli_clients_2 = tempest_lib.cli.base.CLIClient(
username=user_name,
password=password,
tenant_name=self.cli_clients.tenant_name,
uri=self.cli_clients.uri,
cli_dir=self.cli_clients.cli_dir)
def another_nova(self, action, flags='', params='', fail_ok=False,
endpoint_type='publicURL', merge_stderr=False):
flags += " --os-compute-api-version %s " % self.COMPUTE_API_VERSION
return self.cli_clients_2.nova(action, flags, params, fail_ok,
endpoint_type, merge_stderr)
def test_create_and_list_keypair(self):
name = self.name_generate("v2_10")
self.nova("keypair-add %s --user %s" % (name, self.user_id))