Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
b78ac34d
Commit
b78ac34d
authored
Oct 12, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
30e37b73
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
38 deletions
+40
-38
slapos/cli/configure_local/__init__.py
slapos/cli/configure_local/__init__.py
+3
-5
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+3
-3
slapos/grid/svcbackend.py
slapos/grid/svcbackend.py
+2
-2
slapos/proxy/__init__.py
slapos/proxy/__init__.py
+3
-1
slapos/proxy/views.py
slapos/proxy/views.py
+7
-8
slapos/slap/slap.py
slapos/slap/slap.py
+9
-11
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+3
-1
slapos/tests/slapproxy/__init__.py
slapos/tests/slapproxy/__init__.py
+10
-7
No files found.
slapos/cli/configure_local/__init__.py
View file @
b78ac34d
...
...
@@ -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 =
\
...
...
slapos/grid/SlapObject.py
View file @
b78ac34d
...
...
@@ -481,8 +481,8 @@ class Partition(object):
}
def
addCustomGroup
(
self
,
group_suffix
,
partition_id
,
program_list
):
group_partition_template
=
pkg_resources
.
resource_str
eam
(
__name__
,
'templates/group_partition_supervisord.conf.in'
).
read
(
)
group_partition_template
=
pkg_resources
.
resource_str
ing
(
__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
,
...
...
slapos/grid/svcbackend.py
View file @
b78ac34d
...
...
@@ -89,8 +89,8 @@ def createSupervisordConfiguration(instance_root, watchdog_command=''):
# Creates supervisord configuration
updateFile
(
supervisord_configuration_file_path
,
pkg_resources
.
resource_str
eam
(
__name__
,
'templates/supervisord.conf.in'
).
read
(
)
%
{
pkg_resources
.
resource_str
ing
(
__name__
,
'templates/supervisord.conf.in'
).
decode
(
'utf-8'
)
%
{
'supervisord_configuration_directory'
:
supervisord_configuration_directory
,
'supervisord_socket'
:
os
.
path
.
abspath
(
supervisord_socket
),
'supervisord_loglevel'
:
'info'
,
...
...
slapos/proxy/__init__.py
View file @
b78ac34d
...
...
@@ -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
'
)]
...
...
slapos/proxy/views.py
View file @
b78ac34d
...
...
@@ -57,10 +57,10 @@ class UnauthorizedError(Exception):
# cast everything to string, utf-8 encoded
def
to_str
(
v
):
if
isinstance
(
v
,
s
tr
):
if
isinstance
(
v
,
s
ix
.
binary_type
):
return
v
if
not
isinstance
(
v
,
unicod
e
):
v
=
unicod
e
(
v
)
if
not
isinstance
(
v
,
six
.
text_typ
e
):
v
=
six
.
text_typ
e
(
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
=
unicod
e
(
parameter_value
)
parameter_value
=
six
.
text_typ
e
(
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
unicod
e
:
if
type
(
value
)
is
six
.
text_typ
e
:
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
:
...
...
slapos/slap/slap.py
View file @
b78ac34d
...
...
@@ -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
)
...
...
slapos/tests/slapformat.py
View file @
b78ac34d
...
...
@@ -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
)))
...
...
slapos/tests/slapproxy/__init__.py
View file @
b78ac34d
...
...
@@ -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_str
eam
(
configuration
=
pkg_resources
.
resource_str
ing
(
'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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment