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
19
Merge Requests
19
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
bfb0168f
Commit
bfb0168f
authored
Oct 23, 2014
by
Cédric de Saint Martin
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.slap: add getHateoasUrl support.
parent
45cbfc0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
10 deletions
+75
-10
slapos/slap/slap.py
slapos/slap/slap.py
+8
-3
slapos/tests/slap.py
slapos/tests/slap.py
+55
-0
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+12
-7
No files found.
slapos/slap/slap.py
View file @
bfb0168f
...
...
@@ -262,7 +262,7 @@ class OpenOrder(SlapRequester):
def
getInformation
(
self
,
partition_reference
):
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
raise
Exception
(
'SlapOS Master
REST URL (master_rest_url) has not been configured
.'
)
raise
Exception
(
'SlapOS Master
Hateoas API required for this operation is not availble
.'
)
raw_information
=
self
.
_hateoas_navigator
.
getHostingSubscriptionRootSoftwareInstanceInformation
(
partition_reference
)
software_instance
=
SoftwareInstance
()
# XXX redefine SoftwareInstance to be more consistent
...
...
@@ -490,7 +490,7 @@ class ComputerPartition(SlapRequester):
in the Instance tree of the current Computer Partition.
"""
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
raise
Exception
(
'SlapOS Master
REST URL (master_rest_url) has not been configured
.'
)
raise
Exception
(
'SlapOS Master
Hateoas API required for this operation is not availble
.'
)
return
self
.
_hateoas_navigator
.
getSoftwareReleaseInformation
(
partition_reference
)
def
getId
(
self
):
...
...
@@ -710,6 +710,11 @@ class slap:
self
.
_connection_helper
=
ConnectionHelper
(
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
if
not
slapgrid_rest_uri
:
try
:
slapgrid_rest_uri
=
self
.
_connection_helper
.
GET
(
'getHateoasUrl'
)
except
:
pass
if
slapgrid_rest_uri
:
self
.
_hateoas_navigator
=
HateoasNavigator
(
slapgrid_rest_uri
,
...
...
@@ -795,7 +800,7 @@ class slap:
def
getOpenOrderDict
(
self
):
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
raise
Exception
(
'SlapOS Master
REST URL (master_rest_url) has not been configured
.'
)
raise
Exception
(
'SlapOS Master
Hateoas API required for this operation is not availble
.'
)
return
self
.
_hateoas_navigator
.
getHostingSubscriptionDict
()
...
...
slapos/tests/slap.py
View file @
bfb0168f
...
...
@@ -335,6 +335,61 @@ class TestSlap(SlapMixin):
self
.
slap
.
getSoftwareReleaseListFromSoftwareProduct
)
def
test_initializeConnection_getHateoasUrl
(
self
):
"""
Test that by default, slap will try to fetch Hateoas URL from XML/RPC URL.
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
urlparse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
return
{
'status_code'
:
200
,
'content'
:
hateoas_url
}
with
httmock
.
HTTMock
(
handler
):
self
.
slap
.
initializeConnection
(
'http://bar'
)
self
.
assertEqual
(
self
.
slap
.
_hateoas_navigator
.
slapos_master_hateoas_uri
,
hateoas_url
)
def
test_initializeConnection_specifiedHateoasUrl
(
self
):
"""
Test that if rest URL is specified, slap will NOT try to fetch
Hateoas URL from XML/RPC URL.
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
urlparse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
self
.
fail
(
'slap should not have contacted master to get Hateoas URL.'
)
with
httmock
.
HTTMock
(
handler
):
self
.
slap
.
initializeConnection
(
'http://bar'
,
slapgrid_rest_uri
=
hateoas_url
)
self
.
assertEqual
(
self
.
slap
.
_hateoas_navigator
.
slapos_master_hateoas_uri
,
hateoas_url
)
def
test_initializeConnection_noHateoasUrl
(
self
):
"""
Test that if no rest URL is specified and master does not know about rest,
it still work.
"""
hateoas_url
=
'foo'
def
handler
(
url
,
req
):
qs
=
urlparse
.
parse_qs
(
url
.
query
)
if
(
url
.
path
==
'/getHateoasUrl'
):
return
{
'status_code'
:
404
,
}
with
httmock
.
HTTMock
(
handler
):
self
.
slap
.
initializeConnection
(
'http://bar'
)
self
.
assertEqual
(
None
,
getattr
(
self
.
slap
,
'_hateoas_navigator'
,
None
))
class
TestComputer
(
SlapMixin
):
"""
Tests slapos.slap.slap.Computer class functionality
...
...
slapos/tests/slapgrid.py
View file @
bfb0168f
...
...
@@ -638,7 +638,7 @@ chmod 755 etc/run/wrapper
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
...
...
@@ -698,7 +698,7 @@ exit 1
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -734,7 +734,7 @@ exit 1
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/availableComputerPartition'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
...
...
@@ -1196,9 +1196,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
])
def
test_partition_timestamp_no_timestamp
(
self
):
...
...
@@ -1218,8 +1221,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance
.
timestamp
=
None
self
.
launchSlapgrid
()
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
...
...
Jérome Perrin
@jerome
mentioned in merge request
erp5!650 (merged)
·
May 08, 2018
mentioned in merge request
erp5!650 (merged)
mentioned in merge request nexedi/erp5!650
Toggle commit list
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