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
Gabriel Monnerat
slapos.core
Commits
a5d41e2b
Commit
a5d41e2b
authored
Oct 17, 2012
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to fetch status for computer and partition.
parent
5c592a04
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
340 additions
and
3 deletions
+340
-3
master/product/Vifib/Tool/SlapTool.py
master/product/Vifib/Tool/SlapTool.py
+75
-3
master/product/Vifib/tests/testVifibSlapComputerGetStatus.py
master/product/Vifib/tests/testVifibSlapComputerGetStatus.py
+123
-0
master/product/Vifib/tests/testVifibSlapComputerPartitionGetStatus.py
...ct/Vifib/tests/testVifibSlapComputerPartitionGetStatus.py
+111
-0
slapos/slap/interface/slap.py
slapos/slap/interface/slap.py
+20
-0
slapos/slap/slap.py
slapos/slap/slap.py
+11
-0
No files found.
master/product/Vifib/Tool/SlapTool.py
View file @
a5d41e2b
...
...
@@ -336,6 +336,34 @@ class SlapTool(BaseTool):
self
.
REQUEST
.
response
.
setBody
(
result
)
return
self
.
REQUEST
.
response
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getComputerPartitionStatus'
)
def
getComputerPartitionStatus
(
self
,
computer_id
,
computer_partition_id
):
"""
Get the connection status of the partition
"""
try
:
instance
=
self
.
_getSoftwareInstanceForComputerPartition
(
computer_id
,
computer_partition_id
)
except
NotFound
:
return
self
.
_getAccessStatus
(
None
)
else
:
return
self
.
_getAccessStatus
(
instance
.
getReference
())
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getComputerStatus'
)
def
getComputerStatus
(
self
,
computer_id
):
"""
Get the connection status of the partition
"""
computer
=
self
.
getPortalObject
().
portal_catalog
.
unrestrictedSearchResults
(
portal_type
=
'Computer'
,
reference
=
computer_id
,
validation_state
=
"validated"
)[
0
].
getObject
()
# Be sure to prevent accessing information to disallowed users
computer
=
_assertACI
(
computer
)
return
self
.
_getAccessStatus
(
computer_id
)
####################################################
# Public POST methods
####################################################
...
...
@@ -543,6 +571,9 @@ class SlapTool(BaseTool):
"""
Fire up bung on Computer
"""
user
=
self
.
getPortalObject
().
portal_membership
.
getAuthenticatedMember
()
\
.
getUserName
()
self
.
_logAccess
(
user
,
computer_id
,
'#error bang'
)
return
self
.
_getComputerDocument
(
computer_id
).
reportComputerBang
(
comment
=
message
)
...
...
@@ -670,6 +701,11 @@ class SlapTool(BaseTool):
slap_partition
.
_parameter_dict
.
update
(
parameter_dict
)
result
=
xml_marshaller
.
xml_marshaller
.
dumps
(
slap_partition
)
user
=
self
.
getPortalObject
().
portal_membership
.
\
getAuthenticatedMember
().
getUserName
()
self
.
_logAccess
(
user
,
user
,
'#access %s %s'
%
(
computer_reference
,
computer_partition_reference
))
# Keep in cache server for 7 days
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
...
...
@@ -950,10 +986,46 @@ class SlapTool(BaseTool):
Fire up bang on Software Instance
Add an error for the software Instance Workflow
"""
return
self
.
_getSoftwareInstanceForComputerPartition
(
software_instance
=
self
.
_getSoftwareInstanceForComputerPartition
(
computer_id
,
computer_partition_id
).
bang
(
bang_tree
=
True
,
comment
=
message
)
computer_partition_id
)
user
=
self
.
getPortalObject
().
portal_membership
.
\
getAuthenticatedMember
().
getUserName
()
self
.
_logAccess
(
user
,
software_instance
.
getReference
(),
'#error bang called'
)
return
software_instance
.
bang
(
bang_tree
=
True
,
comment
=
message
)
def
_getAccessStatus
(
self
,
context_reference
):
memcached_dict
=
self
.
_getMemcachedDict
()
try
:
if
context_reference
is
None
:
raise
KeyError
else
:
d
=
memcached_dict
[
context_reference
]
except
KeyError
:
if
context_reference
is
None
:
d
=
{
"user"
:
"SlapOS Master"
,
'created_at'
:
'%s'
%
rfc1123_date
(
DateTime
()),
"text"
:
"#error no data found"
}
else
:
d
=
{
"user"
:
"SlapOS Master"
,
'created_at'
:
'%s'
%
rfc1123_date
(
DateTime
()),
"text"
:
"#error no data found for %s"
%
context_reference
}
else
:
d
=
json
.
loads
(
d
)
# Keep in cache server for 7 days
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
'public, max-age=60, stale-if-error=604800'
)
self
.
REQUEST
.
response
.
setHeader
(
'Vary'
,
'REMOTE_USER'
)
self
.
REQUEST
.
response
.
setHeader
(
'Last-Modified'
,
rfc1123_date
(
DateTime
()))
self
.
REQUEST
.
response
.
setBody
(
xml_marshaller
.
xml_marshaller
.
dumps
(
d
))
return
self
.
REQUEST
.
response
@
convertToREST
def
_startedComputerPartition
(
self
,
computer_id
,
computer_partition_id
):
...
...
master/product/Vifib/tests/testVifibSlapComputerGetStatus.py
0 → 100644
View file @
a5d41e2b
from
Products.ZSQLCatalog.SQLCatalog
import
Query
,
ComplexQuery
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.backportUnittest
import
skip
import
transaction
import
unittest
from
testVifibSlapWebService
import
TestVifibSlapWebServiceMixin
from
slapos
import
slap
class
TestVifibSlapComputerGetStatus
(
TestVifibSlapWebServiceMixin
):
########################################
# Computer.getStatus
########################################
def
stepCheckNoDataComputerGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer
=
self
.
slap
.
registerComputer
(
computer_guid
)
status
=
computer
.
getStatus
()
self
.
assertEquals
(
'SlapOS Master'
,
status
[
'user'
])
self
.
assertEquals
(
'#error no data found for %s'
%
\
sequence
[
"computer_reference"
],
status
[
'text'
])
def
test_Computer_getStatus_noComputer
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_computer
+
'
\
SlapLoginCurrentComputer
\
CheckNoDataComputerGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
stepCheckOKComputerGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer
=
self
.
slap
.
registerComputer
(
computer_guid
)
status
=
computer
.
getStatus
()
self
.
assertEquals
(
sequence
[
'computer_reference'
],
status
[
'user'
])
self
.
assertEquals
(
'#access %s'
%
sequence
[
"computer_reference"
],
status
[
'text'
])
def
test_Computer_OK_getStatus
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_computer
+
'
\
SlapLoginCurrentComputer
\
CheckSuccessComputerGetComputerPartitionCall
\
CheckOKComputerGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
stepCheckErrorComputerGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer
=
self
.
slap
.
registerComputer
(
computer_guid
)
status
=
computer
.
getStatus
()
self
.
assertEquals
(
sequence
[
'computer_reference'
],
status
[
'user'
])
self
.
assertEquals
(
'#error bang'
,
status
[
'text'
])
def
stepSoftwareReleaseError
(
self
,
sequence
,
**
kw
):
"""
"""
url
=
sequence
[
"software_release_uri"
]
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
software_release
=
self
.
slap
.
registerSoftwareRelease
(
url
)
software_release
.
error
(
"ErrorLog"
)
def
stepComputerBang
(
self
,
sequence
,
**
kw
):
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
slap_computer
=
self
.
slap
.
registerComputer
(
sequence
[
'computer_reference'
])
slap_computer
.
bang
(
'foo'
)
def
test_Computer_Error_getStatus
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_formated_computer
+
'
\
SlapLoginCurrentComputer
\
ComputerBang
\
CheckErrorComputerGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestVifibSlapComputerGetStatus
))
return
suite
master/product/Vifib/tests/testVifibSlapComputerPartitionGetStatus.py
0 → 100644
View file @
a5d41e2b
from
Products.ERP5Type.tests.Sequence
import
SequenceList
import
unittest
from
testVifibSlapWebService
import
TestVifibSlapWebServiceMixin
from
slapos
import
slap
class
TestVifibSlapComputerPartitionGetStatus
(
TestVifibSlapWebServiceMixin
):
########################################
# ComputerPartition.getStatus
########################################
def
stepCheckNoDataComputerPartitionGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
partition_id
=
sequence
.
get
(
"computer_partition_reference"
,
sequence
[
'computer_partition_reference_list'
][
0
])
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer_partition
=
self
.
slap
.
registerComputerPartition
(
computer_guid
,
partition_id
)
status
=
computer_partition
.
getStatus
()
self
.
assertEquals
(
'SlapOS Master'
,
status
[
'user'
])
self
.
assertEquals
(
'#error no data found'
,
status
[
'text'
])
def
test_ComputerPartition_getStatus_emptyPartition
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_formated_computer
+
'
\
SlapLoginCurrentComputer
\
CheckNoDataComputerPartitionGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
stepCheckOKComputerPartitionGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
partition_id
=
sequence
.
get
(
"computer_partition_reference"
,
sequence
[
'computer_partition_reference_list'
][
0
])
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer_partition
=
self
.
slap
.
registerComputerPartition
(
computer_guid
,
partition_id
)
status
=
computer_partition
.
getStatus
()
self
.
assertEquals
(
sequence
[
'software_instance_reference'
],
status
[
'user'
])
self
.
assertEquals
(
'#access %s %s'
%
(
sequence
[
'computer_reference'
],
sequence
[
'software_instance_reference'
]),
status
[
'text'
])
def
test_ComputerPartition_OK_getStatus
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_building_computer_partition_sequence_string
+
'
\
SlapLoginCurrentSoftwareInstance
\
CheckSuccessSlapRegisterComputerPartitionCall
\
SlapLogout
\
SlapLoginCurrentComputer
\
CheckOKComputerPartitionGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
stepCheckErrorComputerPartitionGetStatusCall
(
self
,
sequence
,
**
kw
):
"""
"""
computer_guid
=
sequence
[
"computer_reference"
]
partition_id
=
sequence
.
get
(
"computer_partition_reference"
,
sequence
[
'computer_partition_reference_list'
][
0
])
self
.
slap
=
slap
.
slap
()
self
.
slap
.
initializeConnection
(
self
.
server_url
,
timeout
=
None
)
computer_partition
=
self
.
slap
.
registerComputerPartition
(
computer_guid
,
partition_id
)
status
=
computer_partition
.
getStatus
()
self
.
assertEquals
(
sequence
[
'computer_reference'
],
status
[
'user'
])
self
.
assertEquals
(
'#error while instanciating'
,
status
[
'text'
])
def
test_ComputerPartition_Error_getStatus
(
self
):
"""
"""
sequence_list
=
SequenceList
()
sequence_string
=
self
.
prepare_building_computer_partition_sequence_string
+
'
\
SlapLoginCurrentComputer
\
CheckSuccessComputerPartitionErrorCall
\
CheckErrorComputerPartitionGetStatusCall
\
SlapLogout
\
LoginERP5TypeTestCase
\
CheckSiteConsistency
\
Logout
\
'
sequence_list
.
addSequenceString
(
sequence_string
)
sequence_list
.
play
(
self
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestVifibSlapComputerPartitionGetStatus
))
return
suite
slapos/slap/interface/slap.py
View file @
a5d41e2b
...
...
@@ -283,6 +283,16 @@ class IComputerPartition(IBuildoutController, IRequester):
slave_reference -- current reference of the slave instance to modify
"""
def
getStatus
():
"""
Returns a dictionnary containing the latest status of the
computer partition.
The dictionnary keys are:
user -- user who reported the latest status
created_at -- date of the status
text -- message log of the status
"""
class
IComputer
(
Interface
):
"""
Computer interface specification
...
...
@@ -334,6 +344,16 @@ class IComputer(Interface):
configuration_xml -- computer XML description generated by slapformat
"""
def
getStatus
():
"""
Returns a dictionnary containing the latest status of the
computer.
The dictionnary keys are:
user -- user who reported the latest status
created_at -- date of the status
text -- message log of the status
"""
class
IOpenOrder
(
IRequester
):
"""
Open Order interface specification
...
...
slapos/slap/slap.py
View file @
a5d41e2b
...
...
@@ -292,6 +292,11 @@ class Computer(SlapDocument):
'certificate'
:
getattr
(
self
,
'_certificate'
,
None
)
}
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
'/getComputerStatus?computer_id=%s'
%
self
.
_computer_id
)
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
())
def
_syncComputerPartitionInformation
(
func
):
"""
Synchronize computer partition object with server information
...
...
@@ -528,6 +533,12 @@ class ComputerPartition(SlapDocument):
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
())
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
'/getComputerPartitionStatus?computer_id=%s&'
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
())
class
ConnectionHelper
:
error_message_timeout
=
"
\
n
The connection timed out. Please try again later."
error_message_connect_fail
=
"Couldn't connect to the server. Please "
\
...
...
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