All attributes of node model are collected for fuel-stats
White list added for Node model attributes. Collecting of node info for fuel-stats refactored for using node attributes white list. Closes-Bug: #1577759 Change-Id: I7b5332c4c094b1f68ae8fc47da95d882770e6bf1
This commit is contained in:
parent
21c2b195ff
commit
998b3dbdbb
|
@ -183,6 +183,38 @@ class InstallationInfo(object):
|
|||
WhiteListRule(('tasks',), 'tasks', None),
|
||||
)
|
||||
|
||||
node_info_white_list = (
|
||||
# ((path, to, property), 'map_to_name', transform_function)
|
||||
WhiteListRule(('id',), 'id', None),
|
||||
WhiteListRule(('group_id',), 'group_id', None),
|
||||
WhiteListRule(('cluster_id',), 'cluster_id', None),
|
||||
|
||||
WhiteListRule(('name',), 'name', None),
|
||||
WhiteListRule(('labels',), 'labels', None),
|
||||
WhiteListRule(('roles',), 'roles', None),
|
||||
WhiteListRule(('primary_roles',), 'primary_roles', None),
|
||||
WhiteListRule(('os_platform',), 'os', None),
|
||||
WhiteListRule(('manufacturer',), 'manufacturer', None),
|
||||
WhiteListRule(('platform_name',), 'platform_name', None),
|
||||
WhiteListRule(('kernel_params',), 'kernel_params', None),
|
||||
WhiteListRule(('extensions',), 'extensions', None),
|
||||
WhiteListRule(('attributes',), 'attributes', None),
|
||||
|
||||
WhiteListRule(('status',), 'status', None),
|
||||
WhiteListRule(('online',), 'online', None),
|
||||
WhiteListRule(('error_type',), 'error_type', None),
|
||||
WhiteListRule(('error_msg',), 'error_msg', None),
|
||||
WhiteListRule(('progress',), 'progress', None),
|
||||
|
||||
WhiteListRule(('pending_addition',), 'pending_addition', None),
|
||||
WhiteListRule(('pending_deletion',), 'pending_deletion', None),
|
||||
WhiteListRule(('pending_roles',), 'pending_roles', None),
|
||||
|
||||
WhiteListRule(('meta',), 'meta', None),
|
||||
WhiteListRule(('network_template',), 'network_template', None),
|
||||
WhiteListRule(('vms_conf',), 'vms_conf', None),
|
||||
)
|
||||
|
||||
def fuel_release_info(self):
|
||||
return settings.VERSION
|
||||
|
||||
|
@ -305,29 +337,13 @@ class InstallationInfo(object):
|
|||
def get_nodes_info(self, nodes):
|
||||
nodes_info = []
|
||||
for node in nodes:
|
||||
node_info = {
|
||||
'id': node.id,
|
||||
'group_id': node.group_id,
|
||||
'roles': node.roles,
|
||||
'os': node.os_platform,
|
||||
node_info = self.get_attributes(node, self.node_info_white_list)
|
||||
|
||||
'status': node.status,
|
||||
'error_type': node.error_type,
|
||||
'online': node.online,
|
||||
|
||||
'manufacturer': node.manufacturer,
|
||||
'platform_name': node.platform_name,
|
||||
'meta': self.get_node_meta(node),
|
||||
|
||||
'pending_addition': node.pending_addition,
|
||||
'pending_deletion': node.pending_deletion,
|
||||
'pending_roles': node.pending_roles,
|
||||
|
||||
'nic_interfaces':
|
||||
self.get_node_intefaces_info(node.nic_interfaces, bond=False),
|
||||
'bond_interfaces':
|
||||
self.get_node_intefaces_info(node.bond_interfaces, bond=True),
|
||||
}
|
||||
node_info['meta'] = self.get_node_meta(node)
|
||||
node_info['nic_interfaces'] = self.get_node_intefaces_info(
|
||||
node.nic_interfaces, bond=False)
|
||||
node_info['bond_interfaces'] = self.get_node_intefaces_info(
|
||||
node.bond_interfaces, bond=True)
|
||||
nodes_info.append(node_info)
|
||||
return nodes_info
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ from sqlalchemy.inspection import inspect
|
|||
from nailgun.test.base import BaseTestCase
|
||||
|
||||
from nailgun import consts
|
||||
from nailgun.db.sqlalchemy.models import cluster as cluster_model
|
||||
from nailgun.db.sqlalchemy.models import plugins
|
||||
from nailgun.db.sqlalchemy import models
|
||||
from nailgun.objects import Cluster
|
||||
from nailgun.objects import ReleaseCollection
|
||||
from nailgun.objects import VmwareAttributes
|
||||
|
@ -340,6 +339,15 @@ class TestInstallationInfo(BaseTestCase):
|
|||
self.assertTrue('contact_info_provided' in info['user_information'])
|
||||
self.assertDictEqual(settings.VERSION, info['fuel_release'])
|
||||
|
||||
def get_model_schema(self, model, with_relationships=True):
|
||||
schema = {}
|
||||
for column in inspect(model).columns:
|
||||
schema[six.text_type(column.name)] = None
|
||||
if with_relationships:
|
||||
for rel in inspect(model).relationships:
|
||||
schema[six.text_type(rel.table.name)] = None
|
||||
return schema
|
||||
|
||||
def test_all_cluster_data_collected(self):
|
||||
self.env.create(nodes_kwargs=[{'roles': ['compute']}])
|
||||
self.env.create_node(status=consts.NODE_STATUSES.discover)
|
||||
|
@ -349,12 +357,7 @@ class TestInstallationInfo(BaseTestCase):
|
|||
info = info.get_installation_info()
|
||||
actual_cluster = info['clusters'][0]
|
||||
|
||||
# Creating cluster schema
|
||||
cluster_schema = {}
|
||||
for column in inspect(cluster_model.Cluster).columns:
|
||||
cluster_schema[six.text_type(column.name)] = None
|
||||
for rel in inspect(cluster_model.Cluster).relationships:
|
||||
cluster_schema[six.text_type(rel.table.name)] = None
|
||||
cluster_schema = self.get_model_schema(models.Cluster)
|
||||
|
||||
# Removing of not required fields
|
||||
remove_fields = (
|
||||
|
@ -485,10 +488,8 @@ class TestInstallationInfo(BaseTestCase):
|
|||
info = InstallationInfo().get_cluster_plugins_info(cluster)
|
||||
actual_plugin = info[0]
|
||||
|
||||
# Creating plugin data schema
|
||||
plugin_schema = {}
|
||||
for column in inspect(plugins.Plugin).columns:
|
||||
plugin_schema[six.text_type(column.name)] = None
|
||||
plugin_schema = self.get_model_schema(models.Plugin,
|
||||
with_relationships=False)
|
||||
|
||||
# Removing of not required fields
|
||||
remove_fields = ('description', 'title', 'authors', 'homepage')
|
||||
|
@ -501,16 +502,52 @@ class TestInstallationInfo(BaseTestCase):
|
|||
for key in six.iterkeys(plugin_schema):
|
||||
self.assertIn(key, actual_plugin)
|
||||
|
||||
def test_wite_list_unique_names(self):
|
||||
names = set(rule.map_to_name for rule in
|
||||
InstallationInfo.attributes_white_list)
|
||||
self.assertEqual(len(InstallationInfo.attributes_white_list),
|
||||
len(names))
|
||||
names = set(rule.map_to_name for rule in
|
||||
InstallationInfo.vmware_attributes_white_list)
|
||||
self.assertEqual(len(InstallationInfo.vmware_attributes_white_list),
|
||||
len(names))
|
||||
names = set(rule.map_to_name for rule in
|
||||
InstallationInfo.plugin_info_white_list)
|
||||
self.assertEqual(len(InstallationInfo.plugin_info_white_list),
|
||||
len(names))
|
||||
def test_all_node_data_collected(self):
|
||||
cluster = self.env.create_cluster(api=False)
|
||||
self.env.create_node(cluster_id=cluster.id)
|
||||
|
||||
# Fetching nodes info
|
||||
info = InstallationInfo().get_nodes_info(cluster.nodes)
|
||||
actual_node = info[0]
|
||||
|
||||
node_schema = self.get_model_schema(models.Node)
|
||||
|
||||
# Removing of not required fields
|
||||
remove_fields = (
|
||||
'ip', 'uuid', 'agent_checksum', 'hostname', 'timestamp',
|
||||
'replaced_provisioning_info', 'replaced_deployment_info',
|
||||
'mac',
|
||||
# Related tables
|
||||
'clusters', 'cluster_changes',
|
||||
'nodegroups', 'ip_addrs', 'node_nic_interfaces',
|
||||
'node_bond_interfaces', 'network_groups'
|
||||
)
|
||||
for field in remove_fields:
|
||||
node_schema.pop(field)
|
||||
|
||||
# Renaming fields for matching
|
||||
rename_fields = (
|
||||
('os_platform', 'os'),
|
||||
)
|
||||
|
||||
for name_from, name_to in rename_fields:
|
||||
node_schema.pop(name_from)
|
||||
node_schema[name_to] = None
|
||||
|
||||
# If test failed here it means, that you have added properties
|
||||
# to node and they are not exported into statistics.
|
||||
# If you don't know what to do, contact fuel-stats team please.
|
||||
for key in six.iterkeys(node_schema):
|
||||
self.assertIn(key, actual_node)
|
||||
|
||||
def test_white_list_unique_names(self):
|
||||
white_list_attrs = (
|
||||
'attributes_white_list',
|
||||
'vmware_attributes_white_list',
|
||||
'plugin_info_white_list',
|
||||
'node_info_white_list'
|
||||
)
|
||||
for white_list_attr in white_list_attrs:
|
||||
white_list = getattr(InstallationInfo, white_list_attr)
|
||||
names = set(rule.map_to_name for rule in white_list)
|
||||
self.assertEqual(len(white_list), len(names))
|
||||
|
|
Loading…
Reference in New Issue