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
Eric Zheng
slapos.core
Commits
889711ed
Commit
889711ed
authored
Jun 01, 2017
by
Tomáš Peterka
Committed by
Rafael Monnerat
Jun 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Do not check non-function commands
parent
07629dce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
37 deletions
+62
-37
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+62
-37
No files found.
slapos/tests/slapformat.py
View file @
889711ed
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
##############################################################################
##############################################################################
from
__future__
import
print_function
import
logging
import
logging
import
slapos.format
import
slapos.format
...
@@ -68,7 +69,7 @@ class FakeCallAndRead:
...
@@ -68,7 +69,7 @@ class FakeCallAndRead:
retval
=
0
,
'UP'
retval
=
0
,
'UP'
global
INTERFACE_DICT
global
INTERFACE_DICT
if
'useradd'
in
argument_list
:
if
'useradd'
in
argument_list
:
print
argument_list
print
(
argument_list
)
global
USER_LIST
global
USER_LIST
username
=
argument_list
[
-
1
]
username
=
argument_list
[
-
1
]
if
username
==
'-r'
:
if
username
==
'-r'
:
...
@@ -230,6 +231,33 @@ class SlapformatMixin(unittest.TestCase):
...
@@ -230,6 +231,33 @@ class SlapformatMixin(unittest.TestCase):
setattr
(
slapos
.
util
,
name
,
original_value
)
setattr
(
slapos
.
util
,
name
,
original_value
)
del
self
.
saved_slapos_util
del
self
.
saved_slapos_util
def
assertEqualCommands
(
self
,
seq1
,
seq2
):
"""Assert that all items in seq1 are present in right order in seq2.
This is useful for ``logger.bucket_list`` where we save executed commands
which mix together with logging messages.
"""
if
len
(
seq1
)
==
0
:
return
assert
len
(
seq1
)
<=
len
(
seq2
),
"First argument should contain mandatory items
\
n
"
if
len
(
seq1
)
!=
len
(
seq2
):
logging
.
getLogger
(
'test.slap.format'
).
warning
(
"Comparing uneven sequences!
\
n
"
)
print
(
"
\
n
"
.
join
(
map
(
str
,
seq1
)))
print
(
"
\
n
"
.
join
(
map
(
str
,
seq2
)))
# we cannot do simple filter s2 in s1 because commands might repeat
iter1
,
iter2
=
iter
(
seq1
),
iter
(
seq2
)
item1
,
item2
=
next
(
iter1
),
next
(
iter2
)
try
:
while
item1
!=
item2
:
item2
=
next
(
iter2
)
item1
=
next
(
iter1
)
except
StopIteration
as
e
:
raise
AssertionError
(
"Following sequences differs at line
\
"
{!s}
\
"
\
n
{}
\
n
!=
\
n
{}
\
n
"
.
format
(
item1
,
"
\
n
"
.
join
(
map
(
str
,
seq1
)),
"
\
n
"
.
join
(
map
(
str
,
seq2
))))
def
setUp
(
self
):
def
setUp
(
self
):
config
=
FakeConfig
()
config
=
FakeConfig
()
config
.
dry_run
=
True
config
.
dry_run
=
True
...
@@ -290,14 +318,14 @@ class TestComputer(SlapformatMixin):
...
@@ -290,14 +318,14 @@ class TestComputer(SlapformatMixin):
computer
.
instance_root
=
'/instance_root'
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
computer
.
software_root
=
'/software_root'
computer
.
construct
()
computer
.
construct
()
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chown('/software_root', 0, 0)"
,
"chmod('/software_root', 493)"
],
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
([
'ip addr list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
'groupadd slapsoft'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
'useradd -d /software_root -g slapsoft slapsoft -r'
],
],
...
@@ -311,7 +339,7 @@ class TestComputer(SlapformatMixin):
...
@@ -311,7 +339,7 @@ class TestComputer(SlapformatMixin):
computer
.
instance_root
=
'/instance_root'
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
computer
.
software_root
=
'/software_root'
computer
.
construct
(
alter_user
=
False
)
computer
.
construct
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
"chmod('/software_root', 493)"
],
...
@@ -328,13 +356,13 @@ class TestComputer(SlapformatMixin):
...
@@ -328,13 +356,13 @@ class TestComputer(SlapformatMixin):
computer
.
instance_root
=
'/instance_root'
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
computer
.
software_root
=
'/software_root'
computer
.
construct
(
alter_network
=
False
)
computer
.
construct
(
alter_network
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chown('/software_root', 0, 0)"
,
"chmod('/software_root', 493)"
],
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'ip addr list bridge'
,
'groupadd slapsoft'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
'useradd -d /software_root -g slapsoft slapsoft -r'
...
@@ -349,15 +377,12 @@ class TestComputer(SlapformatMixin):
...
@@ -349,15 +377,12 @@ class TestComputer(SlapformatMixin):
computer
.
instance_root
=
'/instance_root'
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
computer
.
software_root
=
'/software_root'
computer
.
construct
(
alter_network
=
False
,
alter_user
=
False
)
computer
.
construct
(
alter_network
=
False
,
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqualCommands
([],
self
.
fakeCallAndRead
.
external_command_list
)
'ip addr list bridge'
,
],
self
.
fakeCallAndRead
.
external_command_list
)
@
unittest
.
skip
(
"Not implemented"
)
@
unittest
.
skip
(
"Not implemented"
)
def
test_construct_prepared
(
self
):
def
test_construct_prepared
(
self
):
...
@@ -379,7 +404,7 @@ class TestComputer(SlapformatMixin):
...
@@ -379,7 +404,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
()
computer
.
construct
()
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chown('/software_root', 0, 0)"
,
...
@@ -389,7 +414,7 @@ class TestComputer(SlapformatMixin):
...
@@ -389,7 +414,7 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'ip addr list bridge'
,
'groupadd slapsoft'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
...
@@ -397,12 +422,12 @@ class TestComputer(SlapformatMixin):
...
@@ -397,12 +422,12 @@ class TestComputer(SlapformatMixin):
'useradd -d /instance_root/partition -g testuser -G slapsoft testuser -r'
,
'useradd -d /instance_root/partition -g testuser -G slapsoft testuser -r'
,
'tunctl -t tap -u testuser'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
'ip link set tap up'
,
'brctl show'
,
# 'brctl show', # don't track non-functional commands
'brctl addif bridge tap'
,
'brctl addif bridge tap'
,
'ip addr add ip/255.255.255.255 dev bridge'
,
'ip addr add ip/255.255.255.255 dev bridge'
,
'ip addr list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip addr list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
...
@@ -427,7 +452,7 @@ class TestComputer(SlapformatMixin):
...
@@ -427,7 +452,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
(
alter_user
=
False
)
computer
.
construct
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
@@ -435,16 +460,16 @@ class TestComputer(SlapformatMixin):
...
@@ -435,16 +460,16 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'ip addr list bridge'
,
'tunctl -t tap -u testuser'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
'ip link set tap up'
,
'brctl show'
,
# 'brctl show', # don't track non-functional commands
'brctl addif bridge tap'
,
'brctl addif bridge tap'
,
'ip addr add ip/255.255.255.255 dev bridge'
,
'ip addr add ip/255.255.255.255 dev bridge'
,
# 'ip addr list bridge',
# 'ip addr list bridge',
# don't track non-functional commands
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip -6 addr list bridge'
,
# 'ip -6 addr list bridge', # don't track non-functional commands
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
...
@@ -474,7 +499,7 @@ class TestComputer(SlapformatMixin):
...
@@ -474,7 +499,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
(
alter_user
=
False
)
computer
.
construct
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
@@ -482,7 +507,7 @@ class TestComputer(SlapformatMixin):
...
@@ -482,7 +507,7 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list iface'
,
'ip addr list iface'
,
'tunctl -t tap -u testuser'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
'ip link set tap up'
,
...
@@ -490,7 +515,7 @@ class TestComputer(SlapformatMixin):
...
@@ -490,7 +515,7 @@ class TestComputer(SlapformatMixin):
'route add -host 10.8.0.2 dev tap'
,
'route add -host 10.8.0.2 dev tap'
,
'ip addr add ip/255.255.255.255 dev iface'
,
'ip addr add ip/255.255.255.255 dev iface'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev iface'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev iface'
,
'ip -6 addr list iface'
# 'ip -6 addr list iface' # don't track non-functional commands
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
self
.
assertEqual
(
partition
.
tap
.
ipv4_addr
,
'10.8.0.2'
)
self
.
assertEqual
(
partition
.
tap
.
ipv4_addr
,
'10.8.0.2'
)
...
@@ -518,7 +543,7 @@ class TestComputer(SlapformatMixin):
...
@@ -518,7 +543,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
(
alter_network
=
False
)
computer
.
construct
(
alter_network
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chown('/software_root', 0, 0)"
,
...
@@ -528,8 +553,8 @@ class TestComputer(SlapformatMixin):
...
@@ -528,8 +553,8 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
# 'ip addr list bridge',
# 'ip addr list bridge',
# don't track non-functional commands
'groupadd slapsoft'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
'groupadd testuser'
,
'groupadd testuser'
,
...
@@ -560,7 +585,7 @@ class TestComputer(SlapformatMixin):
...
@@ -560,7 +585,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
(
alter_network
=
False
,
alter_user
=
False
)
computer
.
construct
(
alter_network
=
False
,
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
@@ -568,12 +593,12 @@ class TestComputer(SlapformatMixin):
...
@@ -568,12 +593,12 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
'ip addr add ip/255.255.255.255 dev bridge'
,
'ip addr add ip/255.255.255.255 dev bridge'
,
# 'ip addr list bridge',
# 'ip addr list bridge',
# don't track non-functional commands
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev bridge'
,
'ip -6 addr list bridge'
,
# 'ip -6 addr list bridge', # don't track non-functional commands
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
...
@@ -601,7 +626,7 @@ class TestComputer(SlapformatMixin):
...
@@ -601,7 +626,7 @@ class TestComputer(SlapformatMixin):
}
}
computer
.
construct
(
use_unique_local_address_block
=
True
,
alter_user
=
False
,
create_tap
=
False
)
computer
.
construct
(
use_unique_local_address_block
=
True
,
alter_user
=
False
,
create_tap
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
@@ -609,12 +634,12 @@ class TestComputer(SlapformatMixin):
...
@@ -609,12 +634,12 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
"chmod('/instance_root/partition', 488)"
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list myinterface'
,
# 'ip addr list myinterface', # don't track non-functional commands
'ip address add dev myinterface fd00::1/64'
,
'ip address add dev myinterface fd00::1/64'
,
'ip addr add ip/255.255.255.255 dev myinterface'
,
'ip addr add ip/255.255.255.255 dev myinterface'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev myinterface'
,
'ip addr add ip/ffff:ffff:ffff:ffff:: dev myinterface'
,
'ip -6 addr list myinterface'
# 'ip -6 addr list myinterface' # don't track non-functional commands
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
...
@@ -622,7 +647,7 @@ class TestPartition(SlapformatMixin):
...
@@ -622,7 +647,7 @@ class TestPartition(SlapformatMixin):
def
test_createPath_no_alter_user
(
self
):
def
test_createPath_no_alter_user
(
self
):
self
.
partition
.
createPath
(
False
)
self
.
partition
.
createPath
(
False
)
self
.
assertEqual
(
self
.
assertEqual
Commands
(
[
[
"mkdir('/part_path', 488)"
,
"mkdir('/part_path', 488)"
,
"chmod('/part_path', 488)"
"chmod('/part_path', 488)"
...
...
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