Add scalability test support
[slapos.git] / slapos / recipe / erp5testnode / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27 import ConfigParser
28 import json
29 import os
30 import StringIO
31
32 from slapos.recipe.librecipe import GenericBaseRecipe
33
34 class Recipe(GenericBaseRecipe):
35 def install(self):
36 self.path_list = []
37 options = self.options.copy()
38 del options['recipe']
39 CONFIG = {k.replace('-', '_'): v for k, v in options.iteritems()}
40 CONFIG['PATH'] = os.environ['PATH']
41
42 if self.options['instance-dict']:
43 config_instance_dict = ConfigParser.ConfigParser()
44 config_instance_dict.add_section('instance_dict')
45 instance_dict = json.loads(self.options['instance-dict'])
46
47 for k ,v in instance_dict.iteritems():
48 config_instance_dict.set('instance_dict', k, v)
49 value = StringIO.StringIO()
50 config_instance_dict.write(value)
51 CONFIG['instance_dict'] = value.getvalue()
52
53 software_path_list = json.loads(self.options['software-path-list'])
54 if software_path_list:
55 CONFIG["software_path_list"] = "[software_list]"
56 CONFIG["software_path_list"] += \
57 "\npath_list = %s" % ",".join(software_path_list)
58 CONFIG['computer_id'] = self.buildout['slap-connection']['computer-id']
59 CONFIG['server_url'] = self.buildout['slap-connection']['server-url']
60 configuration_file = self.createFile(
61 self.options['configuration-file'],
62 self.substituteTemplate(
63 self.getTemplateFilename('erp5testnode.cfg.in'),
64 CONFIG
65 ),
66 )
67 self.path_list.append(configuration_file)
68 self.path_list.append(
69 self.createPythonScript(
70 self.options['wrapper'],
71 'slapos.recipe.librecipe.execute.executee',
72 [ # Executable
73 [ self.options['testnode'], '-l', self.options['log-file'],
74 configuration_file],
75 # Environment
76 {
77 'GIT_SSL_NO_VERIFY': '1',
78 }
79 ],
80 )
81 )
82 self.installApache()
83 return self.path_list
84
85 def installApache(self):
86 apache_config = dict(
87 pid_file=self.options['httpd-pid-file'],
88 lock_file=self.options['httpd-lock-file'],
89 ip=self.options['httpd-ip'],
90 port=self.options['httpd-port'],
91 software_access_port=self.options['httpd-software-access-port'],
92 testnode_srv_directory=self.options['srv-directory'],
93 error_log=os.path.join(self.options['httpd-log-directory'],
94 'httpd-error.log'),
95 access_log=os.path.join(self.options['httpd-log-directory'],
96 'httpd-access.log'),
97 certificate=self.options['httpd-cert-file'],
98 key=self.options['httpd-key-file'],
99 testnode_log_directory=self.options['log-directory'],
100 testnode_software_directory=self.options['software-directory'],
101 )
102 config_file = self.createFile(self.options['httpd-conf-file'],
103 self.substituteTemplate(self.getTemplateFilename('httpd.conf.in'),
104 apache_config)
105 )
106 self.path_list.append(config_file)
107 wrapper = self.createPythonScript(self.options['httpd-wrapper'],
108 'slapos.recipe.librecipe.execute.execute',
109 [self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'])
110 self.path_list.append(wrapper)
111 # create empty html page to not allow listing of /
112 page = open(os.path.join(self.options['log-directory'], "index.html"), "w")
113 page.write("<html/>")
114 page.close()