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
0c9ffad7
Commit
0c9ffad7
authored
Sep 15, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: First implementation with jIO API
parent
08a76947
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
10 deletions
+121
-10
slapos/format.py
slapos/format.py
+43
-10
slapos/tests/test_slapformat.py
slapos/tests/test_slapformat.py
+78
-0
No files found.
slapos/format.py
View file @
0c9ffad7
...
...
@@ -338,8 +338,40 @@ class Computer(object):
if
conf
.
key_file
and
conf
.
cert_file
:
connection_dict
[
'key_file'
]
=
conf
.
key_file
connection_dict
[
'cert_file'
]
=
conf
.
cert_file
if
conf
.
slapgrid_jio_uri
:
connection_dict
[
"slapgrid_jio_uri"
]
=
conf
.
slapgrid_jio_uri
slap_instance
.
initializeConnection
(
conf
.
master_url
,
**
connection_dict
)
if
slap_instance
.
jio_api_connector
:
partition_list
=
[]
for
partition
in
self
.
partition_list
:
ip_list
=
[]
network_interface
=
partition
.
tap
.
name
if
partition
.
tap
else
partition
.
reference
for
address
in
partition
.
address_list
:
ip_list
.
append
({
"ip-address"
:
address
[
"addr"
],
"network-interface"
:
network_interface
,
})
if
partition
.
tap
and
partition
.
tap
.
ipv4_addr
:
ip_list
.
append
({
"ip-address"
:
partition
.
tap
.
ipv4_addr
,
"network-interface"
:
partition
.
tap
.
name
,
"gateway-ip-address"
:
partition
.
tap
.
ipv4_gateway
,
"netmask"
:
partition
.
tap
.
netmask
,
"network-address"
:
partition
.
tap
.
ipv4_network
})
partition_list
.
append
({
"partition_id"
:
partition
.
reference
,
"ip_list"
:
ip_list
})
if
conf
.
dry_run
:
return
slap_instance
.
jio_api_connector
.
put
({
"compute_node_id"
:
self
.
reference
,
"compute_partition_list"
:
partition_list
})
else
:
slap_computer
=
slap_instance
.
registerComputer
(
self
.
reference
)
if
conf
.
dry_run
:
...
...
@@ -1404,6 +1436,7 @@ def do_format(conf):
computer
.
update
()
# Dumping and sending to the erp5 the current configuration
import
pdb
;
pdb
.
set_trace
()
if
not
conf
.
dry_run
:
computer
.
dump
(
path_to_xml
=
conf
.
computer_xml
,
path_to_json
=
conf
.
computer_json
,
...
...
slapos/tests/test_slapformat.py
View file @
0c9ffad7
...
...
@@ -29,6 +29,7 @@
from
__future__
import
print_function
import
glob
import
json
import
logging
import
os
import
shutil
...
...
@@ -51,6 +52,8 @@ import os
import
pwd
import
time
import
mock
import
httmock
from
six.moves.urllib
import
parse
from
.test_slapgrid
import
DummyManager
...
...
@@ -686,6 +689,81 @@ class TestFormatDump(SlapformatMixin):
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
super
(
TestFormatDump
,
self
).
tearDown
()
class
TestConfForAPI
():
def
__init__
(
self
):
self
.
master_url
=
"https://127.0.0.1"
self
.
slapgrid_jio_uri
=
"https://127.0.0.1/api/"
self
.
key_file
=
None
self
.
cert_file
=
None
self
.
dry_run
=
False
class
TestFormatSendToMaster
(
SlapformatMixin
):
def
setUp
(
self
):
super
(
TestFormatSendToMaster
,
self
).
setUp
()
self
.
restoreOs
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
sequence
=
[]
self
.
body_sequence
=
[]
def
jio_api_request_handler
(
self
,
url
,
req
):
self
.
sequence
.
append
(
url
.
path
)
if
req
.
method
==
'GET'
:
qs
=
parse
.
parse_qs
(
url
.
query
)
else
:
qs
=
parse
.
parse_qs
(
req
.
body
)
if
url
.
path
.
startswith
(
'/api/'
):
content
=
json
.
loads
(
req
.
body
)
self
.
body_sequence
.
append
(
content
)
return
json
.
dumps
({})
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
)
test_configuration
=
TestConfForAPI
()
with
httmock
.
HTTMock
(
self
.
jio_api_request_handler
):
computer
.
send
(
test_configuration
)
self
.
assertEqual
(
self
.
sequence
,
[
'/getHateoasUrl'
,
'/api/put/'
])
self
.
assertEqual
(
self
.
body_sequence
,
[
{
'compute_node_id'
:
'computer'
,
'compute_partition_list'
:
[
{
'ip_list'
:
[
{
'ip-address'
:
computer
.
partition_list
[
0
].
address_list
[
0
][
"addr"
],
'network-interface'
:
'tap'
},
{
'ip-address'
:
computer
.
partition_list
[
0
].
address_list
[
1
][
"addr"
],
'network-interface'
:
'tap'
}
],
'partition_id'
:
'partition'
}
]
}
]
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
_tempdir
,
True
)
super
(
TestFormatSendToMaster
,
self
).
tearDown
()
class
SlapGridPartitionMock
:
...
...
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