Merge "tests: Add tests for loading, unloading metadefs"
This commit is contained in:
commit
6f5f24623c
@ -1958,8 +1958,10 @@ def _task_format(task_ref, task_info_ref=None):
|
|||||||
return task_dict
|
return task_dict
|
||||||
|
|
||||||
|
|
||||||
def metadef_namespace_get_all(context, marker=None, limit=None, sort_key=None,
|
def metadef_namespace_get_all(
|
||||||
sort_dir=None, filters=None, session=None):
|
context, marker=None, limit=None, sort_key='created_at',
|
||||||
|
sort_dir='desc', filters=None, session=None,
|
||||||
|
):
|
||||||
"""List all available namespaces."""
|
"""List all available namespaces."""
|
||||||
session = session or get_session()
|
session = session or get_session()
|
||||||
namespaces = metadef_namespace_api.get_all(
|
namespaces = metadef_namespace_api.get_all(
|
||||||
@ -2161,8 +2163,9 @@ def metadef_resource_type_association_get_all_by_namespace(
|
|||||||
|
|
||||||
|
|
||||||
def metadef_tag_get_all(
|
def metadef_tag_get_all(
|
||||||
context, namespace_name, filters=None, marker=None, limit=None,
|
context, namespace_name, filters=None, marker=None, limit=None,
|
||||||
sort_key=None, sort_dir=None, session=None):
|
sort_key='created_at', sort_dir='desc', session=None,
|
||||||
|
):
|
||||||
"""Get metadata-schema tags or raise if none exist."""
|
"""Get metadata-schema tags or raise if none exist."""
|
||||||
session = session or get_session()
|
session = session or get_session()
|
||||||
return metadef_tag_api.get_all(
|
return metadef_tag_api.get_all(
|
||||||
|
@ -13,14 +13,28 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
from glance.common import config
|
from glance.common import config
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance import context
|
from glance import context
|
||||||
|
from glance.db.sqlalchemy import metadata
|
||||||
import glance.tests.functional.db as db_tests
|
import glance.tests.functional.db as db_tests
|
||||||
from glance.tests import utils as test_utils
|
from glance.tests import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
|
# root of repo
|
||||||
|
ROOT_DIR = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
os.pardir,
|
||||||
|
os.pardir,
|
||||||
|
os.pardir,
|
||||||
|
os.pardir,
|
||||||
|
)
|
||||||
|
METADEFS_DIR = os.path.join(ROOT_DIR, 'etc', 'metadefs')
|
||||||
|
|
||||||
|
|
||||||
def build_namespace_fixture(**kwargs):
|
def build_namespace_fixture(**kwargs):
|
||||||
namespace = {
|
namespace = {
|
||||||
'namespace': 'MyTestNamespace',
|
'namespace': 'MyTestNamespace',
|
||||||
@ -102,6 +116,7 @@ class TestMetadefDriver(test_utils.BaseTestCase):
|
|||||||
"""Run before each test method to initialize test environment."""
|
"""Run before each test method to initialize test environment."""
|
||||||
super(TestMetadefDriver, self).setUp()
|
super(TestMetadefDriver, self).setUp()
|
||||||
config.parse_args(args=[])
|
config.parse_args(args=[])
|
||||||
|
self.config(metadata_source_path=METADEFS_DIR)
|
||||||
context_cls = context.RequestContext
|
context_cls = context.RequestContext
|
||||||
self.adm_context = context_cls(is_admin=True,
|
self.adm_context = context_cls(is_admin=True,
|
||||||
auth_token='user:user:admin')
|
auth_token='user:user:admin')
|
||||||
@ -741,11 +756,108 @@ class MetadefTagTests(object):
|
|||||||
created_tag['name'])
|
created_tag['name'])
|
||||||
|
|
||||||
|
|
||||||
|
class MetadefLoadUnloadTests:
|
||||||
|
|
||||||
|
# if additional default schemas are added, you need to update this
|
||||||
|
_namespace_count = 33
|
||||||
|
_namespace_object_counts = {
|
||||||
|
'OS::Compute::Quota': 3,
|
||||||
|
'OS::Software::WebServers': 3,
|
||||||
|
'OS::Software::DBMS': 12,
|
||||||
|
'OS::Software::Runtimes': 5,
|
||||||
|
}
|
||||||
|
_namespace_property_counts = {
|
||||||
|
'CIM::ProcessorAllocationSettingData': 3,
|
||||||
|
'CIM::ResourceAllocationSettingData': 19,
|
||||||
|
'CIM::StorageAllocationSettingData': 13,
|
||||||
|
'CIM::VirtualSystemSettingData': 17,
|
||||||
|
'OS::Compute::XenAPI': 1,
|
||||||
|
'OS::Compute::InstanceData': 2,
|
||||||
|
'OS::Compute::Libvirt': 3,
|
||||||
|
'OS::Compute::VMwareQuotaFlavor': 2,
|
||||||
|
'OS::Cinder::Volumetype': 1,
|
||||||
|
'OS::Glance::Signatures': 4,
|
||||||
|
'OS::Compute::AggregateIoOpsFilter': 1,
|
||||||
|
'OS::Compute::RandomNumberGenerator': 3,
|
||||||
|
'OS::Compute::VTPM': 2,
|
||||||
|
'OS::Compute::Hypervisor': 2,
|
||||||
|
'OS::Compute::CPUPinning': 2,
|
||||||
|
'OS::OperatingSystem': 3,
|
||||||
|
'OS::Compute::AggregateDiskFilter': 1,
|
||||||
|
'OS::Compute::AggregateNumInstancesFilter': 1,
|
||||||
|
'OS::Compute::CPUMode': 1,
|
||||||
|
'OS::Compute::HostCapabilities': 7,
|
||||||
|
'OS::Compute::VirtCPUTopology': 6,
|
||||||
|
'OS::Glance::CommonImageProperties': 10,
|
||||||
|
'OS::Compute::GuestShutdownBehavior': 1,
|
||||||
|
'OS::Compute::VMwareFlavor': 2,
|
||||||
|
'OS::Compute::TPM': 1,
|
||||||
|
'OS::Compute::GuestMemoryBacking': 1,
|
||||||
|
'OS::Compute::LibvirtImage': 16,
|
||||||
|
'OS::Compute::VMware': 6,
|
||||||
|
'OS::Compute::Watchdog': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_metadef_load_unload(self):
|
||||||
|
# load the metadata definitions
|
||||||
|
metadata.db_load_metadefs(self.db_api.get_engine())
|
||||||
|
|
||||||
|
# trust but verify
|
||||||
|
expected = self._namespace_count
|
||||||
|
namespaces = self.db_api.metadef_namespace_get_all(self.adm_context)
|
||||||
|
actual = len(namespaces)
|
||||||
|
self.assertEqual(
|
||||||
|
expected,
|
||||||
|
actual,
|
||||||
|
f"expected {expected} namespaces but got {actual}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for namespace in namespaces:
|
||||||
|
expected = self._namespace_object_counts.get(
|
||||||
|
namespace['namespace'],
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
objects = self.db_api.metadef_object_get_all(
|
||||||
|
self.adm_context,
|
||||||
|
namespace['namespace'],
|
||||||
|
)
|
||||||
|
actual = len(objects)
|
||||||
|
self.assertEqual(
|
||||||
|
expected,
|
||||||
|
actual,
|
||||||
|
f"expected {expected} objects in {namespace['namespace']} "
|
||||||
|
f"namespace but got {actual}: "
|
||||||
|
f"{', '.join(o['name'] for o in objects)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for namespace in namespaces:
|
||||||
|
expected = self._namespace_property_counts.get(
|
||||||
|
namespace['namespace'],
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
properties = self.db_api.metadef_property_get_all(
|
||||||
|
self.adm_context,
|
||||||
|
namespace['namespace'],
|
||||||
|
)
|
||||||
|
actual = len(properties)
|
||||||
|
self.assertEqual(
|
||||||
|
expected,
|
||||||
|
actual,
|
||||||
|
f"expected {expected} properties in {namespace['namespace']} "
|
||||||
|
f"namespace but got {actual}: "
|
||||||
|
f"{', '.join(p['name'] for p in properties)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# unload the definitions
|
||||||
|
metadata.db_unload_metadefs(self.db_api.get_engine())
|
||||||
|
|
||||||
|
|
||||||
class MetadefDriverTests(MetadefNamespaceTests,
|
class MetadefDriverTests(MetadefNamespaceTests,
|
||||||
MetadefResourceTypeTests,
|
MetadefResourceTypeTests,
|
||||||
MetadefResourceTypeAssociationTests,
|
MetadefResourceTypeAssociationTests,
|
||||||
MetadefPropertyTests,
|
MetadefPropertyTests,
|
||||||
MetadefObjectTests,
|
MetadefObjectTests,
|
||||||
MetadefTagTests):
|
MetadefTagTests,
|
||||||
|
MetadefLoadUnloadTests):
|
||||||
# collection class
|
# collection class
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user