Commit b696fd3d authored by Jérome Perrin's avatar Jérome Perrin

Use python3 only for software release tests

See merge request nexedi/slapos!1247
parents 405f2b7e d3aed928
...@@ -45,7 +45,7 @@ class TestBackupServer(InstanceTestCase): ...@@ -45,7 +45,7 @@ class TestBackupServer(InstanceTestCase):
# Check that there is a RSS feed # Check that there is a RSS feed
self.assertTrue('rss' in parameter_dict) self.assertTrue('rss' in parameter_dict)
self.assertTrue(parameter_dict['rss'].startswith( self.assertTrue(parameter_dict['rss'].startswith(
'https://[%s]:9443/' % (self._ipv6_address, ) f'https://[{self._ipv6_address}]:9443/'
)) ))
result = requests.get( result = requests.get(
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import unicode_literals
import os import os
import requests import requests
......
...@@ -51,7 +51,6 @@ setup(name=name, ...@@ -51,7 +51,6 @@ setup(name=name,
# caucase needed to connect to the KeDiFa caucase # caucase needed to connect to the KeDiFa caucase
'caucase', 'caucase',
'cryptography', 'cryptography',
'backports.lzma',
], ],
zip_safe=True, zip_safe=True,
test_suite='test', test_suite='test',
......
...@@ -51,18 +51,13 @@ import urllib.parse ...@@ -51,18 +51,13 @@ import urllib.parse
import socket import socket
import sys import sys
import logging import logging
import lzma
import random import random
import string import string
from slapos.slap.standalone import SlapOSNodeInstanceError from slapos.slap.standalone import SlapOSNodeInstanceError
import caucase.client import caucase.client
import caucase.utils import caucase.utils
try:
import lzma
except ImportError:
from backports import lzma
import datetime import datetime
from cryptography import x509 from cryptography import x509
......
...@@ -45,7 +45,6 @@ setup(name=name, ...@@ -45,7 +45,6 @@ setup(name=name,
'slapos.cookbook', 'slapos.cookbook',
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'requests', 'requests',
'six',
'PyPDF2', 'PyPDF2',
], ],
zip_safe=True, zip_safe=True,
......
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved.
# #
...@@ -31,8 +30,8 @@ import csv ...@@ -31,8 +30,8 @@ import csv
import multiprocessing import multiprocessing
import os import os
import json import json
import six.moves.xmlrpc_client as xmlrpclib import xmlrpc.client as xmlrpclib
import six.moves.urllib.parse as urllib_parse import urllib.parse as urllib_parse
import ssl import ssl
import base64 import base64
import io import io
...@@ -63,6 +62,7 @@ class CloudOooTestCase(_CloudOooTestCase): ...@@ -63,6 +62,7 @@ class CloudOooTestCase(_CloudOooTestCase):
context=ssl_context, context=ssl_context,
allow_none=True, allow_none=True,
) )
self.addCleanup(self.server('close'))
def normalizeFontName(font_name): def normalizeFontName(font_name):
...@@ -111,16 +111,16 @@ class HTMLtoPDFConversionFontTestMixin: ...@@ -111,16 +111,16 @@ class HTMLtoPDFConversionFontTestMixin:
def test(self): def test(self):
actual_font_mapping_mapping = {} actual_font_mapping_mapping = {}
for font in self.expected_font_mapping: for font in self.expected_font_mapping:
src_html = ''' src_html = f'''
<style> <style>
p {{ font-family: "{font}"; font-size: 20pt; }} p {{ font-family: "{font}"; font-size: 20pt; }}
</style> </style>
<p>the quick brown fox jumps over the lazy dog.</p> <p>the quick brown fox jumps over the lazy dog.</p>
<p>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</p> <p>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</p>
'''.format(**locals()) '''
pdf_data = self._convert_html_to_pdf(src_html) pdf_data = self._convert_html_to_pdf(src_html)
pdf_reader = PyPDF2.PdfFileReader(io.BytesIO((pdf_data))) pdf_reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_data))
self.assertEqual( self.assertEqual(
self.pdf_producer, self.pdf_producer,
pdf_reader.getDocumentInfo()['/Producer']) pdf_reader.getDocumentInfo()['/Producer'])
...@@ -165,7 +165,7 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -165,7 +165,7 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
'Liberation Sans Narrow': 'LiberationSansNarrow', 'Liberation Sans Narrow': 'LiberationSansNarrow',
'Liberation Serif': 'LiberationSerif', 'Liberation Serif': 'LiberationSerif',
'Linux LibertineG': 'LiberationSans', 'Linux LibertineG': 'LiberationSans',
'OpenSymbol': set(['DejaVuSans', 'OpenSymbol']), 'OpenSymbol': {'DejaVuSans', 'OpenSymbol'},
'Palatino': 'LiberationSans', 'Palatino': 'LiberationSans',
'Roboto Black': 'LiberationSans', 'Roboto Black': 'LiberationSans',
'Roboto Condensed Light': 'LiberationSans', 'Roboto Condensed Light': 'LiberationSans',
...@@ -180,9 +180,9 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -180,9 +180,9 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
} }
def _convert_html_to_pdf(self, src_html): def _convert_html_to_pdf(self, src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'pdf', 'pdf',
False, False,
...@@ -238,9 +238,9 @@ class TestLibreoffice(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -238,9 +238,9 @@ class TestLibreoffice(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
} }
def _convert_html_to_pdf(self, src_html): def _convert_html_to_pdf(self, src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'pdf', 'pdf',
).encode()) ).encode())
...@@ -251,10 +251,10 @@ class TestLibreOfficeTextConversion(CloudOooTestCase): ...@@ -251,10 +251,10 @@ class TestLibreOfficeTextConversion(CloudOooTestCase):
def test_html_to_text(self): def test_html_to_text(self):
self.assertEqual( self.assertEqual(
base64.decodestring( base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring( base64.encodebytes(
u'<html>héhé</html>'.encode('utf-8')).decode(), '<html>héhé</html>'.encode()).decode(),
'html', 'html',
'txt', 'txt',
).encode()), ).encode()),
...@@ -274,19 +274,18 @@ class TestLibreOfficeCluster(CloudOooTestCase): ...@@ -274,19 +274,18 @@ class TestLibreOfficeCluster(CloudOooTestCase):
global _convert_html_to_text global _convert_html_to_text
def _convert_html_to_text(src_html): def _convert_html_to_text(src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'txt', 'txt',
).encode()) ).encode())
pool = multiprocessing.Pool(5) pool = multiprocessing.Pool(5)
# TODO py3: use with pool with pool:
converted = pool.map(_convert_html_to_text, converted = pool.map(
['<html><body>hello</body></html>'] * 100) _convert_html_to_text,
pool.terminate() ['<html><body>hello</body></html>'] * 100)
pool.join()
self.assertEqual(converted, [codecs.BOM_UTF8 + b'hello\n'] * 100) self.assertEqual(converted, [codecs.BOM_UTF8 + b'hello\n'] * 100)
...@@ -294,9 +293,8 @@ class TestLibreOfficeCluster(CloudOooTestCase): ...@@ -294,9 +293,8 @@ class TestLibreOfficeCluster(CloudOooTestCase):
res = requests.get( res = requests.get(
urllib_parse.urljoin(self.url, '/haproxy;csv'), urllib_parse.urljoin(self.url, '/haproxy;csv'),
verify=False, verify=False,
stream=True,
) )
reader = csv.DictReader(res.raw) reader = csv.DictReader(io.StringIO(res.text))
line_list = list(reader) line_list = list(reader)
# requests have been balanced # requests have been balanced
total_hrsp_2xx = { total_hrsp_2xx = {
...@@ -309,8 +307,8 @@ class TestLibreOfficeCluster(CloudOooTestCase): ...@@ -309,8 +307,8 @@ class TestLibreOfficeCluster(CloudOooTestCase):
# ideally there should be 25% of requests on each backend, because we use # ideally there should be 25% of requests on each backend, because we use
# round robin scheduling, but it can happen that some backend take longer # round robin scheduling, but it can happen that some backend take longer
# to start, so we are tolerant here and just check that each backend # to start, so we are tolerant here and just check that each backend
# process at least 15% of requests. # process at least one request.
self.assertGreater(total_hrsp_2xx[backend], 15) self.assertGreater(total_hrsp_2xx[backend], 0)
# no errors # no errors
total_eresp = { total_eresp = {
line['svname']: int(line['eresp'] or 0) line['svname']: int(line['eresp'] or 0)
......
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved.
# #
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from __future__ import absolute_import
from setuptools import setup, find_packages from setuptools import setup, find_packages
version = '0.0.1.dev0' version = '0.0.1.dev0'
...@@ -49,7 +48,6 @@ setup(name=name, ...@@ -49,7 +48,6 @@ setup(name=name,
'psutil', 'psutil',
'requests', 'requests',
'mysqlclient', 'mysqlclient',
'backports.lzma',
'cryptography', 'cryptography',
'pexpect', 'pexpect',
'pyOpenSSL', 'pyOpenSSL',
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
# #
############################################################################## ##############################################################################
from __future__ import absolute_import
import json import json
import os import os
......
This diff is collapsed.
This diff is collapsed.
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved.
# #
...@@ -26,11 +25,10 @@ ...@@ -26,11 +25,10 @@
# #
############################################################################## ##############################################################################
from __future__ import absolute_import
import os import os
import json import json
import glob import glob
import six.moves.urllib.parse import urllib.parse
import socket import socket
import sys import sys
import time import time
...@@ -39,7 +37,7 @@ import datetime ...@@ -39,7 +37,7 @@ import datetime
import subprocess import subprocess
import gzip import gzip
from backports import lzma import lzma
import MySQLdb import MySQLdb
from slapos.testing.utils import CrontabMixin from slapos.testing.utils import CrontabMixin
...@@ -84,7 +82,7 @@ class MariaDBTestCase(ERP5InstanceTestCase): ...@@ -84,7 +82,7 @@ class MariaDBTestCase(ERP5InstanceTestCase):
# type: () -> MySQLdb.connections.Connection # type: () -> MySQLdb.connections.Connection
connection_parameter_dict = json.loads( connection_parameter_dict = json.loads(
self.computer_partition.getConnectionParameterDict()['_']) self.computer_partition.getConnectionParameterDict()['_'])
db_url = six.moves.urllib.parse.urlparse(connection_parameter_dict['database-list'][0]) db_url = urllib.parse.urlparse(connection_parameter_dict['database-list'][0])
self.assertEqual('mysql', db_url.scheme) self.assertEqual('mysql', db_url.scheme)
self.assertTrue(db_url.path.startswith('/')) self.assertTrue(db_url.path.startswith('/'))
...@@ -208,7 +206,7 @@ class TestMariaDB(MariaDBTestCase): ...@@ -208,7 +206,7 @@ class TestMariaDB(MariaDBTestCase):
""" """
select * from test_utf8_collation where col1 = "a" select * from test_utf8_collation where col1 = "a"
""") """)
self.assertEqual(((u'à',),), cnx.store_result().fetch_row(maxrows=2)) self.assertEqual((('à',),), cnx.store_result().fetch_row(maxrows=2))
class TestMroonga(MariaDBTestCase): class TestMroonga(MariaDBTestCase):
...@@ -232,7 +230,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -232,7 +230,7 @@ class TestMroonga(MariaDBTestCase):
SELECT mroonga_normalize("ABCDあぃうぇ㍑") SELECT mroonga_normalize("ABCDあぃうぇ㍑")
""") """)
# XXX this is returned as bytes by mroonga/mariadb (this might be a bug) # XXX this is returned as bytes by mroonga/mariadb (this might be a bug)
self.assertEqual(((u'abcdあぃうぇリットル'.encode('utf-8'),),), self.assertEqual((('abcdあぃうぇリットル'.encode(),),),
cnx.store_result().fetch_row(maxrows=2)) cnx.store_result().fetch_row(maxrows=2))
if 0: if 0:
...@@ -245,7 +243,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -245,7 +243,7 @@ class TestMroonga(MariaDBTestCase):
""" """
SELECT mroonga_normalize("aBcDあぃウェ㍑", "NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark") SELECT mroonga_normalize("aBcDあぃウェ㍑", "NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark")
""") """)
self.assertEqual(((u'ABCDあぃうぇ㍑'.encode('utf-8'),),), self.assertEqual((('ABCDあぃうぇ㍑'.encode(),),),
cnx.store_result().fetch_row(maxrows=2)) cnx.store_result().fetch_row(maxrows=2))
def test_mroonga_full_text_normalizer(self): def test_mroonga_full_text_normalizer(self):
...@@ -282,7 +280,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -282,7 +280,7 @@ class TestMroonga(MariaDBTestCase):
WHERE MATCH (content) AGAINST ("+ブラック" IN BOOLEAN MODE) WHERE MATCH (content) AGAINST ("+ブラック" IN BOOLEAN MODE)
""") """)
self.assertEqual( self.assertEqual(
((datetime.date(2013, 4, 23), u'ブラックコーヒーを飲んだ。'),), ((datetime.date(2013, 4, 23), 'ブラックコーヒーを飲んだ。'),),
cnx.store_result().fetch_row(maxrows=2), cnx.store_result().fetch_row(maxrows=2),
) )
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from __future__ import absolute_import
import json import json
import os.path import os.path
import unittest import unittest
...@@ -76,5 +75,5 @@ def lookupMount(zurl): ...@@ -76,5 +75,5 @@ def lookupMount(zurl):
# readfile returns content of file @path. # readfile returns content of file @path.
def readfile(path): def readfile(path):
with open(path, 'r') as f: with open(path) as f:
return f.read() return f.read()
...@@ -44,7 +44,6 @@ setup(name=name, ...@@ -44,7 +44,6 @@ setup(name=name,
'slapos.core', 'slapos.core',
'supervisor', 'supervisor',
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'typing; python_version<"3"',
], ],
test_suite='test', test_suite='test',
) )
...@@ -35,8 +35,8 @@ import tempfile ...@@ -35,8 +35,8 @@ import tempfile
import time import time
import requests import requests
import six.moves.urllib as urllib import urllib.parse
import six.moves.xmlrpc_client import xmlrpc.client
import urllib3 import urllib3
from slapos.grid.utils import md5digest from slapos.grid.utils import md5digest
...@@ -83,8 +83,8 @@ class ERP5UpgradeTestCase(SlapOSInstanceTestCase): ...@@ -83,8 +83,8 @@ class ERP5UpgradeTestCase(SlapOSInstanceTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
# request and instanciate with old software url # request and instantiate with old software url
super(ERP5UpgradeTestCase, cls).setUpClass() super().setUpClass()
cls.setUpOldInstance() cls.setUpOldInstance()
...@@ -155,7 +155,7 @@ class TestERP5Upgrade(ERP5UpgradeTestCase): ...@@ -155,7 +155,7 @@ class TestERP5Upgrade(ERP5UpgradeTestCase):
# wait for old site creation # wait for old site creation
cls.session.get( cls.session.get(
'{zope_base_url}/person_module'.format(zope_base_url=cls.zope_base_url), f'{cls.zope_base_url}/person_module',
auth=requests.auth.HTTPBasicAuth( auth=requests.auth.HTTPBasicAuth(
username=param_dict['inituser-login'], username=param_dict['inituser-login'],
password=param_dict['inituser-password'], password=param_dict['inituser-password'],
...@@ -171,16 +171,12 @@ class TestERP5Upgrade(ERP5UpgradeTestCase): ...@@ -171,16 +171,12 @@ class TestERP5Upgrade(ERP5UpgradeTestCase):
ssl_context = ssl.create_default_context() ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE ssl_context.verify_mode = ssl.CERT_NONE
erp5_xmlrpc_client = six.moves.xmlrpc_client.ServerProxy( erp5_xmlrpc_client = xmlrpc.client.ServerProxy(
cls.authenticated_zope_base_url, cls.authenticated_zope_base_url,
context=ssl_context, context=ssl_context,
) )
# BBB use as a context manager only on python3 with erp5_xmlrpc_client:
if sys.version_info < (3, ):
yield erp5_xmlrpc_client yield erp5_xmlrpc_client
else:
with erp5_xmlrpc_client:
yield erp5_xmlrpc_client
def addPythonScript(script_id, params, body): def addPythonScript(script_id, params, body):
with getXMLRPCClient() as erp5_xmlrpc_client: with getXMLRPCClient() as erp5_xmlrpc_client:
...@@ -188,7 +184,7 @@ class TestERP5Upgrade(ERP5UpgradeTestCase): ...@@ -188,7 +184,7 @@ class TestERP5Upgrade(ERP5UpgradeTestCase):
try: try:
custom.manage_addProduct.PythonScripts.manage_addPythonScript( custom.manage_addProduct.PythonScripts.manage_addPythonScript(
script_id) script_id)
except six.moves.xmlrpc_client.ProtocolError as e: except xmlrpc.client.ProtocolError as e:
if e.errcode != 302: if e.errcode != 302:
raise raise
getattr(custom, script_id).ZPythonScriptHTML_editAction( getattr(custom, script_id).ZPythonScriptHTML_editAction(
......
[buildout]
extends =
software.cfg
[python]
part = python2.7
...@@ -46,7 +46,6 @@ setup(name=name, ...@@ -46,7 +46,6 @@ setup(name=name,
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'erp5.util', 'erp5.util',
'supervisor', 'supervisor',
'six',
], ],
zip_safe=True, zip_safe=True,
test_suite='test', test_suite='test',
......
...@@ -34,11 +34,10 @@ import struct ...@@ -34,11 +34,10 @@ import struct
import subprocess import subprocess
import tempfile import tempfile
import time import time
import six
import sys import sys
from six.moves.SimpleHTTPServer import SimpleHTTPRequestHandler from http.server import SimpleHTTPRequestHandler
from six.moves.socketserver import StreamRequestHandler, TCPServer from socketserver import StreamRequestHandler, TCPServer
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
from slapos.testing.utils import findFreeTCPPort from slapos.testing.utils import findFreeTCPPort
...@@ -49,8 +48,8 @@ FLUSH_INTERVAL = 1 ...@@ -49,8 +48,8 @@ FLUSH_INTERVAL = 1
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath( os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
'software%s.cfg' % ("-py2" if six.PY2 else ""))))
class FluentdTestCase(SlapOSInstanceTestCase): class FluentdTestCase(SlapOSInstanceTestCase):
__partition_reference__ = 'fluentd' __partition_reference__ = 'fluentd'
...@@ -135,11 +134,11 @@ class WendelinTutorialTestCase(FluentdTestCase): ...@@ -135,11 +134,11 @@ class WendelinTutorialTestCase(FluentdTestCase):
return subprocess.check_output( return subprocess.check_output(
[self._fluentd_bin, '-c', conf_path, '--dry-run'], [self._fluentd_bin, '-c', conf_path, '--dry-run'],
env={'GEM_PATH': self._gem_path}, env={'GEM_PATH': self._gem_path},
universal_newlines=True, text=True,
) )
def _test_configuration(self, expected_str): def _test_configuration(self, expected_str):
self.assertRegexpMatches( self.assertRegex(
self.read_fluentd_conf(self._conf), self.read_fluentd_conf(self._conf),
expected_str, expected_str,
) )
...@@ -168,12 +167,12 @@ class SensorConfTestCase(WendelinTutorialTestCase): ...@@ -168,12 +167,12 @@ class SensorConfTestCase(WendelinTutorialTestCase):
@classmethod @classmethod
def sensor_conf(cls, script_path): def sensor_conf(cls, script_path):
return '''\ return f'''\
<source> <source>
@type exec @type exec
tag tag.name tag tag.name
command %s %s command {sys.executable} {script_path}
run_interval %ss run_interval {FLUSH_INTERVAL}s
<parse> <parse>
keys pressure, humidity, temperature keys pressure, humidity, temperature
</parse> </parse>
...@@ -182,25 +181,25 @@ class SensorConfTestCase(WendelinTutorialTestCase): ...@@ -182,25 +181,25 @@ class SensorConfTestCase(WendelinTutorialTestCase):
@type forward @type forward
<server> <server>
name myserver1 name myserver1
host %s host {cls._ipv6_address}
</server> </server>
<buffer> <buffer>
flush_mode immediate flush_mode immediate
</buffer> </buffer>
</match>''' % (sys.executable, script_path, FLUSH_INTERVAL, cls._ipv6_address) </match>'''
@classmethod @classmethod
def sensor_script(cls, measurementList): def sensor_script(cls, measurementList):
return '''\ measurement_text = "\t".join(measurementList)
#!/usr/bin/python return f'''\
#!{sys.executable}
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
print("%s")''' % "\t".join(measurementList) print("{measurement_text}")'''
def test_configuration(self): def test_configuration(self):
self._test_configuration( self._test_configuration(
r'adding forwarding server \'myserver1\' host="%s" port=%s weight=60' fr'adding forwarding server \'myserver1\' host="{self._ipv6_address}" port={FLUENTD_PORT} weight=60'
% (self._ipv6_address, FLUENTD_PORT)
) )
def test_send_data(self): def test_send_data(self):
...@@ -229,25 +228,24 @@ class GatewayConfTestCase(WendelinTutorialTestCase): ...@@ -229,25 +228,24 @@ class GatewayConfTestCase(WendelinTutorialTestCase):
@classmethod @classmethod
def gateway_conf(cls, fluentd_port, wendelin_port): def gateway_conf(cls, fluentd_port, wendelin_port):
return '''\ return f'''\
<source> <source>
@type forward @type forward
port %s port {fluentd_port}
bind %s bind {cls._ipv6_address}
</source> </source>
<match tag.name> <match tag.name>
@type wendelin @type wendelin
streamtool_uri http://[%s]:%s/erp5/portal_ingestion_policies/default streamtool_uri http://[{cls._ipv6_address}]:{wendelin_port}/erp5/portal_ingestion_policies/default
user foo user foo
password bar password bar
<buffer> <buffer>
flush_mode interval flush_mode interval
@type file @type file
path fluentd-buffer-file/ path fluentd-buffer-file/
flush_interval %ss flush_interval {FLUSH_INTERVAL}s
</buffer> </buffer>
</match>''' % (fluentd_port, cls._ipv6_address, cls._ipv6_address, </match>'''
wendelin_port, FLUSH_INTERVAL)
@classmethod @classmethod
def get_configuration(cls): def get_configuration(cls):
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
import os import os
import logging import logging
from six.moves.urllib.parse import urlparse from urllib.parse import urlparse
import requests import requests
......
...@@ -48,7 +48,6 @@ setup(name=name, ...@@ -48,7 +48,6 @@ setup(name=name,
'erp5.util', 'erp5.util',
'supervisor', 'supervisor',
'psutil', 'psutil',
'six',
], ],
zip_safe=True, zip_safe=True,
test_suite='test', test_suite='test',
......
This diff is collapsed.
...@@ -45,7 +45,6 @@ setup(name=name, ...@@ -45,7 +45,6 @@ setup(name=name,
'slapos.cookbook', 'slapos.cookbook',
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'supervisor', 'supervisor',
'six',
'requests' 'requests'
], ],
zip_safe=True, zip_safe=True,
......
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved.
# #
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
import os import os
import json import json
from six.moves.urllib import parse from urllib import parse
import requests import requests
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
......
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2018 Nexedi SA and Contributors. All Rights Reserved.
# #
...@@ -29,7 +28,7 @@ ...@@ -29,7 +28,7 @@
import os import os
import json import json
import glob import glob
import urlparse import urllib.parse
import socket import socket
import sys import sys
import time import time
...@@ -38,7 +37,7 @@ import datetime ...@@ -38,7 +37,7 @@ import datetime
import subprocess import subprocess
import gzip import gzip
from backports import lzma import lzma
import MySQLdb import MySQLdb
from slapos.testing.utils import CrontabMixin from slapos.testing.utils import CrontabMixin
...@@ -80,7 +79,7 @@ class MariaDBTestCase(ERP5InstanceTestCase): ...@@ -80,7 +79,7 @@ class MariaDBTestCase(ERP5InstanceTestCase):
def getDatabaseConnection(self): def getDatabaseConnection(self):
connection_parameter_dict = json.loads( connection_parameter_dict = json.loads(
self.computer_partition.getConnectionParameterDict()['_']) self.computer_partition.getConnectionParameterDict()['_'])
db_url = urlparse.urlparse(connection_parameter_dict['database-list'][0]) db_url = urllib.parse.urlparse(connection_parameter_dict['database-list'][0])
self.assertEqual('mysql', db_url.scheme) self.assertEqual('mysql', db_url.scheme)
self.assertTrue(db_url.path.startswith('/')) self.assertTrue(db_url.path.startswith('/'))
...@@ -91,6 +90,8 @@ class MariaDBTestCase(ERP5InstanceTestCase): ...@@ -91,6 +90,8 @@ class MariaDBTestCase(ERP5InstanceTestCase):
host=db_url.hostname, host=db_url.hostname,
port=db_url.port, port=db_url.port,
db=database_name, db=database_name,
use_unicode=True,
charset='utf8mb4'
) )
...@@ -106,7 +107,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin): ...@@ -106,7 +107,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin):
'mariadb-full', 'mariadb-full',
'20500101000000.sql.gz', '20500101000000.sql.gz',
), ),
'r') as dump: 'rt') as dump:
self.assertIn('CREATE TABLE', dump.read()) self.assertIn('CREATE TABLE', dump.read())
def test_logrotate_and_slow_query_digest(self): def test_logrotate_and_slow_query_digest(self):
...@@ -148,7 +149,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin): ...@@ -148,7 +149,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin):
'slowquery_digest', 'slowquery_digest',
'slowquery_digest.txt-2050-01-01.xz', 'slowquery_digest.txt-2050-01-01.xz',
) )
with lzma.open(slow_query_report, 'r') as f: with lzma.open(slow_query_report, 'rt') as f:
# this is the hash for our "select sleep(n)" slow query # this is the hash for our "select sleep(n)" slow query
self.assertIn("ID 0xF9A57DD5A41825CA", f.read()) self.assertIn("ID 0xF9A57DD5A41825CA", f.read())
...@@ -170,7 +171,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin): ...@@ -170,7 +171,7 @@ class TestCrontabs(MariaDBTestCase, CrontabMixin):
subprocess.check_output('faketime 2050-01-01 %s' % check_slow_query_promise_plugin['command'], shell=True) subprocess.check_output('faketime 2050-01-01 %s' % check_slow_query_promise_plugin['command'], shell=True)
self.assertEqual( self.assertEqual(
error_context.exception.output, error_context.exception.output,
"""\ b"""\
Threshold is lower than expected: Threshold is lower than expected:
Expected total queries : 1.0 and current is: 2 Expected total queries : 1.0 and current is: 2
Expected slowest query : 0.1 and current is: 3 Expected slowest query : 0.1 and current is: 3
...@@ -220,7 +221,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -220,7 +221,7 @@ class TestMroonga(MariaDBTestCase):
""" """
SELECT mroonga_normalize("ABCDあぃうぇ㍑") SELECT mroonga_normalize("ABCDあぃうぇ㍑")
""") """)
self.assertEqual((('abcdあぃうぇリットル',),), self.assertEqual((('abcdあぃうぇリットル'.encode(),),),
cnx.store_result().fetch_row(maxrows=2)) cnx.store_result().fetch_row(maxrows=2))
if 0: if 0:
...@@ -233,7 +234,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -233,7 +234,7 @@ class TestMroonga(MariaDBTestCase):
""" """
SELECT mroonga_normalize("aBcDあぃウェ㍑", "NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark") SELECT mroonga_normalize("aBcDあぃウェ㍑", "NormalizerMySQLUnicodeCIExceptKanaCIKanaWithVoicedSoundMark")
""") """)
self.assertEqual((('ABCDあぃうぇ㍑',),), self.assertEqual((('ABCDあぃうぇ㍑'.encode(),),),
cnx.store_result().fetch_row(maxrows=2)) cnx.store_result().fetch_row(maxrows=2))
def test_mroonga_full_text_normalizer(self): def test_mroonga_full_text_normalizer(self):
...@@ -321,7 +322,7 @@ class TestMroonga(MariaDBTestCase): ...@@ -321,7 +322,7 @@ class TestMroonga(MariaDBTestCase):
cnx = self.getDatabaseConnection() cnx = self.getDatabaseConnection()
with contextlib.closing(cnx): with contextlib.closing(cnx):
cnx.query("SELECT mroonga_command('register token_filters/stem')") cnx.query("SELECT mroonga_command('register token_filters/stem')")
self.assertEqual((('true',),), cnx.store_result().fetch_row(maxrows=2)) self.assertEqual(((b'true',),), cnx.store_result().fetch_row(maxrows=2))
cnx.query( cnx.query(
""" """
CREATE TABLE memos ( CREATE TABLE memos (
......
...@@ -75,5 +75,5 @@ def lookupMount(zurl): ...@@ -75,5 +75,5 @@ def lookupMount(zurl):
# readfile returns content of file @path. # readfile returns content of file @path.
def readfile(path): def readfile(path):
with open(path, 'r') as f: with open(path) as f:
return f.read() return f.read()
...@@ -17,7 +17,6 @@ changes to the code, run tests and publish changes. ...@@ -17,7 +17,6 @@ changes to the code, run tests and publish changes.
```bash ```bash
# install this software release and request an instance # install this software release and request an instance
# use software-py3.cfg instead of software.cfg if the SR you want to test is written in Python 3
SR=https://lab.nexedi.com/nexedi/slapos/raw/1.0/software/slapos-sr-testing/software.cfg SR=https://lab.nexedi.com/nexedi/slapos/raw/1.0/software/slapos-sr-testing/software.cfg
COMP=slaprunner COMP=slaprunner
INSTANCE_NAME=$COMP INSTANCE_NAME=$COMP
......
[buildout]
extends =
software.cfg
[python]
part = python3
[python-interpreter]
extra-eggs +=
# plantuml 0.3.0 is only available for Python 3
${slapos.test.plantuml-setup:egg}
[template]
extra =
# The following list is for SR whose buildout runs only with Python 3.
caddy-frontend ${slapos.test.caddy-frontend-setup:setup}
caucase ${slapos.test.caucase-setup:setup}
erp5testnode ${slapos.test.erp5testnode-setup:setup}
galene ${slapos.test.galene-setup:setup}
grafana ${slapos.test.grafana-setup:setup}
headless-chromium ${slapos.test.headless-chromium-setup:setup}
helloworld ${slapos.test.helloworld-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
html5as-base ${slapos.test.html5as-base-setup:setup}
htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup}
hugo ${slapos.test.hugo-setup:setup}
jscrawler ${slapos.test.jscrawler-setup:setup}
jstestnode ${slapos.test.jstestnode-setup:setup}
jupyter ${slapos.test.jupyter-setup:setup}
kvm ${slapos.test.kvm-setup:setup}
matomo ${slapos.test.matomo-setup:setup}
metabase ${slapos.test.metabase-setup:setup}
monitor ${slapos.test.monitor-setup:setup}
nextcloud ${slapos.test.nextcloud-setup:setup}
nginx-push-stream ${slapos.test.nginx-push-stream-setup:setup}
ors-amarisoft ${slapos.test.ors-amarisoft-setup:setup}
plantuml ${slapos.test.plantuml-setup:setup}
powerdns ${slapos.test.powerdns-setup:setup}
proftpd ${slapos.test.proftpd-setup:setup}
repman ${slapos.test.repman-setup:setup}
restic-rest-server ${slapos.test.restic_rest_server-setup:setup}
seleniumserver ${slapos.test.seleniumserver-setup:setup}
theia ${slapos.test.theia-setup:setup}
turnserver ${slapos.test.turnserver-setup:setup}
...@@ -27,9 +27,6 @@ parts = ...@@ -27,9 +27,6 @@ parts =
shared-part-list = shared-part-list =
[python]
part = python2.7
[setup-develop-egg] [setup-develop-egg]
recipe = zc.recipe.egg:develop recipe = zc.recipe.egg:develop
...@@ -250,8 +247,7 @@ egg = slapos.core ...@@ -250,8 +247,7 @@ egg = slapos.core
setup = ${slapos.core-repository:location} setup = ${slapos.core-repository:location}
[python-interpreter] [python-interpreter]
eggs += ${:extra-eggs} eggs +=
extra-eggs =
${lxml-python:egg} ${lxml-python:egg}
${python-PyYAML:egg} ${python-PyYAML:egg}
${slapos.core-setup:egg} ${slapos.core-setup:egg}
...@@ -289,10 +285,11 @@ extra-eggs = ...@@ -289,10 +285,11 @@ extra-eggs =
${slapos.test.kvm-setup:egg} ${slapos.test.kvm-setup:egg}
${slapos.test.matomo-setup:egg} ${slapos.test.matomo-setup:egg}
${slapos.test.metabase-setup:egg} ${slapos.test.metabase-setup:egg}
${slapos.test.ors-amarisoft-setup:egg}
${slapos.test.monitor-setup:egg} ${slapos.test.monitor-setup:egg}
${slapos.test.nextcloud-setup:egg} ${slapos.test.nextcloud-setup:egg}
${slapos.test.nginx-push-stream-setup:egg} ${slapos.test.nginx-push-stream-setup:egg}
${slapos.test.ors-amarisoft-setup:egg}
${slapos.test.plantuml-setup:egg}
${slapos.test.powerdns-setup:egg} ${slapos.test.powerdns-setup:egg}
${slapos.test.proftpd-setup:egg} ${slapos.test.proftpd-setup:egg}
${slapos.test.re6stnet-setup:egg} ${slapos.test.re6stnet-setup:egg}
...@@ -352,27 +349,46 @@ context = ...@@ -352,27 +349,46 @@ context =
tests = tests =
json-schemas ${slapos.cookbook-setup:setup} json-schemas ${slapos.cookbook-setup:setup}
# The following list is for SR that work with either Python 2 and 3
# (as main Python). The test egg must supply a URL which depends on
# the version of Python that is used to run the test.
# Due to a bug in the way promises are run, we may also list some Py3-only SR
# here, to check there's no promise issue when slapos node runs with Python 2.
erp5 ${slapos.test.erp5-setup:setup}
fluentd ${slapos.test.fluentd-setup:setup}
###
${:extra}
extra =
# WARNING: This is for SR that only support Python 2.
# You should not add more lines here.
backupserver ${slapos.test.backupserver-setup:setup} backupserver ${slapos.test.backupserver-setup:setup}
beremiz-ide ${slapos.test.beremiz-ide-setup:setup} beremiz-ide ${slapos.test.beremiz-ide-setup:setup}
caddy-frontend ${slapos.test.caddy-frontend-setup:setup}
caucase ${slapos.test.caucase-setup:setup}
cloudooo ${slapos.test.cloudooo-setup:setup} cloudooo ${slapos.test.cloudooo-setup:setup}
dream ${slapos.test.dream-setup:setup} dream ${slapos.test.dream-setup:setup}
erp5 ${slapos.test.erp5-setup:setup}
erp5testnode ${slapos.test.erp5testnode-setup:setup}
fluentd ${slapos.test.fluentd-setup:setup}
galene ${slapos.test.galene-setup:setup}
gitlab ${slapos.test.gitlab-setup:setup} gitlab ${slapos.test.gitlab-setup:setup}
grafana ${slapos.test.grafana-setup:setup}
headless-chromium ${slapos.test.headless-chromium-setup:setup}
helloworld ${slapos.test.helloworld-setup:setup}
html5as ${slapos.test.html5as-setup:setup}
html5as-base ${slapos.test.html5as-base-setup:setup}
htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup}
hugo ${slapos.test.hugo-setup:setup}
jscrawler ${slapos.test.jscrawler-setup:setup}
jstestnode ${slapos.test.jstestnode-setup:setup}
jupyter ${slapos.test.jupyter-setup:setup}
kvm ${slapos.test.kvm-setup:setup}
matomo ${slapos.test.matomo-setup:setup}
metabase ${slapos.test.metabase-setup:setup}
monitor ${slapos.test.monitor-setup:setup}
nextcloud ${slapos.test.nextcloud-setup:setup}
nginx-push-stream ${slapos.test.nginx-push-stream-setup:setup}
ors-amarisoft ${slapos.test.ors-amarisoft-setup:setup}
plantuml ${slapos.test.plantuml-setup:setup}
powerdns ${slapos.test.powerdns-setup:setup}
proftpd ${slapos.test.proftpd-setup:setup}
re6stnet ${slapos.test.re6stnet-setup:setup} re6stnet ${slapos.test.re6stnet-setup:setup}
repman ${slapos.test.repman-setup:setup}
restic-rest-server ${slapos.test.restic_rest_server-setup:setup}
seleniumserver ${slapos.test.seleniumserver-setup:setup}
slapos-master ${slapos.test.slapos-master-setup:setup} slapos-master ${slapos.test.slapos-master-setup:setup}
slaprunner ${slapos.test.slaprunner-setup:setup} slaprunner ${slapos.test.slaprunner-setup:setup}
theia ${slapos.test.theia-setup:setup}
turnserver ${slapos.test.turnserver-setup:setup}
upgrade_erp5 ${slapos.test.upgrade_erp5-setup:setup} upgrade_erp5 ${slapos.test.upgrade_erp5-setup:setup}
[versions] [versions]
...@@ -397,11 +413,9 @@ PyPDF2 = 1.26.0+SlapOSPatched001 ...@@ -397,11 +413,9 @@ PyPDF2 = 1.26.0+SlapOSPatched001
# Django 1.11 is python 2 compatible # Django 1.11 is python 2 compatible
Django = 1.11 Django = 1.11
mock = 2.0.0:whl
testfixtures = 6.11.0 testfixtures = 6.11.0
funcsigs = 1.0.2 funcsigs = 1.0.2
mysqlclient = 1.3.12 mysqlclient = 1.3.12
pexpect = 4.8.0 pexpect = 4.8.0
ptyprocess = 0.6.0 ptyprocess = 0.6.0
typing = 3.7.4.3
psycopg2 = 2.8.6 psycopg2 = 2.8.6
...@@ -48,7 +48,6 @@ setup(name=name, ...@@ -48,7 +48,6 @@ setup(name=name,
'supervisor', 'supervisor',
'psutil', 'psutil',
'paramiko', 'paramiko',
'six',
'requests', 'requests',
], ],
zip_safe=True, zip_safe=True,
......
...@@ -35,12 +35,11 @@ import subprocess ...@@ -35,12 +35,11 @@ import subprocess
import json import json
import time import time
from six.moves.urllib.parse import urlparse from urllib.parse import urlparse
from six.moves.urllib.parse import quote from urllib.parse import quote
from six.moves.urllib.parse import urljoin from urllib.parse import urljoin
from six.moves.configparser import ConfigParser from configparser import ConfigParser
import requests import requests
import six
from slapos.recipe.librecipe import generateHashFromFiles from slapos.recipe.librecipe import generateHashFromFiles
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
...@@ -61,7 +60,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -61,7 +60,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
data = { data = {
"path": "workspace/slapos/software/%s" % software_release, "path": "workspace/slapos/software/%s" % software_release,
} }
resp = self._postToSlaprunner(url, data) resp = self._postToSlaprunner(url, data)
self.assertEqual(requests.codes.ok, resp.status_code) self.assertEqual(requests.codes.ok, resp.status_code)
self.assertNotEqual(json.loads(resp.text)['code'], 0, self.assertNotEqual(json.loads(resp.text)['code'], 0,
'Unexpecting result in call to setCurrentProject: %s' % resp.text) 'Unexpecting result in call to setCurrentProject: %s' % resp.text)
...@@ -69,7 +68,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -69,7 +68,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def _buildSoftwareRelease(self): def _buildSoftwareRelease(self):
parameter_dict = self.computer_partition.getConnectionParameterDict() parameter_dict = self.computer_partition.getConnectionParameterDict()
url = "%s/runSoftwareProfile" % parameter_dict['url'] url = "%s/runSoftwareProfile" % parameter_dict['url']
resp = self._postToSlaprunner(url, {}) resp = self._postToSlaprunner(url, {})
self.assertEqual(requests.codes.ok, resp.status_code) self.assertEqual(requests.codes.ok, resp.status_code)
self.assertEqual(json.loads(resp.text)['result'], True, self.assertEqual(json.loads(resp.text)['result'], True,
'Unexpecting result in call to runSoftwareProfile: %s' % resp.text) 'Unexpecting result in call to runSoftwareProfile: %s' % resp.text)
...@@ -77,7 +76,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -77,7 +76,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def _deployInstance(self): def _deployInstance(self):
parameter_dict = self.computer_partition.getConnectionParameterDict() parameter_dict = self.computer_partition.getConnectionParameterDict()
url = "%s/runInstanceProfile" % parameter_dict['url'] url = "%s/runInstanceProfile" % parameter_dict['url']
resp = self._postToSlaprunner(url, {}) resp = self._postToSlaprunner(url, {})
self.assertEqual(requests.codes.ok, resp.status_code) self.assertEqual(requests.codes.ok, resp.status_code)
self.assertEqual(json.loads(resp.text)['result'], True, self.assertEqual(json.loads(resp.text)['result'], True,
'Unexpecting result in call to runSoftwareProfile: %s' % resp.text) 'Unexpecting result in call to runSoftwareProfile: %s' % resp.text)
...@@ -100,7 +99,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -100,7 +99,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
def _isSoftwareReleaseReady(self): def _isSoftwareReleaseReady(self):
parameter_dict = self.computer_partition.getConnectionParameterDict() parameter_dict = self.computer_partition.getConnectionParameterDict()
url = "%s/isSRReady" % parameter_dict['url'] url = "%s/isSRReady" % parameter_dict['url']
resp = self._getFromSlaprunner(url) resp = self._getFromSlaprunner(url)
if requests.codes.ok != resp.status_code: if requests.codes.ok != resp.status_code:
return -1 return -1
return resp.text return resp.text
...@@ -125,7 +124,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -125,7 +124,7 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
} }
while True: while True:
time.sleep(25) time.sleep(25)
resp = self._postToSlaprunner(url, data) resp = self._postToSlaprunner(url, data)
if requests.codes.ok != resp.status_code: if requests.codes.ok != resp.status_code:
continue continue
if json.loads(resp.text)["instance"]["state"] is False: if json.loads(resp.text)["instance"]["state"] is False:
...@@ -153,9 +152,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -153,9 +152,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
url = "%s/getFileContent" % parameter_dict['url'] url = "%s/getFileContent" % parameter_dict['url']
data = { data = {
"file": relative_path "file": relative_path
} }
resp = self._postToSlaprunner(url, data) resp = self._postToSlaprunner(url, data)
self.assertEqual(requests.codes.ok, resp.status_code) self.assertEqual(requests.codes.ok, resp.status_code)
self.assertNotEqual(json.loads(resp.text)['code'], 0, self.assertNotEqual(json.loads(resp.text)['code'], 0,
'Unexpecting result in call to getFileContent: %s' % resp.text) 'Unexpecting result in call to getFileContent: %s' % resp.text)
...@@ -189,9 +188,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase): ...@@ -189,9 +188,9 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
parameter_dict = self.computer_partition.getConnectionParameterDict() parameter_dict = self.computer_partition.getConnectionParameterDict()
takeover_url = parameter_dict["takeover-%s-url" % scope] takeover_url = parameter_dict["takeover-%s-url" % scope]
takeover_password = parameter_dict["takeover-%s-password" % scope] takeover_password = parameter_dict["takeover-%s-password" % scope]
resp = requests.get( resp = requests.get(
"%s?password=%s" % (takeover_url, takeover_password), f"{takeover_url}?password={takeover_password}",
verify=True) verify=True)
self.assertEqual(requests.codes.ok, resp.status_code) self.assertEqual(requests.codes.ok, resp.status_code)
self.assertNotIn("Error", resp.text, self.assertNotIn("Error", resp.text,
...@@ -236,7 +235,7 @@ class TestWebRunnerAutorun(SlaprunnerTestCase): ...@@ -236,7 +235,7 @@ class TestWebRunnerAutorun(SlaprunnerTestCase):
@classmethod @classmethod
def getInstanceParameterDict(cls): def getInstanceParameterDict(cls):
return { return {
# Auto deploy is required for the isSRReady works. # Auto deploy is required for the isSRReady works.
'auto-deploy': 'true', 'auto-deploy': 'true',
'autorun': 'true', 'autorun': 'true',
'software-root': os.path.join(cls.slap._instance_root, "..", "soft"), 'software-root': os.path.join(cls.slap._instance_root, "..", "soft"),
...@@ -363,7 +362,7 @@ class TestSSH(SlaprunnerTestCase): ...@@ -363,7 +362,7 @@ class TestSSH(SlaprunnerTestCase):
self.assertTrue(fingerprint_from_url.startswith('ssh-rsa-'), fingerprint_from_url) self.assertTrue(fingerprint_from_url.startswith('ssh-rsa-'), fingerprint_from_url)
fingerprint_from_url = fingerprint_from_url[len('ssh-rsa-'):] fingerprint_from_url = fingerprint_from_url[len('ssh-rsa-'):]
class KeyPolicy(object): class KeyPolicy:
"""Accept server key and keep it in self.key for inspection """Accept server key and keep it in self.key for inspection
""" """
def missing_host_key(self, client, hostname, key): def missing_host_key(self, client, hostname, key):
...@@ -507,7 +506,7 @@ class TestResilientInstance(SlaprunnerTestCase): ...@@ -507,7 +506,7 @@ class TestResilientInstance(SlaprunnerTestCase):
# just check that keys returned on requested partition are for resilient # just check that keys returned on requested partition are for resilient
self.assertSetEqual( self.assertSetEqual(
set(self.computer_partition.getConnectionParameterDict().keys()), set(self.computer_partition.getConnectionParameterDict().keys()),
set([ {
'backend-url', 'backend-url',
'feed-url-runner-1-pull', 'feed-url-runner-1-pull',
'feed-url-runner-1-push', 'feed-url-runner-1-push',
...@@ -520,7 +519,7 @@ class TestResilientInstance(SlaprunnerTestCase): ...@@ -520,7 +519,7 @@ class TestResilientInstance(SlaprunnerTestCase):
'takeover-runner-1-password', 'takeover-runner-1-password',
'takeover-runner-1-url', 'takeover-runner-1-url',
'url', 'url',
'webdav-url'])) 'webdav-url'})
class TestResilientCustomFrontend(TestCustomFrontend): class TestResilientCustomFrontend(TestCustomFrontend):
instance_max_retry = 20 instance_max_retry = 20
...@@ -589,7 +588,7 @@ class TestResilientDummyInstance(SlaprunnerTestCase): ...@@ -589,7 +588,7 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
self._waitForCloneToBeReadyForTakeover() self._waitForCloneToBeReadyForTakeover()
self._doTakeover() self._doTakeover()
self.slap.waitForInstance(20) self.slap.waitForInstance(20)
previous_computer_partition = self.computer_partition previous_computer_partition = self.computer_partition
self.computer_partition = self.requestDefaultInstance() self.computer_partition = self.requestDefaultInstance()
...@@ -601,5 +600,5 @@ class TestResilientDummyInstance(SlaprunnerTestCase): ...@@ -601,5 +600,5 @@ class TestResilientDummyInstance(SlaprunnerTestCase):
self.assertTrue(result_after.startswith("Hello"), result_after) self.assertTrue(result_after.startswith("Hello"), result_after)
self.assertIn(result, result_after, self.assertIn(result, result_after,
"%s not in %s" % (result, result_after)) f"{result} not in {result_after}")
...@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase): ...@@ -391,52 +391,49 @@ class TestTheiaEnv(TheiaTestCase):
# Start a theia shell that inherits the environment of the theia process # Start a theia shell that inherits the environment of the theia process
# This simulates the environment of a shell launched from the browser application # This simulates the environment of a shell launched from the browser application
theia_shell_process = pexpect.spawnu('{}/bin/theia-shell'.format(self.getPath()), env=theia_env) theia_shell_process = pexpect.spawnu('{}/bin/theia-shell'.format(self.getPath()), env=theia_env)
try: self.addCleanup(theia_shell_process.wait)
theia_shell_process.expect_exact('Standalone SlapOS for computer `slaprunner` activated') self.addCleanup(theia_shell_process.terminate)
# Launch slapos node software from theia shell theia_shell_process.expect_exact('Standalone SlapOS for computer `slaprunner` activated')
theia_shell_process.sendline('slapos node software')
theia_shell_process.expect('Installing software release %s' % self.dummy_software_path) # Launch slapos node software from theia shell
theia_shell_process.expect('Finished software releases.') theia_shell_process.sendline('slapos node software')
theia_shell_process.expect('Installing software release %s' % self.dummy_software_path)
# Get the theia shell environment theia_shell_process.expect('Finished software releases.')
with open(env_json_path) as f:
theia_shell_env = json.load(f) # Get the theia shell environment
with open(env_json_path) as f:
# Remove the env.json file to later be sure that a new one has been generated theia_shell_env = json.load(f)
os.remove(env_json_path)
# Remove the env.json file to later be sure that a new one has been generated
# Launch slapos node software service from the embedded supervisord. os.remove(env_json_path)
# Note that we have two services, slapos-node-software and slapos-node-software-all
# The later uses --all which is what we want to use here, because the software # Launch slapos node software service from the embedded supervisord.
# is already installed and we want to install it again, this time from supervisor # Note that we have two services, slapos-node-software and slapos-node-software-all
embedded_run_path = self.getPath('srv', 'runner', 'var', 'run') # The later uses --all which is what we want to use here, because the software
embedded_supervisord_socket_path = _getSupervisordSocketPath(embedded_run_path, self.logger) # is already installed and we want to install it again, this time from supervisor
with getSupervisorRPC(embedded_supervisord_socket_path) as embedded_supervisor: embedded_run_path = self.getPath('srv', 'runner', 'var', 'run')
previous_stop_time = embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] embedded_supervisord_socket_path = _getSupervisordSocketPath(embedded_run_path, self.logger)
embedded_supervisor.startProcess('slapos-node-software-all') with getSupervisorRPC(embedded_supervisord_socket_path) as embedded_supervisor:
for _retries in range(20): previous_stop_time = embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop']
time.sleep(1) embedded_supervisor.startProcess('slapos-node-software-all')
if embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] != previous_stop_time: for _retries in range(20):
break time.sleep(1)
else: if embedded_supervisor.getProcessInfo('slapos-node-software-all')['stop'] != previous_stop_time:
self.fail("the supervisord service 'slapos-node-software-all' takes too long to finish") break
else:
# Get the supervisord environment self.fail("the supervisord service 'slapos-node-software-all' takes too long to finish")
with open(env_json_path) as f:
supervisord_env = json.load(f) # Get the supervisord environment
with open(env_json_path) as f:
# Compare relevant variables from both environments supervisord_env = json.load(f)
self.maxDiff = None
self.assertEqual(theia_shell_env['PATH'].split(':'), supervisord_env['PATH'].split(':')) # Compare relevant variables from both environments
self.assertEqual(theia_shell_env['SLAPOS_CONFIGURATION'], supervisord_env['SLAPOS_CONFIGURATION']) self.maxDiff = None
self.assertEqual(theia_shell_env['SLAPOS_CLIENT_CONFIGURATION'], supervisord_env['SLAPOS_CLIENT_CONFIGURATION']) self.assertEqual(theia_shell_env['PATH'].split(':'), supervisord_env['PATH'].split(':'))
self.assertEqual(theia_shell_env['HOME'], supervisord_env['HOME']) self.assertEqual(theia_shell_env['SLAPOS_CONFIGURATION'], supervisord_env['SLAPOS_CONFIGURATION'])
self.assertEqual(theia_shell_env['SLAPOS_CLIENT_CONFIGURATION'], supervisord_env['SLAPOS_CLIENT_CONFIGURATION'])
finally: self.assertEqual(theia_shell_env['HOME'], supervisord_env['HOME'])
# Cleanup the theia shell process
theia_shell_process.terminate()
theia_shell_process.wait()
class ResilientTheiaMixin(object): class ResilientTheiaMixin(object):
......
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