Func test for os-traits and os-resource-classes lib sync

Placement synchronizes the content of the os-traits and
os-resource-classes lib to its internal DB at service startup. We had
gabbi tests to test that by asserting a hard coded number of traits and
RCs. These test were always blocking the global version bump of such os-
libs as the placement test needed to be updated. This created a deadlock
between the version bump in the requirements repo and the test update in
the placement repo. To avoid the need to always do three steps for a lib
version bump (turn of test, bump global req, update an re-enable the test)
the test logic is changed. Now these tests compares the content of the
lib with the DB automatically instead of hard coding a number of
expected traits and RCs. To be able to this these tests are move from
gabbi to python.

Change-Id: I31431a6eb4f144135da0dc9c6d5e4c6b75d1af5d
This commit is contained in:
Balazs Gibizer 2022-08-03 10:31:38 +02:00
parent eb95805e94
commit 9c7f869b84
3 changed files with 47 additions and 10 deletions

View File

@ -47,11 +47,6 @@ tests:
data: data
status: 415
- name: what is at resource classes
GET: /resource_classes
response_json_paths:
$.resource_classes.`len`: 21 # Number of standard resource classes
- name: non admin forbidden
GET: /resource_classes
request_headers:

View File

@ -9,11 +9,6 @@ defaults:
openstack-api-version: placement 1.6
tests:
- name: what is at traits
GET: /traits
response_json_paths:
$.traits.`len`: 344 # Number of standard traits
- name: create a trait without custom namespace
PUT: /traits/TRAIT_X
status: 400

View File

@ -0,0 +1,47 @@
# 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_resource_classes
import os_traits
from placement import direct
from placement.tests.functional import base
class TestLibSync(base.TestCase):
"""Test that traits and resource classes are synced from os-traits and
os-resource-classes libs to the DB at service startup.
"""
def setUp(self):
super().setUp()
self.headers = {
'x-auth-token': 'admin',
'content-type': 'application/json',
'OpenStack-API-Version': 'placement latest',
}
def test_traits_sync(self):
with direct.PlacementDirect(self.conf_fixture.conf) as client:
resp = client.get('/traits', headers=self.headers)
self.assertItemsEqual(
os_traits.get_traits(),
resp.json()['traits'],
)
def test_resource_classes_sync(self):
with direct.PlacementDirect(self.conf_fixture.conf) as client:
resp = client.get('/resource_classes', headers=self.headers)
self.assertItemsEqual(
os_resource_classes.STANDARDS,
[rc['name'] for rc in resp.json()['resource_classes']],
resp.json(),
)