Commit 3e8439b3 authored by Lisa Casino's avatar Lisa Casino

sotware/html5as-base: switch to switch-softwaretype

Also improve the recipe `switch-softwaretype' by catching the possible errors.

- directory html5as: final version 
- directory html5as-base: initial version

See merge request !1006
parents b10757c4 b9a16442
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
# #
############################################################################## ##############################################################################
from zc.buildout.buildout import Buildout, MissingOption, MissingSection
from zc.buildout.buildout import Buildout from zc.buildout import UserError
class SubBuildout(Buildout): class SubBuildout(Buildout):
"""Run buildout in buildout, partially copied from infrae.buildout """Run buildout in buildout, partially copied from infrae.buildout
...@@ -71,8 +70,21 @@ class Recipe: ...@@ -71,8 +70,21 @@ class Recipe:
self.buildout = buildout self.buildout = buildout
self.options = options self.options = options
self.name = name self.name = name
self.software_type = buildout["slap-configuration"]["slap-software-type"] try:
section, key = self.options[self.software_type].split(":") self.software_type = buildout["slap-configuration"]["slap-software-type"]
except (MissingSection, MissingOption):
raise UserError("The section to retrieve slap partition parameters "
"(with slapos.cookbook:slapconfiguration recipe or a derived one) "
"must be named [slap-configuration].")
try:
section, key = self.options[self.software_type].split(":")
except MissingOption:
raise MissingOption("This software type (%s) isn't mapped. RootSoftwareInstance "
"is the default software type." % self.software_type)
except ValueError:
raise UserError("The software types in the section [%s] must be separated "
"by a colon such as: 'section:key', where key is usually 'rendered'. "
"Don't use: ${section:key}" % self.name)
self.base = self.buildout[section][key] self.base = self.buildout[section][key]
def install(self): def install(self):
......
...@@ -21,7 +21,16 @@ filename = instance-html5as.cfg ...@@ -21,7 +21,16 @@ filename = instance-html5as.cfg
context = context =
section buildout buildout section buildout buildout
section parameter_list profile-common section parameter_list profile-common
# partition_ipv6 is the random ipv6 allocated to the local partition
key partition_ipv6 slap-configuration:ipv6-random
[switch-softwaretype] [switch-softwaretype]
recipe = slapos.cookbook:softwaretype recipe = slapos.cookbook:switch-softwaretype
default = ${instance-html5as:rendered} RootSoftwareInstance = ${:default}
default = instance-html5as:rendered
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
...@@ -70,7 +70,7 @@ scgi_temp_path = ${:tmp}/scgi_temp_path ...@@ -70,7 +70,7 @@ scgi_temp_path = ${:tmp}/scgi_temp_path
nb_workers = 2 nb_workers = 2
# Network # Network
ip = ${slap-network-information:global-ipv6} ip = {{ partition_ipv6 }}
port = 8081 port = 8081
access_url = http://[${:ip}]:${:port} access_url = http://[${:ip}]:${:port}
......
...@@ -27,7 +27,7 @@ recipe = slapos.recipe.template:jinja2 ...@@ -27,7 +27,7 @@ recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/template.cfg rendered = ${buildout:directory}/template.cfg
template = ${:_profile_base_location_}/${:filename} template = ${:_profile_base_location_}/${:filename}
filename = instance.cfg.in filename = instance.cfg.in
md5sum = 5a6ebc126bcad3cdff1b51fb51f82a35 md5sum = 9bff013ed8b610f7cc5452c1582eccf2
mode = 0644 mode = 0644
context = context =
section buildout buildout section buildout buildout
...@@ -43,7 +43,7 @@ context = ...@@ -43,7 +43,7 @@ context =
recipe = slapos.recipe.build:download recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_} url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = instance_html5as.cfg.in _update_hash_filename_ = instance_html5as.cfg.in
md5sum = 4a8c98cc5ca141f78f14fb9cec203cb8 md5sum = 9b7ed68551cac5967915979383238669
mode = 0644 mode = 0644
[template_nginx_conf] [template_nginx_conf]
...@@ -71,8 +71,3 @@ mode = 0644 ...@@ -71,8 +71,3 @@ mode = 0644
recipe = zc.recipe.egg recipe = zc.recipe.egg
eggs = eggs =
plone.recipe.command plone.recipe.command
# Pin versions of eggs used that are not already pinned by stack/slapos.cfg
[versions]
slapos.recipe.template = 4.4
plone.recipe.command = 1.1
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
[template-cfg] [template-cfg]
filename = instance.cfg.in filename = instance.cfg.in
md5sum = 0a7aceffa5222e88125b72da42ddedd7 md5sum = 1b6d628b3a04497f525f860dd0003d84
[instance_html5as] [instance_html5as]
_update_hash_filename_ = instance_html5as.cfg.in _update_hash_filename_ = instance_html5as.cfg.in
md5sum = 96fe1540aa458db434abc20353e034c8 md5sum = 2aee5fede6e804c1b9c1400f41f2f51e
[template_nginx_conf] [template_nginx_conf]
_update_hash_filename_ = templates/nginx_conf.in _update_hash_filename_ = templates/nginx_conf.in
...@@ -45,4 +45,4 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2 ...@@ -45,4 +45,4 @@ md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2
[template_instance_replicate] [template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in _update_hash_filename_ = instance_replicate.cfg.in
md5sum = 38d1d352307f79c9c99bf2a80a5c76b8 md5sum = aef3b91f4cbaf6f7a14986bc8d1aba65
...@@ -13,7 +13,7 @@ tar_location = {{ tar_location }} ...@@ -13,7 +13,7 @@ tar_location = {{ tar_location }}
curl_location = {{ curl_location }} curl_location = {{ curl_location }}
template_nginx_conf = {{ template_nginx_conf_target }} template_nginx_conf = {{ template_nginx_conf_target }}
template_mime_types = {{ template_mime_types_target }} template_mime_types = {{ template_mime_types_target }}
template_launcher = {{ template_launcher_target }} template_launcher = {{ template_launcher_target }}
template_index_html = {{ template_index_html_target }} template_index_html = {{ template_index_html_target }}
template_graceful = {{ template_graceful_target }} template_graceful = {{ template_graceful_target }}
template_monitor = {{ template_monitor }} template_monitor = {{ template_monitor }}
...@@ -26,24 +26,41 @@ filename = instance-html5as.cfg ...@@ -26,24 +26,41 @@ filename = instance-html5as.cfg
context = context =
section buildout buildout section buildout buildout
section parameter_list profile-common section parameter_list profile-common
# partition_ipv6 is the random ipv6 allocated to the local partition
key partition_ipv6 slap-configuration:ipv6-random
key slapparameter_dict slap-configuration:configuration
jsonkey default_parameter_dict :default-parameters
default-parameters =
{
"title": "",
"download_url": "",
"port": 8081
}
[instance-replicate] [instance-replicate]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
template = {{ template_instance_replicate }} template = {{ template_instance_replicate }}
rendered = ${buildout:directory}/${:filename} rendered = ${buildout:directory}/${:filename}
filename = instance-replicate-html5as.cfg filename = instance-replicate-html5as.cfg
context = context =
section buildout buildout section buildout buildout
section parameter_list profile-common section parameter_list profile-common
key slapparameter_dict slap-parameters:configuration key slapparameter_dict slap-configuration:configuration
jsonkey default_parameter_dict :default-parameters
default-parameters =
{
"download_url": "",
"replicate-quantity": 1
}
[switch-softwaretype] [switch-softwaretype]
recipe = slapos.cookbook:softwaretype recipe = slapos.cookbook:switch-softwaretype
default = ${instance-html5as:rendered} RootSoftwareInstance = ${:default}
replicate = ${instance-replicate:rendered} default = instance-html5as:rendered
replicate = instance-replicate:rendered
# Section needed to be added manually here to retrieve parameters [slap-configuration]
[slap-parameters]
recipe = slapos.cookbook:slapconfiguration recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id} computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id} partition = ${slap-connection:partition-id}
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# Deploy html5as instance # Deploy html5as instance
# #
############################# #############################
{% set parameter_dict = dict(default_parameter_dict, **slapparameter_dict) %}
[buildout] [buildout]
parts = parts =
nginx_conf nginx_conf
...@@ -76,8 +78,8 @@ scgi_temp_path = ${:tmp}/scgi_temp_path ...@@ -76,8 +78,8 @@ scgi_temp_path = ${:tmp}/scgi_temp_path
nb_workers = 2 nb_workers = 2
# Network # Network
ip = ${slap-network-information:global-ipv6} ip = {{ partition_ipv6 }}
port = ${slap-parameter:port} port = {{ parameter_dict['port'] }}
access_url = http://[${:ip}]:${:port} access_url = http://[${:ip}]:${:port}
# Paths # Paths
...@@ -138,7 +140,7 @@ stop-on-error = true ...@@ -138,7 +140,7 @@ stop-on-error = true
# If the parameter is not provided it fallback to the default template # If the parameter is not provided it fallback to the default template
command = command =
rm -rf ${html5as:docroot}/*; rm -rf ${html5as:docroot}/*;
URL="${slap-parameter:download_url}"; URL = {{ parameter_dict['download_url'] }};
if [ -n "$URL" ]; if [ -n "$URL" ];
then then
${html5as:curl-binary} -Lks $URL | ${html5as:tar-binary} xzv -C ${html5as:docroot} --strip-components 1; ${html5as:curl-binary} -Lks $URL | ${html5as:tar-binary} xzv -C ${html5as:docroot} --strip-components 1;
...@@ -150,8 +152,9 @@ command = ...@@ -150,8 +152,9 @@ command =
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = {{ parameter_list['template_index_html'] }} template = {{ parameter_list['template_index_html'] }}
rendered = ${directory:srv}/index.html rendered = ${directory:srv}/index.html
title = {{ parameter_dict['title'] }}
context = context =
key title slap-parameter:title key title :title
### Nginx Graceful ### Nginx Graceful
[nginx-graceful] [nginx-graceful]
...@@ -177,7 +180,7 @@ monitor-httpd-port = 8197 ...@@ -177,7 +180,7 @@ monitor-httpd-port = 8197
# Monitor Stack also provides logrotate stack. We only need to extend # Monitor Stack also provides logrotate stack. We only need to extend
# the logrotate-entry-base defined in instance-logrotate-base.cfg.in . # the logrotate-entry-base defined in instance-logrotate-base.cfg.in .
# More parameters can be added following the logrotate-entry-base section # More parameters can be added following the logrotate-entry-base section
[logrotate-entry-nginx] [logrotate-entry-nginx]
<= logrotate-entry-base <= logrotate-entry-base
name = nginx name = nginx
...@@ -191,7 +194,7 @@ recipe = slapos.cookbook:publish ...@@ -191,7 +194,7 @@ recipe = slapos.cookbook:publish
# be deployed. The parameters needed for accessing monitoring will be published # be deployed. The parameters needed for accessing monitoring will be published
<= monitor-publish <= monitor-publish
server_url = ${html5as:access_url} server_url = ${html5as:access_url}
title = Title ${slap-parameter:title}! title = Title {{ parameter_dict['title'] }}!
# Add dependency to the promise so that frontend sections are processed # Add dependency to the promise so that frontend sections are processed
# and there is no need to declare the new part in buildout:parts # and there is no need to declare the new part in buildout:parts
server-cdn-url = ${html5as-frontend-promise:url} server-cdn-url = ${html5as-frontend-promise:url}
...@@ -220,8 +223,3 @@ name = html5as-http-frontend.py ...@@ -220,8 +223,3 @@ name = html5as-http-frontend.py
url = ${html5as-frontend:connection-secure_access} url = ${html5as-frontend:connection-secure_access}
config-url = ${:url} config-url = ${:url}
config-check-secure = 1 config-check-secure = 1
[slap-parameter]
title =
download_url =
port = 8081
{% set replicate_quantity = slapparameter_dict.pop('replicate-quantity', '1') | int %} {%- set parameter_dict = dict(default_parameter_dict, **slapparameter_dict) %}
{%- set replicate_quantity = int(parameter_dict['replicate-quantity']) %}
# Set default title and port for each replicate based on requested quantity
{%- for i in range(1, replicate_quantity + 1) %}
{%- do parameter_dict.setdefault("title-%d" % i, "") %}
{%- do parameter_dict.setdefault("port-%d" % i, 8081 + i) %}
{%- endfor %}
# Standard buildout section
[buildout] [buildout]
parts = parts =
publish-connection-information publish-connection-information
...@@ -7,6 +15,11 @@ eggs-directory = {{ buildout['eggs-directory'] }} ...@@ -7,6 +15,11 @@ eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = {{ buildout['develop-eggs-directory'] }} develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
offline = true offline = true
################################
# Sections to Request instances
################################
# Macro section sharing request parameters
[instance-request-base] [instance-request-base]
<= slap-connection <= slap-connection
recipe = slapos.cookbook:request recipe = slapos.cookbook:request
...@@ -17,29 +30,23 @@ software-type = default ...@@ -17,29 +30,23 @@ software-type = default
# What parameter are neede to be retrieved # What parameter are neede to be retrieved
return = server_url server-cdn-url monitor-setup-url return = server_url server-cdn-url monitor-setup-url
# Provided parameters # Provided parameters
config-title = ${slap-parameter:title} config-download_url = {{ parameter_dict['download_url'] }}
config-download_url = ${slap-parameter:download_url}
# Create request section in a loop.
{% for i in range(1, replicate_quantity + 1) %} {% for i in range(1, replicate_quantity + 1) %}
# Request a normal html5as instance # Request a normal html5as instance
[instance-{{ i }}] [instance-{{ i }}]
<= instance-request-base <= instance-request-base
# Name of the instance # Name of the instance
name = instance-html5as-{{ i }} name = instance-html5as-{{ i }}
config-port = ${slap-parameter:port-{{ i }}} config-port = {{ parameter_dict["port-%s" % i] }}
config-title = ${slap-parameter:title-{{ i }}} config-title = {{ parameter_dict["title-%s" % i] }}
{% if "sla-%s-computer-guid" % i in slapparameter_dict -%} {% if "sla-%s-computer-guid" % i in parameter_dict -%}
sla-computer_guid = {{ slapparameter_dict["sla-%s-computer-guid" % i] }} sla-computer_guid = {{ parameter_dict["sla-%s-computer-guid" % i] }}
{% endif -%} {% endif -%}
{% endfor %} {% endfor %}
[slap-parameter] # Publish information to connect to the two instances
download_url =
{% for i in range(1, replicate_quantity + 1) %}
title-{{ i }} =
port-{{ i }} = 808{{ i }}
{% endfor %}
[publish-connection-information] [publish-connection-information]
recipe = slapos.cookbook:publish recipe = slapos.cookbook:publish
{% for i in range(1, replicate_quantity + 1) %} {% for i in range(1, replicate_quantity + 1) %}
......
...@@ -79,7 +79,3 @@ mode = 0644 ...@@ -79,7 +79,3 @@ mode = 0644
[template_instance_replicate] [template_instance_replicate]
<= download-base <= download-base
# Pin versions of eggs used that are not already pinned by stack/slapos.cfg
[versions]
slapos.recipe.template = 4.4
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