def test_custom_host_attribute_transform(old, new): attributes = [{ 'add_custom_macro': True, 'help': u'', 'name': 'attr1', 'show_in_table': True, 'title': u'Attribute 1', 'topic': old, 'type': 'TextAscii', }] transformed_attributes = attrs.transform_pre_16_host_topics(attributes) assert transformed_attributes[0]["topic"] == new
def test_custom_host_attribute_transform(old, new): attributes = [{ "add_custom_macro": True, "help": "", "name": "attr1", "show_in_table": True, "title": "Attribute 1", "topic": old, "type": "TextAscii", }] transformed_attributes = attrs.transform_pre_16_host_topics(attributes) assert transformed_attributes[0]["topic"] == new
def load_custom_attrs_from_mk_file(lock): filename = os.path.join(watolib.multisite_dir(), "custom_attrs.mk") vars_ = store.load_mk_file(filename, { 'wato_user_attrs': [], 'wato_host_attrs': [], }, lock=lock) attrs = {} for what in ["user", "host"]: attributes = vars_.get("wato_%s_attrs" % what, []) if what == "host": attributes = transform_pre_16_host_topics(attributes) attrs[what] = attributes return attrs
def _update_config_based_host_attributes() -> None: global _update_config_based_host_attributes_config_hash def _compute_config_hash() -> str: return str(hash(repr(active_config.tags.get_dict_format()))) + repr( active_config.wato_host_attrs ) # The topic conversion needs to take place before the _compute_config_hash runs # The actual generated topics may be pre-1.5 converted topics # e.g. "Custom attributes" -> "custom_attributes" # If we do not convert the topics here, the config_hash comparison will always fail transform_pre_16_host_topics(active_config.wato_host_attrs) if _update_config_based_host_attributes_config_hash == _compute_config_hash(): return # No re-register needed :-) _clear_config_based_host_attributes() _declare_host_tag_attributes() declare_custom_host_attrs() Folder.invalidate_caches() _update_config_based_host_attributes_config_hash = _compute_config_hash()