Commit 519c0e9f authored by Łukasz Nowak's avatar Łukasz Nowak

erp5_web_monitoring_ui_test: Simulate backend in ERP5

Thanks to not starting backend separately, the test became much simpler
and shall be easier to run and check.

Use Zope's access rule in the folder in order to set headers for OPTIONS
method too and also to avoid having ? in the backend URL.
parent e2f04123
......@@ -6,6 +6,72 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__before_publishing_traverse__</string> </key>
<value>
<object>
<klass>
<global name="MultiHook" module="ZPublisher.BeforeTraverse"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_defined_in_class</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>_hookname</string> </key>
<value> <string>__before_publishing_traverse__</string> </value>
</item>
<item>
<key> <string>_list</string> </key>
<value>
<list>
<object id="1.1">
<klass>
<global name="AccessRule" module="Products.SiteAccess.AccessRule"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>name</string> </key>
<value> <string>MonitorBackend_accessRule</string> </value>
</item>
</dictionary>
</state>
</object>
</list>
</value>
</item>
<item>
<key> <string>_prior</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>__before_traverse__</string> </key>
<value>
<dictionary>
<item>
<key>
<tuple>
<int>1</int>
<string>AccessRule</string>
</tuple>
</key>
<value> <reference id="1.1"/> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
......
setHeader = context.REQUEST.response.setHeader
setHeader("Access-Control-Allow-Origin", "*")
setHeader("Access-Control-Allow-Methods", "HEAD, OPTIONS, GET, POST")
setHeader("Access-Control-Allow-Headers", "Overwrite, Destination, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Authorization")
PATH = context.REQUEST['PATH_INFO']
if '/simulator' in PATH:
real, simulator = PATH.split('simulator')
container.REQUEST.set('PATH_INFO', real)
container.REQUEST.set('SIMULATOR_PATH', simulator)
container.REQUEST.set('SCRIPT_NAME', 'MonitorBackend_simulator')
container.REQUEST.set('TraversalRequestNameStack', ['MonitorBackend_simulator'])
<?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></string> </value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string>misc_/SiteAccess/AccessRule.gif</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MonitorBackend_accessRule</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MonitorBackend_getBaseUrl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
path = container.REQUEST['SIMULATOR_PATH']
value = container.MonitorBackend_simulatorMapping(path)
if value is not None:
return value
else:
return 'OK'
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MonitorBackend_simulator</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
base = context.portal_tests.web_monitoring_ui_zuite.MonitorBackend_getBaseUrl()
# normalize
path = path.strip('/')
# normalize share
path = path.replace('share/', '')
value = {
'rootInstance/public/feeds': """<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by SlapOS -->
<opml version="1.1">
<head>
<title>TEST Hosting Subscription</title>
<dateCreated>Fri, 17 Jan 2020 12:16:59 +0000</dateCreated>
<dateModified>Fri, 17 Jan 2020 12:16:59 +0000</dateModified>
</head>
<body>
<outline text="Monitoring RSS Feed list">
<outline text="rootInstance" title="rootInstance" type="rss" version="RSS" htmlUrl="%(base)s/rootInstance/public/feed" xmlUrl="%(base)s/rootInstance/public/feed" url="%(base)s/rootInstance/share/private/" />
<outline text="subInstance-1" title="subInstance-1" type="rss" version="RSS" htmlUrl="%(base)s/subInstance-1/public/feed" xmlUrl="%(base)s/subInstance-1/public/feed" url="%(base)s/subInstance-1/share/private/" />
<outline text="subInstance-2" title="subInstance-2" type="rss" version="RSS" htmlUrl="%(base)s/subInstance-2/public/feed" xmlUrl="%(base)s/subInstance-2/public/feed" url="%(base)s/subInstance-2/share/private/" /> </outline>
</body>
</opml>""",
'rootInstance/public/feed': """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>rootInstance</title>
<link>%(base)s/rootInstance/public/feed</link>
<description>TEST Hosting Subscription</description>
<lastBuildDate>Fri, 17 Jan 2020 12:16:59 +0000</lastBuildDate>
<docs>%(base)s/gc//blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>test_promise_3</title>
<link>%(base)s/rootInstance/share/private/</link>
<description>description of test_promise_3</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/rootInstance/share/public/">test_promise_3</source>
</item>
<item>
<title>test_promise_0</title>
<link>%(base)s/rootInstance/share/private/</link>
<description>description of test_promise_0</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/rootInstance/share/public/">test_promise_0</source>
</item>
<item>
<title>test_promise_2</title>
<link>%(base)s/rootInstance/share/private/</link>
<description>description of test_promise_2</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/rootInstance/share/public/">test_promise_2</source>
</item>
<item>
<title>test_promise_1</title>
<link>%(base)s/rootInstance/share/private/</link>
<description>description of test_promise_1</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/rootInstance/share/public/">test_promise_1</source>
</item>
<item>
<title>test_promise_4</title>
<link>%(base)s/rootInstance/share/private/</link>
<description>description of test_promise_4</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/rootInstance/share/public/">test_promise_4</source>
</item>
</channel>
</rss>""",
'rootInstance/public/test_promise_0.json': """{"status": "OK", "change-time": 1579263419.246462, "instance": "rootInstance", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_0", "_links": {"monitor": {"href": "%(base)s/rootInstance/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'rootInstance/public/test_promise_1.json': """{"status": "OK", "change-time": 1579263419.246462, "instance": "rootInstance", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_1", "_links": {"monitor": {"href": "%(base)s/rootInstance/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'rootInstance/public/test_promise_2.json': """{"status": "OK", "change-time": 1579263419.246462, "instance": "rootInstance", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_2", "_links": {"monitor": {"href": "%(base)s/rootInstance/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'rootInstance/public/test_promise_3.json': """{"status": "OK", "change-time": 1579263419.246462, "instance": "rootInstance", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_3", "_links": {"monitor": {"href": "%(base)s/rootInstance/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'rootInstance/public/test_promise_4.json': """{"status": "OK", "change-time": 1579263419.246462, "instance": "rootInstance", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_4", "_links": {"monitor": {"href": "%(base)s/rootInstance/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'rootInstance/private/_document_list': """monitor.global""",
'rootInstance/private/monitor.global.json': """{"status": "OK", "_links": {"rss_url": {"href": "%(base)s/rootInstance/public/feed"}, "public_url": {"href": "%(base)s/rootInstance/share/public/"}, "private_url": {"href": "%(base)s/rootInstance/share/private/"}}, "state": {"warning": 0, "success": 3, "error": 0}, "_embedded": {"instance": {"partition": "slappart1", "ipv6": "2001:67c:1254:e:c4::c748", "computer": "slaprunner", "ipv4": "10.0.165.37", "software-release": "http://xxx.yyy.zz/asoftware/software.cfg", "software-type": "pull-backup"}}, "parameters": [{"key": "", "value": "some parameter", "title": "demo"}], "title": "rootInstance", "date": "2020-01-17 13:16:59", "type": "global", "hosting-title": "TEST Hosting Subscription", "data": {"process_state": "monitor_process_resource.status", "io_resource": "monitor_resource_io.data", "state": "monitor_state.data", "memory_resource": "monitor_resource_memory.data", "process_resource": "monitor_resource_process.data", "monitor_process_state": "monitor_resource.status"}}""",
'subInstance-1/public/feed': """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>subInstance-1</title>
<link>%(base)s/subInstance-1/public/feed</link>
<description>TEST Hosting Subscription</description>
<lastBuildDate>Fri, 17 Jan 2020 12:16:59 +0000</lastBuildDate>
<docs>%(base)s/gc//blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>test_promise_3</title>
<link>>%(base)s/subInstance-1/share/private/</link>
<description>description of test_promise_3</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url=">%(base)s/subInstance-1/share/public/">test_promise_3</source>
</item>
<item>
<title>test_promise_0</title>
<link>>%(base)s/subInstance-1/share/private/</link>
<description>description of test_promise_0</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url=">%(base)s/subInstance-1/share/public/">test_promise_0</source>
</item>
<item>
<title>test_promise_2</title>
<link>>%(base)s/subInstance-1/share/private/</link>
<description>description of test_promise_2</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url=">%(base)s/subInstance-1/share/public/">test_promise_2</source>
</item>
<item>
<title>test_promise_1</title>
<link>>%(base)s/subInstance-1/share/private/</link>
<description>description of test_promise_1</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url=">%(base)s/subInstance-1/share/public/">test_promise_1</source>
</item>
</channel>
</rss>""",
'subInstance-1/private/_document_list': """monitor.global""",
'subInstance-1/private/monitor.global.json': """{"status": "ERROR", "_links": {"rss_url": {"href": "%(base)s/subInstance-1/public/feed"}, "public_url": {"href": "%(base)s/subInstance-1/share/public/"}, "private_url": {"href": "%(base)s/subInstance-1/share/private/"}}, "state": {"warning": 0, "success": 3, "error": 0}, "_embedded": {"instance": {"partition": "slappart1", "ipv6": "2001:67c:1254:e:c4::c748", "computer": "slaprunner", "ipv4": "10.0.165.37", "software-release": "http://xxx.yyy.zz/asoftware/software.cfg", "software-type": "pull-backup"}}, "parameters": [{"key": "", "value": "some parameter", "title": "demo"}], "title": "subInstance-1", "date": "2020-01-17 13:16:59", "type": "global", "hosting-title": "TEST Hosting Subscription", "data": {"process_state": "monitor_process_resource.status", "io_resource": "monitor_resource_io.data", "state": "monitor_state.data", "memory_resource": "monitor_resource_memory.data", "process_resource": "monitor_resource_process.data", "monitor_process_state": "monitor_resource.status"}}""",
'subInstance-1/public/test_promise_0.json': """{"status": "ERROR", "change-time": 1579263419.247024, "instance": "subInstance-1", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_0", "_links": {"monitor": {"href": "%(base)s/subInstance-1/share/private/"}}, "message": "Test Promise ran with status ERROR", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-1/public/test_promise_1.json': """{"status": "ERROR", "change-time": 1579263419.247024, "instance": "subInstance-1", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_1", "_links": {"monitor": {"href": "%(base)s/subInstance-1/share/private/"}}, "message": "Test Promise ran with status ERROR", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-1/public/test_promise_2.json': """{"status": "ERROR", "change-time": 1579263419.247024, "instance": "subInstance-1", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_2", "_links": {"monitor": {"href": "%(base)s/subInstance-1/share/private/"}}, "message": "Test Promise ran with status ERROR", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-1/public/test_promise_3.json': """{"status": "ERROR", "change-time": 1579263419.247024, "instance": "subInstance-1", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_3", "_links": {"monitor": {"href": "%(base)s/subInstance-1/share/private/"}}, "message": "Test Promise ran with status ERROR", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/feed': """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>subInstance-2</title>
<link>%(base)s/subInstance-2/public/feed</link>
<description>TEST Hosting Subscription</description>
<lastBuildDate>Fri, 17 Jan 2020 12:16:59 +0000</lastBuildDate>
<docs>%(base)s/gc//blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>test_promise_5</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_5</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_5</source>
</item>
<item>
<title>test_promise_3</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_3</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_3</source>
</item>
<item>
<title>test_promise_6</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_6</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_6</source>
</item>
<item>
<title>test_promise_0</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_0</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_0</source>
</item>
<item>
<title>test_promise_2</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_2</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_2</source>
</item>
<item>
<title>test_promise_1</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_1</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_1</source>
</item>
<item>
<title>test_promise_4</title>
<link>%(base)s/subInstance-2/share/private/</link>
<description>description of test_promise_4</description>
<category>OK</category>
<comments />
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l1579263419==</guid>
<pubDate>Fri, 17 Jan 2020 12:16:59 +0000</pubDate>
<source url="%(base)s/subInstance-2/share/public/">test_promise_4</source>
</item>
</channel>
</rss>""",
'subInstance-2/public/test_promise_0.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_0", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_1.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_1", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_2.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_2", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_3.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_3", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_4.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_4", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_5.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_5", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/public/test_promise_6.json': """{"status": "OK", "change-time": 1579263419.247408, "instance": "subInstance-2", "hosting_subscription": "TEST Hosting Subscription", "title": "test_promise_6", "_links": {"monitor": {"href": "%(base)s/subInstance-2/share/private/"}}, "message": "Test Promise ran with status OK", "start-date": "2020-01-17 13:16:59", "type": "status"}""",
'subInstance-2/private/_document_list': """monitor.global""",
'subInstance-2/private/monitor.global.json': """{"status": "OK", "_links": {"rss_url": {"href": "%(base)s/subInstance-2/public/feed"}, "public_url": {"href": "%(base)s/subInstance-2/share/public/"}, "private_url": {"href": "%(base)s/subInstance-2/share/private/"}}, "state": {"warning": 0, "success": 3, "error": 0}, "_embedded": {"instance": {"partition": "slappart1", "ipv6": "2001:67c:1254:e:c4::c748", "computer": "slaprunner", "ipv4": "10.0.165.37", "software-release": "http://xxx.yyy.zz/asoftware/software.cfg", "software-type": "pull-backup"}}, "parameters": [{"key": "", "value": "some parameter", "title": "demo"}], "title": "subInstance-2", "date": "2020-01-17 13:16:59", "type": "global", "hosting-title": "TEST Hosting Subscription", "data": {"process_state": "monitor_process_resource.status", "io_resource": "monitor_resource_io.data", "state": "monitor_state.data", "memory_resource": "monitor_resource_memory.data", "process_resource": "monitor_resource_process.data", "monitor_process_state": "monitor_resource.status"}}""",
}.get(path, None)
if 'json' in path:
context.REQUEST.response.setHeader('Content-Type', 'application/json')
if value is None:
value = '{}'
if value is not None:
return value % {'base': base}
<?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>path</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MonitorBackend_simulatorMapping</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -10,6 +10,11 @@
<tr><td rowspan="1" colspan="3">Test SlapOS Monitoring UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<tr>
<td>store</td>
<td tal:content="here/portal_tests/web_monitoring_ui_zuite/MonitorBackend_getBaseUrl">http://example.com/erp5</td>
<td>monitor_simulator_url</td>
</tr>
<!-- Clean Up -->
<tr>
<td>open</td>
......@@ -89,7 +94,7 @@
</tr>
<tr>
<td>store</td>
<td>http://localhost:5378/rootInstance/public/feeds</td>
<td>${monitor_simulator_url}/rootInstance/public/feeds</td>
<td>opml_url</td>
</tr>
<tr>
......
......@@ -27,285 +27,19 @@
import unittest
from Products.ERP5Type.tests.ERP5TypeFunctionalTestCase import ERP5TypeFunctionalTestCase
from SimpleHTTPServer import SimpleHTTPRequestHandler
from threading import Thread
from datetime import datetime
import SocketServer
import tempfile
import shutil
import time
import os
import json
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPRequestHandler.end_headers(self)
def send_respond(self, code=200, content_type='text/html'):
self.send_response(code)
self.send_header("Content-type", content_type)
self.end_headers()
def send_my_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "HEAD, OPTIONS, GET, POST")
self.send_header("Access-Control-Allow-Headers", "Overwrite, Destination, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Authorization")
def do_GET(self):
SimpleHTTPRequestHandler.do_GET(self)
def do_OPTIONS(self):
self.send_respond(200)
def do_HEAD(self):
self.send_respond()
class TestZeleniumCore(ERP5TypeFunctionalTestCase):
class TestFunctionalOfficejsMonitoring(ERP5TypeFunctionalTestCase):
foreground = 0
run_only = "web_monitoring_ui_zuite"
base_url = 'http://localhost:5378'
instance_list = []
httpd = None
httpd_is_alive = False
root_title = "TEST Hosting Subscription"
def start_httpd_server(self, root_folder):
self.httpd = SocketServer.TCPServer(('localhost', 5378), CustomHTTPRequestHandler)
self.httpd.timeout = 2
os.chdir(root_folder)
#self.httpd.serve_forever()
while self.httpd_is_alive:
self.httpd.handle_request()
self.httpd = None
def afterSetUp(self):
ERP5TypeFunctionalTestCase.afterSetUp(self)
self.http_root_dir = tempfile.mkdtemp()
print "Serving files on http from %r" % self.http_root_dir
self.generateMonitoringInstanceTree()
self.httpd_is_alive = True
thread = Thread(target=self.start_httpd_server, args=(self.http_root_dir,))
thread.daemon = True
thread.start()
def beforeTearDown(self):
self.httpd_is_alive = False
# Wait for httpd server stop
time.sleep(3)
if os.path.exists(self.http_root_dir):
shutil.rmtree(self.http_root_dir)
ERP5TypeFunctionalTestCase.beforeTearDown(self)
def getBusinessTemplateList(self):
return (
'erp5_ui_test',
'erp5_web_monitoring',
'erp5_web_monitoring_ui_test',
'erp5_ui_test_core',
)
def generateInstanceDirectory(self, name):
root_dir = os.path.join(self.http_root_dir, name)
public_http_dir = os.path.join(root_dir, 'public')
private_http_dir = os.path.join(root_dir, 'private')
webdav_http_dir = os.path.join(root_dir, 'share')
os.mkdir(root_dir)
os.mkdir(public_http_dir)
os.mkdir(private_http_dir)
os.mkdir(webdav_http_dir)
webdav_public_dir = os.path.join(webdav_http_dir, 'public')
webdav_private_dir = os.path.join(webdav_http_dir, 'private')
os.symlink(public_http_dir, webdav_public_dir)
os.symlink(private_http_dir, webdav_private_dir)
instance = dict(
title=name,
public_dir=public_http_dir,
private_dir=private_http_dir,
url=self.base_url + '/' + name
)
self.instance_list.append(instance)
return instance
def generatePromiseResult(self, instance, status='OK', amount=1):
now_time = time.time()
start_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
for i in range(0, amount):
title = 'test_promise_%s' % i
result_dict = {
"status": status,
"change-time": now_time,
"hosting_subscription": self.root_title,
"title": title,
"start-date": start_date,
"instance": instance['title'],
"_links": {
"monitor": {
"href": "%s/share/private/" % instance['url']
}
},
"message": "Test Promise ran with status %s" % status,
"type": "status"
}
with open(os.path.join(instance['public_dir'], '%s.json' % title), 'w') as f:
f.write(json.dumps(result_dict))
def generateOPMLFile(self, instance, sub_instance_list=[]):
creation_date = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
opml_content = """<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by SlapOS -->
<opml version="1.1">
<head>
<title>%(root_title)s</title>
<dateCreated>%(creation_date)s</dateCreated>
<dateModified>%(creation_date)s</dateModified>
</head>
<body>
<outline text="Monitoring RSS Feed list">""" % {
"root_title": self.root_title,
"creation_date": creation_date
}
opml_content += '\n<outline text="%(title)s" title="%(title)s" type="rss" version="RSS" htmlUrl="%(html_url)s" xmlUrl="%(html_url)s" url="%(global_url)s" />' % {
"title": instance['title'],
"html_url": '%s/public/feed' % instance['url'],
"global_url": "%s/share/private/" % instance['url'],
}
for sub_instance in sub_instance_list:
opml_content += '\n<outline text="%(title)s" title="%(title)s" type="rss" version="RSS" htmlUrl="%(html_url)s" xmlUrl="%(html_url)s" url="%(global_url)s" />' % {
"title": sub_instance['title'],
"html_url": '%s/public/feed' % sub_instance['url'],
"global_url": "%s/share/private/" % sub_instance['url'],
}
opml_content += """ </outline>
</body>
</opml>"""
with open(os.path.join(instance['public_dir'], 'feeds'), 'w') as f:
f.write(opml_content)
def generateInstanceRssFeed(self, instance):
promise_list = [name.rstrip('.json')
for name in os.listdir(instance['public_dir']) if name.endswith('.json')]
rss_content = """<rss version="2.0">
<channel>
<title>%(instance)s</title>
<link>%(link)s</link>
<description>%(description)s</description>
<lastBuildDate>%(date)s</lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>""" % {
"description": self.root_title,
"link": '%s/public/feed' % instance['url'],
"instance": instance['title'],
"date": datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
}
for promise in promise_list:
item = """<item>
<title>%(title)s</title>
<link>
%(base_url)s/share/private/
</link>
<description>%(description)s</description>
<category>%(status)s</category>
<comments/>
<guid isPermaLink="false">VU5LTk9XTiwgc2xhcHJ1bm5l%(id)s==</guid>
<pubDate>%(date)s</pubDate>
<source url="%(base_url)s/share/public/">%(title)s</source>
</item>""" % {
"base_url": instance['url'],
"title": promise,
"status": "OK",
"description": "description of %s" % promise,
"id": int(time.time()),
"date": datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000")
}
rss_content += item
rss_content += """</channel></rss>"""
with open(os.path.join(instance['public_dir'], 'feed'), 'w') as f:
f.write(rss_content.replace('\n', ''))
def generateMonitoringStatusFile(self, instance, status="OK"):
monitor_dict = {
"status": status,
"state": {
"warning": 0,
"success": 3,
"error": 0
},
"title": instance['title'],
"date": datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
"data": {
"process_state": "monitor_process_resource.status",
"io_resource": "monitor_resource_io.data",
"state": "monitor_state.data",
"memory_resource": "monitor_resource_memory.data",
"process_resource": "monitor_resource_process.data",
"monitor_process_state": "monitor_resource.status"
},
"hosting-title": self.root_title,
"type": "global",
"_embedded": {
"instance": {
"partition": "slappart1",
"ipv6": "2001:67c:1254:e:c4::c748",
"computer": "slaprunner",
"ipv4": "10.0.165.37",
"software-release": "http://xxx.yyy.zz/asoftware/software.cfg",
"software-type": "pull-backup"
}
},
"parameters": [{"title": "demo", "value": "some parameter", "key": ""}],
"_links": {
"rss_url": {
"href": "%s/public/feed" % instance['url']
},
"public_url": {
"href": "%s/share/public/" % instance['url']
},
"private_url": {
"href": "%s/share/private/" % instance['url']
}
}
}
with open(os.path.join(instance['private_dir'], 'monitor.global.json'), 'w') as f:
f.write(json.dumps(monitor_dict))
with open(os.path.join(instance['private_dir'], '_document_list'), 'w') as f:
f.write("monitor.global")
def generateMonitoringInstanceTree(self):
# root instance
root_instance = self.generateInstanceDirectory("rootInstance")
self.generatePromiseResult(root_instance, status='OK', amount=5)
self.generateInstanceRssFeed(root_instance)
self.generateMonitoringStatusFile(root_instance, status='OK')
# sub instance1
sub_instance1 = self.generateInstanceDirectory("subInstance-1")
self.generatePromiseResult(sub_instance1, status='ERROR', amount=4)
self.generateInstanceRssFeed(sub_instance1)
self.generateMonitoringStatusFile(sub_instance1, status='ERROR')
# sub instance2
sub_instance2 = self.generateInstanceDirectory("subInstance-2")
self.generatePromiseResult(sub_instance2, status='OK', amount=7)
self.generateInstanceRssFeed(sub_instance2)
self.generateMonitoringStatusFile(sub_instance2, status='OK')
self.generateOPMLFile(root_instance, [sub_instance1, sub_instance2])
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestZeleniumCore))
suite.addTest(unittest.makeSuite(TestFunctionalOfficejsMonitoring))
return suite
\ No newline at end of file
......@@ -45,9 +45,7 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W:161, 2: Dangerous default value [] as argument (dangerous-default-value)</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......
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