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
Titouan Soulard
slapos.core
Commits
e348d913
Commit
e348d913
authored
Dec 12, 2012
by
Cédric Le Ninivin
Committed by
Cédric de Saint Martin
Dec 17, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update test for watchdog to check certificates
parent
d573a5fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
10 deletions
+42
-10
slapos/tests/mock/httplib.py
slapos/tests/mock/httplib.py
+15
-1
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+27
-9
No files found.
slapos/tests/mock/httplib.py
View file @
e348d913
...
...
@@ -79,8 +79,22 @@ class HTTPSConnection(HTTPConnection):
def
__init__
(
self
,
host
,
port
=
None
,
key_file
=
None
,
cert_file
=
None
,
strict
=
None
,
timeout
=
None
,
source_address
=
None
):
super
(
).
__init__
(
self
,
host
,
port
,
strict
,
timeout
,
super
(
HTTPSConnection
,
self
).
__init__
(
host
,
port
,
strict
,
timeout
,
source_address
)
self
.
certificate
=
open
(
cert_file
,
'r'
).
read
()
self
.
key
=
open
(
key_file
,
'r'
).
read
()
def
request
(
self
,
method
,
url
,
body
=
None
,
headers
=
None
):
headers
[
'certificate'
]
=
self
.
certificate
headers
[
'key'
]
=
self
.
key
status
,
headers
,
body
=
self
.
_callback
(
url
,
method
,
body
,
headers
)
self
.
__response
=
HTTPResponse
(
'HTTP/1.1'
,
status
,
'OK'
,
body
,
headers
)
def
getresponse
(
self
):
response
=
self
.
__response
self
.
__response
=
None
return
response
class
HTTPResponse
(
object
):
...
...
slapos/tests/slapgrid.py
View file @
e348d913
...
...
@@ -29,6 +29,7 @@ from slapos.grid import slapgrid
import
httplib
import
logging
import
os
from
random
import
random
import
shutil
import
signal
import
slapos.slap.slap
...
...
@@ -262,6 +263,7 @@ class ComputerForTest:
def
setServerResponse
(
self
):
httplib
.
HTTPConnection
.
_callback
=
self
.
getServerResponse
()
httplib
.
HTTPSConnection
.
_callback
=
self
.
getServerResponse
()
def
getServerResponse
(
self
):
"""
...
...
@@ -283,6 +285,7 @@ class ComputerForTest:
if
method
==
'POST'
and
'computer_partition_id'
in
parsed_qs
:
instance
=
self
.
instance_list
[
int
(
parsed_qs
[
'computer_partition_id'
][
0
])]
instance
.
sequence
.
append
(
parsed_url
.
path
)
instance
.
header_list
.
append
(
header
)
if
parsed_url
.
path
==
'availableComputerPartition'
:
return
(
200
,
{},
''
)
if
parsed_url
.
path
==
'startedComputerPartition'
:
...
...
@@ -333,6 +336,7 @@ class InstanceForTest:
self
.
error
=
False
self
.
error_log
=
None
self
.
sequence
=
[]
self
.
header_list
=
[]
self
.
name
=
name
self
.
partition_path
=
os
.
path
.
join
(
self
.
instance_root
,
self
.
name
)
os
.
mkdir
(
self
.
partition_path
,
0750
)
...
...
@@ -367,10 +371,21 @@ class InstanceForTest:
promise_path
=
os
.
path
.
join
(
self
.
partition_path
,
'etc'
,
'promise'
)
if
not
os
.
path
.
isdir
(
promise_path
):
os
.
makedirs
(
promise_path
)
promise
=
os
.
path
.
join
(
promise_path
,
promise_name
)
promise
=
os
.
path
.
join
(
promise_path
,
promise_name
)
open
(
promise
,
'w'
).
write
(
promise_content
)
os
.
chmod
(
promise
,
0777
)
def
setCertificate
(
self
,
certificate_repository_path
):
if
not
os
.
path
.
exists
(
certificate_repository_path
):
os
.
mkdir
(
certificate_repository_path
)
self
.
cert_file
=
os
.
path
.
join
(
certificate_repository_path
,
"%s.crt"
%
self
.
name
)
self
.
certificate
=
str
(
random
())
open
(
self
.
cert_file
,
'w'
).
write
(
self
.
certificate
)
self
.
key_file
=
os
.
path
.
join
(
certificate_repository_path
,
"%s.key"
%
self
.
name
)
self
.
key
=
str
(
random
())
open
(
self
.
key_file
,
'w'
).
write
(
self
.
key
)
class
SoftwareForTest
:
"""
...
...
@@ -831,22 +846,27 @@ touch worked
"""
Test that a process going to fatal or exited mode in supervisord
is banged if watched by watchdog
Certificates used for the bang are also checked
(ie: watchdog id in process name)
"""
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
instance
=
computer
.
instance_list
[
0
]
certificate_repository_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'partition_pki'
)
instance
.
setCertificate
(
certificate_repository_path
)
watchdog
=
Watchdog
(
dict
(
master_url
=
self
.
master_url
,
watchdog
=
Watchdog
(
dict
(
master_url
=
'https://127.0.0.1/'
,
computer_id
=
self
.
computer_id
,
key_file
=
None
,
cert_file
=
None
))
certificate_repository_path
=
certificate_repository_path
))
for
event
in
watchdog
.
process_state_events
:
instance
.
sequence
=
[]
instance
.
header_list
=
[]
headers
=
dict
(
eventname
=
event
)
payload
=
"processname:%s groupname:%s from_state:RUNNING"
\
%
(
'daemon'
+
getWatchdogID
(),
instance
.
name
)
watchdog
.
handle_event
(
headers
,
payload
)
self
.
assertEqual
(
instance
.
sequence
,[
'softwareInstanceBang'
])
self
.
assertEqual
(
instance
.
header_list
[
0
][
'key'
],
instance
.
key
)
self
.
assertEqual
(
instance
.
header_list
[
0
][
'certificate'
],
instance
.
certificate
)
def
test_unwanted_events_will_not_bang
(
self
):
"""
...
...
@@ -858,8 +878,7 @@ touch worked
watchdog
=
Watchdog
(
dict
(
master_url
=
self
.
master_url
,
computer_id
=
self
.
computer_id
,
key_file
=
None
,
cert_file
=
None
))
certificate_repository_path
=
None
))
for
event
in
[
'EVENT'
,
'PROCESS_STATE'
,
'PROCESS_STATE_RUNNING'
,
'PROCESS_STATE_BACKOFF'
,
'PROCESS_STATE_STOPPED'
]:
computer
.
sequence
=
[]
...
...
@@ -881,8 +900,7 @@ touch worked
watchdog
=
Watchdog
(
dict
(
master_url
=
self
.
master_url
,
computer_id
=
self
.
computer_id
,
key_file
=
None
,
cert_file
=
None
))
certificate_repository_path
=
None
))
for
event
in
watchdog
.
process_state_events
:
computer
.
sequence
=
[]
headers
=
dict
(
eventname
=
event
)
...
...
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