Commit db3b4bea authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Re-implement assert dumped configuration

  Now the goal is save the configuration and later assert with saved configuration on the actual site.

  This may give us other uses for this tooling, like, save before and after an upgrade (to know the actual delta) and save after an upgrade to know later the local changes done over time.

  This without loose the possibility of audit (since you can upload a file after fetch the configuration from the unit tests)
parent ac583c46
portal = context.getPortalObject() portal = context.getPortalObject()
import difflib import difflib
current_confguration = portal.ERP5Site_saveDumpedConfiguration(save=0)
try:
save_file = portal.document_module[filename]
except KeyError:
raise ValueError("You must save the dumped configuration first with ERP5Site_saveDumpedConfiguration")
def resolveDiff(title, expected_file, found): saved_configuration = save_file.getData()
expected = str(expected_file.data)
return """########################################################################
# %s
########################################################################
%s
########################################################################
""" % (title, '\n'.join(difflib.unified_diff(expected.split("\n"), found.split("\n"))))
if show_all or configuration == "alarm":
expected_file = portal.expected_alarm_tool_dumped_configuration
found = portal.ERP5Site_dumpAlarmToolConfiguration()
print resolveDiff("Alarm Configuration Diff", expected_file, found)
if show_all or configuration == "builder":
expected_file = portal.expected_builder_dumped_configuration
found = portal.ERP5Site_dumpBuilderList()
print resolveDiff("Builder Configuration Diff", expected_file, found)
if show_all or configuration == "bt":
expected_file = portal.expected_business_template_dumped_configuration
found = portal.ERP5Site_dumpInstalledBusinessTemplateList(
ignore_business_template_list=["rapid_space_web_site",
'erp5_ui_test_core',
'slapos_vifib',
'slapos_jio_zh_ui_test',
'slapos_jio_ui_test',
'rapid_space_ui_test'])
print resolveDiff("Business Template Configuration Diff", expected_file, found)
if show_all or configuration == "order_builder":
expected_file = portal.expected_order_builder_dumped_configuration
found = portal.ERP5Site_dumpOrderBuilderList()
print resolveDiff("Order Builder Configuration Diff", expected_file, found)
if show_all or configuration == "property_sheet":
expected_file = portal.expected_property_sheet_dumped_configuration
found = portal.ERP5Site_dumpPropertySheetList(
ignore_property_sheet_list=["Foo"]
)
print resolveDiff("Property Sheet Configuration Diff", expected_file, found)
if show_all or configuration == "skins":
expected_file = portal.expected_portal_skins_dumped_configuration
found = portal.ERP5Site_dumpPortalSkinsContent(
ignore_folder_list=[
"rapid_space",
"slapos_vifib",
"rapid_space_ui_test",
"slapos_ui_test",
"slapos_zh_ui_test",
"erp5_web_renderjs_ui_test_core"
],
ignore_skin_list=[
"expected_alarm_tool_dumped_configuration",
"expected_builder_dumped_configuration",
"expected_business_template_dumped_configuration",
"expected_order_builder_dumped_configuration",
"expected_portal_skins_dumped_configuration",
"expected_portal_type_dumped_configuration",
"expected_property_sheet_dumped_configuration",
"expected_role_dumped_configuration",
"expected_rule_dumped_configuration",
"expected_skin_property_dumped_configuration",
"expected_type_actions_dumped_configuration",
"expected_web_page_module_configuration",
"expected_workflow_dumped_configuration",
]
)
print resolveDiff("Skins Configuration Diff", expected_file, found)
if show_all or configuration == "web_content":
expected_file = portal.expected_web_page_module_configuration
found = portal.ERP5Site_dumpWebPageModuleContent(
ignore_string_on_reference_list=["rapid_"])
print resolveDiff("Web Content Configuration Diff", expected_file, found)
if show_all or configuration == "actions":
expected_file = portal.expected_type_actions_dumped_configuration
found = portal.ERP5Site_dumpPortalTypeActionList()
print resolveDiff("Portal Type Actions Configuration Diff", expected_file, found)
if show_all or configuration == "portal_type":
expected_file = portal.expected_portal_type_dumped_configuration
found = portal.ERP5Site_dumpPortalTypeList()
print resolveDiff("Portal Type Configuration Diff", expected_file, found)
if show_all or configuration == "role":
expected_file = portal.expected_role_dumped_configuration
found = portal.ERP5Site_dumpPortalTypeRoleList()
print resolveDiff("Role Configuration Diff", expected_file, found)
if show_all or configuration == "rule":
expected_file = portal.expected_rule_dumped_configuration
found = portal.ERP5Site_dumpRuleTesterList()
print resolveDiff("Rule Configuration Diff", expected_file, found)
if show_all or configuration == "skin_property":
expected_file = portal.expected_skin_property_dumped_configuration
found = portal.ERP5Site_dumpSkinProperty(
ignore_skin_folder_list=[
"rapid_space",
"slapos_vifib",
"rapid_space_ui_test",
"slapos_ui_test",
"slapos_zh_ui_test",
"erp5_web_renderjs_ui_test_core"
]
)
print resolveDiff("Skin Property Configuration Diff", expected_file, found)
if show_all or configuration == "workflow":
expected_file = portal.expected_workflow_dumped_configuration
found = portal.ERP5Site_dumpWorkflowChain()
print resolveDiff("Workflow Configuration Diff", expected_file, found)
return printed return '\n'.join(difflib.unified_diff(saved_configuration.split("\n"), current_confguration.split("\n")))
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>configuration=None, show_all=True</string> </value> <value> <string>filename=\'erp5_dumped_configuration\'</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
portal = context.getPortalObject()
msg = ""
def render(title, body):
return """########################################################################
# %s
########################################################################
%s
########################################################################
""" % (title, body)
msg += render("Alarm Configuration Diff",
portal.ERP5Site_dumpAlarmToolConfiguration())
msg += render("Builder Configuration Diff",
portal.ERP5Site_dumpBuilderList())
msg += render("Business Template Configuration Diff",
portal.ERP5Site_dumpInstalledBusinessTemplateList())
msg += render("Order Builder Configuration Diff",
portal.ERP5Site_dumpOrderBuilderList())
msg += render("Property Sheet Configuration Diff",
portal.ERP5Site_dumpPropertySheetList())
msg += render("Skins Configuration Diff",
portal.ERP5Site_dumpPortalSkinsContent())
msg += render("Web Content Configuration Diff",
portal.ERP5Site_dumpWebPageModuleContent())
msg += render("Portal Type Actions Configuration Diff",
portal.ERP5Site_dumpPortalTypeActionList())
msg += render("Portal Type Configuration Diff",
portal.ERP5Site_dumpPortalTypeList())
msg += render("Role Configuration Diff",
portal.ERP5Site_dumpPortalTypeRoleList())
msg += render("Rule Configuration Diff",
portal.ERP5Site_dumpRuleTesterList())
msg += render("Skin Property Configuration Diff",
portal.ERP5Site_dumpSkinProperty())
msg += render("Workflow Configuration Diff",
portal.ERP5Site_dumpWorkflowChain())
if save:
module = portal.document_module
try:
save_file = portal.document_module['erp5_dumped_configuration']
except KeyError:
backup = 0
save_file = module.document_module.newContent(
id='erp5_dumped_configuration',
portal_type='File')
if backup:
# We should only backup on really special cases
backup_file = module.document_module.newContent(
reference='F-backuped-configuration',
portal_type='File')
backup_file.setData(save_file.getData())
save_file.setData(msg)
return msg
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>save=1, backup=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_saveDumpedConfiguration</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment