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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
61386852
Commit
61386852
authored
May 04, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: Fix python3 bytes/str mismatch in dump
parent
783894a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
3 deletions
+48
-3
slapos/format.py
slapos/format.py
+3
-3
slapos/tests/test_slapformat.py
slapos/tests/test_slapformat.py
+45
-0
No files found.
slapos/format.py
View file @
61386852
...
@@ -364,8 +364,8 @@ class Computer(object):
...
@@ -364,8 +364,8 @@ class Computer(object):
computer_dict
=
_getDict
(
self
)
computer_dict
=
_getDict
(
self
)
if
path_to_json
:
if
path_to_json
:
with
open
(
path_to_json
,
'w
b
'
)
as
fout
:
with
open
(
path_to_json
,
'w'
)
as
fout
:
fout
.
write
(
json
.
dumps
(
computer_dict
,
sort_keys
=
True
,
indent
=
2
)
)
json
.
dump
(
computer_dict
,
fout
,
sort_keys
=
True
,
indent
=
2
)
new_xml
=
dumps
(
computer_dict
)
new_xml
=
dumps
(
computer_dict
)
new_pretty_xml
=
prettify_xml
(
new_xml
)
new_pretty_xml
=
prettify_xml
(
new_xml
)
...
@@ -767,7 +767,7 @@ class Partition(object):
...
@@ -767,7 +767,7 @@ class Partition(object):
# dumped resources didn't change
# dumped resources didn't change
return
return
with
open
(
file_path
,
"w
b
"
)
as
fo
:
with
open
(
file_path
,
"w"
)
as
fo
:
fo
.
write
(
content
)
fo
.
write
(
content
)
owner_pw
=
pwd
.
getpwnam
(
self
.
user
.
name
)
owner_pw
=
pwd
.
getpwnam
(
self
.
user
.
name
)
os
.
chmod
(
file_path
,
0o644
)
os
.
chmod
(
file_path
,
0o644
)
...
...
slapos/tests/test_slapformat.py
View file @
61386852
...
@@ -30,6 +30,9 @@ from __future__ import print_function
...
@@ -30,6 +30,9 @@ from __future__ import print_function
import
glob
import
glob
import
logging
import
logging
import
os
import
shutil
import
tempfile
import
slapos.format
import
slapos.format
import
slapos.util
import
slapos.util
import
slapos.manager.cpuset
import
slapos.manager.cpuset
...
@@ -684,6 +687,48 @@ class TestComputer(SlapformatMixin):
...
@@ -684,6 +687,48 @@ class TestComputer(SlapformatMixin):
self
.
fakeCallAndRead
.
external_command_list
)
self
.
fakeCallAndRead
.
external_command_list
)
class
TestFormatDump
(
SlapformatMixin
):
def
setUp
(
self
):
super
(
TestFormatDump
,
self
).
setUp
()
self
.
restoreOs
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
def
test
(
self
):
computer
=
slapos
.
format
.
Computer
(
'computer'
,
instance_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance_root'
),
software_root
=
os
.
path
.
join
(
self
.
_tempdir
,
'software_root'
),
tap_ipv6
=
True
,
interface
=
slapos
.
format
.
Interface
(
logger
=
self
.
logger
,
name
=
'myinterface'
,
ipv4_local_network
=
'127.0.0.1/16'
),
partition_list
=
[
slapos
.
format
.
Partition
(
'partition'
,
'part_path'
,
slapos
.
format
.
User
(
'testuser'
),
[],
tap
=
slapos
.
format
.
Tap
(
'tap'
)),
])
global
USER_LIST
USER_LIST
=
[
'testuser'
]
global
INTERFACE_DICT
INTERFACE_DICT
[
'myinterface'
]
=
{
socket
.
AF_INET
:
[{
'addr'
:
'192.168.242.77'
,
'broadcast'
:
'127.0.0.1'
,
'netmask'
:
'255.255.255.0'
}],
socket
.
AF_INET6
:
[{
'addr'
:
'2a01:e35:2e27::e59c'
,
'netmask'
:
'ffff:ffff:ffff:ffff::'
}]
}
computer
.
format
(
alter_user
=
False
,
alter_network
=
False
,
create_tap
=
False
)
partition_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'instance_root'
,
'partition'
)
self
.
assertTrue
(
os
.
path
.
exists
(
partition_path
))
self
.
assertFalse
(
os
.
listdir
(
partition_path
))
xml_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'slapos.xml'
)
json_path
=
os
.
path
.
join
(
self
.
_tempdir
,
'slapos.json'
)
computer
.
dump
(
xml_path
,
json_path
,
self
.
logger
)
self
.
assertEqual
(
os
.
listdir
(
partition_path
),
[
'.slapos-resource'
])
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
super
(
TestFormatDump
,
self
).
tearDown
()
class
SlapGridPartitionMock
:
class
SlapGridPartitionMock
:
def
__init__
(
self
,
partition
):
def
__init__
(
self
,
partition
):
...
...
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