Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
105
Merge Requests
105
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
37cb0fff
Commit
37cb0fff
authored
Sep 17, 2021
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kvm: small cleanup before further changes about iso image path
parent
840f25fb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
52 deletions
+38
-52
software/kvm/buildout.hash.cfg
software/kvm/buildout.hash.cfg
+1
-1
software/kvm/instance.cfg.in
software/kvm/instance.cfg.in
+1
-1
software/kvm/test/test.py
software/kvm/test/test.py
+36
-50
No files found.
software/kvm/buildout.hash.cfg
View file @
37cb0fff
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
[template]
[template]
filename = instance.cfg.in
filename = instance.cfg.in
md5sum = 0d
34ff81779115bf899f7bc752877b70
md5sum = 0d
9d24ef59248da8fa47535f54b83ba8
[template-kvm]
[template-kvm]
filename = instance-kvm.cfg.jinja2
filename = instance-kvm.cfg.jinja2
...
...
software/kvm/instance.cfg.in
View file @
37cb0fff
...
@@ -82,7 +82,7 @@ extra-context =
...
@@ -82,7 +82,7 @@ extra-context =
raw dash_executable_location ${dash:location}/bin/dash
raw dash_executable_location ${dash:location}/bin/dash
raw dnsresolver_executable ${buildout:bin-directory}/dnsresolver
raw dnsresolver_executable ${buildout:bin-directory}/dnsresolver
raw dcron_executable_location ${dcron:location}/sbin/crond
raw dcron_executable_location ${dcron:location}/sbin/crond
raw debian_amd64_netinst_location ${debian-amd64-netinst.iso:
location}/${debian-amd64-netinst.iso:filename
}
raw debian_amd64_netinst_location ${debian-amd64-netinst.iso:
target
}
raw whitelist_domains_default ${whitelist-domains-default:location}/${whitelist-domains-default:filename}
raw whitelist_domains_default ${whitelist-domains-default:location}/${whitelist-domains-default:filename}
raw whitelist_firewall_download_controller ${whitelist-firewall-download-controller:target}
raw whitelist_firewall_download_controller ${whitelist-firewall-download-controller:target}
raw image_download_controller ${image-download-controller:target}
raw image_download_controller ${image-download-controller:target}
...
...
software/kvm/test/test.py
View file @
37cb0fff
...
@@ -31,10 +31,12 @@ import os
...
@@ -31,10 +31,12 @@ import os
import
glob
import
glob
import
hashlib
import
hashlib
import
psutil
import
psutil
import
re
import
requests
import
requests
import
six
import
six
import
slapos.util
import
slapos.util
import
sqlite3
import
sqlite3
import
stat
from
six.moves.urllib.parse
import
parse_qs
,
urlparse
from
six.moves.urllib.parse
import
parse_qs
,
urlparse
import
unittest
import
unittest
import
subprocess
import
subprocess
...
@@ -812,6 +814,28 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
...
@@ -812,6 +814,28 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
self
.
stopImageHttpServer
()
self
.
stopImageHttpServer
()
super
(
InstanceTestCase
,
self
).
tearDown
()
super
(
InstanceTestCase
,
self
).
tearDown
()
def
getRunningImageList
(
self
,
kvm_instance_partition
,
_match_cdrom
=
re
.
compile
(
'file=(.+),media=cdrom$'
).
match
,
):
with
self
.
slap
.
instance_supervisor_rpc
as
instance_supervisor
:
kvm_pid
=
next
(
q
for
q
in
instance_supervisor
.
getAllProcessInfo
()
if
'kvm-'
in
q
[
'name'
])[
'pid'
]
software_root
=
os
.
path
.
join
(
self
.
slap
.
software_directory
,
hashlib
.
md5
(
self
.
getSoftwareURL
().
encode
()).
hexdigest
())
image_list
=
[]
for
entry
in
psutil
.
Process
(
kvm_pid
).
cmdline
():
m
=
_match_cdrom
(
entry
)
if
m
:
path
=
m
.
group
(
1
)
st
=
os
.
stat
(
path
)
if
stat
.
S_ISREG
(
st
.
st_mode
)
and
st
.
st_size
:
image_list
.
append
(
path
.
replace
(
kvm_instance_partition
,
'${inst}'
)
.
replace
(
software_root
,
'${soft}'
)
)
return
image_list
def
test
(
self
):
def
test
(
self
):
partition_parameter_kw
=
{
partition_parameter_kw
=
{
self
.
key
:
self
.
test_input
%
(
self
.
key
:
self
.
test_input
%
(
...
@@ -843,23 +867,6 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
...
@@ -843,23 +867,6 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
self
.
assertTrue
(
os
.
path
.
islink
(
image2_link
))
self
.
assertTrue
(
os
.
path
.
islink
(
image2_link
))
self
.
assertEqual
(
os
.
readlink
(
image2_link
),
image2
)
self
.
assertEqual
(
os
.
readlink
(
image2_link
),
image2
)
def
getRunningImageList
():
running_image_list
=
[]
with
self
.
slap
.
instance_supervisor_rpc
as
instance_supervisor
:
kvm_pid
=
[
q
for
q
in
instance_supervisor
.
getAllProcessInfo
()
if
'kvm-'
in
q
[
'name'
]][
0
][
'pid'
]
kvm_process
=
psutil
.
Process
(
kvm_pid
)
software_root
=
'/'
.
join
([
self
.
slap
.
software_directory
,
hashlib
.
md5
(
self
.
getSoftwareURL
().
encode
(
'utf-8'
)).
hexdigest
()])
for
entry
in
kvm_process
.
cmdline
():
if
entry
.
startswith
(
'file'
)
and
'media=cdrom'
in
entry
:
# do cleanups
entry
=
entry
.
replace
(
software_root
,
''
)
entry
=
entry
.
replace
(
kvm_instance_partition
,
''
)
running_image_list
.
append
(
entry
)
return
running_image_list
# mimic the requirement: restart the instance by requesting it stopped and
# mimic the requirement: restart the instance by requesting it stopped and
# then started started, like user have to do it
# then started started, like user have to do it
self
.
rerequestInstance
(
partition_parameter_kw
,
state
=
'stopped'
)
self
.
rerequestInstance
(
partition_parameter_kw
,
state
=
'stopped'
)
...
@@ -869,12 +876,11 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
...
@@ -869,12 +876,11 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
self
.
assertEqual
(
self
.
assertEqual
(
[
[
'file=/srv/%s/image_001,media=cdrom'
%
(
self
.
image_directory
,),
'${inst}/srv/%s/image_001'
%
self
.
image_directory
,
'file=/srv/%s/image_002,media=cdrom'
%
(
self
.
image_directory
,),
'${inst}/srv/%s/image_002'
%
self
.
image_directory
,
'file=/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso,'
'${soft}/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso'
,
'media=cdrom'
],
],
getRunningImageList
(
)
self
.
getRunningImageList
(
kvm_instance_partition
)
)
)
# cleanup of images works, also asserts that configuration changes are
# cleanup of images works, also asserts that configuration changes are
...
@@ -896,9 +902,8 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
...
@@ -896,9 +902,8 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
# again only default image is available in the running process
# again only default image is available in the running process
self
.
assertEqual
(
self
.
assertEqual
(
[
'file=/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso,'
[
'${soft}/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso'
],
'media=cdrom'
],
self
.
getRunningImageList
(
kvm_instance_partition
)
getRunningImageList
()
)
)
def
assertPromiseFails
(
self
,
promise
):
def
assertPromiseFails
(
self
,
promise
):
...
@@ -1032,23 +1037,6 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
...
@@ -1032,23 +1037,6 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
kvm_instance_partition
=
os
.
path
.
join
(
kvm_instance_partition
=
os
.
path
.
join
(
self
.
slap
.
instance_directory
,
self
.
kvm_instance_partition_reference
)
self
.
slap
.
instance_directory
,
self
.
kvm_instance_partition_reference
)
def
getRunningImageList
():
running_image_list
=
[]
with
self
.
slap
.
instance_supervisor_rpc
as
instance_supervisor
:
kvm_pid
=
[
q
for
q
in
instance_supervisor
.
getAllProcessInfo
()
if
'kvm-'
in
q
[
'name'
]][
0
][
'pid'
]
kvm_process
=
psutil
.
Process
(
kvm_pid
)
software_root
=
'/'
.
join
([
self
.
slap
.
software_directory
,
hashlib
.
md5
(
self
.
getSoftwareURL
().
encode
(
'utf-8'
)).
hexdigest
()])
for
entry
in
kvm_process
.
cmdline
():
if
entry
.
startswith
(
'file'
)
and
'media=cdrom'
in
entry
:
# do cleanups
entry
=
entry
.
replace
(
software_root
,
''
)
entry
=
entry
.
replace
(
kvm_instance_partition
,
''
)
running_image_list
.
append
(
entry
)
return
running_image_list
# mimic the requirement: restart the instance by requesting it stopped and
# mimic the requirement: restart the instance by requesting it stopped and
# then started started, like user have to do it
# then started started, like user have to do it
self
.
rerequestInstance
(
partition_parameter_kw
,
state
=
'stopped'
)
self
.
rerequestInstance
(
partition_parameter_kw
,
state
=
'stopped'
)
...
@@ -1058,12 +1046,11 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
...
@@ -1058,12 +1046,11 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
self
.
assertEqual
(
self
.
assertEqual
(
[
[
'file=/srv/boot-image-url-select-repository/image_001,media=cdrom'
,
'${inst}/srv/boot-image-url-select-repository/image_001'
,
'file=/srv/boot-image-url-list-repository/image_001,media=cdrom'
,
'${inst}/srv/boot-image-url-list-repository/image_001'
,
'file=/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso,'
'${soft}/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso'
,
'media=cdrom'
],
],
getRunningImageList
(
)
self
.
getRunningImageList
(
kvm_instance_partition
)
)
)
# cleanup of images works, also asserts that configuration changes are
# cleanup of images works, also asserts that configuration changes are
...
@@ -1100,9 +1087,8 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
...
@@ -1100,9 +1087,8 @@ class TestBootImageUrlSelect(TestBootImageUrlList):
# again only default image is available in the running process
# again only default image is available in the running process
self
.
assertEqual
(
self
.
assertEqual
(
[
'file=/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso,'
[
'${soft}/parts/debian-amd64-netinst.iso/debian-amd64-netinst.iso'
],
'media=cdrom'
],
self
.
getRunningImageList
(
kvm_instance_partition
)
getRunningImageList
()
)
)
...
...
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