Commit 7d1e2d89 authored by Benjamin Blanc's avatar Benjamin Blanc

erp5_bootstrap: change way to bootstrap scalability business configuration

parent b70fdde8
...@@ -6,14 +6,7 @@ import base64 ...@@ -6,14 +6,7 @@ import base64
import time import time
MAX_INSTALLATION_TIME = 60*30 MAX_INSTALLATION_TIME = 60*30
MAX_TESTING_TIME = 60
def getConnection(protocol, host):
if protocol == 'https':
return httplib.HTTPSConnection(host)
elif protocol == 'http':
return httplib.HTTPConnection(host)
else:
raise ValueError("Protocol not implemented")
user = "%(user)s" user = "%(user)s"
password = "%(password)s" password = "%(password)s"
...@@ -22,24 +15,50 @@ site_id = "%(site_id)s" ...@@ -22,24 +15,50 @@ site_id = "%(site_id)s"
mysql_url = "%(sql_connection_string)s" mysql_url = "%(sql_connection_string)s"
protocol = "%(protocol)s" protocol = "%(protocol)s"
scalability = "%(scalability)s" == "True" scalability = "%(scalability)s" == "True"
erp5_catalog_storage = 'erp5_mysql_innodb_catalog' erp5_catalog_storage = 'erp5_mysql_innodb_catalog'
header_dict = {'Authorization': 'Basic %%s' %% \ header_dict = {'Authorization': 'Basic %%s' %% \
base64.encodestring('%%s:%%s' %% (user, password)).strip()} base64.encodestring('%%s:%%s' %% (user, password)).strip()}
zope_connection = getConnection(protocol,host) def getConnection():
if protocol == 'https':
return httplib.HTTPSConnection(host)
elif protocol == 'http':
return httplib.HTTPConnection(host)
else:
raise ValueError("Protocol not implemented")
def waitFor0PendingActivities():
# TODO: tolerate 1 pending activities ? (mail server...)
start_time = time.time()
while MAX_INSTALLATION_TIME > time.time()-start_time:
zope_connection = getConnection()
zope_connection.request(
'GET', '/%%s/portal_activities/getMessageList' %%(site_id),
headers=header_dict
)
message_list_text = result.read()
message_list = [s.strip() for s in message_list_text[1:-1].split(',')]
if len(message_list)==0:
print "There is no pending activities."
break
print "There is %d pending activities" %len(message_list)
def testIfExist(page, unexcepted_word_content="Site Error"):
zope_connection = getConnection()
zope_connection.request('GET', '/%%s/%%s', site_id, pages)
result = zope_connection.getresponse()
return not unexcepted_content in result.read()
# Check if an ERP5 site is already created, as ERP5 does support having # Check if an ERP5 site is already created, as ERP5 does support having
# 2 instances in the same zope, and this script should not destroy user data # 2 instances in the same zope, and this script should not destroy user data
zope_connection = getConnection()
zope_connection.request('GET', '/isERP5SitePresent', headers=header_dict) zope_connection.request('GET', '/isERP5SitePresent', headers=header_dict)
result = zope_connection.getresponse() result = zope_connection.getresponse()
if result.status == 204: # and (result.read() == "False"): if result.status == 204: # and (result.read() == "False"):
# Use a new connection # Use a new connection
zope_connection = getConnection(protocol,host) zope_connection = getConnection()
# Create the expected ERP5 instance # Create the expected ERP5 instance
zope_connection.request( zope_connection.request(
'POST', '/manage_addProduct/ERP5/manage_addERP5Site', 'POST', '/manage_addProduct/ERP5/manage_addERP5Site',
...@@ -60,64 +79,33 @@ if result.status == 204: # and (result.read() == "False"): ...@@ -60,64 +79,33 @@ if result.status == 204: # and (result.read() == "False"):
print "ERP5 site created." print "ERP5 site created."
#dirty way to wait erp5 site creation # Scalability case
time.sleep(30)
# Scalability: Install and configure small buisiness
if scalability: if scalability:
print "Scalability case"
# Here check if configurator is available # Fix site consistency
configurator_available = False if not testIfExist("/%%s/portal_configurator/" %site_id):
if not configurator_available: zope_connection = getConnection()
# Fix site consistency
zope_connection = getConnection(protocol,host)
zope_connection.request( zope_connection.request(
'GET', '/%%s/ERP5Site_launchFixConfigurationConsistency' %%(site_id), 'GET', '/%%s/ERP5Site_launchFixConfigurationConsistency' %%(site_id),
headers=header_dict headers=header_dict
) )
print "Check consistency..."
print "Check consistency sent"
result = zope_connection.getresponse() result = zope_connection.getresponse()
print result.read() print result.read()
print "Response read" # Wait activities
waitFor0PendingActivities()
# Dirty way to wait configurator availability print "Site consistency checking: done."
time.sleep(30)
# Install testing scalability business configuration if not exists
# Here check if configurator is available if testIfExist("/%%s/portal_configurator/" %site_id) \
# Send a request ? How to know if it is ready/available ? and not testIfExist("/%%s/sale_order_module/" %site_id):
configurator_available = False zope_connection = getConnection()
# Here check if S&MB not already installed
configurator_already_applied = False
business_object_name = "1"
if configurator_available and not configurator_already_applied:
# Install testing scalability business configuration
zope_connection = getConnection(protocol,host)
zope_connection.request( zope_connection.request(
'GET', '/%%s/business_configuration_module/%%s/build' %%(business_object_name, site_id), 'GET', '/%%s/business_configuration_module/1/build' %%(business_object_name, site_id),
headers=header_dict headers=header_dict
) )
print "Business building sent" print "Build scalability business configuration..."
print result.read() print result.read()
print "Response read" # Wait activities
waitFor0PendingActivities()
# Wait for 0-pending activities print "Scalability business configuration building: done."
start_time = time.time() \ No newline at end of file
while MAX_INSTALLATION_TIME > time.time()-start_time:
zope_connection = getConnection(protocol,host)
zope_connection.request(
'GET', '/%%s/portal_activities/getMessageList' %%(site_id),
headers=header_dict
)
message_list_text = result.read()
message_list = [s.strip() for s in message_list_text[1:-1].split(',')]
if len(message_list)==0:
print "There is no pending activities."
print "Testing scalability business configuration is ready."
break
print "Testing scalability business configuration not ready yet"
time.sleep(15)
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