Commit 5fe3c196 authored by Lisa Casino's avatar Lisa Casino

html5as: first commit, same as html5as-base

parent 0e4c73a9
......@@ -21,7 +21,15 @@ filename = instance-html5as.cfg
context =
section buildout buildout
section parameter_list profile-common
key ipv6_random slap-configuration:ipv6-random
[switch-softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${instance-html5as:rendered}
recipe = slapos.cookbook:switch-softwaretype
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}
......@@ -27,7 +27,7 @@ recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/template.cfg
template = ${:_profile_base_location_}/${:filename}
filename = instance.cfg.in
md5sum = 5a6ebc126bcad3cdff1b51fb51f82a35
md5sum = 77dff459e525c3d5e6e023cc58a3e000
mode = 0644
context =
section buildout buildout
......@@ -43,7 +43,7 @@ context =
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = 4a8c98cc5ca141f78f14fb9cec203cb8
md5sum = c17e861cdf132787f0a21184d76dc9fc
mode = 0644
[template_nginx_conf]
......
# To learn more about how to generate this file read
# ../../README.update-hash.rst
# THIS IS NOT A BUILDOUT FILE, despite purposedly using a compatible syntax.
# The only allowed lines here are (regexes):
# - "^#" comments, copied verbatim
# - "^[" section beginings, copied verbatim
# - lines containing an "=" sign which must fit in the following categorie.
# - "^\s*filename\s*=\s*path\s*$" where "path" is relative to this file
# Copied verbatim.
# - "^\s*hashtype\s*=.*" where "hashtype" is one of the values supported
# by the re-generation script.
# Re-generated.
# - other lines are copied verbatim
# Substitution (${...:...}), extension ([buildout] extends = ...) and
# section inheritance (< = ...) are NOT supported (but you should really
# not need these here).
[template-cfg]
filename = instance.cfg.in
md5sum = 0a7aceffa5222e88125b72da42ddedd7
[instance_html5as]
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = ec808dba866d85f7d37b85d75c13df2b
[template_nginx_conf]
_update_hash_filename_ = templates/nginx_conf.in
md5sum = 61dc4c82bf48563228ce4dea6c5c6319
[template_launcher]
_update_hash_filename_ = templates/launcher.in
md5sum = 6cb0d64905ae7fc67277c1bf76b86875
[template_mime_types]
_update_hash_filename_ = templates/mime_types.in
md5sum = 4ef94a7b458d885cd79ba0b930a5727e
[template_index_html]
_update_hash_filename_ = templates/index.html.in
md5sum = d57cb01df5941e139b02a2f7bdabcdc8
[template_graceful]
_update_hash_filename_ = templates/graceful.in
md5sum = 1c0ee16966e1fcdb3fd11c09f12ee2b2
[template_instance_replicate]
_update_hash_filename_ = instance_replicate.cfg.in
md5sum = 38d1d352307f79c9c99bf2a80a5c76b8
......@@ -9,14 +9,9 @@ offline = true
[profile-common]
nginx_location = {{ nginx_location }}
dash_location = {{ dash_location }}
tar_location = {{ tar_location }}
curl_location = {{ curl_location }}
template_nginx_conf = {{ template_nginx_conf_target }}
template_mime_types = {{ template_mime_types_target }}
template_launcher = {{ template_launcher_target }}
template_index_html = {{ template_index_html_target }}
template_graceful = {{ template_graceful_target }}
template_monitor = {{ template_monitor }}
[instance-html5as]
recipe = slapos.recipe.template:jinja2
......@@ -26,27 +21,15 @@ filename = instance-html5as.cfg
context =
section buildout buildout
section parameter_list profile-common
[instance-replicate]
recipe = slapos.recipe.template:jinja2
template = {{ template_instance_replicate }}
rendered = ${buildout:directory}/${:filename}
filename = instance-replicate-html5as.cfg
context =
section buildout buildout
section parameter_list profile-common
key slapparameter_dict slap-parameters:configuration
key ipv6_random slap-configuration:ipv6-random
[switch-softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${instance-html5as:rendered}
replicate = ${instance-replicate:rendered}
recipe = slapos.cookbook:switch-softwaretype
RootSoftwareInstance = ${:default}
default = instance-html5as:rendered
# Section needed to be added manually here to retrieve parameters
[slap-parameters]
[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = ${slap-connection:computer-id}
partition = ${slap-connection:partition-id}
url = ${slap-connection:server-url}
key = ${slap-connection:key-file}
cert = ${slap-connection:cert-file}
......@@ -9,9 +9,6 @@ parts =
downloader
mime_types
launcher
nginx-graceful
port-listening-promise
logrotate-entry-nginx
publish-connection-information
# Define egg directories to be the one from Software Release
......@@ -21,9 +18,6 @@ eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
offline = true
# Instance profile extends monitoring stack
extends = {{ parameter_list['template_monitor'] }}
# partition tree
# /
# |- etc/
......@@ -76,8 +70,8 @@ scgi_temp_path = ${:tmp}/scgi_temp_path
nb_workers = 2
# Network
ip = ${slap-network-information:global-ipv6}
port = ${slap-parameter:port}
ip = {{ ipv6_random }}
port = 8081
access_url = http://[${:ip}]:${:port}
# Paths
......@@ -95,11 +89,9 @@ path_nginx_conf = ${directory:etc}/nginx.conf
path_mime_types = ${directory:etc}/mime_types
# Binaries
path_shell = {{ parameter_list['dash_location'] }}/bin/dash
curl-binary = {{ parameter_list['curl_location'] }}/bin/curl
tar-binary = {{ parameter_list['tar_location'] }}/bin/tar
# Executables
bin_launcher = ${basedirectory:service}/launcher
bin_launcher = ${basedirectory:script}/launcher
# Utils
path_nginx = {{ parameter_list['nginx_location'] }}/sbin/nginx
......@@ -128,100 +120,12 @@ mode = 700
context =
section param_html5as html5as
# Command to put content in the docroot
# Simple command to put content in the docroot
[downloader]
recipe = plone.recipe.command
# This section will fail if the command fails.
stop-on-error = true
# If a tarball is passed as a parameter in download url
# it's content will be served by the instance.
# If the parameter is not provided it fallback to the default template
command =
rm -rf ${html5as:docroot}/*;
URL="${slap-parameter:download_url}";
if [ -n "$URL" ];
then
${html5as:curl-binary} -Lks $URL | ${html5as:tar-binary} xzv -C ${html5as:docroot} --strip-components 1;
else
cp ${default_index_html:rendered} ${html5as:docroot}/;
fi
[default_index_html]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_list['template_index_html'] }}
rendered = ${directory:srv}/index.html
context =
key title slap-parameter:title
### Nginx Graceful
[nginx-graceful]
recipe = slapos.recipe.template:jinja2
template = {{ parameter_list['template_graceful'] }}
rendered = ${basedirectory:script}/nginx-graceful
mode = 0700
context =
section param_html5as html5as
# Port Listening checking promise
[port-listening-promise]
<= monitor-promise-base
module = check_port_listening
name = nginx-port-listening.py
config-hostname = ${html5as:ip}
config-port = ${html5as:port}
# Use a port different from the default one in order to be able to
# use it in a SlapOS webrunner or a Theia SlapOS Runner
[monitor-instance-parameter]
monitor-httpd-port = 8197
# Monitor Stack also provides logrotate stack. We only need to extend
# the logrotate-entry-base defined in instance-logrotate-base.cfg.in .
# More parameters can be added following the logrotate-entry-base section
[logrotate-entry-nginx]
<= logrotate-entry-base
name = nginx
log = ${html5as:path_access_log} ${html5as:path_error_log}
post = kill -USR1 $(cat ${html5as:path_pid})
command = rm -r ${html5as:docroot}/*; echo "Hello World!" > ${html5as:docroot}/index.html
# Publish nginx address
[publish-connection-information]
recipe = slapos.cookbook:publish
# By extending monitor publish, all the section deploying monitoring will
# be deployed. The parameters needed for accessing monitoring will be published
<= monitor-publish
server_url = ${html5as:access_url}
title = Title ${slap-parameter:title}!
# Add dependency to the promise so that frontend sections are processed
# and there is no need to declare the new part in buildout:parts
server-cdn-url = ${html5as-frontend-promise:url}
# Request a CDN entry to master
[html5as-frontend]
# Extend slap-connnection to get the credentials for the request
<= slap-connection
# Recipe used to make requests
recipe = slapos.cookbook:requestoptional
name = HTM5AS frontend
# Specify the software url of the frontend software release
software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
# It is not a dedicated instance but an instance allocated on a shared instance
slave = true
config-url = ${html5as:access_url}
config-https-only = true
# The parameter expected to be received from the request are listed here.
return = domain secure_access
# Add a promise to make sure the cdn is properly configured
[html5as-frontend-promise]
<= monitor-promise-base
module = check_url_available
name = html5as-http-frontend.py
url = ${html5as-frontend:connection-secure_access}
config-url = ${:url}
config-check-secure = 1
[slap-parameter]
title =
download_url =
port = 8081
{% set replicate_quantity = slapparameter_dict.pop('replicate-quantity', '1') | int %}
[buildout]
parts =
publish-connection-information
eggs-directory = {{ buildout['eggs-directory'] }}
develop-eggs-directory = {{ buildout['develop-eggs-directory'] }}
offline = true
[instance-request-base]
<= slap-connection
recipe = slapos.cookbook:request
# It is the same software as the current one
software-url = ${slap-connection:software-release-url}
# We want the default behaviour
software-type = default
# What parameter are neede to be retrieved
return = server_url server-cdn-url monitor-setup-url
# Provided parameters
config-title = ${slap-parameter:title}
config-download_url = ${slap-parameter:download_url}
{% for i in range(1, replicate_quantity + 1) %}
# Request a normal html5as instance
[instance-{{ i }}]
<= instance-request-base
# Name of the instance
name = instance-html5as-{{ i }}
config-port = ${slap-parameter:port-{{ i }}}
config-title = ${slap-parameter:title-{{ i }}}
{% if "sla-%s-computer-guid" % i in slapparameter_dict -%}
sla-computer_guid = {{ slapparameter_dict["sla-%s-computer-guid" % i] }}
{% endif -%}
{% endfor %}
[slap-parameter]
download_url =
{% for i in range(1, replicate_quantity + 1) %}
title-{{ i }} =
port-{{ i }} = 808{{ i }}
{% endfor %}
[publish-connection-information]
recipe = slapos.cookbook:publish
{% for i in range(1, replicate_quantity + 1) %}
instance-{{ i }}-server_url = ${instance-{{ i }}:connection-server_url}
instance-{{ i }}-server-cdn-url = ${instance-{{ i }}:connection-server-cdn-url}
instance-{{ i }}-server-monitor-setup-url = ${instance-{{ i }}:connection-monitor-setup-url}
{% endfor %}
[buildout]
extends =
# buildout.hash.cfg is used for automated hash calculation of managed
# instance files by calling update-hash
buildout.hash.cfg
# "slapos" stack describes basic things needed for 99.9% of SlapOS Software
# Releases
../../stack/slapos.cfg
# Extend monitoring stack to provide necessary tools for monitoring
../../stack/monitor/buildout.cfg
# Extend here component profiles, like openssl, apache, mariadb, curl...
# Or/and extend a stack (lamp, tomcat) that does most of the work for you
# In this example we extend needed components for html5as.
../../component/nginx/buildout.cfg
../../component/dash/buildout.cfg
../../component/tar/buildout.cfg
../../component/curl/buildout.cfg
parts =
# Call installation of slapos.cookbook egg defined in stack/slapos.cfg (needed
......@@ -23,6 +16,8 @@ parts =
# Call creation of instance.cfg file that will be called for deployment of
# instance
template-cfg
# Add extra egg
extra-eggs
# Download instance.cfg.in (buildout profile used to deployment of instance),
# replace all {{ foo_bar }} parameters by real values
......@@ -31,55 +26,53 @@ parts =
recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/template.cfg
template = ${:_profile_base_location_}/${:filename}
filename = instance.cfg.in
md5sum = 77dff459e525c3d5e6e023cc58a3e000
mode = 0644
context =
section buildout buildout
key nginx_location nginx:location
key dash_location dash:location
key curl_location curl:location
key tar_location tar:location
key template_nginx_conf_target template_nginx_conf:target
key template_mime_types_target template_mime_types:target
key template_launcher_target template_launcher:target
key template_instance_html5as_target instance_html5as:target
key template_index_html_target template_index_html:target
key template_graceful_target template_graceful:target
key template_instance_replicate template_instance_replicate:target
# Monitor stack also provides a template for the instance
key template_monitor monitor2-template:rendered
# Have one shared section to define the default behaviour to download
# templates. Sections inheriting from this one won't need to redefine
# shared parameters
[download-base]
# Download instance_html5as.cfg.in
[instance_html5as]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = instance_html5as.cfg.in
md5sum = c2f57b361a07d15a7fc57c8bb522d60b
mode = 0644
# Download instance_html5as.cfg.in
[instance_html5as]
# This section inherit from download-base
<= download-base
# Filename and md5sum is defined in buildout.hash.cfg
[template_nginx_conf]
<= download-base
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = templates/nginx_conf.in
md5sum = 61dc4c82bf48563228ce4dea6c5c6319
mode = 0644
[template_launcher]
<= download-base
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = templates/launcher.in
md5sum = 6cb0d64905ae7fc67277c1bf76b86875
mode = 0644
[template_mime_types]
<= download-base
[template_index_html]
<= download-base
[template_graceful]
<= download-base
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:_update_hash_filename_}
_update_hash_filename_ = templates/mime_types.in
md5sum = 4ef94a7b458d885cd79ba0b930a5727e
mode = 0644
[template_instance_replicate]
<= download-base
[extra-eggs]
recipe = zc.recipe.egg
eggs =
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
#! {{ param_html5as['path_shell'] }}
# BEWARE: This file is operated by slapos node
# BEWARE: It will be overwritten automatically
# Run graceful
exec kill -s SIGHUP $(cat {{ param_html5as['path_pid'] }})
{% if title %}
<h1>{{ title }}</h1>
{% endif %}
<p>Hello World</p>
Tests for html5as software release
Tests for html5as-base software release
......@@ -27,14 +27,14 @@
from setuptools import setup, find_packages
version = '0.0.1.dev0'
name = 'slapos.test.html5as'
name = 'slapos.test.html5asbase'
with open("README.md") as f:
long_description = f.read()
setup(
name=name,
version=version,
description="Test for SlapOS' HTML5AS",
description="Test for SlapOS' HTML5AS Base",
long_description=long_description,
long_description_content_type='text/markdown',
maintainer="Nexedi",
......
......@@ -27,7 +27,6 @@
import os
import requests
from urlparse import urlparse
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
......@@ -36,9 +35,9 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
class HTML5ASTestCase(SlapOSInstanceTestCase):
class HTML5ASBaseTestCase(SlapOSInstanceTestCase):
"""
Common class for testing html5as.
Common class for testing html5as base.
It inherit from SlapOSInstanceTestCase which:
* Install the software release.
* Checks it compile without issue.
......@@ -57,126 +56,16 @@ class HTML5ASTestCase(SlapOSInstanceTestCase):
return response
class TestEmptyDeploy(HTML5ASTestCase):
class TestEmptyDeploy(HTML5ASBaseTestCase):
"""
This class test the instance with no parameters.
"""
def test_deploy_with_no_paramater(self):
url = self.requestDefaultInstance().getConnectionParameterDict()['server_url']
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertFalse("<h1>" in result)
self.assertTrue("<p>Hello World</p>" in result)
class TestDeployWithTitle(HTML5ASTestCase):
"""
This class test an instance with the parameter "title"
"""
@classmethod
def getInstanceParameterDict(cls):
return {
'title': 'Test1',
}
def test_deploy_with_title_parameter(self):
connection_parameter_dict = self.computer_partition.getConnectionParameterDict()
self.assertEqual(connection_parameter_dict["title"], "Title Test1!")
url = connection_parameter_dict['server_url']
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertTrue("<h1>Test1</h1>" in result)
self.assertTrue("<p>Hello World</p>" in result)
class TestGracefulWithPortChange(HTML5ASTestCase):
"""
This class test the instance with the parameter "port"
"""
instance_parameter_dict = {
'port': 8087
}
@classmethod
def getInstanceParameterDict(cls):
return cls.instance_parameter_dict
def test_change_port_parameter(self):
"""
This test test port change and its application with graceful restart
Get the connection URL and check it is accessible
"""
# Check initial connection parameter match expected port
url = self.computer_partition.getConnectionParameterDict()['server_url']
self.assertEqual(urlparse(url).port, 8087)
# Check port is listening even thought it is duplicated with the promise:
# "port-listening-promise"
self.checkUrlAndGetResponse(url)
# Update port parameter
self.instance_parameter_dict.update({
'port': 8086,
})
# Request instance with the new port parameter
self.requestDefaultInstance()
# Reprocess the instance to apply new port and run promises
self.slap.waitForInstance(self.instance_max_retry)
# Rerequest instance to get update connection parameter
url = self.requestDefaultInstance().getConnectionParameterDict()['server_url']
# Make sure the new port is the one being used
self.assertEqual(urlparse(url).port, 8086)
# Check port is listening even thought it is duplicated with the promise:
# "port-listening-promise"
self.checkUrlAndGetResponse(url)
class TestReplicateHTML5AS(HTML5ASTestCase):
"""
This class test the instance with the parameter "port"
"""
instance_parameter_dict = {
"port-1": 8088,
"title-1": "Title 1",
}
@classmethod
def getInstanceSoftwareType(cls):
return 'replicate'
@classmethod
def getInstanceParameterDict(cls):
return cls.instance_parameter_dict
def test_replicate_instance(self):
# Check First instance is deployed with proper parameters
connection_parameter_dict = self.computer_partition.getConnectionParameterDict()
url = connection_parameter_dict['instance-1-server_url']
self.assertEqual(urlparse(url).port, 8088)
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertTrue("<h1>Title 1</h1>" in result)
# Check only one instance is deployed by default
self.assertTrue("instance-2-server_url" not in connection_parameter_dict)
# Update replicate quantity parameter
self.instance_parameter_dict.update({
'replicate-quantity': 2,
'port-2': 8089,
'sla-2-computer_guid': self.slap._computer_id,
"title-2": "Title 314",
})
# Request instance with the one more replicate
self.requestDefaultInstance()
self.slap.waitForInstance(self.instance_max_retry)
# Check the second replicate
connection_parameter_dict = self.requestDefaultInstance().getConnectionParameterDict()
url = connection_parameter_dict['instance-2-server_url']
self.assertEqual(urlparse(url).port, 8089)
response = self.checkUrlAndGetResponse(url)
result = response.text
self.assertTrue("<h1>Title 314</h1>" in result)
self.assertEqual("Hello World!\n", result)
\ No newline at end of file
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