Commit d1e941b3 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

wip

parent 064ee487
......@@ -39,6 +39,7 @@ from slapos.cli.config import ConfigCommand
from slapos.grid.slapgrid import create_slapgrid_object
from slapos.grid.utils import updateFile, createPrivateDirectory
from slapos.grid.svcbackend import launchSupervisord
from slapos.util import bytes2str
DEFAULT_COMPUTER_ID = 'local_computer'
......@@ -127,7 +128,7 @@ def _replaceParameterValue(original_content, to_replace):
def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
template_arg_list = (__name__, '../../slapos.cfg.example')
slapos_node_configuration_template = \
pkg_resources.resource_string(*template_arg_list).decode('utf-8')
bytes2str(pkg_resources.resource_string(*template_arg_list))
master_url = 'http://%s:%s' % (args.daemon_listen_ip, args.daemon_listen_port)
slapos_home = args.slapos_buildout_directory
to_replace = [
......@@ -154,7 +155,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
def _generateSlaposProxyConfigurationFile(conf):
template_arg_list = (__name__, '../../slapos-proxy.cfg.example')
slapos_proxy_configuration_template = \
pkg_resources.resource_string(*template_arg_list).decode('utf-8')
bytes2str(pkg_resources.resource_string(*template_arg_list))
slapos_proxy_configuration_path = os.path.join(
conf.slapos_configuration_directory, 'slapos-proxy.cfg')
listening_ip, listening_port = \
......
......@@ -51,6 +51,7 @@ from slapos.grid.exception import (BuildoutFailedError, WrongPermissionError,
PathDoesNotExistError, DiskSpaceError)
from slapos.grid.networkcache import download_network_cached, upload_network_cached
from slapos.human import bytes2human
from slapos.util import bytes2str
WATCHDOG_MARK = '-on-watch'
......@@ -481,8 +482,8 @@ class Partition(object):
}
def addCustomGroup(self, group_suffix, partition_id, program_list):
group_partition_template = pkg_resources.resource_string(__name__,
'templates/group_partition_supervisord.conf.in').decode('utf-8')
group_partition_template = bytes2str(pkg_resources.resource_string(__name__,
'templates/group_partition_supervisord.conf.in'))
group_id = '{}-{}'.format(partition_id, group_suffix)
self.supervisor_configuration_group += group_partition_template % {
......@@ -568,8 +569,8 @@ class Partition(object):
# fill generated buildout with additional information
buildout_text = open(config_location).read()
buildout_text += '\n\n' + pkg_resources.resource_string(__name__,
'templates/buildout-tail.cfg.in').decode('utf-8') % {
buildout_text += '\n\n' + bytes2str(pkg_resources.resource_string(__name__,
'templates/buildout-tail.cfg.in')) % {
'computer_id': self.computer_id,
'partition_id': self.partition_id,
'server_url': self.server_url,
......
......@@ -38,6 +38,7 @@ import time
from six.moves import xmlrpc_client as xmlrpclib
from slapos.grid.utils import (createPrivateDirectory, SlapPopen, updateFile)
from slapos.util import bytes2str
from supervisor import xmlrpc, states
......@@ -89,8 +90,8 @@ def createSupervisordConfiguration(instance_root, watchdog_command=''):
# Creates supervisord configuration
updateFile(supervisord_configuration_file_path,
pkg_resources.resource_string(__name__,
'templates/supervisord.conf.in').decode('utf-8') % {
bytes2str(pkg_resources.resource_string(__name__,
'templates/supervisord.conf.in')) % {
'supervisord_configuration_directory': supervisord_configuration_directory,
'supervisord_socket': os.path.abspath(supervisord_socket),
'supervisord_loglevel': 'info',
......
# -*- coding: utf-8 -*-
import pkg_resources
from slapos.util import bytes2str
DB_VERSION = pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline().strip().split(b':')[1]
import six
if six.PY3:
DB_VERSION = DB_VERSION.decode('utf-8')
DB_VERSION = bytes2str(pkg_resources.resource_stream('slapos.proxy', 'schema.sql').readline().strip().split(b':')[1])
......@@ -46,7 +46,7 @@ import slapos.proxy
import slapos.proxy.views as views
import slapos.slap
import slapos.slap.slap
from slapos.util import sqlite_connect
from slapos.util import sqlite_connect, bytes2str
import sqlite3
import pkg_resources
......@@ -1055,9 +1055,9 @@ database_uri = %(tempdir)s/lib/external_proxy.db
Overwrite default slapos configuration file to enable specific multimaster
behaviours.
"""
configuration = pkg_resources.resource_string(
configuration = bytes2str(pkg_resources.resource_string(
'slapos.tests.slapproxy', 'slapos_multimaster.cfg.in'
).decode('utf-8') % {
)) % {
'tempdir': self._tempdir, 'proxyaddr': self.proxyaddr,
'external_proxy_host': self.external_proxy_host,
'external_proxy_port': self.external_proxy_port
......@@ -1272,10 +1272,10 @@ class TestMigrateVersion10To11(TestInformation, TestRequest, TestSlaveRequest, T
"""
def setUp(self):
super(TestMigrateVersion10To11, self).setUp()
schema = pkg_resources.resource_string(
schema = bytes2str(pkg_resources.resource_string(
'slapos.tests.slapproxy',
'database_dump_version_10.sql'
).decode('utf-8') % dict(version='11')
)) % dict(version='11')
self.db = sqlite_connect(self.proxy_db)
self.db.cursor().executescript(schema)
self.db.commit()
......
......@@ -99,3 +99,11 @@ def sqlite_connect(dburi, timeout=None):
conn = sqlite3.connect(dburi, **connect_kw)
conn.text_factory = str # allow 8-bit strings
return conn
if str is bytes:
def bytes2str(s):
return s
else:
def bytes2str(s):
return s.decode()
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