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 @@ ...@@ -25,65 +25,42 @@
# #
############################################################################# #############################################################################
import os
import sys
import zc.buildout import zc.buildout
import slapos.slap from slapos.recipe.librecipe import GenericBaseRecipe
from slapos.recipe.librecipe import BaseSlapRecipe import sys
from slapos.recipe.librecipe import GenericSlapRecipe
import json
import ConfigParser
# XXX: BaseSlapRecipe and GenericSlapRecipe are deprecated, use class Recipe(GenericBaseRecipe):
# GenericBaseRecipe and move partition parameter fetching to software release.
class Recipe(BaseSlapRecipe, GenericSlapRecipe):
def install(self): def install(self):
self.path_list = [] path_list = []
crond = self.installCrond()
configuration_path = self.options["config"]
header = """[DEFAULT]
master_url = %s
key = %s
slap = slapos.slap.slap() cert = %s
slap.initializeConnection(self.server_url, self.key_file, self.cert_file)
parameter_dict = slap.registerComputerPartition( max_install_duration = %s
self.computer_id, max_uninstall_duration = %s
self.computer_partition_id, max_request_duration = %s
).getInstanceParameterDict() 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: with open(configuration_path, "w") as configuration:
configuration.write(parameter_dict["configuration"]) configuration.write(header + self.options["configuration"])
agent_crond_path = os.path.join(crond, "agent")
with open(agent_crond_path, "w") as agent_crond: path_list.append(self.createPythonScript(
agent_crond.write("*/5 * * * * %s -S %s --pidfile=%s --log=%s " self.options['wrapper'],
"%s 2>&1 > /dev/null\n" % ( 'slapos.recipe.librecipe.execute.execute',
self.options["python_binary"], [self.options["agent_binary"], '--pidfile=%s' % self.options["pidfile"],
self.options["agent_binary"], "--log=%s" % self.options["log"], configuration_path]))
self.options["pidfile"],
self.options["log"],
configuration_path,
))
return self.path_list + [configuration_path, agent_crond_path] path_list.append(configuration_path)
def installCrond(self): return path_list
_, 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
[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] [buildout]
parts = parts =
instance switch_softwaretype
eggs-directory = ${buildout:eggs-directory} eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory} develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[instance] [switch_softwaretype]
recipe = ${instance-recipe:egg}:${instance-recipe:module} recipe = slapos.cookbook:softwaretype
agent_binary = ${buildout:directory}/bin/agent default = ${template-agent:output}
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
[buildout] [buildout]
extends = extends =
../../component/dcron/buildout.cfg ../../component/python-2.7/buildout.cfg
../../component/lxml-python/buildout.cfg
../../stack/slapos.cfg ../../stack/slapos.cfg
develop =
${:parts-directory}/slapos.cookbook-repository
parts = parts =
template template
template-agent
slapos.cookbook-repository
check-recipe
eggs
instance-recipe-egg instance-recipe-egg
dcron python2.7
script 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] [instance-recipe]
egg = slapos.cookbook egg = slapos.cookbook
module = agent module = agent
...@@ -21,7 +44,14 @@ eggs = ${instance-recipe:egg} ...@@ -21,7 +44,14 @@ eggs = ${instance-recipe:egg}
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg url = ${:_profile_base_location_}/instance.cfg
output = ${buildout:directory}/template.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 mode = 0644
[script] [script]
...@@ -36,6 +66,7 @@ eggs = ...@@ -36,6 +66,7 @@ eggs =
# signature certificates of the following uploaders. # signature certificates of the following uploaders.
# Romain Courteaud # Romain Courteaud
# Cedric de Saint Martin # Cedric de Saint Martin
# Rafael Monnerat
signature-certificate-list = signature-certificate-list =
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIB4DCCAUkCADANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJGUjEZMBcGA1UE MIIB4DCCAUkCADANBgkqhkiG9w0BAQsFADA5MQswCQYDVQQGEwJGUjEZMBcGA1UE
...@@ -50,7 +81,6 @@ signature-certificate-list = ...@@ -50,7 +81,6 @@ signature-certificate-list =
q7jdfWO18Zp/BG7tagz0jmmC4y/8akzHsVlruo2+2du2freE8dK746uoMlXlP93g q7jdfWO18Zp/BG7tagz0jmmC4y/8akzHsVlruo2+2du2freE8dK746uoMlXlP93g
QUUGLQ== QUUGLQ==
-----END CERTIFICATE----- -----END CERTIFICATE-----
signature-certificate-list =
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIB9jCCAV+gAwIBAgIJAO4V/jiMoICoMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV MIIB9jCCAV+gAwIBAgIJAO4V/jiMoICoMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
BAMMCENPTVAtMjMyMCAXDTEyMDIxNjExMTAyM1oYDzIxMTIwMTIzMTExMDIzWjAT BAMMCENPTVAtMjMyMCAXDTEyMDIxNjExMTAyM1oYDzIxMTIwMTIzMTExMDIzWjAT
...@@ -64,105 +94,16 @@ signature-certificate-list = ...@@ -64,105 +94,16 @@ signature-certificate-list =
Gn9t8mdVQflNqOlAMkOlUv1ZugCt9rXYQOV7rrEYJBWirn43BOMn9Flp2nibblby Gn9t8mdVQflNqOlAMkOlUv1ZugCt9rXYQOV7rrEYJBWirn43BOMn9Flp2nibblby
If1a2ZoqHRxoNo2yTmm7TSYRORWVS+vvfjY= If1a2ZoqHRxoNo2yTmm7TSYRORWVS+vvfjY=
-----END CERTIFICATE----- -----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
[versions] MIIB9jCCAV+gAwIBAgIJAOcKrOH/2Da6MA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
Jinja2 = 2.6 BAMMCENPTVAtMjk3MCAXDTEyMDYyNjAzMDU1MVoYDzIxMTIwNjAyMDMwNTUxWjAT
Pygments = 1.5 MREwDwYDVQQDDAhDT01QLTI5NzCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
Werkzeug = 0.8.3 xzbOGlcoin2q+Mtp52r26Njliz2aoxIXbnOBUyDc/OGtk9nWA5uBtTc2zwR17um6
apache-libcloud = 0.10.1 KV0bGyvuBA78XcvU+AIV/5s0ohBAX7yjRKmEhAYcFvov3EyWSdjOrqqo4qFSzOrK
async = 0.6.1 sVQBlxIDpjQBH4F3lf6dBv6/M+tCT3iSv3aOZbsG0E8CAwEAAaNQME4wHQYDVR0O
buildout-versions = 1.7 BBYEFLqtrfTu+BIVt+TFiRUkIoiWIYrxMB8GA1UdIwQYMBaAFLqtrfTu+BIVt+TF
docutils = 0.9.1 iRUkIoiWIYrxMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAc8N5P5gW
erp5.util = 0.4.5 Jrdk9gF/3Cpp6THDiy93+WcuAm7zFwXPFNttJtFKMNObP2YRZvsQkvjezfrZoRBF
gitdb = 0.5.4 j8LgKB3tZCbBj+HDj+AeD+q9V+cqMFLKc6LezvQYUuum6bZdfUNnPv1K1ULYSPjq
hexagonit.recipe.cmmi = 1.6 /jsRBbabCWSXqxR6gYEM6ooauj3udBMXhHE=
ipython = 0.13 -----END CERTIFICATE----
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
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