Commit 939b057e authored by Benjamin Blanc's avatar Benjamin Blanc

fixup! bootstrap erp5: change the way to get zope password and username

parent a49f7809
...@@ -46,24 +46,62 @@ class Recipe(GenericBaseRecipe): ...@@ -46,24 +46,62 @@ class Recipe(GenericBaseRecipe):
password=parsed.password password=parsed.password
) )
zope_parsed = urlparse.urlparse(self.options['zope-url']) # Init zope configuration
zope_username = None
zope_password = None
zope_hostname = None
zope_port = None
zope_protocol = None
# Extract zope username/password from url, or get it from options # Get informations from zope url
if zope_parsed.username: if self.options.get('zope-url'):
zope_username = zope_parsed.username zope_parsed = urlparse.urlparse(self.options['zope-url'])
# Zope hostname
if self.options.get('zope-hostname'):
zope_hostname = self.options['zope-hostname']
elif self.options.get('zope-url'):
zope_hostname = zope_parsed.hostname
else: else:
zope_hostname = 'localhost'
# Zope port
if self.options.get('zope-port'):
zope_port = self.options['zope-port']
elif self.options.get('zope-url'):
zope_port = zope_parsed.port
else:
zope_port = 8080
# Zope username and password
if self.options.get('zope-username') and self.options.get('zope-password'):
zope_username = self.options['zope-username'] zope_username = self.options['zope-username']
if zope_parsed.password: zope_password = self.options['zope-password']
elif self.options.get('zope-url'):
zope_username = zope_parsed.username
zope_password = zope_parsed.password zope_password = zope_parsed.password
else: else:
zope_password = self.options['zope-password'] zope_username = 'zope'
zope_password = 'insecure'
# Zope protocol
if self.options.get('zope-protocol'):
zope_protocol = self.options['zope-protocol']
elif self.options.get('zope-url'):
zope_protocol = zope_parsed.scheme
else:
zope_protocol = 'http'
# Zope site-id
if self.options.get('zope-site-id'):
zope_site_id = self.options['zope-site-id']
elif self.options.get('zope-url'):
zope_site_id = zope_parsed.path.split('/')[1],
else:
zope_site_id = 'erp5'
config = dict( config = dict(
python_path=sys.executable, python_path=sys.executable,
user=zope_username, user=zope_username,
password=zope_password, password=zope_password,
site_id=zope_parsed.path.split('/')[1], site_id=zope_site_id,
host="%s:%s" % (zope_parsed.hostname, zope_parsed.port), host="%s:%s" % (zope_hostname, zope_port),
protocol=zope_protocol,
sql_connection_string=mysql_connection_string, sql_connection_string=mysql_connection_string,
) )
......
...@@ -10,10 +10,17 @@ host = "%(host)s" ...@@ -10,10 +10,17 @@ host = "%(host)s"
site_id = "%(site_id)s" site_id = "%(site_id)s"
erp5_catalog_storage = 'erp5_mysql_innodb_catalog' erp5_catalog_storage = 'erp5_mysql_innodb_catalog'
mysql_url = "%(sql_connection_string)s" mysql_url = "%(sql_connection_string)s"
protocol = "%(protocol)s"
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 = httplib.HTTPConnection(host)
if protocol == 'https':
zope_connection = httplib.HTTPSConnection(host)
elif protocol == 'http':
zope_connection = httplib.HTTPConnection(host)
else:
raise ValueError("Protocol '%s' is not implemented" %(protocol))
# 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
...@@ -23,7 +30,12 @@ result = zope_connection.getresponse() ...@@ -23,7 +30,12 @@ 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
if protocol == 'https':
zope_connection = httplib.HTTPSConnection(host)
elif protocol == 'http':
zope_connection = httplib.HTTPConnection(host) zope_connection = httplib.HTTPConnection(host)
else:
raise ValueError("Protocol '%s' is not implemented" %(protocol))
# Create the expected ERP5 instance # Create the expected ERP5 instance
zope_connection.request( zope_connection.request(
......
...@@ -329,7 +329,7 @@ md5sum = c745d794b28cae64feba527f894d7340 ...@@ -329,7 +329,7 @@ md5sum = c745d794b28cae64feba527f894d7340
[template-scalability] [template-scalability]
< = download-base < = download-base
filename = instance-scalability.cfg.in filename = instance-scalability.cfg.in
md5sum = c8f9af16a3cf00c2f61c5cbdb1439c6e md5sum = 761ff41d4f79cba89034a18aaf29ab27
[template-zeo] [template-zeo]
< = download-base < = download-base
......
...@@ -98,7 +98,7 @@ runner-path = ${basedirectory:services}/erp5-bootstrap ...@@ -98,7 +98,7 @@ runner-path = ${basedirectory:services}/erp5-bootstrap
mysql-url = ${erp5-cluster:connection-mariadb-url} mysql-url = ${erp5-cluster:connection-mariadb-url}
zope-username = zope zope-username = zope
zope-password = insecure zope-password = insecure
zope-url = ${erp5-cluster:connection-family-scalability}/erp5 zope-url = ${erp5-cluster:connection-family-scalability}/{{ site_id }}
[erp5-promise] [erp5-promise]
recipe = slapos.cookbook:erp5.promise recipe = slapos.cookbook:erp5.promise
......
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