Commit 6ec741bf authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Cédric de Saint Martin

Refactor agent deployment

 - Cron usage was dropped, not agent is ran directly on supervisord
 - Use softwareswitch
 - Added Rafael Credentials
 - Use development egg for slapos.cookbook
parent 283ba8c4
......@@ -25,65 +25,42 @@
#
#############################################################################
import os
import sys
import zc.buildout
import slapos.slap
from slapos.recipe.librecipe import BaseSlapRecipe
from slapos.recipe.librecipe import GenericSlapRecipe
import json
import ConfigParser
from slapos.recipe.librecipe import GenericBaseRecipe
import sys
# XXX: BaseSlapRecipe and GenericSlapRecipe are deprecated, use
# GenericBaseRecipe and move partition parameter fetching to software release.
class Recipe(BaseSlapRecipe, GenericSlapRecipe):
class Recipe(GenericBaseRecipe):
def install(self):
self.path_list = []
crond = self.installCrond()
path_list = []
configuration_path = self.options["config"]
header = """[DEFAULT]
master_url = %s
key = %s
slap = slapos.slap.slap()
slap.initializeConnection(self.server_url, self.key_file, self.cert_file)
parameter_dict = slap.registerComputerPartition(
self.computer_id,
self.computer_partition_id,
).getInstanceParameterDict()
cert = %s
max_install_duration = %s
max_uninstall_duration = %s
max_request_duration = %s
max_destroy_duration = %s
""" % (self.options["master-url"],
"\n ".join(self.options["key"].split("\n")),
"\n ".join(self.options["cert"].split("\n")),
self.options["default_max_install_duration"],
self.options["default_max_uninstall_duration"],
self.options["default_max_request_duration"],
self.options["default_max_destroy_duration"])
# XXX: should probably expect one more (SR-originating) parameter instead
# of using self.work_directory .
configuration_path = os.path.join(self.work_directory, "agent.cfg")
with open(configuration_path, "w") as configuration:
configuration.write(parameter_dict["configuration"])
agent_crond_path = os.path.join(crond, "agent")
with open(agent_crond_path, "w") as agent_crond:
agent_crond.write("*/5 * * * * %s -S %s --pidfile=%s --log=%s "
"%s 2>&1 > /dev/null\n" % (
self.options["python_binary"],
self.options["agent_binary"],
self.options["pidfile"],
self.options["log"],
configuration_path,
))
configuration.write(header + self.options["configuration"])
path_list.append(self.createPythonScript(
self.options['wrapper'],
'slapos.recipe.librecipe.execute.execute',
[self.options["agent_binary"], '--pidfile=%s' % self.options["pidfile"],
"--log=%s" % self.options["log"], configuration_path]))
return self.path_list + [configuration_path, agent_crond_path]
path_list.append(configuration_path)
def installCrond(self):
_, ws = self.egg.working_set()
timestamps = self.createDataDirectory('cronstamps')
cron_output = os.path.join(self.log_directory, 'cron-output')
self._createDirectory(cron_output)
catcher = zc.buildout.easy_install.scripts([('catchcron',
__name__ + '.catdatefile', 'catdatefile')], ws, sys.executable,
self.bin_directory, arguments=[cron_output])[0]
self.path_list.append(catcher)
cron_d = os.path.join(self.etc_directory, 'cron.d')
crontabs = os.path.join(self.etc_directory, 'crontabs')
self._createDirectory(cron_d)
self._createDirectory(crontabs)
wrapper = zc.buildout.easy_install.scripts([('crond',
'slapos.recipe.librecipe.execute', 'execute')], ws, sys.executable,
self.wrapper_directory, arguments=[
self.options['dcrond_binary'].strip(), '-s', cron_d, '-c', crontabs,
'-t', timestamps, '-f', '-l', '5', '-M', catcher]
)[0]
self.path_list.append(wrapper)
return cron_d
return path_list
[buildout]
parts =
instance
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module}
agent_binary = ${buildout:directory}/bin/agent
pidfile = $${directory:srv}/agent.pid
log = $${directory:agentlog}/agent.log
wrapper = $${directory:run}/agent
config = $${directory:etc}/agent.cfg
master-url = $${slap-parameter:master-url}
key = $${slap-parameter:userkey}
cert = $${slap-parameter:usercertificate}
configuration = $${slap-parameter:configuration}
default_max_install_duration = $${slap-parameter:default_max_install_duration}
default_max_uninstall_duration = $${slap-parameter:default_max_uninstall_duration}
default_max_request_duration = $${slap-parameter:default_max_request_duration}
default_max_destroy_duration = $${slap-parameter:default_max_destroy_duration}
[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
run = $${:etc}/run
agentlog = $${buildout:directory}/var/log/agent
srv = $${buildout:directory}/srv
bin = $${buildout:directory}/bin
[buildout]
parts =
instance
switch_softwaretype
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[instance]
recipe = ${instance-recipe:egg}:${instance-recipe:module}
agent_binary = ${buildout:directory}/bin/agent
report_start = ${buildout:directory}/bin/report_start
report_stop = ${buildout:directory}/bin/report_stop
dcrond_binary = ${dcron:location}/sbin/crond
python_binary = ${buildout:executable}
pidfile = $${rootdirectory:run}/agent.pid
log = $${rootdirectory:agentlog}/agent.log
[rootdirectory]
recipe = slapos.cookbook:mkdirectory
run = $${buildout:directory}/etc/run
agentlog = $${buildout:directory}/var/log/agent
srv = $${buildout:directory}/srv
bin = $${buildout:directory}/bin
[switch_softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${template-agent:output}
[buildout]
extends =
../../component/dcron/buildout.cfg
../../component/python-2.7/buildout.cfg
../../component/lxml-python/buildout.cfg
../../stack/slapos.cfg
develop =
${:parts-directory}/slapos.cookbook-repository
parts =
template
template-agent
slapos.cookbook-repository
check-recipe
eggs
instance-recipe-egg
dcron
python2.7
script
# Local development
[slapos.cookbook-repository]
recipe = plone.recipe.command
stop-on-error = true
branch = agent
location = ${buildout:parts-directory}/${:_buildout_section_name_}
command = ${git:location}/bin/git clone --branch ${:branch} --quiet http://git.erp5.org/repos/slapos.git ${:location}
update-command = cd ${:location} && ${git:location}/bin/git pull --quiet
[check-recipe]
recipe = plone.recipe.command
stop-on-error = true
update-command = ${:command}
command = grep parts ${buildout:develop-eggs-directory}/slapos.cookbook.egg-link
[instance-recipe]
egg = slapos.cookbook
module = agent
......@@ -21,7 +44,14 @@ eggs = ${instance-recipe:egg}
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
output = ${buildout:directory}/template.cfg
md5sum = 122ddf2bda31b84648562d8335683e91
md5sum = bcd3b3cb8a305c83bb048d5ac1c583fe
mode = 0644
[template-agent]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-agent.cfg
output = ${buildout:directory}/template-agent.cfg
md5sum = fd9670d8473be402b10990398b553b00
mode = 0644
[script]
......@@ -36,6 +66,7 @@ eggs =
# signature certificates of the following uploaders.
# Romain Courteaud
# Cedric de Saint Martin
# Rafael Monnerat
signature-certificate-list =
-----BEGIN CERTIFICATE-----
MIIB4DCCAUkCADANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJGUjEZMBcGA1UE
......@@ -50,7 +81,6 @@ signature-certificate-list =
q7jdfWO18Zp/BG7tagz0jmmC4y/8akzHsVlruo2+2du2freE8dK746uoMlXlP93g
QUUGLQ==
-----END CERTIFICATE-----
signature-certificate-list =
-----BEGIN CERTIFICATE-----
MIIB9jCCAV+gAwIBAgIJAO4V/jiMoICoMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
BAMMCENPTVAtMjMyMCAXDTEyMDIxNjExMTAyM1oYDzIxMTIwMTIzMTExMDIzWjAT
......@@ -64,105 +94,16 @@ signature-certificate-list =
Gn9t8mdVQflNqOlAMkOlUv1ZugCt9rXYQOV7rrEYJBWirn43BOMn9Flp2nibblby
If1a2ZoqHRxoNo2yTmm7TSYRORWVS+vvfjY=
-----END CERTIFICATE-----
[versions]
Jinja2 = 2.6
Pygments = 1.5
Werkzeug = 0.8.3
apache-libcloud = 0.10.1
async = 0.6.1
buildout-versions = 1.7
docutils = 0.9.1
erp5.util = 0.4.5
gitdb = 0.5.4
hexagonit.recipe.cmmi = 1.6
ipython = 0.13
meld3 = 0.6.8
pycrypto = 2.6
slapos.cookbook = 0.58
slapos.recipe.template = 2.4
slapos.toolbox = 0.26
smmap = 0.8.2
z3c.recipe.scripts = 1.0.1
# Required by:
# slapos.core==0.26.1
# slapos.toolbox==0.26
Flask = 0.9
# Required by:
# slapos.toolbox==0.26
GitPython = 0.3.2.RC1
# Required by:
# slapos.cookbook==0.58
PyXML = 0.8.4
# Required by:
# netaddr==0.7.7
Sphinx = 1.1.3
# Required by:
# slapos.toolbox==0.26
atomize = 0.1.1
# Required by:
# slapos.toolbox==0.26
feedparser = 5.1.2
# Required by:
# slapos.cookbook==0.58
inotifyx = 0.2.0
# Required by:
# slapos.cookbook==0.58
# slapos.core==0.26.1
# slapos.toolbox==0.26
# xml-marshaller==0.9.7
lxml = 2.3.4
# Required by:
# slapos.cookbook==0.58
netaddr = 0.7.7
# Required by:
# slapos.core==0.26.1
netifaces = 0.8
# Required by:
# slapos.toolbox==0.26
paramiko = 1.7.7.2
# Required by:
# slapos.toolbox==0.26
psutil = 0.5.1
# Required by:
# erp5.util==0.4.5
# slapos.cookbook==0.58
# slapos.core==0.26.1
# slapos.toolbox==0.26
# zc.buildout==1.6.0-dev-SlapOS-006
# zc.recipe.egg==1.3.2
setuptools = 0.6c12dev-r88846
# Required by:
# slapos.cookbook==0.58
slapos.core = 0.26.1
# Required by:
# slapos.core==0.26.1
supervisor = 3.0a12
# Required by:
# slapos.cookbook==0.58
# slapos.toolbox==0.26
xml-marshaller = 0.9.7
# Required by:
# slapos.cookbook==0.58
zc.recipe.egg = 1.3.2
# Required by:
# slapos.core==0.26.1
zope.interface = 4.0.1
-----BEGIN CERTIFICATE-----
MIIB9jCCAV+gAwIBAgIJAOcKrOH/2Da6MA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
BAMMCENPTVAtMjk3MCAXDTEyMDYyNjAzMDU1MVoYDzIxMTIwNjAyMDMwNTUxWjAT
MREwDwYDVQQDDAhDT01QLTI5NzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
xzbOGlcoin2q+Mtp52r26Njliz2aoxIXbnOBUyDc/OGtk9nWA5uBtTc2zwR17um6
KV0bGyvuBA78XcvU+AIV/5s0ohBAX7yjRKmEhAYcFvov3EyWSdjOrqqo4qFSzOrK
sVQBlxIDpjQBH4F3lf6dBv6/M+tCT3iSv3aOZbsG0E8CAwEAAaNQME4wHQYDVR0O
BBYEFLqtrfTu+BIVt+TFiRUkIoiWIYrxMB8GA1UdIwQYMBaAFLqtrfTu+BIVt+TF
iRUkIoiWIYrxMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAc8N5P5gW
Jrdk9gF/3Cpp6THDiy93+WcuAm7zFwXPFNttJtFKMNObP2YRZvsQkvjezfrZoRBF
j8LgKB3tZCbBj+HDj+AeD+q9V+cqMFLKc6LezvQYUuum6bZdfUNnPv1K1ULYSPjq
/jsRBbabCWSXqxR6gYEM6ooauj3udBMXhHE=
-----END CERTIFICATE----
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