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

wip

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