Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos
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
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos
Commits
550377ee
Commit
550377ee
authored
Jul 25, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP erp5 test
parent
466ff9fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
44 deletions
+105
-44
software/erp5/test/test/test_balancer.py
software/erp5/test/test/test_balancer.py
+105
-44
No files found.
software/erp5/test/test/test_balancer.py
View file @
550377ee
...
...
@@ -19,9 +19,11 @@ import shutil
import
subprocess
import
tempfile
import
time
import
logging
setUpModule
# pyflakes
class
TestHandler
(
BaseHTTPRequestHandler
):
def
do_GET
(
self
):
self
.
send_response
(
200
)
...
...
@@ -33,21 +35,15 @@ class TestHandler(BaseHTTPRequestHandler):
response
=
json
.
dumps
(
response
,
indent
=
2
)
self
.
end_headers
()
self
.
wfile
.
write
(
response
)
log_message
=
logging
.
getLogger
(
__name__
+
'.TestHandler'
).
info
class
TestFrontendXForwardedFor
(
ERP5InstanceTestCase
):
__partition_reference__
=
'xff'
http_server_process
=
None
frontend_caucase_dir
=
None
frontend_caucased_process
=
None
backend_caucase_dir
=
None
backend_caucased_process
=
None
@
classmethod
def
getInstanceSoftwareType
(
cls
):
return
'balancer'
class
EchoServerMixin
(
object
):
"""Mixin class which starts a web server
"""
@
classmethod
def
s
etUpClass
(
cls
):
def
s
tartEchoServer
(
cls
):
# start a dummy web server echoing headers.
http_server_port
=
findFreeTCPPort
(
cls
.
_ipv4_address
)
server
=
HTTPServer
(
...
...
@@ -57,7 +53,89 @@ class TestFrontendXForwardedFor(ERP5InstanceTestCase):
target
=
server
.
serve_forever
,
name
=
'HTTPServer'
)
cls
.
http_server_process
.
start
()
cls
.
http_server_netloc
=
'%s:%s'
%
(
cls
.
_ipv4_address
,
http_server_port
)
@
classmethod
def
stopEchoServer
(
cls
):
if
cls
.
http_server_process
:
cls
.
http_server_process
.
terminate
()
class
BalancerTestCase
(
ERP5InstanceTestCase
,
EchoServerMixin
):
http_server_process
=
None
@
classmethod
def
getInstanceSoftwareType
(
cls
):
return
'balancer'
@
classmethod
def
setUpClass
(
cls
):
cls
.
startEchoServer
()
super
(
BalancerTestCase
,
cls
).
setUpClass
()
@
classmethod
def
_cleanup
(
cls
,
snapshot_name
):
cls
.
stopEchoServer
()
super
(
BalancerTestCase
,
cls
).
_cleanup
(
snapshot_name
)
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
'_'
:
json
.
dumps
({
'tcpv4-port'
:
8000
,
'computer-memory-percent-threshold'
:
100
,
# XXX what is this ? should probably not be needed here
'name'
:
cls
.
__name__
,
'monitor-passwd'
:
'secret'
,
'apachedex-configuration'
:
''
,
'apachedex-promise-threshold'
:
100
,
'haproxy-server-check-path'
:
'/'
,
'zope-family-dict'
:
{
'default'
:
[
'dummy_http_server'
],
},
'dummy_http_server'
:
[[
cls
.
http_server_netloc
,
1
,
False
]],
'backend-path-dict'
:
{
'default'
:
'/'
,
},
# XXX don't pass any SSL settings by default, because it works without this
# and this make test easier (in other words, if you introduced changes which
# makes it required and this test started to fail, please extend the test)
'ssl-authentication-dict'
:
{},
'ssl'
:
{
'caucase-url'
:
None
,
}
})
}
class
LogTestCase
(
BalancerTestCase
):
"""Check access logs emitted by balancer
"""
__partition_reference__
=
'l'
def
test_log_format
(
self
):
balancer_url
=
json
.
loads
(
self
.
computer_partition
.
getConnectionParameterDict
()[
'_'
])[
'default'
]
requests
.
get
(
balancer_url
,
verify
=
False
,
)
import
pdb
;
pdb
.
set_trace
()
#self.assertEqual(result['Incoming Headers'].get('x-forwarded-for').split(', ')[0], '1.2.3.4')
class
TestFrontendXForwardedFor
(
BalancerTestCase
,
EchoServerMixin
):
__partition_reference__
=
'xff'
frontend_caucase_dir
=
None
frontend_caucased_process
=
None
backend_caucase_dir
=
None
backend_caucased_process
=
None
@
classmethod
def
setUpClass
(
cls
):
# start a caucased and generate a valid client certificate.
cls
.
computer_partition_root_path
=
os
.
path
.
abspath
(
os
.
curdir
)
cls
.
frontend_caucase_dir
=
tempfile
.
mkdtemp
()
...
...
@@ -145,7 +223,6 @@ class TestFrontendXForwardedFor(ERP5InstanceTestCase):
stderr
=
subprocess
.
STDOUT
,
)
result
=
caucase_process
.
communicate
()
print
result
csr_id
=
result
[
0
].
split
()[
0
]
subprocess
.
check_call
(
...
...
@@ -224,45 +301,28 @@ class TestFrontendXForwardedFor(ERP5InstanceTestCase):
time
.
sleep
(
1
)
else
:
raise
RuntimeError
,
'caucased failed to start.'
super
(
TestFrontendXForwardedFor
,
cls
).
setUpClass
()
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
'_'
:
json
.
dumps
({
'tcpv4-port'
:
3306
,
'computer-memory-percent-threshold'
:
100
,
# XXX what is this ? should probably not be needed here
'name'
:
cls
.
__name__
,
'monitor-passwd'
:
'secret'
,
'apachedex-configuration'
:
''
,
'apachedex-promise-threshold'
:
100
,
'haproxy-server-check-path'
:
'/'
,
'zope-family-dict'
:
{
'default'
:
[
'dummy_http_server'
],
'default-auth'
:
[
'dummy_http_server'
],
},
'dummy_http_server'
:
[[
cls
.
http_server_netloc
,
1
,
False
]],
'backend-path-dict'
:
{
'default'
:
'/'
,
'default-auth'
:
'/'
,
},
'ssl-authentication-dict'
:
{
'default'
:
False
,
'default-auth'
:
True
,
},
'ssl'
:
{
'caucase-url'
:
cls
.
backend_caucased_url
,
'frontend-caucase-url-list'
:
[
cls
.
frontend_caucased_url
],
},
})
parameter_dict
=
json
.
loads
(
super
(
TestFrontendXForwardedFor
,
cls
).
getInstanceParameterDict
()[
'_'
])
# add another "-auth" backend, that will have ssl-authentication enabled
parameter_dict
[
'zope-family-dict'
][
'default-auth'
]
=
[
'dummy_http_server'
]
parameter_dict
[
'backend-path-dict'
][
'default-auth'
]
=
'/'
parameter_dict
[
'ssl-authentication-dict'
]
=
{
'default'
:
False
,
'default-auth'
:
True
,
}
parameter_dict
[
'ssl'
]
=
{
'caucase-url'
:
cls
.
backend_caucased_url
,
'frontend-caucase-url-list'
:
[
cls
.
frontend_caucased_url
],
}
return
{
'_'
:
json
.
dumps
(
parameter_dict
)}
@
classmethod
def
_cleanup
(
cls
,
snapshot_name
):
if
cls
.
http_server_process
:
cls
.
http_server_process
.
terminate
()
if
cls
.
frontend_caucased_process
:
cls
.
frontend_caucased_process
.
terminate
()
if
cls
.
frontend_caucase_dir
:
...
...
@@ -271,7 +331,6 @@ class TestFrontendXForwardedFor(ERP5InstanceTestCase):
cls
.
backend_caucased_process
.
terminate
()
if
cls
.
backend_caucase_dir
:
shutil
.
rmtree
(
cls
.
backend_caucase_dir
)
super
(
TestFrontendXForwardedFor
,
cls
).
_cleanup
(
snapshot_name
)
def
test_x_forwarded_for_added_when_verified_connection
(
self
):
...
...
@@ -300,3 +359,5 @@ class TestFrontendXForwardedFor(ERP5InstanceTestCase):
headers
=
{
'X-Forwarded-For'
:
'1.2.3.4'
},
verify
=
False
,
)
del
TestFrontendXForwardedFor
\ No newline at end of file
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