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
Guillaume Hervier
slapos.core
Commits
01c5ead5
Commit
01c5ead5
authored
Oct 19, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update slapgrid tests
parent
42956176
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
7 deletions
+83
-7
slapos/tests/slapgrid.py
slapos/tests/slapgrid.py
+83
-7
No files found.
slapos/tests/slapgrid.py
View file @
01c5ead5
...
@@ -621,6 +621,41 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
...
@@ -621,6 +621,41 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'/startedComputerPartition'
])
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
self
.
assertEqual
(
partition
.
state
,
'started'
)
def
test_one_partition_started_fail
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
partition
=
computer
.
instance_list
[
0
]
partition
.
requested_state
=
'started'
partition
.
software
.
setBuildout
(
WRAPPER_CONTENT
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertItemsEqual
(
os
.
listdir
(
partition
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
wrapper_log
=
os
.
path
.
join
(
partition
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertItemsEqual
(
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
instance
=
computer
.
instance_list
[
0
]
instance
.
software
.
setBuildout
(
"""#!/bin/sh
exit 1
"""
)
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_FAIL
)
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/availableComputerPartition'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
def
test_one_partition_started_stopped
(
self
):
def
test_one_partition_started_stopped
(
self
):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
with
httmock
.
HTTMock
(
computer
.
request_handler
):
with
httmock
.
HTTMock
(
computer
.
request_handler
):
...
@@ -725,7 +760,8 @@ exit 1
...
@@ -725,7 +760,8 @@ exit 1
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertInstanceDirectoryListEqual
([
'0'
])
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
self
.
assertItemsEqual
(
os
.
listdir
(
instance
.
partition_path
),
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
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
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
...
@@ -1988,9 +2024,49 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
...
@@ -1988,9 +2024,49 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
class
TestSlapgridCPWithFirewall
(
MasterMixin
,
unittest
.
TestCase
):
class
TestSlapgridCPWithFirewall
(
MasterMixin
,
unittest
.
TestCase
):
def
setFirewallConfig
(
self
,
source_ip
=
""
):
def
setFirewallConfig
(
self
,
source_ip
=
""
):
self
.
firewall_cmd_add
=
os
.
path
.
join
(
self
.
_tempdir
,
'firewall_cmd_add'
)
with
open
(
self
.
firewall_cmd_add
,
'w'
)
as
f
:
f
.
write
(
"""#!/bin/sh
var="$*"
R=$(echo $var | grep "query-rule") > /dev/null
if [ $? -eq 0 ]; then
echo "no"
exit 0
fi
R=$(echo $var | grep "add-rule")
if [ $? -eq 0 ]; then
echo "success"
exit 0
fi
echo "ERROR: $var"
exit 1
"""
)
self
.
firewall_cmd_remove
=
os
.
path
.
join
(
self
.
_tempdir
,
'firewall_cmd_remove'
)
with
open
(
self
.
firewall_cmd_remove
,
'w'
)
as
f
:
f
.
write
(
"""#!/bin/sh
var="$*"
R=$(echo $var | grep "query-rule")
if [ $? -eq 0 ]; then
echo "yes"
exit 0
fi
R=$(echo $var | grep "remove-rule")
if [ $? -eq 0 ]; then
echo "success"
exit 0
fi
echo "ERROR: $var"
exit 1
"""
)
os
.
chmod
(
self
.
firewall_cmd_add
,
0755
)
os
.
chmod
(
self
.
firewall_cmd_remove
,
0755
)
firewall_conf
=
dict
(
firewall_conf
=
dict
(
authorized_sources
=
source_ip
,
authorized_sources
=
source_ip
,
firewall_cmd
=
'/bin/echo "no" #'
,
firewall_cmd
=
self
.
firewall_cmd_add
,
firewall_executable
=
'/bin/echo "service firewall started"'
,
firewall_executable
=
'/bin/echo "service firewall started"'
,
reload_config_cmd
=
'/bin/echo "Config reloaded."'
,
reload_config_cmd
=
'/bin/echo "Config reloaded."'
,
log_file
=
'fw-log.log'
,
log_file
=
'fw-log.log'
,
...
@@ -2090,7 +2166,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
...
@@ -2090,7 +2166,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
setFirewallConfig
()
self
.
setFirewallConfig
()
# For simulate query rule success
# For simulate query rule success
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
'/bin/echo "no" #'
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
self
.
firewall_cmd_add
self
.
ip_address_list
=
computer
.
ip_address_list
self
.
ip_address_list
=
computer
.
ip_address_list
instance
=
computer
.
instance_list
[
0
]
instance
=
computer
.
instance_list
[
0
]
ip
=
instance
.
full_ip_list
[
0
][
1
]
ip
=
instance
.
full_ip_list
[
0
][
1
]
...
@@ -2111,14 +2187,14 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
...
@@ -2111,14 +2187,14 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
self
.
checkRuleFromIpSource
(
ip
,
[],
rules_list
)
self
.
checkRuleFromIpSource
(
ip
,
[],
rules_list
)
# Remove all rules
# Remove all rules
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
'/bin/echo "yes" #'
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
self
.
firewall_cmd_remove
self
.
grid
.
_checkAddFirewallRules
(
name
,
cmd_list
,
add
=
False
)
self
.
grid
.
_checkAddFirewallRules
(
name
,
cmd_list
,
add
=
False
)
with
open
(
rules_path
,
'r'
)
as
frules
:
with
open
(
rules_path
,
'r'
)
as
frules
:
rules_list
=
json
.
loads
(
frules
.
read
())
rules_list
=
json
.
loads
(
frules
.
read
())
self
.
assertEqual
(
rules_list
,
[])
self
.
assertEqual
(
rules_list
,
[])
# Add one more ip in the authorized list
# Add one more ip in the authorized list
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
'/bin/echo "no" #'
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
self
.
firewall_cmd_add
self
.
ip_address_list
.
append
((
'interface1'
,
'10.0.8.7'
))
self
.
ip_address_list
.
append
((
'interface1'
,
'10.0.8.7'
))
cmd_list
=
self
.
grid
.
_getFirewallAcceptRules
(
ip
,
cmd_list
=
self
.
grid
.
_getFirewallAcceptRules
(
ip
,
[
elt
[
1
]
for
elt
in
self
.
ip_address_list
],
[
elt
[
1
]
for
elt
in
self
.
ip_address_list
],
...
@@ -2209,7 +2285,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
...
@@ -2209,7 +2285,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
self
.
checkRuleFromIpSourceReject
(
ip
,
[
'10.0.8.11'
],
rules_list
)
self
.
checkRuleFromIpSourceReject
(
ip
,
[
'10.0.8.11'
],
rules_list
)
# For remove rules
# For remove rules
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
'/bin/echo "yes" #'
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
self
.
firewall_cmd_remove
instance
.
setFilterParameter
({
'fw_restricted_access'
:
'on'
,
instance
.
setFilterParameter
({
'fw_restricted_access'
:
'on'
,
'fw_authorized_sources'
:
''
})
'fw_authorized_sources'
:
''
})
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
...
@@ -2313,7 +2389,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
...
@@ -2313,7 +2389,7 @@ class TestSlapgridCPWithFirewall(MasterMixin, unittest.TestCase):
# 'fw_authorized_sources': source_ip[0]}
# 'fw_authorized_sources': source_ip[0]}
# For simulate query rule exist
# For simulate query rule exist
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
'/bin/echo "yes" #'
self
.
grid
.
firewall_conf
[
'firewall_cmd'
]
=
self
.
firewall_cmd_remove
self
.
grid
.
firewall_conf
[
'authorized_sources'
]
=
[]
self
.
grid
.
firewall_conf
[
'authorized_sources'
]
=
[]
computer
.
ip_address_list
.
append
((
'route_interface1'
,
'10.10.8.4'
))
computer
.
ip_address_list
.
append
((
'route_interface1'
,
'10.10.8.4'
))
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
...
...
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