1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2014 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from .slaprunner import SlaprunnerTestSuite
import json
import random
import string
import time
import urllib
import urllib2
class NotHttpOkException(Exception):
pass
class ERP5TestSuite(SlaprunnerTestSuite):
"""
Run ERP5 inside Slaprunner Resiliency Test.
Note: requires specific kernel allowing long shebang paths.
"""
def _setERP5InstanceParameter(self):
"""
Set inside of slaprunner the instance parameter to use to deploy erp5 instance.
"""
self._connectToSlaprunner(
resource='saveParameterXml',
data='software_type=production¶meter=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Cinstance%3E%0A%3Cparameter+id%3D%22json%22%3E%7B%0A++%22backup-periodicity%22%3A+%22*%2F6+*+*+*+*%22%2C%0A++%22site-id%22%3A+%22erp5%22%2C%0A++%22erp5-ca%22%3A+%7B%0A++++%22country-code%22%3A+%22FR%22%2C%0A++++%22city%22%3A+%22Lille%22%2C%0A++++%22state%22%3A+%22Nord-Pas-de-Calais%22%2C%0A++++%22company%22%3A+%22ViFiB+SARL%22%2C%0A++++%22email%22%3A+%22admin%40vifib.org%22%0A++%7D%2C%0A++%22zeo%22%3A+%7B%0A++++%22Zeo-Server-1%22%3A+%5B%7B%0A++++++%22zodb-name%22%3A+%22main%22%2C%0A++++++%22serialize-path%22%3A+%22%2F%25(site-id)s%2Faccount_module%2F%22%2C%0A++++++%22mount-point%22%3A+%22%2F%22%2C%0A++++++%22zope-cache-size%22%3A+%222000%22%2C%0A++++++%22storage-name%22%3A+%22main%22%2C%0A++++++%22zeo-cache-size%22%3A+%22400MB%22%0A++++%7D%5D%0A++%7D%2C%0A++%22activity%22%3A+%7B%0A++++%22zopecount%22%3A+1%2C%0A++++%22timerservice%22%3A+true%0A++%7D%2C%0A++%22timezone%22%3A+%22Europe%2FParis%22%2C%0A++%22backend%22%3A+%7B%0A++++%22login%22%3A+%7B%0A++++++%22zopecount%22%3A+1%2C%0A++++++%22access-control-string%22%3A+%22all%22%2C%0A++++++%22scheme%22%3A+%5B%22https%22%5D%2C%0A++++++%22maxconn%22%3A+1%2C%0A++++++%22thread-amount%22%3A+1%0A++++%7D%2C%0A++++%22erp5%22%3A+%7B%0A++++++%22zopecount%22%3A+1%2C%0A++++++%22access-control-string%22%3A+%22all%22%2C%0A++++++%22scheme%22%3A+%5B%22https%22%5D%2C%0A++++++%22maxconn%22%3A+1%2C%0A++++++%22thread-amount%22%3A+1%0A++++%7D%0A++%7D%0A%7D%3C%2Fparameter%3E%0A%3Cparameter+id%3D%22mariadb-json%22%3E%7B%22backup-periodicity%22%3A+%22*%2F6+*+*+*+*%22%7D%3C%2Fparameter%3E%0A%3C%2Finstance%3E%0A'
)
def _getERP5Url(self):
"""
Return the backend url of erp5 instance.
Note: it is not connection parameter of slaprunner,
but connection parameter of what is inside of webrunner.
"""
data = self._connectToSlaprunner(
resource='getConnectionParameter/slappart5'
)
url = json.loads(data)['url-erp5']
self.logger.info('Retrieved erp5 url is:\n%s' % url)
return url
def _connectToERP5(self, url, data=None):
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='Zope', uri=url, user='zope', passwd='insecure')
opener_director = urllib2.build_opener(auth_handler)
self.logger.info('Calling ERP5 url %s' % url)
if data:
result = opener_director.open(url, data=data)
else:
result = opener_director.open(url)
if result.getcode() is not 200:
raise NotHttpOkException(result.getcode())
return result.read()
def _createRandomERP5Document(self):
""" Create a document with random content in erp5 site."""
# XXX currently only sets erp5 site title.
erp5_site_title = self.slaprunner_user
url = "%s/erp5?__ac_name=zope&__ac_password=insecure" % self._getERP5Url()
form = 'title%%3AUTF-8:string=%s&manage_editProperties%%3Amethod=Save+Changes' % erp5_site_title
self._connectToERP5(url, form)
return erp5_site_title
def _getCreatedERP5Document(self):
""" Fetch and return content of ERP5 document created above."""
url = "%s/erp5/getTitle" % self._getERP5Url()
return self._connectToERP5(url)
def _editHAProxyconfiguration(self):
"""
XXX pure hack.
haproxy processes don't support long path for sockets.
Edit haproxy configuration file of erp5 to make it compatible with long paths
Then restart haproxy.
"""
self.logger.info('Editing HAProxy configuration...')
result = self._connectToSlaprunner(
resource='/getFileContent',
data='file=runner_workdir%2Finstance%2Fslappart5%2Fetc%2Fhaproxy-erp5.cfg'
)
file_content = json.loads(result)['result']
file_content = file_content.replace('var/run/haproxy-erp5.sock', 'ha-erp5.sock')
self._connectToSlaprunner(
resource='/saveFileContent',
data='file=runner_workdir%%2Finstance%%2Fslappart5%%2Fetc%%2Fhaproxy-erp5.cfg&content=%s' % urllib.quote(file_content)
)
# Restart HAProxy
self._connectToSlaprunner(
resource='/startStopProccess/name/slappart5:haproxy-erp5/cmd/STOPPED'
)
time.sleep(15)
def generateData(self):
self.slaprunner_password = ''.join(
random.SystemRandom().sample(string.ascii_lowercase, 8)
)
self.slaprunner_user = 'slapos'
self.logger.info('Generated slaprunner user is: %s' % self.slaprunner_user)
self.logger.info('Generated slaprunner password is: %s' % self.slaprunner_password)
def pushDataOnMainInstance(self):
"""
Create a dummy Software Release,
Build it,
Wait for build to be successful,
Deploy instance,
Wait for instance to be started.
Store the main IP of the slaprunner for future use.
"""
self.logger.debug('Getting the backend URL and recovery code...')
parameter_dict = self._getPartitionParameterDict()
self.slaprunner_backend_url = parameter_dict['backend_url']
self.logger.info('backend_url is %s.' % self.slaprunner_backend_url)
self.monitor_url = parameter_dict['monitor_backend_url']
slaprunner_recovery_code = self._getRcode()
self.logger.debug('Creating the slaprunner account...')
self._connectToSlaprunner(
resource='configAccount',
data='name=slapos&username=%s&email=slapos@slapos.org&password=%s&rcode=%s' % (
self.slaprunner_user,
self.slaprunner_password,
slaprunner_recovery_code
)
)
self._login()
self._gitClone()
self._openSoftwareRelease('erp5')
self._setERP5InstanceParameter()
self._buildSoftwareRelease()
self._deployInstance()
self._deployInstance()
self._deployInstance()
self._editHAProxyconfiguration()
self.data = self._createRandomERP5Document()
self.logger.info('Wait one hour for clone to have compiled ERP5 SR...')
time.sleep(3600)
def checkDataOnCloneInstance(self):
"""
Check that:
* backend_url is different
* Software Release profile is the same,
* Software Release is built and is the same,
* Instance is deployed and is the same (contains same new data).
"""
old_slaprunner_backend_url = self.slaprunner_backend_url
self.slaprunner_backend_url = self._returnNewInstanceParameter(
parameter_key='backend_url',
old_parameter_value=old_slaprunner_backend_url
)
self._login()
self._waitForSoftwareBuild()
self._deployInstance()
time.sleep(30)
self._editHAProxyconfiguration()
new_data = self._getCreatedERP5Document()
if new_data == self.data:
self.logger.info('Data are the same: success.')
return True
else:
self.logger.info('Data are different: failure.')
def runTestSuite(*args, **kwargs):
"""
Run Slaprunner Resiliency Test.
"""
return ERP5TestSuite(*args, **kwargs).runTestSuite()