Commit e3492d2f authored by Roque Porchetto's avatar Roque Porchetto

erp5_scalability_test: new script for metrics

- ERP5Site_getScalabilityTestMetric script gets metrics of last created objects
- Bootstrap script now creates the users for test
parent 6e20efd7
# Script that installs the configurator for scalabiility tests: # Script that installs the configurator and create users for scalabiility tests:
import time import time
from DateTime import DateTime
import random
import string
import json
request = context.REQUEST
portal = context.getPortalObject() portal = context.getPortalObject()
portal_catalog = portal.portal_catalog portal_catalog = portal.portal_catalog
now = DateTime()
status_code = 0 status_code = 0
error_message = "No error." error_message = "No error."
configurator = portal_catalog.getResultValue( # check erp5_scalability_test business template is present
portal_type = "Business Configuration", configurator = portal.business_configuration_module.default_standard_configuration
id = "default_standard_configuration",
title = "Small And Medium Business")
if configurator == None or not configurator.contentValues(portal_type='Configuration Save'): if configurator == None or not configurator.contentValues(portal_type='Configuration Save'):
error_message = "Could not find the scalability business configuration object. Be sure to have erp5_scalability_test business template installed." error_message = "Could not find the scalability business configuration object. Be sure to have erp5_scalability_test business template installed."
return {'status_code' : 1, 'error_message': error_message } return json.dumps({"status_code" : 1, "error_message": error_message })
try: # install configurator if not intalled
if configurator.getSimulationState() == "Draft":
try:
configurator.buildConfiguration() configurator.buildConfiguration()
# wait 15 minutes while configurator is installed # wait 15 minutes while configurator is installed
time.sleep(15*60) time.sleep(15*60)
except Exception as e: except Exception as e:
status_code = 1 status_code = 1
error_message = "Error during installation: " + str(e) error_message = "Error during installation: " + str(e)
return {'status_code' : status_code, 'error_message': error_message } # create users
user_quantity = request.get('user_quantity')
if user_quantity is None: return json.dumps({"status_code" : 1, "error_message": "Parameter 'user_quantity' is required.", "password" : None })
password = ''.join(random.choice(string.digits + string.letters) for i in xrange(10))
try:
organisation = portal_catalog.getResultValue(
portal_type="Organisation",
title = 'Scalability company')
if organisation is None:
error_message = "Could not find the scalability organisation. Standard configuration not installed?"
return json.dumps({"status_code" : 1, "error_message": error_message, "password" : None })
organisation = organisation.getObject().getRelativeUrl()
for i in xrange(0, int(user_quantity)):
user_id = "scalability_user_%i" % i
person = portal_catalog.getResultValue(
portal_type="Person",
id = user_id)
if person is None:
person = portal.person_module.newContent(
portal_type = "Person",
id = user_id,
first_name = "scalability",
last_name = "user %i" % i,
function_list = ["company/manager"],
)
person.validate()
assignment_id_list = [x.getId() for x in person.objectValues(portal_type="Assignment")]
if assignment_id_list: person.manage_delObjects(ids=assignment_id_list)
assignment = person.newContent(
portal_type = "Assignment",
id = "assignment_%s" % user_id,
title = "user assignment",
function_list = ["company/manager"],
destination_relative_url = organisation,
destination = organisation,
group_list = ["my_group"],
start_date = now,
stop_date = DateTime(3000, 1, 1)
)
assignment.open()
user_id_list = [x.getId() for x in person.objectValues(portal_type="ERP5 Login")]
if user_id_list: person.manage_delObjects(ids=user_id_list)
user = person.newContent(
portal_type = "ERP5 Login",
id = "login_%s" % user_id,
default_reference = user_id,
password = password,
)
user.validate()
except Exception as e:
status_code = 1
error_message = str(e)
return json.dumps({"status_code" : status_code, "error_message": error_message, "password" : password, "quantity" : user_quantity })
import json
from DateTime import DateTime
now = DateTime()
now_minus_6 = now - 1.0/24/60*6
now_minus_1 = now - 1.0/24/60*1
catalog_kw = {'creation_date': {'query': (now_minus_6, now_minus_1), 'range': 'minmax'}, 'validation_state': 'validated'}
portal = context.getPortalObject()
portal_catalog = portal.portal_catalog
person_count = len(portal_catalog(portal_type="Person", **catalog_kw))
sale_order_count = len(portal_catalog(portal_type="Sale Order", **catalog_kw))
person_per_hour = 60*person_count/5
sale_order_per_hour = 60*sale_order_count/5
output_string = """Person: %r doc/hour SaleOrder: %r doc/hour""" % (person_per_hour, sale_order_per_hour)
return json.dumps({"person_per_hour" : person_per_hour, "sale_order_per_hour": sale_order_per_hour})
<?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>ERP5Site_getScalabilityTestMetric</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