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
Léo-Paul Géneau
slapos.core
Commits
2b90fc01
Commit
2b90fc01
authored
Jun 02, 2017
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into amarisoft
Conflicts: slapos/tests/slapformat.py
parents
d393206c
889711ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
41 deletions
+67
-41
slapos/README.console.txt
slapos/README.console.txt
+2
-2
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+65
-39
No files found.
slapos/README.console.txt
View file @
2b90fc01
...
...
@@ -47,11 +47,11 @@ documentation.
This allows to request instances in a few words, i.e::
request("
mykvm", "http://www.url.com/path/to/current/best/known/kvm/software.cfg
")
request("
http://www.url.com/path/to/current/best/known/kvm/software.cfg", "mykvm
")
can be simplified into ::
request(
"mykvm", product.kvm
)
request(
product.kvm, "mykvm"
)
* "slap" is an instance of the SLAP library. It is only used for advanced usages.
"slap" instance is obtained by doing ::
...
...
slapos/tests/slapformat.py
View file @
2b90fc01
...
...
@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
__future__
import
print_function
import
logging
import
slapos.format
...
...
@@ -82,7 +83,7 @@ class FakeCallAndRead:
retval
=
0
,
'UP'
global
INTERFACE_DICT
if
'useradd'
in
argument_list
:
print
argument_list
print
(
argument_list
)
global
USER_LIST
username
=
argument_list
[
-
1
]
if
username
==
'-r'
:
...
...
@@ -254,6 +255,33 @@ class SlapformatMixin(unittest.TestCase):
setattr
(
slapos
.
util
,
name
,
original_value
)
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
):
config
=
FakeConfig
()
config
.
dry_run
=
True
...
...
@@ -263,6 +291,9 @@ class SlapformatMixin(unittest.TestCase):
self
.
test_result
=
TestLoggerHandler
()
logger
.
addHandler
(
self
.
test_result
)
config
.
logger
=
logger
if
hasattr
(
self
,
"logger"
):
raise
ValueError
(
"{} already has logger attached"
.
format
(
self
.
__class__
.
__name__
))
self
.
logger
=
logger
self
.
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
global
USER_LIST
...
...
@@ -311,14 +342,14 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'bridge'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[])
computer
.
format
()
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
'ip addr list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
],
...
...
@@ -332,7 +363,7 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'bridge'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[])
computer
.
format
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
...
...
@@ -349,13 +380,13 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'bridge'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[])
computer
.
format
(
alter_network
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
...
...
@@ -370,15 +401,12 @@ class TestComputer(SlapformatMixin):
logger
=
self
.
logger
,
name
=
'bridge'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[])
computer
.
format
(
alter_network
=
False
,
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
'ip addr list bridge'
,
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
assertEqualCommands
([],
self
.
fakeCallAndRead
.
external_command_list
)
@
unittest
.
skip
(
"Not implemented"
)
def
test_construct_prepared
(
self
):
...
...
@@ -391,7 +419,6 @@ class TestComputer(SlapformatMixin):
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
INTERFACE_DICT
INTERFACE_DICT
[
'bridge'
]
=
{
socket
.
AF_INET
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
...
...
@@ -400,7 +427,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
()
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
...
...
@@ -410,7 +437,7 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
...
...
@@ -418,12 +445,12 @@ class TestComputer(SlapformatMixin):
'useradd -d /instance_root/partition -g testuser -G slapsoft testuser -r'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
'brctl show'
,
# 'brctl show', # don't track non-functional commands
'brctl addif bridge tap'
,
'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 list bridge'
,
# 'ip addr list bridge', # don't track non-functional commands
],
self
.
fakeCallAndRead
.
external_command_list
)
...
...
@@ -437,7 +464,6 @@ class TestComputer(SlapformatMixin):
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
None
),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
...
...
@@ -450,7 +476,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
...
@@ -458,16 +484,16 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list bridge'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
'brctl show'
,
# 'brctl show', # don't track non-functional commands
'brctl addif bridge tap'
,
'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 -6 addr list bridge'
,
# 'ip -6 addr list bridge', # don't track non-functional commands
],
self
.
fakeCallAndRead
.
external_command_list
)
...
...
@@ -497,7 +523,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
(
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
...
@@ -505,7 +531,7 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
'ip addr list iface'
,
'tunctl -t tap -u testuser'
,
'ip link set tap up'
,
...
...
@@ -513,7 +539,7 @@ class TestComputer(SlapformatMixin):
'route add -host 10.8.0.2 dev tap'
,
'ip addr add ip/255.255.255.255 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
.
assertEqual
(
partition
.
tap
.
ipv4_addr
,
'10.8.0.2'
)
...
...
@@ -541,7 +567,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
(
alter_network
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
...
...
@@ -551,8 +577,8 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
# 'ip addr list bridge',
self
.
assertEqual
Commands
([
# 'ip addr list bridge',
# don't track non-functional commands
'groupadd slapsoft'
,
'useradd -d /software_root -g slapsoft slapsoft -r'
,
'groupadd testuser'
,
...
...
@@ -583,7 +609,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
(
alter_network
=
False
,
alter_user
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
...
@@ -591,12 +617,12 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
'ip addr list bridge'
,
self
.
assertEqual
Commands
([
# 'ip addr list bridge', # don't track non-functional commands
'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 -6 addr list bridge'
,
# 'ip -6 addr list bridge', # don't track non-functional commands
],
self
.
fakeCallAndRead
.
external_command_list
)
...
...
@@ -624,7 +650,7 @@ class TestComputer(SlapformatMixin):
}
computer
.
format
(
use_unique_local_address_block
=
True
,
alter_user
=
False
,
create_tap
=
False
)
self
.
assertEqual
([
self
.
assertEqual
Commands
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
...
...
@@ -632,12 +658,12 @@ class TestComputer(SlapformatMixin):
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
'ip addr list myinterface'
,
self
.
assertEqual
Commands
([
# 'ip addr list myinterface', # don't track non-functional commands
'ip address add dev myinterface fd00::1/64'
,
'ip addr add ip/255.255.255.255 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
)
...
...
@@ -707,7 +733,7 @@ class TestPartition(SlapformatMixin):
def
test_createPath_no_alter_user
(
self
):
self
.
partition
.
createPath
(
False
)
self
.
assertEqual
(
self
.
assertEqual
Commands
(
[
"mkdir('/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