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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Gambier
slapos.core
Commits
2fad6ceb
Commit
2fad6ceb
authored
Nov 14, 2014
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.slap: parse ipv6 and adds bracket s if missing.
Needed for requests, that now NEEDS brackets for ipv6.
parent
4fa72c5d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
slapos/slap/slap.py
slapos/slap/slap.py
+22
-0
slapos/tests/slap.py
slapos/tests/slap.py
+60
-0
No files found.
slapos/slap/slap.py
View file @
2fad6ceb
...
...
@@ -41,6 +41,7 @@ import re
import
urlparse
from
util
import
xml2dict
import
netaddr
from
xml.sax
import
saxutils
import
zope.interface
from
interface
import
slap
as
interface
...
...
@@ -599,10 +600,31 @@ class ComputerPartition(SlapRequester):
)
return
xml_marshaller
.
loads
(
xml
)
def
_addIpv6Brackets
(
url
):
# if master_url contains an ipv6 without bracket, add it
# Note that this is mostly to limit specific issues with
# backward compatiblity, not to ensure generic detection.
api_scheme
,
api_netloc
,
api_path
,
api_query
,
api_fragment
=
urlparse
.
urlsplit
(
url
)
try
:
ip
=
netaddr
.
IPAddress
(
api_netloc
)
port
=
None
except
netaddr
.
AddrFormatError
:
try
:
ip
=
netaddr
.
IPAddress
(
':'
.
join
(
api_netloc
.
split
(
':'
)[:
-
1
]))
port
=
api_netloc
.
split
(
':'
)[
-
1
]
except
netaddr
.
AddrFormatError
:
ip
=
port
=
None
if
ip
and
ip
.
version
==
6
:
api_netloc
=
'[%s]'
%
ip
if
port
:
api_netloc
=
'%s:%s'
%
(
api_netloc
,
port
)
url
=
urlparse
.
urlunsplit
((
api_scheme
,
api_netloc
,
api_path
,
api_query
,
api_fragment
))
return
url
class
ConnectionHelper
:
def
__init__
(
self
,
master_url
,
key_file
=
None
,
cert_file
=
None
,
master_ca_file
=
None
,
timeout
=
None
):
master_url
=
_addIpv6Brackets
(
master_url
)
if
master_url
.
endswith
(
'/'
):
self
.
slapgrid_uri
=
master_url
else
:
...
...
slapos/tests/slap.py
View file @
2fad6ceb
...
...
@@ -78,6 +78,66 @@ class TestSlap(SlapMixin):
slap_instance
.
initializeConnection
(
self
.
server_url
)
self
.
assertEquals
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
self
.
server_url
)
def
test_slap_initialisation_ipv6_and_port
(
self
):
"""
Asserts that slap correctly understand master_url containing
ipv6 and adds brackets if not there.
"""
slap_instance
=
slapos
.
slap
.
slap
()
slap_instance
.
initializeConnection
(
"http://1234:1234:1234:1234:1:1:1:1:5000/foo/"
)
self
.
assertEqual
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
"http://[1234:1234:1234:1234:1:1:1:1]:5000/foo/"
)
def
test_slap_initialisation_ipv6_without_port
(
self
):
"""
Asserts that slap correctly understand master_url containing
ipv6 and adds brackets if not there.
"""
slap_instance
=
slapos
.
slap
.
slap
()
slap_instance
.
initializeConnection
(
"http://1234:1234:1234:1234:1:1:1:1/foo/"
)
self
.
assertEqual
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
"http://[1234:1234:1234:1234:1:1:1:1]/foo/"
)
def
test_slap_initialisation_ipv6_with_bracket
(
self
):
"""
Asserts that slap correctly understand master_url containing
ipv6 and adds brackets if not there.
"""
slap_instance
=
slapos
.
slap
.
slap
()
slap_instance
.
initializeConnection
(
"http://[1234:1234:1234:1234:1:1:1:1]:5000/foo/"
)
self
.
assertEqual
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
"http://[1234:1234:1234:1234:1:1:1:1]:5000/foo/"
)
def
test_slap_initialisation_ipv4
(
self
):
"""
Asserts that slap correctly understand master_url containing
ipv6 and adds brackets if not there.
"""
slap_instance
=
slapos
.
slap
.
slap
()
slap_instance
.
initializeConnection
(
"http://127.0.0.1:5000/foo/"
)
self
.
assertEqual
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
"http://127.0.0.1:5000/foo/"
)
def
test_slap_initialisation_hostname
(
self
):
"""
Asserts that slap correctly understand master_url containing
ipv6 and adds brackets if not there.
"""
slap_instance
=
slapos
.
slap
.
slap
()
slap_instance
.
initializeConnection
(
"http://foo.com:5000/foo/"
)
self
.
assertEqual
(
slap_instance
.
_connection_helper
.
slapgrid_uri
,
"http://foo.com:5000/foo/"
)
def
test_registerComputer_with_new_guid
(
self
):
"""
Asserts that calling slap.registerComputer with new guid returns
...
...
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