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
49ba5035
Commit
49ba5035
authored
Aug 09, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prove alter_network and alter_user switches.
Additionaly fix small issue with test assertions.
parent
24cec7cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
4 deletions
+120
-4
slapos/tests/slapformat.py
slapos/tests/slapformat.py
+120
-4
No files found.
slapos/tests/slapformat.py
View file @
49ba5035
...
@@ -30,6 +30,7 @@ class FakeCallAndRead:
...
@@ -30,6 +30,7 @@ class FakeCallAndRead:
self
.
external_command_list
=
[]
self
.
external_command_list
=
[]
def
__call__
(
self
,
argument_list
,
raise_on_error
=
True
):
def
__call__
(
self
,
argument_list
,
raise_on_error
=
True
):
retval
=
0
,
'UP'
global
INTERFACE_DICT
global
INTERFACE_DICT
if
'useradd'
in
argument_list
:
if
'useradd'
in
argument_list
:
global
USER_LIST
global
USER_LIST
...
@@ -52,10 +53,9 @@ class FakeCallAndRead:
...
@@ -52,10 +53,9 @@ class FakeCallAndRead:
# stabilise by mangling ip to just ip string
# stabilise by mangling ip to just ip string
argument_list
[
3
]
=
'ip/%s'
%
netmask
argument_list
[
3
]
=
'ip/%s'
%
netmask
elif
argument_list
[:
3
]
==
[
'ip'
,
'addr'
,
'list'
]:
elif
argument_list
[:
3
]
==
[
'ip'
,
'addr'
,
'list'
]:
return
0
,
str
(
INTERFACE_DICT
)
retval
=
0
,
str
(
INTERFACE_DICT
)
self
.
external_command_list
.
append
(
argument_list
)
self
.
external_command_list
.
append
(
argument_list
)
return
0
,
'UP'
return
retval
class
LoggableWrapper
:
class
LoggableWrapper
:
def
__init__
(
self
,
logger
,
name
):
def
__init__
(
self
,
logger
,
name
):
...
@@ -286,6 +286,7 @@ class TestComputer(SlapformatMixin):
...
@@ -286,6 +286,7 @@ class TestComputer(SlapformatMixin):
],
],
self
.
test_result
.
bucket
)
self
.
test_result
.
bucket
)
self
.
assertEqual
([
self
.
assertEqual
([
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'groupadd'
,
'slapsoft'
],
[
'groupadd'
,
'slapsoft'
],
[
'useradd'
,
'-d'
,
'/software_root'
,
'-g'
,
'slapsoft'
,
'-s'
,
[
'useradd'
,
'-d'
,
'/software_root'
,
'-g'
,
'slapsoft'
,
'-s'
,
'/bin/false'
,
'slapsoft'
],
[
'groupadd'
,
'testuser'
],
'/bin/false'
,
'slapsoft'
],
[
'groupadd'
,
'testuser'
],
...
@@ -296,7 +297,122 @@ class TestComputer(SlapformatMixin):
...
@@ -296,7 +297,122 @@ class TestComputer(SlapformatMixin):
[
'brctl'
,
'show'
],
[
'brctl'
,
'show'
],
[
'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'
,
'add'
,
'ip/ffff:ffff:ffff:ffff::'
,
'dev'
,
'bridge'
]
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/ffff:ffff:ffff:ffff::'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
],
self
.
fakeCallAndRead
.
external_command_list
)
def
test_construct_prepared_no_alter_user
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
bridge
=
slapos
.
format
.
Bridge
(
'bridge'
,
'127.0.0.1/16'
))
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
computer
.
partition_list
=
[
partition
]
global
INTERFACE_DICT
INTERFACE_DICT
[
'bridge'
]
=
{
2
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
'netmask'
:
'255.255.255.0'
}],
10
:
[{
'addr'
:
'2a01:e35:2e27::e59c'
,
'netmask'
:
'ffff:ffff:ffff:ffff::'
}]
}
computer
.
construct
(
alter_user
=
False
)
self
.
assertEqual
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"mkdir('/instance_root/partition', 488)"
,
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'tunctl'
,
'-t'
,
'tap'
,
'-u'
,
'root'
],
[
'ip'
,
'link'
,
'set'
,
'tap'
,
'up'
],
[
'brctl'
,
'show'
],
[
'brctl'
,
'addif'
,
'bridge'
,
'tap'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/255.255.255.255'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/ffff:ffff:ffff:ffff::'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
],
self
.
fakeCallAndRead
.
external_command_list
)
def
test_construct_prepared_no_alter_network
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
bridge
=
slapos
.
format
.
Bridge
(
'bridge'
,
'127.0.0.1/16'
))
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
computer
.
partition_list
=
[
partition
]
global
INTERFACE_DICT
INTERFACE_DICT
[
'bridge'
]
=
{
2
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
'netmask'
:
'255.255.255.0'
}],
10
:
[{
'addr'
:
'2a01:e35:2e27::e59c'
,
'netmask'
:
'ffff:ffff:ffff:ffff::'
}]
}
computer
.
construct
(
alter_network
=
False
)
self
.
assertEqual
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chown('/software_root', 0, 0)"
,
"chmod('/software_root', 493)"
,
"mkdir('/instance_root/partition', 488)"
,
"chown('/instance_root/partition', 0, 0)"
,
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'groupadd'
,
'slapsoft'
],
[
'useradd'
,
'-d'
,
'/software_root'
,
'-g'
,
'slapsoft'
,
'-s'
,
'/bin/false'
,
'slapsoft'
],
[
'groupadd'
,
'testuser'
],
[
'useradd'
,
'-d'
,
'/instance_root/partition'
,
'-g'
,
'testuser'
,
'-s'
,
'/bin/false'
,
'-G'
,
'slapsoft'
,
'testuser'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/255.255.255.255'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/ffff:ffff:ffff:ffff::'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
],
self
.
fakeCallAndRead
.
external_command_list
)
def
test_construct_prepared_no_alter_network_user
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
bridge
=
slapos
.
format
.
Bridge
(
'bridge'
,
'127.0.0.1/16'
))
computer
.
instance_root
=
'/instance_root'
computer
.
software_root
=
'/software_root'
partition
=
slapos
.
format
.
Partition
(
'partition'
,
'/part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
None
)
partition
.
tap
=
slapos
.
format
.
Tap
(
'tap'
)
computer
.
partition_list
=
[
partition
]
global
INTERFACE_DICT
INTERFACE_DICT
[
'bridge'
]
=
{
2
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
'netmask'
:
'255.255.255.0'
}],
10
:
[{
'addr'
:
'2a01:e35:2e27::e59c'
,
'netmask'
:
'ffff:ffff:ffff:ffff::'
}]
}
computer
.
construct
(
alter_network
=
False
,
alter_user
=
False
)
self
.
assertEqual
([
"makedirs('/instance_root', 493)"
,
"makedirs('/software_root', 493)"
,
"chmod('/software_root', 493)"
,
"mkdir('/instance_root/partition', 488)"
,
"chmod('/instance_root/partition', 488)"
],
self
.
test_result
.
bucket
)
self
.
assertEqual
([
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/255.255.255.255'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
[
'ip'
,
'addr'
,
'add'
,
'ip/ffff:ffff:ffff:ffff::'
,
'dev'
,
'bridge'
],
[
'ip'
,
'addr'
,
'list'
,
'bridge'
],
],
],
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
...
...
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