neutron-tempest-plugin/neutron_tempest_plugin/api/admin/test_logging.py
Slawek Kaplonski ec162e0f56 Remove usage of testscenarios and replace it with ddt library
As our internal QE reported to us, ddt is producing more consistent
names of the same tests with different variables then testscenarios.
With testscenarios it is something like:

foo_tempest_plugin.tests.something.SomeClass.test_foo[id-123456](c1,c2)

and with ddt is more similar to tests without scenarios:

foo_tempest_plugin.tests.something.SomeClass.test_foo_1[id-123456]

Apparently due to this inconsistency results of some tests couldn't be
properly reported properly to some tools which we are using downstream.

So this patch proposes to remove usage of testscenarios in
neutron_tempest_plugin and replace it with ddt where it is needed.
Actually ddt was already used in some of the tests here so this will
make it also more consistent across the tests in that repo.

Also as part of this effort I relalised that in some cases testscenarios
where used, tests were running e.g. 2 times but actually variable set to
different value in different scenarios were not used at all. So in such
case I simply dropped usage of testscenarios and left only one variant
of the test to be run.

Change-Id: Ieabab4ccaa0e2a365939425dff0c0776839251eb
2024-03-06 14:27:39 +01:00

98 lines
4.1 KiB
Python

# Copyright 2017 Fujitsu Limited.
#
# 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.common.utils import data_utils
from tempest.lib import decorators
from tempest.lib import exceptions
from neutron_tempest_plugin.api import base
class LoggingTestJSON(base.BaseAdminNetworkTest):
required_extensions = ['logging', 'standard-attr-description']
@decorators.idempotent_id('8d2e1ba5-455b-4519-a88e-e587002faba6')
def test_log_lifecycle(self):
security_group = self.create_security_group()
name = data_utils.rand_name('test-log')
description = data_utils.rand_name('test-log-desc')
log = self.create_log(name=name, description=description,
resource_id=security_group['id'],
resource_type='security_group', enabled=True)
# Test 'show log'
retrieved_log = self.admin_client.show_log(log['id'])['log']
self.assertEqual(name, retrieved_log['name'])
self.assertEqual(description, retrieved_log['description'])
self.assertEqual('security_group', retrieved_log['resource_type'])
self.assertTrue(retrieved_log['enabled'])
# Test 'list logs'
logs = self.admin_client.list_logs()['logs']
logs_ids = [log_object['id'] for log_object in logs]
self.assertIn(log['id'], logs_ids)
# Test 'update log'
update_description = data_utils.rand_name('test-log')
self.admin_client.update_log(log['id'],
description=update_description,
enabled=False)
retrieved_log = self.admin_client.show_log(log['id'])['log']
self.assertEqual(update_description, retrieved_log['description'])
self.assertFalse(retrieved_log['enabled'])
# Test 'delete log'
self.admin_client.delete_log(log['id'])
self.assertRaises(exceptions.NotFound,
self.admin_client.show_log, log['id'])
@decorators.idempotent_id('1af6cdab-0eb0-4e13-8027-d89cf1c7a87a')
def test_list_supported_logging_types(self):
# List supported logging types
# Since returned logging types depends on loaded backend drivers
# this test is checking only if returned keys are same as expected keys
expected_log_keys = ['type']
log_types = self.admin_client.list_loggable_resources()
actual_list_log_types = log_types['loggable_resources']
# Verify that only required fields present in logging types
for log_type in actual_list_log_types:
self.assertEqual(tuple(expected_log_keys), tuple(log_type.keys()))
@decorators.idempotent_id('1ab4eb2a-76f5-45b9-816b-1aa497a71eea')
def test_log_deleted_with_corresponding_security_group(self):
security_group = self.create_security_group()
name = data_utils.rand_name('test-log')
log = self.create_log(
name=name,
resource_type='security_group',
resource_id=security_group['id'],
enabled=True)
# Ensure log was created
retrieved_log = self.admin_client.show_log(log['id'])['log']
self.assertEqual(name, retrieved_log['name'])
self.assertEqual(security_group['id'], retrieved_log['resource_id'])
self.assertEqual('security_group', retrieved_log['resource_type'])
self.assertTrue(retrieved_log['enabled'])
# Delete SG
self.delete_security_group(security_group)
# Ensure log is also deleted
self.assertRaises(exceptions.NotFound,
self.admin_client.show_log, log['id'])