Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alain Takoudjou
slapos
Commits
ba3fa2d1
Commit
ba3fa2d1
authored
Oct 11, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/*/test: update tests now that computer_partition_root_path is a pathlib.Path
parent
a8b6376f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
47 deletions
+31
-47
software/erp5/test/test/test_balancer.py
software/erp5/test/test/test_balancer.py
+20
-34
software/erp5/test/test/test_erp5.py
software/erp5/test/test/test_erp5.py
+4
-4
software/kvm/test/test.py
software/kvm/test/test.py
+2
-2
software/proftpd/test/test.py
software/proftpd/test/test.py
+2
-2
software/ssh/test/test.py
software/ssh/test/test.py
+3
-5
No files found.
software/erp5/test/test/test_balancer.py
View file @
ba3fa2d1
import
glob
import
ipaddress
import
ipaddress
import
json
import
json
import
logging
import
logging
...
@@ -267,17 +266,13 @@ class TestLog(BalancerTestCase, CrontabMixin):
...
@@ -267,17 +266,13 @@ class TestLog(BalancerTestCase, CrontabMixin):
# crontab for apachedex is executed
# crontab for apachedex is executed
self._executeCrontabAtDate('
generate
-
apachedex
-
report
', '
23
:
59
')
self._executeCrontabAtDate('
generate
-
apachedex
-
report
', '
23
:
59
')
# it creates a report for the day
# it creates a report for the day
apachedex_report, = glob.glob(
apachedex_report, = (
os.path.join(
self.computer_partition_root_path
self.computer_partition_root_path,
/ '
srv
'
'
srv
',
/ '
monitor
'
'
monitor
',
/ '
private
'
'
private
',
/ '
apachedex
').glob('
ApacheDex
-*
.
html
')
'
apachedex
',
report_text = apachedex_report.read_text()
'
ApacheDex
-*
.
html
',
))
with open(apachedex_report) as f:
report_text = f.read()
self.assertIn('
APacheDEX
', report_text)
self.assertIn('
APacheDEX
', report_text)
# having this table means that apachedex could parse some lines.
# having this table means that apachedex could parse some lines.
self.assertIn('
<
h2
>
Hits
per
status
code
</
h2
>
', report_text)
self.assertIn('
<
h2
>
Hits
per
status
code
</
h2
>
', report_text)
...
@@ -318,8 +313,8 @@ class TestLog(BalancerTestCase, CrontabMixin):
...
@@ -318,8 +313,8 @@ class TestLog(BalancerTestCase, CrontabMixin):
self.assertEqual(
self.assertEqual(
requests.get(self.default_balancer_zope_url, verify=False).status_code,
requests.get(self.default_balancer_zope_url, verify=False).status_code,
requests.codes.service_unavailable)
requests.codes.service_unavailable)
with open(os.path.join(self.computer_partition_root_path, '
var
', '
log
', '
apache
-
error
.
log
')) as error_log_file:
error_log_file = self.computer_partition_root_path / '
var
' / '
log
' / '
apache
-
error
.
log
'
error_line = error_log_file.read
().splitlines()[-1]
error_line = error_log_file.read_text
().splitlines()[-1]
self.assertIn('
backend
default
has
no
server
available
!
', error_line)
self.assertIn('
backend
default
has
no
server
available
!
', error_line)
# this log also include a timestamp
# this log also include a timestamp
self.assertRegex(error_line, r'
\
d
{
4
}
-
\
d
{
2
}
-
\
d
{
2
}
T
\
d
{
2
}:
\
d
{
2
}:
\
d
{
2
}
')
self.assertRegex(error_line, r'
\
d
{
4
}
-
\
d
{
2
}
-
\
d
{
2
}
T
\
d
{
2
}:
\
d
{
2
}:
\
d
{
2
}
')
...
@@ -416,7 +411,7 @@ class TestBalancer(BalancerTestCase):
...
@@ -416,7 +411,7 @@ class TestBalancer(BalancerTestCase):
# real time statistics can be obtained by using the stats socket and there
# real time statistics can be obtained by using the stats socket and there
# is a wrapper which makes this a bit easier.
# is a wrapper which makes this a bit easier.
socat_process
=
subprocess
.
Popen
(
socat_process
=
subprocess
.
Popen
(
[
self
.
computer_partition_root_path
+
'/bin/
haproxy-socat-stats'
],
[
self
.
computer_partition_root_path
/
'bin'
/
'
haproxy-socat-stats'
],
stdin
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
stderr
=
subprocess
.
STDOUT
...
@@ -604,14 +599,10 @@ class TestServerTLSEmbeddedCaucase(BalancerTestCase):
...
@@ -604,14 +599,10 @@ class TestServerTLSEmbeddedCaucase(BalancerTestCase):
balancer_parsed_url
.
port
)
balancer_parsed_url
.
port
)
# run caucase updater in the future, so that certificate is renewed
# run caucase updater in the future, so that certificate is renewed
caucase_updater
,
=
glob
.
glob
(
caucase_updater
,
=
(
os
.
path
.
join
(
self
.
computer_partition_root_path
/
'etc'
/
'service'
self
.
computer_partition_root_path
,
).
glob
(
'caucase-updater-haproxy-certificate-*'
)
'etc'
,
process
=
pexpect
.
spawnu
(
f"faketime +90days
{
caucase_updater
}
"
)
'service'
,
'caucase-updater-haproxy-certificate-*'
,
))
process
=
pexpect
.
spawnu
(
"faketime +90days "
+
caucase_updater
)
logger
=
self
.
logger
logger
=
self
.
logger
class
DebugLogFile
:
class
DebugLogFile
:
def
write
(
self
,
msg
):
def
write
(
self
,
msg
):
...
@@ -953,21 +944,16 @@ class TestClientTLS(BalancerTestCase):
...
@@ -953,21 +944,16 @@ class TestClientTLS(BalancerTestCase):
# We have two services in charge of updating CRL and CA certificates for
# We have two services in charge of updating CRL and CA certificates for
# each frontend CA, plus the one for the balancer's own certificate
# each frontend CA, plus the one for the balancer's own certificate
caucase_updater_list
=
glob
.
glob
(
caucase_updater_list
=
list
((
os
.
path
.
join
(
self
.
computer_partition_root_path
/
'etc'
/
'service'
self
.
computer_partition_root_path
,
).
glob
(
'caucase-updater-*'
))
'etc'
,
'service'
,
'caucase-updater-*'
,
))
self
.
assertEqual
(
len
(
caucase_updater_list
),
3
)
self
.
assertEqual
(
len
(
caucase_updater_list
),
3
)
# find the one corresponding to this caucase
# find the one corresponding to this caucase
for
caucase_updater_candidate
in
caucase_updater_list
:
for
caucase_updater_candidate
in
caucase_updater_list
:
with
open
(
caucase_updater_candidate
)
as
f
:
if
caucase
.
url
in
caucase_updater_candidate
.
read_text
():
if
caucase
.
url
in
f
.
read
():
caucase_updater
=
caucase_updater_candidate
caucase_updater
=
caucase_updater_candidate
break
break
else
:
else
:
self
.
fail
(
"Could not find caucase updater script for %s"
%
caucase
.
url
)
self
.
fail
(
"Could not find caucase updater script for %s"
%
caucase
.
url
)
...
...
software/erp5/test/test/test_erp5.py
View file @
ba3fa2d1
...
@@ -477,8 +477,8 @@ class TestSeleniumTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMi
...
@@ -477,8 +477,8 @@ class TestSeleniumTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMi
}
}
def
test_test_runner_configuration_json_file
(
self
):
def
test_test_runner_configuration_json_file
(
self
):
runUnitTest_script
,
=
glob
.
glob
(
runUnitTest_script
,
=
self
.
computer_partition_root_path
.
glob
(
self
.
computer_partition_root_path
+
"/
../*/bin/runUnitTest.real"
)
"
../*/bin/runUnitTest.real"
)
config_file
=
None
config_file
=
None
with
open
(
runUnitTest_script
)
as
f
:
with
open
(
runUnitTest_script
)
as
f
:
for
line
in
f
:
for
line
in
f
:
...
@@ -504,8 +504,8 @@ class TestDisableTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMix
...
@@ -504,8 +504,8 @@ class TestDisableTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMix
"""
"""
# self.computer_partition_root_path is the path of root partition.
# self.computer_partition_root_path is the path of root partition.
# we want to assert that no scripts exist in any partition.
# we want to assert that no scripts exist in any partition.
bin_programs
=
list
(
map
(
os
.
path
.
basename
,
bin_programs
=
[
glob
.
glob
(
self
.
computer_partition_root_path
+
"/../*/bin/*"
)))
p
.
name
for
p
in
self
.
computer_partition_root_path
.
glob
(
"../*/bin/*"
)]
self
.
assertTrue
(
bin_programs
)
# just to check the glob was correct.
self
.
assertTrue
(
bin_programs
)
# just to check the glob was correct.
self
.
assertNotIn
(
'runUnitTest'
,
bin_programs
)
self
.
assertNotIn
(
'runUnitTest'
,
bin_programs
)
...
...
software/kvm/test/test.py
View file @
ba3fa2d1
...
@@ -160,7 +160,7 @@ class KVMTestCase(InstanceTestCase):
...
@@ -160,7 +160,7 @@ class KVMTestCase(InstanceTestCase):
return image_list
return image_list
@classmethod
@classmethod
def _findTopLevelPartitionPath(cls, path):
def _findTopLevelPartitionPath(cls, path
: str
):
index = 0
index = 0
while True:
while True:
index = path.find(os.path.sep, index) + len(os.path.sep)
index = path.find(os.path.sep, index) + len(os.path.sep)
...
@@ -551,7 +551,7 @@ class TestAccessDefaultBootstrap(MonitorAccessMixin, KVMTestCase):
...
@@ -551,7 +551,7 @@ class TestAccessDefaultBootstrap(MonitorAccessMixin, KVMTestCase):
def test(self):
def test(self):
# START: mock .slapos-resource with tap.ipv4_addr
# START: mock .slapos-resource with tap.ipv4_addr
# needed for netconfig.sh
# needed for netconfig.sh
partition_path = s
elf.computer_partition_root_path
partition_path = s
tr(self.computer_partition_root_path)
top_partition_path = self._findTopLevelPartitionPath(partition_path)
top_partition_path = self._findTopLevelPartitionPath(partition_path)
with open(os.path.join(top_partition_path, '
.
slapos
-
resource
')) as f:
with open(os.path.join(top_partition_path, '
.
slapos
-
resource
')) as f:
...
...
software/proftpd/test/test.py
View file @
ba3fa2d1
...
@@ -236,7 +236,7 @@ class TestFilesAndSocketsInInstanceDir(ProFTPdTestCase):
...
@@ -236,7 +236,7 @@ class TestFilesAndSocketsInInstanceDir(ProFTPdTestCase):
[],
[],
[
[
f
for
f
in
self
.
proftpdProcess
.
open_files
()
if
f
.
mode
!=
'r'
f
for
f
in
self
.
proftpdProcess
.
open_files
()
if
f
.
mode
!=
'r'
if
not
f
.
path
.
startswith
(
s
elf
.
computer_partition_root_path
)
if
not
f
.
path
.
startswith
(
s
tr
(
self
.
computer_partition_root_path
)
)
])
])
def
test_only_unix_socket_in_instance_dir
(
self
):
def
test_only_unix_socket_in_instance_dir
(
self
):
...
@@ -244,7 +244,7 @@ class TestFilesAndSocketsInInstanceDir(ProFTPdTestCase):
...
@@ -244,7 +244,7 @@ class TestFilesAndSocketsInInstanceDir(ProFTPdTestCase):
[],
[],
[
[
s
for
s
in
self
.
proftpdProcess
.
connections
(
'unix'
)
s
for
s
in
self
.
proftpdProcess
.
connections
(
'unix'
)
if
not
s
.
laddr
.
startswith
(
s
elf
.
computer_partition_root_path
)
if
not
s
.
laddr
.
startswith
(
s
tr
(
self
.
computer_partition_root_path
)
)
])
])
...
...
software/ssh/test/test.py
View file @
ba3fa2d1
...
@@ -28,13 +28,11 @@
...
@@ -28,13 +28,11 @@
import
os
import
os
import
contextlib
import
contextlib
import
paramiko
import
paramiko
import
subprocess
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
import
socket
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.util
import
bytes2str
setUpModule
,
SlapOSInstanceTestCase
=
makeModuleSetUpAndTestCaseClass
(
setUpModule
,
SlapOSInstanceTestCase
=
makeModuleSetUpAndTestCaseClass
(
os
.
path
.
abspath
(
os
.
path
.
abspath
(
...
@@ -71,5 +69,5 @@ class TestSSH(SlapOSInstanceTestCase):
...
@@ -71,5 +69,5 @@ class TestSSH(SlapOSInstanceTestCase):
self
.
assertTrue
(
client
.
get_transport
().
is_active
())
self
.
assertTrue
(
client
.
get_transport
().
is_active
())
# simple commands can also be executed ( this would be like `ssh bash -c 'pwd'` )
# simple commands can also be executed ( this would be like `ssh bash -c 'pwd'` )
# exec_command means `ssh user@host command`
# exec_command means `ssh user@host command`
current_path
=
bytes2str
(
client
.
exec_command
(
"pwd"
)[
1
].
read
(
1000
)
).
strip
()
current_path
=
client
.
exec_command
(
"pwd"
)[
1
].
read
(
1000
).
decode
(
).
strip
()
self
.
assertIn
(
current_path
,
s
elf
.
computer_partition_root_path
)
self
.
assertIn
(
current_path
,
s
tr
(
self
.
computer_partition_root_path
)
)
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