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
Jérome Perrin
slapos.core
Commits
bfb0168f
Commit
bfb0168f
authored
Oct 23, 2014
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.slap: add getHateoasUrl support.
parent
45cbfc0c
Changes
3
Show 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):
...
@@ -262,7 +262,7 @@ class OpenOrder(SlapRequester):
def
getInformation
(
self
,
partition_reference
):
def
getInformation
(
self
,
partition_reference
):
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
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
)
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
...
@@ -490,7 +490,7 @@ class ComputerPartition(SlapRequester):
...
@@ -490,7 +490,7 @@ class ComputerPartition(SlapRequester):
in the Instance tree of the current Computer Partition.
in the Instance tree of the current Computer Partition.
"""
"""
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
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
)
return
self
.
_hateoas_navigator
.
getSoftwareReleaseInformation
(
partition_reference
)
def
getId
(
self
):
def
getId
(
self
):
...
@@ -710,6 +710,11 @@ class slap:
...
@@ -710,6 +710,11 @@ class slap:
self
.
_connection_helper
=
ConnectionHelper
(
slapgrid_uri
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
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
:
if
slapgrid_rest_uri
:
self
.
_hateoas_navigator
=
HateoasNavigator
(
self
.
_hateoas_navigator
=
HateoasNavigator
(
slapgrid_rest_uri
,
slapgrid_rest_uri
,
...
@@ -795,7 +800,7 @@ class slap:
...
@@ -795,7 +800,7 @@ class slap:
def
getOpenOrderDict
(
self
):
def
getOpenOrderDict
(
self
):
if
not
getattr
(
self
,
'_hateoas_navigator'
,
None
):
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
()
return
self
.
_hateoas_navigator
.
getHostingSubscriptionDict
()
...
...
slapos/tests/slap.py
View file @
bfb0168f
...
@@ -335,6 +335,61 @@ class TestSlap(SlapMixin):
...
@@ -335,6 +335,61 @@ class TestSlap(SlapMixin):
self
.
slap
.
getSoftwareReleaseListFromSoftwareProduct
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
):
class
TestComputer
(
SlapMixin
):
"""
"""
Tests slapos.slap.slap.Computer class functionality
Tests slapos.slap.slap.Computer class functionality
...
...
slapos/tests/slapgrid.py
View file @
bfb0168f
...
@@ -638,7 +638,7 @@ chmod 755 etc/run/wrapper
...
@@ -638,7 +638,7 @@ chmod 755 etc/run/wrapper
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
])
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
...
@@ -698,7 +698,7 @@ exit 1
...
@@ -698,7 +698,7 @@ exit 1
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/softwareInstanceError'
])
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
@@ -734,7 +734,7 @@ exit 1
...
@@ -734,7 +734,7 @@ exit 1
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/get
HateoasUrl'
,
'/get
FullComputerInformation'
,
'/availableComputerPartition'
,
'/startedComputerPartition'
])
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
self
.
assertEqual
(
'started'
,
instance
.
state
)
...
@@ -1196,9 +1196,12 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -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
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/getHateoasUrl'
,
'/stoppedComputerPartition'
,
'/getFullComputerInformation'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
])
'/getFullComputerInformation'
])
def
test_partition_timestamp_no_timestamp
(
self
):
def
test_partition_timestamp_no_timestamp
(
self
):
...
@@ -1218,8 +1221,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
...
@@ -1218,8 +1221,10 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
instance
.
timestamp
=
None
instance
.
timestamp
=
None
self
.
launchSlapgrid
()
self
.
launchSlapgrid
()
self
.
assertEqual
(
computer
.
sequence
,
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
[
'/getHateoasUrl'
,
'/stoppedComputerPartition'
,
'/getFullComputerInformation'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/stoppedComputerPartition'
])
'/availableComputerPartition'
,
'/stoppedComputerPartition'
])
def
test_partition_periodicity_remove_timestamp
(
self
):
def
test_partition_periodicity_remove_timestamp
(
self
):
...
...
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