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
Arnaud Véron
slapos.core
Commits
7f45fa10
Commit
7f45fa10
authored
Feb 16, 2022
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: fix some trailing whitespaces and inconsistent indentations
parent
55ff948c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
86 deletions
+79
-86
slapos/tests/test_configure_local.py
slapos/tests/test_configure_local.py
+1
-1
slapos/tests/test_promise.py
slapos/tests/test_promise.py
+4
-5
slapos/tests/test_register.py
slapos/tests/test_register.py
+4
-9
slapos/tests/test_slap.py
slapos/tests/test_slap.py
+1
-2
slapos/tests/test_slapformat.py
slapos/tests/test_slapformat.py
+1
-1
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+40
-40
slapos/tests/test_slapproxy.py
slapos/tests/test_slapproxy.py
+28
-28
No files found.
slapos/tests/test_configure_local.py
View file @
7f45fa10
...
...
@@ -31,7 +31,7 @@ import shutil
import
tempfile
import
slapos.slap
import
slapos.cli.configure_local
from
slapos.cli.configure_local
import
ConfigureLocalCommand
,
_createConfigurationDirectory
from
slapos.cli.configure_local
import
ConfigureLocalCommand
,
_createConfigurationDirectory
from
slapos.cli.entry
import
SlapOSApp
from
argparse
import
Namespace
from
six.moves.configparser
import
ConfigParser
...
...
slapos/tests/test_promise.py
View file @
7f45fa10
...
...
@@ -208,7 +208,7 @@ class RunPromise(GenericPromise):
"title": "%(name)s"
}]
}"""
history_file
=
os
.
path
.
join
(
self
.
partition_dir
,
PROMISE_HISTORY_RESULT_FOLDER_NAME
,
'%s.history.json'
%
name
)
self
.
assertTrue
(
os
.
path
.
exists
(
history_file
))
with
open
(
history_file
)
as
f
:
...
...
@@ -411,7 +411,7 @@ class RunPromise(GenericPromise):
self
.
launcher
.
run
()
self
.
assertTrue
(
os
.
path
.
exists
(
state_folder
))
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
log_dir
,
'my_promise.log'
)))
self
.
assertSuccessResult
(
"my_promise"
)
self
.
assertSuccessHistoryResult
(
"my_promise"
)
self
.
assertSuccessStatsResult
(
1
)
...
...
@@ -1577,10 +1577,10 @@ class TestSlapOSGenericPromise(TestSlapOSPromiseMixin):
def
test_promise_cleanup_plugin_dir
(
self
):
stale_pyc
=
os
.
path
.
join
(
self
.
plugin_dir
,
'stale.pyc'
)
with
open
(
stale_pyc
,
'w'
)
as
fh
:
fh
.
write
(
''
)
fh
.
write
(
''
)
stale_pyo
=
os
.
path
.
join
(
self
.
plugin_dir
,
'stale.pyo'
)
with
open
(
stale_pyo
,
'w'
)
as
fh
:
fh
.
write
(
''
)
fh
.
write
(
''
)
self
.
initialisePromise
()
self
.
launcher
.
run
()
self
.
assertFalse
(
os
.
path
.
exists
(
stale_pyc
))
...
...
@@ -2021,4 +2021,3 @@ class RunPromise(GenericPromise):
if
__name__
==
'__main__'
:
unittest
.
main
()
slapos/tests/test_register.py
View file @
7f45fa10
...
...
@@ -40,18 +40,13 @@ class TestRegister(unittest.TestCase):
template
=
slapos
.
cli
.
register
.
fetch_configuration_template
()
self
.
assertNotEqual
(
""
,
template
)
for
entry
in
[
'computer_id'
,
for
entry
in
[
'computer_id'
,
'master_url'
,
'key_file'
,
'key_file'
,
'cert_file'
,
'certificate_repository_path'
,
'interface_name'
,
'interface_name'
,
'ipv4_local_network'
,
'partition_amount'
,
'partition_amount'
,
'create_tap'
]:
self
.
assertTrue
(
entry
in
template
,
"%s is not in template (%s)"
%
(
entry
,
template
))
slapos/tests/test_slap.py
View file @
7f45fa10
...
...
@@ -1471,7 +1471,7 @@ class TestOpenOrder(SlapMixin):
},
"text_content"
:
{
"title"
:
"Parameter XML"
,
"default"
:
dict2xml
({
'_'
:
json
.
dumps
(
parameter_dict
)}),
"default"
:
dict2xml
({
'_'
:
json
.
dumps
(
parameter_dict
)}),
"key"
:
"field_my_text_content"
,
"type"
:
"TextAreaField"
},
...
...
@@ -1689,4 +1689,3 @@ class TestSoftwareProductCollection(SlapMixin):
self
.
product_collection
.
get
)
self
.
assertEqual
(
self
.
product_collection
.
foo
,
'0'
)
slapos/tests/test_slapformat.py
View file @
7f45fa10
...
...
@@ -993,4 +993,4 @@ class TestFormatConfig(SlapformatMixin):
# TODO add more tests with config file
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
slapos/tests/test_slapgrid.py
View file @
7f45fa10
...
...
@@ -555,7 +555,7 @@ class InstanceForTest(object):
if
self
.
software
is
not
None
:
if
self
.
timestamp
is
not
None
:
partition
.
_parameter_dict
[
'timestamp'
]
=
self
.
timestamp
self
.
current_partition
=
partition
return
partition
...
...
@@ -582,7 +582,7 @@ class InstanceForTest(object):
f
.
write
(
promise_content
)
os
.
chmod
(
promise
,
0o777
)
def
setPluginPromise
(
self
,
promise_name
,
success
=
True
,
failure_count
=
1
,
def
setPluginPromise
(
self
,
promise_name
,
success
=
True
,
failure_count
=
1
,
promise_content
=
""
,
periodicity
=
0.03
):
"""
This function will set plugin promise and return its path
...
...
@@ -591,12 +591,12 @@ class InstanceForTest(object):
if
not
os
.
path
.
isdir
(
promise_dir
):
os
.
makedirs
(
promise_dir
)
_promise_content
=
PROMISE_CONTENT_TEMPLATE
%
\
{
'success'
:
success
,
'content'
:
promise_content
,
{
'success'
:
success
,
'content'
:
promise_content
,
'failure_amount'
:
failure_count
,
'periodicity'
:
periodicity
,
'paths'
:
PROMISE_PATHS
}
with
open
(
os
.
path
.
join
(
promise_dir
,
promise_name
),
'w'
)
as
f
:
f
.
write
(
_promise_content
)
return
os
.
path
.
join
(
promise_dir
,
promise_name
)
...
...
@@ -717,7 +717,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
def
test_one_partition_instance_cfg
(
self
):
...
...
@@ -735,7 +735,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
def
test_one_free_partition
(
self
):
...
...
@@ -769,7 +769,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
...
...
@@ -788,7 +788,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
partition
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
...
...
@@ -803,7 +803,7 @@ exit 1
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
,
'.slapgrid-0-error.log'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/softwareInstanceError'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -843,7 +843,7 @@ chmod 755 etc/run/wrapper
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -856,7 +856,7 @@ chmod 755 etc/run/wrapper
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertLogContent
(
wrapper_log
,
'Signal handler called with signal 15'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'stopped'
)
...
...
@@ -901,7 +901,7 @@ chmod 755 etc/run/wrapper
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -937,7 +937,7 @@ exit 1
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
self
.
assertEqual
(
'stopped'
,
instance
.
state
)
...
...
@@ -954,7 +954,7 @@ exit 1
wrapper_log
=
os
.
path
.
join
(
instance
.
partition_path
,
'.0_wrapper.log'
)
self
.
assertLogContent
(
wrapper_log
,
'Working'
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
...
...
@@ -970,7 +970,7 @@ exit 1
dummy_file_name
=
'dummy_file'
with
open
(
os
.
path
.
join
(
instance
.
partition_path
,
dummy_file_name
),
'w'
)
as
dummy_file
:
dummy_file
.
write
(
'dummy'
)
dummy_file
.
write
(
'dummy'
)
self
.
assertEqual
(
self
.
grid
.
processComputerPartitionList
(),
slapgrid
.
SLAPGRID_SUCCESS
)
...
...
@@ -1432,7 +1432,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
assertEqual
(
self
.
launchSlapgrid
(),
slapgrid
.
SLAPGRID_SUCCESS
)
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
...
...
@@ -1457,7 +1457,7 @@ class TestSlapgridCPPartitionProcessing(MasterMixin, unittest.TestCase):
self
.
launchSlapgrid
()
self
.
assertEqual
(
computer
.
sequence
,
[
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
,
'/getHateoasUrl'
,
'/getFullComputerInformation'
,
'/stoppedComputerPartition'
])
...
...
@@ -1859,7 +1859,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
instance
.
state
,
'started'
)
...
...
@@ -1930,14 +1930,14 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
six
.
assertCountEqual
(
self
,
os
.
listdir
(
self
.
software_root
),
[
instance
.
software
.
software_hash
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
'started'
,
instance
.
state
)
# Then run usage report and see if it is still working
computer
.
sequence
=
[]
self
.
assertEqual
(
self
.
grid
.
agregateAndSendUsage
(),
slapgrid
.
SLAPGRID_SUCCESS
)
# registerComputerPartition will create one more file:
# registerComputerPartition will create one more file:
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
request_list_file
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
instance
.
name
self
.
assertInstanceDirectoryListEqual
([
'0'
])
...
...
@@ -2365,7 +2365,7 @@ class TestSlapgridDestructionLock(MasterMixin, unittest.TestCase):
class
TestSlapgridCPWithFirewall
(
MasterMixin
,
unittest
.
TestCase
):
def
setFirewallConfig
(
self
,
source_ip
=
""
):
self
.
firewall_cmd_add
=
os
.
path
.
join
(
self
.
_tempdir
,
'firewall_cmd_add'
)
...
...
@@ -2416,7 +2416,7 @@ exit 1
testing
=
True
,
)
self
.
grid
.
firewall_conf
=
firewall_conf
def
checkRuleFromIpSource
(
self
,
ip
,
accept_ip_list
,
cmd_list
):
# XXX - rules for one ip contain 2*len(ip_address_list + accept_ip_list) rules ACCEPT and 4 rules REJECT
num_rules
=
len
(
self
.
ip_address_list
)
*
2
+
len
(
accept_ip_list
)
*
2
+
4
...
...
@@ -2438,7 +2438,7 @@ exit 1
# Check that there is REJECT rule on FORWARD, ESTABLISHED,RELATED
rule
=
'%s FORWARD 900 -d %s -m state --state ESTABLISHED,RELATED -j REJECT'
%
(
base_cmd
,
ip
)
self
.
assertIn
(
rule
,
cmd_list
)
# Check that there is INPUT ACCEPT on ip_list
for
_
,
other_ip
in
self
.
ip_address_list
:
rule
=
'%s INPUT 0 -s %s -d %s -j ACCEPT'
%
(
base_cmd
,
other_ip
,
ip
)
...
...
@@ -2452,7 +2452,7 @@ exit 1
self
.
assertIn
(
rule
,
cmd_list
)
rule
=
'%s FORWARD 0 -s %s -d %s -j ACCEPT'
%
(
base_cmd
,
other_ip
,
ip
)
self
.
assertIn
(
rule
,
cmd_list
)
def
checkRuleFromIpSourceReject
(
self
,
ip
,
reject_ip_list
,
cmd_list
):
# XXX - rules for one ip contain 2 + 2*len(ip_address_list) rules ACCEPT and 4*len(reject_ip_list) rules REJECT
num_rules
=
(
len
(
self
.
ip_address_list
)
*
2
)
+
(
len
(
reject_ip_list
)
*
4
)
...
...
@@ -2466,7 +2466,7 @@ exit 1
# Check that there is ACCEPT rule on FORWARD
#rule = '%s FORWARD 0 -d %s -j ACCEPT' % (base_cmd, ip)
#self.assertIn(rule, cmd_list)
# Check that there is INPUT/FORWARD ACCEPT on ip_list
for
_
,
other_ip
in
self
.
ip_address_list
:
rule
=
'%s INPUT 0 -s %s -d %s -j ACCEPT'
%
(
base_cmd
,
other_ip
,
ip
)
...
...
@@ -2491,13 +2491,13 @@ exit 1
self
.
ip_address_list
=
computer
.
ip_address_list
ip
=
computer
.
instance_list
[
0
].
full_ip_list
[
0
][
1
]
source_ip_list
=
[
'10.32.0.15'
,
'10.32.0.0/8'
]
cmd_list
=
self
.
grid
.
_getFirewallAcceptRules
(
ip
,
[
elt
[
1
]
for
elt
in
self
.
ip_address_list
],
source_ip_list
,
ip_type
=
'ipv4'
)
self
.
checkRuleFromIpSource
(
ip
,
source_ip_list
,
cmd_list
)
cmd_list
=
self
.
grid
.
_getFirewallRejectRules
(
ip
,
[
elt
[
1
]
for
elt
in
self
.
ip_address_list
],
source_ip_list
,
...
...
@@ -2514,7 +2514,7 @@ exit 1
instance
=
computer
.
instance_list
[
0
]
ip
=
instance
.
full_ip_list
[
0
][
1
]
name
=
computer
.
instance_list
[
0
].
name
cmd_list
=
self
.
grid
.
_getFirewallAcceptRules
(
ip
,
[
elt
[
1
]
for
elt
in
self
.
ip_address_list
],
[],
...
...
@@ -2577,7 +2577,7 @@ exit 1
self
.
ip_address_list
=
computer
.
ip_address_list
with
open
(
rules_path
,
'r'
)
as
frules
:
rules_list
=
json
.
loads
(
frules
.
read
())
ip
=
instance
.
full_ip_list
[
0
][
1
]
self
.
checkRuleFromIpSource
(
ip
,
[],
rules_list
)
...
...
@@ -2599,7 +2599,7 @@ exit 1
self
.
ip_address_list
=
computer
.
ip_address_list
with
open
(
rules_path
,
'r'
)
as
frules
:
rules_list
=
json
.
loads
(
frules
.
read
())
ip
=
instance
.
full_ip_list
[
0
][
1
]
self
.
checkRuleFromIpSourceReject
(
ip
,
[],
rules_list
)
...
...
@@ -2666,7 +2666,7 @@ exit 1
for
thier_ip
in
source_ip
:
rule_input
=
'%s INPUT 0 -s %s -d %s -j ACCEPT'
%
(
base_cmd
,
thier_ip
,
ip
)
self
.
assertIn
(
rule_input
,
rules_list
)
rule_fwd
=
'%s FORWARD 0 -s %s -d %s -j ACCEPT'
%
(
base_cmd
,
thier_ip
,
ip
)
self
.
assertIn
(
rule_fwd
,
rules_list
)
...
...
@@ -2676,7 +2676,7 @@ exit 1
computer
=
ComputerForTest
(
self
.
software_root
,
self
.
instance_root
)
self
.
setFirewallConfig
()
source_ip
=
'10.0.8.10'
self
.
grid
.
firewall_conf
[
'authorized_sources'
]
=
[
'10.0.8.15'
]
with
httmock
.
HTTMock
(
computer
.
request_handler
):
instance
=
computer
.
instance_list
[
0
]
...
...
@@ -2802,7 +2802,7 @@ exit 0
[
'.slapgrid'
,
'.0_wrapper.log'
,
'buildout.cfg'
,
'etc'
,
'software_release'
,
'worked'
,
'.slapos-retention-lock-delay'
])
self
.
assertEqual
(
computer
.
sequence
,
[
'/getFullComputerInformation'
,
[
'/getFullComputerInformation'
,
'/startedComputerPartition'
])
self
.
assertEqual
(
partition
.
state
,
'started'
)
manager_list
=
slapmanager
.
from_config
({
'manager_list'
:
'prerm'
})
...
...
@@ -3049,7 +3049,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
['/getFullComputerInformation',
'/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
...
...
@@ -3124,7 +3124,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
['/getFullComputerInformation',
'/startedComputerPartition', '/startedComputerPartition'])
self.assertEqual(self.partition.state, 'started')
...
...
@@ -3446,7 +3446,7 @@ class TestSlapgridWithDevPermManagerDevPermAllowLsblk(TestSlapgridWithDevPermLsb
class TestSlapgridWithWhitelistfirewall(MasterMixin, unittest.TestCase):
config = {
'manager_list': 'whitelistfirewall',
'firewall':{
'firewall':
{
'firewall_cmd': 'firewall_cmd',
}
}
...
...
@@ -3711,7 +3711,7 @@ class TestSlapgridManagerLifecycle(MasterMixin, unittest.TestCase):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.computer.sequence,
['/getFullComputerInformation',
['/getFullComputerInformation',
'/startedComputerPartition'])
self.assertEqual(partition.state, 'started')
...
...
@@ -3959,7 +3959,7 @@ class TestSlapgridPromiseWithMaster(MasterMixin, unittest.TestCase):
with open(os.path.join(instance.partition_path, "
.
slapgrid
/
promise
/
result
/
succeeding2
.
status
.
json
"), "r") as f:
result = json.loads(f.read())
self.assertEqual('success',
result["
result
"]["
message
"])
...
...
@@ -4074,7 +4074,7 @@ class TestSlapgridPromiseWithMaster(MasterMixin, unittest.TestCase):
import time
time.sleep(27)""" % (timeout_file, timeout_file)
instance.setPluginPromise(promise_name='timeout_fail.py', success=True, promise_content=fail)
self.assertEqual(self.grid.processPromiseList(),
slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertTrue(os.path.isfile(worked_file))
...
...
slapos/tests/test_slapproxy.py
View file @
7f45fa10
...
...
@@ -315,9 +315,9 @@ class TestInformation(BasicMixin, unittest.TestCase):
rv
=
self
.
app
.
get
(
'/getFullComputerInformation?computer_id=%s'
%
self
.
computer_id
)
computer
=
loads
(
rv
.
data
)
for
slap_partition
in
computer
.
_computer_partition_list
:
self
.
assertIsNone
(
slap_partition
.
_software_release_document
)
self
.
assertEqual
(
slap_partition
.
_requested_state
,
'destroyed'
)
self
.
assertEqual
(
slap_partition
.
_need_modification
,
0
)
self
.
assertIsNone
(
slap_partition
.
_software_release_document
)
self
.
assertEqual
(
slap_partition
.
_requested_state
,
'destroyed'
)
self
.
assertEqual
(
slap_partition
.
_need_modification
,
0
)
def
test_getSoftwareReleaseListFromSoftwareProduct_software_product_reference
(
self
):
"""
...
...
@@ -409,7 +409,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
partition_parameter_kw
=
{}
if
filter_kw
is
None
:
filter_kw
=
{}
# Let's enforce a default software type
# Let's enforce a default software type
if
software_type
is
None
:
software_type
=
'default'
...
...
@@ -462,7 +462,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
def
supply
(
self
,
url
,
computer_id
=
None
,
state
=
'available'
):
if
not
computer_id
:
computer_id
=
self
.
computer_id
request_dict
=
{
'url'
:
url
,
'computer_id'
:
computer_id
,
'state'
:
state
}
request_dict
=
{
'url'
:
url
,
'computer_id'
:
computer_id
,
'state'
:
state
}
rv
=
self
.
app
.
post
(
'/supplySupply'
,
data
=
request_dict
)
# XXX return a Software Release
...
...
@@ -1027,7 +1027,7 @@ class TestSlaveRequest(MasterMixin):
before_timestamp
=
after_timestamp
time
.
sleep
(
0.1
)
self
.
request
(
'http://sr//'
,
None
,
'MySecondSlave'
,
shared
=
True
,
partition_parameter_kw
=
{
'a'
:
'b'
})
self
.
request
(
'http://sr//'
,
None
,
'MySecondSlave'
,
shared
=
True
,
partition_parameter_kw
=
{
'a'
:
'b'
})
after
=
getPartition
()
after_timestamp
=
getTimestamp
(
after
)
self
.
assertEqual
(
len
(
after
.
_parameter_dict
[
'slave_instance_list'
]),
2
)
...
...
@@ -1035,7 +1035,7 @@ class TestSlaveRequest(MasterMixin):
before_timestamp
=
after_timestamp
time
.
sleep
(
0.1
)
self
.
request
(
'http://sr//'
,
None
,
'MySecondSlave'
,
shared
=
True
,
partition_parameter_kw
=
{
'a'
:
'b'
})
self
.
request
(
'http://sr//'
,
None
,
'MySecondSlave'
,
shared
=
True
,
partition_parameter_kw
=
{
'a'
:
'b'
})
after
=
getPartition
()
after_timestamp
=
getTimestamp
(
after
)
self
.
assertEqual
(
len
(
after
.
_parameter_dict
[
'slave_instance_list'
]),
2
)
...
...
@@ -1468,7 +1468,7 @@ class TestMultiNodeSupport(MasterMixin):
self
.
assertEqual
(
rv
.
_status_code
,
404
)
rv
=
self
.
_requestComputerPartition
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart2'
,
filter_kw
=
{
'computer_guid'
:
self
.
computer_id
})
filter_kw
=
{
'computer_guid'
:
self
.
computer_id
})
self
.
assertEqual
(
rv
.
_status_code
,
404
)
# Register default computer: deployment works
...
...
@@ -1480,7 +1480,7 @@ class TestMultiNodeSupport(MasterMixin):
# No free space on default computer: request without SLA fails
rv
=
self
.
_requestComputerPartition
(
'http://sr//'
,
None
,
'CanIHasPartition'
,
'slappart2'
,
filter_kw
=
{
'computer_guid'
:
self
.
computer_id
})
filter_kw
=
{
'computer_guid'
:
self
.
computer_id
})
self
.
assertEqual
(
rv
.
_status_code
,
404
)
def
test_multi_node_support_instance
(
self
):
...
...
@@ -1498,13 +1498,13 @@ class TestMultiNodeSupport(MasterMixin):
# Deploy to first non-default computer using SLA
# It should fail since computer is not registered
rv
=
self
.
_requestComputerPartition
(
software_release_1
,
None
,
'MyFirstInstance'
,
'slappart2'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
rv
=
self
.
_requestComputerPartition
(
software_release_1
,
None
,
'MyFirstInstance'
,
'slappart2'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
self
.
assertEqual
(
rv
.
_status_code
,
404
)
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_0_id
)
# Deploy to first non-default computer using SLA
partition
=
self
.
request
(
software_release_1
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition
=
self
.
request
(
software_release_1
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
self
.
assertEqual
(
partition
.
getState
(),
'started'
)
self
.
assertEqual
(
partition
.
_partition_id
,
'slappart0'
)
self
.
assertEqual
(
partition
.
_computer_id
,
computer_0_id
)
...
...
@@ -1517,7 +1517,7 @@ class TestMultiNodeSupport(MasterMixin):
self
.
assertTrue
(
computer_1
.
_computer_partition_list
[
1
].
_software_release_document
==
None
)
# Deploy to second non-default computer using SLA
partition
=
self
.
request
(
software_release_2
,
None
,
'MySecondInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition
=
self
.
request
(
software_release_2
,
None
,
'MySecondInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
self
.
assertEqual
(
partition
.
getState
(),
'started'
)
self
.
assertEqual
(
partition
.
_partition_id
,
'slappart0'
)
self
.
assertEqual
(
partition
.
_computer_id
,
computer_1_id
)
...
...
@@ -1539,10 +1539,10 @@ class TestMultiNodeSupport(MasterMixin):
computer_1_id
=
'COMP-1'
self
.
format_for_number_of_partitions
(
6
,
computer_id
=
computer_0_id
)
self
.
format_for_number_of_partitions
(
6
,
computer_id
=
computer_1_id
)
partition_first
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition_second
=
self
.
request
(
'http://sr//'
,
None
,
'MySecondInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition_first
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition_second
=
self
.
request
(
'http://sr//'
,
None
,
'MySecondInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition_first
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
},
state
=
'stopped'
)
partition_first
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
},
state
=
'stopped'
)
computer_0
=
loads
(
self
.
app
.
get
(
'/getFullComputerInformation?computer_id=COMP-0'
).
data
)
computer_1
=
loads
(
self
.
app
.
get
(
'/getFullComputerInformation?computer_id=COMP-1'
).
data
)
...
...
@@ -1562,8 +1562,8 @@ class TestMultiNodeSupport(MasterMixin):
computer_1_id
=
'COMP-1'
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_0_id
)
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_1_id
)
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
self
.
assertEqual
(
partition
.
_computer_id
,
computer_0_id
)
...
...
@@ -1582,19 +1582,19 @@ class TestMultiNodeSupport(MasterMixin):
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_0_id
)
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_1_id
)
self
.
format_for_number_of_partitions
(
2
)
self
.
request
(
'http://sr2//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
self
.
request
(
'http://sr//'
,
None
,
'MyOtherInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
self
.
request
(
'http://sr2//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
self
.
request
(
'http://sr//'
,
None
,
'MyOtherInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
# Request slave without SLA: will fail
rv
=
self
.
_requestComputerPartition
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
)
self
.
assertEqual
(
rv
.
_status_code
,
404
)
# Request slave with SLA on incorrect computer: will fail
rv
=
self
.
_requestComputerPartition
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
rv
=
self
.
_requestComputerPartition
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
self
.
assertEqual
(
rv
.
_status_code
,
404
)
# Request computer on correct computer: will succeed
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition
=
self
.
request
(
'http://sr//'
,
None
,
'MySlaveInstance'
,
'slappart2'
,
shared
=
True
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
self
.
assertEqual
(
partition
.
_computer_id
,
computer_1_id
)
def
test_multi_node_support_instance_guid
(
self
):
...
...
@@ -1608,8 +1608,8 @@ class TestMultiNodeSupport(MasterMixin):
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_0_id
)
self
.
format_for_number_of_partitions
(
2
,
computer_id
=
computer_1_id
)
self
.
format_for_number_of_partitions
(
2
)
partition_computer_0
=
self
.
request
(
'http://sr2//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition_computer_1
=
self
.
request
(
'http://sr//'
,
None
,
'MyOtherInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition_computer_0
=
self
.
request
(
'http://sr2//'
,
None
,
'MyFirstInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_0_id
})
partition_computer_1
=
self
.
request
(
'http://sr//'
,
None
,
'MyOtherInstance'
,
'slappart0'
,
filter_kw
=
{
'computer_guid'
:
computer_1_id
})
partition_computer_default
=
self
.
request
(
'http://sr//'
,
None
,
'MyThirdInstance'
,
'slappart0'
)
self
.
assertEqual
(
partition_computer_0
.
getInstanceGuid
(),
'COMP-0-slappart0'
)
...
...
@@ -1675,11 +1675,11 @@ host = %(host)s
port = %(port)s
database_uri = %(rootdir)s/lib/external_proxy.db
"""
%
{
'rootdir'
:
self
.
_rootdir
,
'host'
:
self
.
external_proxy_host
,
'port'
:
self
.
external_proxy_port
,
'external_computer_id'
:
self
.
external_computer_id
})
'rootdir'
:
self
.
_rootdir
,
'host'
:
self
.
external_proxy_host
,
'port'
:
self
.
external_proxy_port
,
'external_computer_id'
:
self
.
external_computer_id
})
def
startExternalProxy
(
self
):
"""
...
...
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