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

wip

parent 30e37b73
...@@ -120,14 +120,13 @@ def _replaceParameterValue(original_content, to_replace): ...@@ -120,14 +120,13 @@ def _replaceParameterValue(original_content, to_replace):
to_replace by their value. to_replace by their value.
""" """
for key, value in to_replace: for key, value in to_replace:
original_content = re.sub(b'%s\s+=.*' % key, b'%s = %s' % (key, value), original_content = re.sub('%s\s+=.*' % key, '%s = %s' % (key, value),
original_content) original_content)
return original_content return original_content
def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args): def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
template_arg_list = (__name__, '../../slapos.cfg.example') template_arg_list = (__name__, '../../slapos.cfg.example')
with pkg_resources.resource_stream(*template_arg_list) as fout: slapos_node_configuration_template = pkg_resources.resource_string(*template_arg_list).decode('utf-8')
slapos_node_configuration_template = fout.read()
master_url = 'http://%s:%s' % (args.daemon_listen_ip, args.daemon_listen_port) master_url = 'http://%s:%s' % (args.daemon_listen_ip, args.daemon_listen_port)
slapos_home = args.slapos_buildout_directory slapos_home = args.slapos_buildout_directory
to_replace = [ to_replace = [
...@@ -153,8 +152,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args): ...@@ -153,8 +152,7 @@ def _generateSlaposNodeConfigurationFile(slapos_node_config_path, args):
def _generateSlaposProxyConfigurationFile(conf): def _generateSlaposProxyConfigurationFile(conf):
template_arg_list = (__name__, '../../slapos-proxy.cfg.example') template_arg_list = (__name__, '../../slapos-proxy.cfg.example')
with pkg_resources.resource_stream(*template_arg_list) as fout: slapos_proxy_configuration_template = pkg_resources.resource_string(*template_arg_list).decode('utf-8')
slapos_proxy_configuration_template = fout.read()
slapos_proxy_configuration_path = os.path.join( slapos_proxy_configuration_path = os.path.join(
conf.slapos_configuration_directory, 'slapos-proxy.cfg') conf.slapos_configuration_directory, 'slapos-proxy.cfg')
listening_ip, listening_port = \ listening_ip, listening_port = \
......
...@@ -481,8 +481,8 @@ class Partition(object): ...@@ -481,8 +481,8 @@ class Partition(object):
} }
def addCustomGroup(self, group_suffix, partition_id, program_list): def addCustomGroup(self, group_suffix, partition_id, program_list):
group_partition_template = pkg_resources.resource_stream(__name__, group_partition_template = pkg_resources.resource_string(__name__,
'templates/group_partition_supervisord.conf.in').read() 'templates/group_partition_supervisord.conf.in').decode('utf-8')
group_id = '{}-{}'.format(partition_id, group_suffix) group_id = '{}-{}'.format(partition_id, group_suffix)
self.supervisor_configuration_group += group_partition_template % { self.supervisor_configuration_group += group_partition_template % {
...@@ -569,7 +569,7 @@ class Partition(object): ...@@ -569,7 +569,7 @@ class Partition(object):
# fill generated buildout with additional information # fill generated buildout with additional information
buildout_text = open(config_location).read() buildout_text = open(config_location).read()
buildout_text += '\n\n' + pkg_resources.resource_string(__name__, buildout_text += '\n\n' + pkg_resources.resource_string(__name__,
'templates/buildout-tail.cfg.in') % { 'templates/buildout-tail.cfg.in').decode('utf-8') % {
'computer_id': self.computer_id, 'computer_id': self.computer_id,
'partition_id': self.partition_id, 'partition_id': self.partition_id,
'server_url': self.server_url, 'server_url': self.server_url,
......
...@@ -89,8 +89,8 @@ def createSupervisordConfiguration(instance_root, watchdog_command=''): ...@@ -89,8 +89,8 @@ def createSupervisordConfiguration(instance_root, watchdog_command=''):
# Creates supervisord configuration # Creates supervisord configuration
updateFile(supervisord_configuration_file_path, updateFile(supervisord_configuration_file_path,
pkg_resources.resource_stream(__name__, pkg_resources.resource_string(__name__,
'templates/supervisord.conf.in').read() % { 'templates/supervisord.conf.in').decode('utf-8') % {
'supervisord_configuration_directory': supervisord_configuration_directory, 'supervisord_configuration_directory': supervisord_configuration_directory,
'supervisord_socket': os.path.abspath(supervisord_socket), 'supervisord_socket': os.path.abspath(supervisord_socket),
'supervisord_loglevel': 'info', 'supervisord_loglevel': 'info',
......
...@@ -33,6 +33,8 @@ import logging ...@@ -33,6 +33,8 @@ import logging
from slapos.proxy.views import app from slapos.proxy.views import app
from slapos.util import sqlite_connect from slapos.util import sqlite_connect
import six
def _generateSoftwareProductListFromString(software_product_list_string): def _generateSoftwareProductListFromString(software_product_list_string):
""" """
Take a string as argument (which usually comes from the software_product_list Take a string as argument (which usually comes from the software_product_list
...@@ -72,7 +74,7 @@ class ProxyConfig(object): ...@@ -72,7 +74,7 @@ class ProxyConfig(object):
elif section.startswith('multimaster/'): elif section.startswith('multimaster/'):
# Merge multimaster configuration if any # Merge multimaster configuration if any
# XXX: check for duplicate SR entries # XXX: check for duplicate SR entries
for key, value in configuration_dict.iteritems(): for key, value in six.iteritems(configuration_dict):
if key == 'software_release_list': if key == 'software_release_list':
# Split multi-lines values # Split multi-lines values
configuration_dict[key] = [line.strip() for line in value.strip().split('\n')] configuration_dict[key] = [line.strip() for line in value.strip().split('\n')]
......
...@@ -57,10 +57,10 @@ class UnauthorizedError(Exception): ...@@ -57,10 +57,10 @@ class UnauthorizedError(Exception):
# cast everything to string, utf-8 encoded # cast everything to string, utf-8 encoded
def to_str(v): def to_str(v):
if isinstance(v, str): if isinstance(v, six.binary_type):
return v return v
if not isinstance(v, unicode): if not isinstance(v, six.text_type):
v = unicode(v) v = six.text_type(v)
return v.encode('utf-8') return v.encode('utf-8')
...@@ -84,7 +84,7 @@ def dict2xml(dictionary): ...@@ -84,7 +84,7 @@ def dict2xml(dictionary):
instance = etree.Element('instance') instance = etree.Element('instance')
for parameter_id, parameter_value in six.iteritems(dictionary): for parameter_id, parameter_value in six.iteritems(dictionary):
# cast everything to string # cast everything to string
parameter_value = unicode(parameter_value) parameter_value = six.text_type(parameter_value)
etree.SubElement(instance, "parameter", etree.SubElement(instance, "parameter",
attrib={'id': parameter_id}).text = parameter_value attrib={'id': parameter_id}).text = parameter_value
return etree.tostring(instance, return etree.tostring(instance,
...@@ -95,7 +95,7 @@ def dict2xml(dictionary): ...@@ -95,7 +95,7 @@ def dict2xml(dictionary):
def partitiondict2partition(partition): def partitiondict2partition(partition):
for key, value in six.iteritems(partition): for key, value in six.iteritems(partition):
if type(value) is unicode: if type(value) is six.text_type:
partition[key] = value.encode() partition[key] = value.encode()
slap_partition = ComputerPartition(partition['computer_reference'], slap_partition = ComputerPartition(partition['computer_reference'],
partition['reference']) partition['reference'])
...@@ -511,8 +511,7 @@ def forwardRequestToExternalMaster(master_url, request_form): ...@@ -511,8 +511,7 @@ def forwardRequestToExternalMaster(master_url, request_form):
new_request_form['filter_xml'] = dumps(filter_kw) new_request_form['filter_xml'] = dumps(filter_kw)
xml = slap._connection_helper.POST('/requestComputerPartition', data=new_request_form) xml = slap._connection_helper.POST('/requestComputerPartition', data=new_request_form)
if type(xml) is unicode: if type(xml) is six.text_type:
xml = str(xml)
xml.encode('utf-8') xml.encode('utf-8')
partition = loads(xml) partition = loads(xml)
...@@ -793,7 +792,7 @@ def getSoftwareReleaseListFromSoftwareProduct(): ...@@ -793,7 +792,7 @@ def getSoftwareReleaseListFromSoftwareProduct():
raise NotImplementedError('software_release_url parameter is not supported yet.') raise NotImplementedError('software_release_url parameter is not supported yet.')
else: else:
assert(software_product_reference is not None) assert(software_product_reference is not None)
if app.config['software_product_list'].has_key(software_product_reference): if software_product_reference in app.config['software_product_list']:
software_release_url_list =\ software_release_url_list =\
[app.config['software_product_list'][software_product_reference]] [app.config['software_product_list'][software_product_reference]]
else: else:
......
...@@ -40,6 +40,7 @@ import os ...@@ -40,6 +40,7 @@ import os
import json import json
import logging import logging
import re import re
import six
from six.moves.urllib import parse from six.moves.urllib import parse
import hashlib import hashlib
...@@ -93,8 +94,7 @@ class SlapRequester(SlapDocument): ...@@ -93,8 +94,7 @@ class SlapRequester(SlapDocument):
request_dict=request_dict, request_dict=request_dict,
connection_helper=self._connection_helper, connection_helper=self._connection_helper,
) )
if type(xml) is unicode: if type(xml) is six.text_type:
xml = str(xml)
xml.encode('utf-8') xml.encode('utf-8')
software_instance = xml_marshaller.loads(xml) software_instance = xml_marshaller.loads(xml)
computer_partition = ComputerPartition( computer_partition = ComputerPartition(
...@@ -210,7 +210,7 @@ class SoftwareInstance(SlapDocument): ...@@ -210,7 +210,7 @@ class SoftwareInstance(SlapDocument):
""" """
Makes easy initialisation of class parameters Makes easy initialisation of class parameters
""" """
for k, v in kwargs.iteritems(): for k, v in six.iteritems(kwargs):
setattr(self, k, v) setattr(self, k, v)
...@@ -281,7 +281,7 @@ class OpenOrder(SlapRequester): ...@@ -281,7 +281,7 @@ class OpenOrder(SlapRequester):
raw_information = self._hateoas_navigator.getHostingSubscriptionRootSoftwareInstanceInformation(partition_reference) raw_information = self._hateoas_navigator.getHostingSubscriptionRootSoftwareInstanceInformation(partition_reference)
software_instance = SoftwareInstance() software_instance = SoftwareInstance()
# XXX redefine SoftwareInstance to be more consistent # XXX redefine SoftwareInstance to be more consistent
for key, value in raw_information.iteritems(): for key, value in six.iteritems(raw_information):
if key in ['_links']: if key in ['_links']:
continue continue
setattr(software_instance, '_%s' % key, value) setattr(software_instance, '_%s' % key, value)
...@@ -308,8 +308,7 @@ def _syncComputerInformation(func): ...@@ -308,8 +308,7 @@ def _syncComputerInformation(func):
return func(self, *args, **kw) return func(self, *args, **kw)
computer = self._connection_helper.getFullComputerInformation(self._computer_id) computer = self._connection_helper.getFullComputerInformation(self._computer_id)
for key, value in computer.__dict__.items(): for key, value in computer.__dict__.items():
if isinstance(value, unicode): if isinstance(value, six.text_type):
# convert unicode to utf-8
setattr(self, key, value.encode('utf-8')) setattr(self, key, value.encode('utf-8'))
else: else:
setattr(self, key, value) setattr(self, key, value)
...@@ -530,7 +529,7 @@ class ComputerPartition(SlapRequester): ...@@ -530,7 +529,7 @@ class ComputerPartition(SlapRequester):
raw_information = self._hateoas_navigator.getRelatedInstanceInformation(partition_reference) raw_information = self._hateoas_navigator.getRelatedInstanceInformation(partition_reference)
software_instance = SoftwareInstance() software_instance = SoftwareInstance()
# XXX redefine SoftwareInstance to be more consistent # XXX redefine SoftwareInstance to be more consistent
for key, value in raw_information.iteritems(): for key, value in six.iteritems(raw_information):
if key in ['_links']: if key in ['_links']:
continue continue
setattr(software_instance, '_%s' % key, value) setattr(software_instance, '_%s' % key, value)
...@@ -729,8 +728,7 @@ class ConnectionHelper: ...@@ -729,8 +728,7 @@ class ConnectionHelper:
# We should stablise slap library soon. # We should stablise slap library soon.
xml = self.GET('getComputerInformation', params=params) xml = self.GET('getComputerInformation', params=params)
if type(xml) is unicode: if type(xml) is six.text_type:
xml = str(xml)
xml.encode('utf-8') xml.encode('utf-8')
return xml_marshaller.loads(xml) return xml_marshaller.loads(xml)
...@@ -755,7 +753,7 @@ class ConnectionHelper: ...@@ -755,7 +753,7 @@ class ConnectionHelper:
# Behavior kept for compatibility with old slapproxies (< v1.3.3). # Behavior kept for compatibility with old slapproxies (< v1.3.3).
# Can be removed when old slapproxies are no longer in use. # Can be removed when old slapproxies are no longer in use.
if data: if data:
for k, v in data.iteritems(): for k, v in six.iteritems(data):
if v is None: if v is None:
data[k] = 'None' data[k] = 'None'
...@@ -1041,7 +1039,7 @@ class SlapHateoasNavigator(HateoasNavigator): ...@@ -1041,7 +1039,7 @@ class SlapHateoasNavigator(HateoasNavigator):
raw_information = self.getHostingSubscriptionRootSoftwareInstanceInformation(hosting_subscription_link['title']) raw_information = self.getHostingSubscriptionRootSoftwareInstanceInformation(hosting_subscription_link['title'])
software_instance = SoftwareInstance() software_instance = SoftwareInstance()
# XXX redefine SoftwareInstance to be more consistent # XXX redefine SoftwareInstance to be more consistent
for key, value in raw_information.iteritems(): for key, value in six.iteritems(raw_information):
if key in ['_links']: if key in ['_links']:
continue continue
setattr(software_instance, '_%s' % key, value) setattr(software_instance, '_%s' % key, value)
......
...@@ -48,6 +48,8 @@ import mock ...@@ -48,6 +48,8 @@ import mock
from .slapgrid import DummyManager from .slapgrid import DummyManager
import six
USER_LIST = [] USER_LIST = []
GROUP_LIST = [] GROUP_LIST = []
INTERFACE_DICT = {} INTERFACE_DICT = {}
...@@ -134,7 +136,7 @@ class LoggableWrapper: ...@@ -134,7 +136,7 @@ class LoggableWrapper:
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
arg_list = [repr(x) for x in args] + [ arg_list = [repr(x) for x in args] + [
'%s=%r' % (x, y) for x, y in kwargs.iteritems()] '%s=%r' % (x, y) for x, y in six.iteritems(kwargs)]
self.__logger.debug('%s(%s)' % (self.__name, ', '.join(arg_list))) self.__logger.debug('%s(%s)' % (self.__name, ', '.join(arg_list)))
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# #
############################################################################## ##############################################################################
import six
from six.moves import configparser from six.moves import configparser
import os import os
import logging import logging
...@@ -1054,9 +1055,9 @@ database_uri = %(tempdir)s/lib/external_proxy.db ...@@ -1054,9 +1055,9 @@ database_uri = %(tempdir)s/lib/external_proxy.db
Overwrite default slapos configuration file to enable specific multimaster Overwrite default slapos configuration file to enable specific multimaster
behaviours. behaviours.
""" """
configuration = pkg_resources.resource_stream( configuration = pkg_resources.resource_string(
'slapos.tests.slapproxy', 'slapos_multimaster.cfg.in' 'slapos.tests.slapproxy', 'slapos_multimaster.cfg.in'
).read() % { ).decode('utf-8') % {
'tempdir': self._tempdir, 'proxyaddr': self.proxyaddr, 'tempdir': self._tempdir, 'proxyaddr': self.proxyaddr,
'external_proxy_host': self.external_proxy_host, 'external_proxy_host': self.external_proxy_host,
'external_proxy_port': self.external_proxy_port 'external_proxy_port': self.external_proxy_port
...@@ -1121,7 +1122,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db ...@@ -1121,7 +1122,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
external_slap.initializeConnection(self.external_master_url) external_slap.initializeConnection(self.external_master_url)
external_computer = external_slap.registerComputer(self.external_computer_id) external_computer = external_slap.registerComputer(self.external_computer_id)
external_partition = external_computer.getComputerPartitionList()[0] external_partition = external_computer.getComputerPartitionList()[0]
for k, v in partition_parameter_kw.iteritems(): for k, v in six.iteritems(partition_parameter_kw):
self.assertEqual( self.assertEqual(
external_partition.getInstanceParameter(k), external_partition.getInstanceParameter(k),
v v
...@@ -1146,7 +1147,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db ...@@ -1146,7 +1147,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
'/getFullComputerInformation?computer_id=%s' % self.computer_id '/getFullComputerInformation?computer_id=%s' % self.computer_id
).data) ).data)
partition = computer._computer_partition_list[0] partition = computer._computer_partition_list[0]
for k, v in partition_parameter_kw.iteritems(): for k, v in six.iteritems(partition_parameter_kw):
self.assertEqual( self.assertEqual(
partition.getInstanceParameter(k), partition.getInstanceParameter(k),
v v
...@@ -1251,7 +1252,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db ...@@ -1251,7 +1252,7 @@ database_uri = %(tempdir)s/lib/external_proxy.db
'/getFullComputerInformation?computer_id=%s' % self.computer_id '/getFullComputerInformation?computer_id=%s' % self.computer_id
).data) ).data)
partition = computer._computer_partition_list[0] partition = computer._computer_partition_list[0]
for k, v in dummy_parameter_dict.iteritems(): for k, v in six.iteritems(dummy_parameter_dict):
self.assertEqual( self.assertEqual(
partition.getInstanceParameter(k), partition.getInstanceParameter(k),
v v
...@@ -1271,8 +1272,10 @@ class TestMigrateVersion10To11(TestInformation, TestRequest, TestSlaveRequest, T ...@@ -1271,8 +1272,10 @@ class TestMigrateVersion10To11(TestInformation, TestRequest, TestSlaveRequest, T
""" """
def setUp(self): def setUp(self):
super(TestMigrateVersion10To11, self).setUp() super(TestMigrateVersion10To11, self).setUp()
schema = pkg_resources.resource_stream('slapos.tests.slapproxy', 'database_dump_version_10.sql') schema = pkg_resources.resource_string(
schema = schema.read() % dict(version='11') 'slapos.tests.slapproxy',
'database_dump_version_10.sql'
).decode('utf-8') % dict(version='11')
self.db = sqlite_connect(self.proxy_db) self.db = sqlite_connect(self.proxy_db)
self.db.cursor().executescript(schema) self.db.cursor().executescript(schema)
self.db.commit() self.db.commit()
......
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