Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos
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
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos
Commits
3806e5d5
Commit
3806e5d5
authored
Apr 22, 2024
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/kvm: Test virtual-hard-drive-url
parent
2f5c02b4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
15 deletions
+93
-15
software/kvm/buildout.hash.cfg
software/kvm/buildout.hash.cfg
+1
-1
software/kvm/template/template-kvm-run.in
software/kvm/template/template-kvm-run.in
+2
-0
software/kvm/test/test.py
software/kvm/test/test.py
+90
-14
No files found.
software/kvm/buildout.hash.cfg
View file @
3806e5d5
...
@@ -59,7 +59,7 @@ md5sum = 6328f99728284847b8dd1146aadeae1b
...
@@ -59,7 +59,7 @@ md5sum = 6328f99728284847b8dd1146aadeae1b
[template-kvm-run]
[template-kvm-run]
filename = template/template-kvm-run.in
filename = template/template-kvm-run.in
md5sum =
1663af08ea7afa8d3fa091bf0c2ea1ca
md5sum =
f0190843e3979742fe9e29b8a607539f
[template-kvm-controller]
[template-kvm-controller]
filename = template/kvm-controller-run.in
filename = template/kvm-controller-run.in
...
...
software/kvm/template/template-kvm-run.in
View file @
3806e5d5
...
@@ -176,6 +176,8 @@ if len(disk_info_list) == 1 and not os.path.exists(disk_info_list[0]['path']) an
...
@@ -176,6 +176,8 @@ if len(disk_info_list) == 1 and not os.path.exists(disk_info_list[0]['path']) an
if image_config['error-amount'] == 0:
if image_config['error-amount'] == 0:
image = image_config['image-list'][0]
image = image_config['image-list'][0]
downloaded_image = os.path.join(image_config['destination-directory'], image['destination'])
downloaded_image = os.path.join(image_config['destination-directory'], image['destination'])
if not os.path.exists(downloaded_image):
raise ValueError('virtual-hard-drive-url not present yet')
# previous version was using disk in place, but here it would result with
# previous version was using disk in place, but here it would result with
# redownload, so copy it
# redownload, so copy it
if virtual_hard_drive_gzipped == 'true':
if virtual_hard_drive_gzipped == 'true':
...
...
software/kvm/test/test.py
View file @
3806e5d5
...
@@ -30,6 +30,7 @@ import http.server
...
@@ -30,6 +30,7 @@ import http.server
import
json
import
json
import
os
import
os
import
glob
import
glob
import
gzip
import
hashlib
import
hashlib
import
psutil
import
psutil
import
re
import
re
...
@@ -878,6 +879,20 @@ class HttpHandler(http.server.SimpleHTTPRequestHandler):
...
@@ -878,6 +879,20 @@ class HttpHandler(http.server.SimpleHTTPRequestHandler):
class
FakeImageServerMixin
(
KvmMixin
):
class
FakeImageServerMixin
(
KvmMixin
):
@
classmethod
def
setUpClass
(
cls
):
try
:
cls
.
startImageHttpServer
()
super
().
setUpClass
()
except
BaseException
:
cls
.
stopImageHttpServer
()
raise
@
classmethod
def
tearDownClass
(
cls
):
super
().
tearDownClass
()
cls
.
stopImageHttpServer
()
@
classmethod
@
classmethod
def
startImageHttpServer
(
cls
):
def
startImageHttpServer
(
cls
):
cls
.
image_source_directory
=
tempfile
.
mkdtemp
()
cls
.
image_source_directory
=
tempfile
.
mkdtemp
()
...
@@ -908,10 +923,31 @@ class FakeImageServerMixin(KvmMixin):
...
@@ -908,10 +923,31 @@ class FakeImageServerMixin(KvmMixin):
cls
.
image_source_directory
,
cls
.
fake_image3_md5sum
),
'wb'
)
as
fh
:
cls
.
image_source_directory
,
cls
.
fake_image3_md5sum
),
'wb'
)
as
fh
:
fh
.
write
(
fake_image3_content
)
fh
.
write
(
fake_image3_content
)
# real fake image
cls
.
image_source_directory
=
tempfile
.
mkdtemp
()
real_image_input
=
os
.
path
.
join
(
cls
.
image_source_directory
,
'real.img'
)
subprocess
.
check_call
([
cls
.
qemu_img
,
"create"
,
"-f"
,
"qcow2"
,
real_image_input
,
"1M"
])
with
open
(
real_image_input
,
'rb'
)
as
fh
:
real_image_content
=
fh
.
read
()
cls
.
real_image_md5sum
=
hashlib
.
md5
(
real_image_content
).
hexdigest
()
with
open
(
os
.
path
.
join
(
cls
.
image_source_directory
,
cls
.
real_image_md5sum
),
'wb'
)
as
fh
:
fh
.
write
(
real_image_content
)
real_gzip_content
=
gzip
.
compress
(
real_image_content
)
cls
.
real_gzip_md5sum
=
hashlib
.
md5
(
real_gzip_content
).
hexdigest
()
with
open
(
os
.
path
.
join
(
cls
.
image_source_directory
,
cls
.
real_gzip_md5sum
),
'wb'
)
as
fh
:
fh
.
write
(
real_gzip_content
)
url
=
'http://%s:%s'
%
server
.
server_address
url
=
'http://%s:%s'
%
server
.
server_address
cls
.
fake_image
=
'/'
.
join
([
url
,
cls
.
fake_image_md5sum
])
cls
.
fake_image
=
'/'
.
join
([
url
,
cls
.
fake_image_md5sum
])
cls
.
fake_image2
=
'/'
.
join
([
url
,
cls
.
fake_image2_md5sum
])
cls
.
fake_image2
=
'/'
.
join
([
url
,
cls
.
fake_image2_md5sum
])
cls
.
fake_image3
=
'/'
.
join
([
url
,
cls
.
fake_image3_md5sum
])
cls
.
fake_image3
=
'/'
.
join
([
url
,
cls
.
fake_image3_md5sum
])
cls
.
real_image
=
'/'
.
join
([
url
,
cls
.
real_image_md5sum
])
cls
.
real_gzip
=
'/'
.
join
([
url
,
cls
.
real_gzip_md5sum
])
old_dir
=
os
.
path
.
realpath
(
os
.
curdir
)
old_dir
=
os
.
path
.
realpath
(
os
.
curdir
)
os
.
chdir
(
cls
.
image_source_directory
)
os
.
chdir
(
cls
.
image_source_directory
)
...
@@ -936,6 +972,60 @@ class FakeImageServerMixin(KvmMixin):
...
@@ -936,6 +972,60 @@ class FakeImageServerMixin(KvmMixin):
shutil
.
rmtree
(
cls
.
image_source_directory
)
shutil
.
rmtree
(
cls
.
image_source_directory
)
@
skipUnlessKvm
class
TestVirtualHardDriveUrl
(
FakeImageServerMixin
,
KVMTestCase
):
__partition_reference__
=
'vhdu'
kvm_instance_partition_reference
=
'vhdu0'
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
"virtual-hard-drive-url"
:
cls
.
real_image
,
"virtual-hard-drive-md5sum"
:
cls
.
real_image_md5sum
}
def
test
(
self
):
kvm_partition
=
os
.
path
.
join
(
self
.
slap
.
instance_directory
,
self
.
kvm_instance_partition_reference
)
image_repository
=
os
.
path
.
join
(
kvm_partition
,
'srv'
,
'virtual-hard-drive-url-repository'
)
self
.
assertEqual
(
[
self
.
getInstanceParameterDict
()[
'virtual-hard-drive-md5sum'
]],
os
.
listdir
(
image_repository
)
)
destination_image
=
os
.
path
.
join
(
kvm_partition
,
'srv'
,
'virtual.qcow2'
)
# compare result of qemu-img info of repository and the one
qemu_img_list
=
[
self
.
qemu_img
,
'info'
,
'-U'
,
'--output'
,
'json'
]
source_image_info_json
=
json
.
loads
(
subprocess
.
check_output
(
qemu_img_list
+
[
os
.
path
.
join
(
self
.
image_source_directory
,
self
.
real_image_md5sum
)]))
destination_image_info_json
=
json
.
loads
(
subprocess
.
check_output
(
qemu_img_list
+
[
destination_image
]))
source_image_info_json
.
pop
(
'filename'
)
destination_image_info_json
.
pop
(
'filename'
)
# the best possible way to assure that provided image is used is by
# comparing the result of qemu-img info for both
self
.
assertEqual
(
source_image_info_json
,
destination_image_info_json
)
@
skipUnlessKvm
class
TestVirtualHardDriveUrlGzipped
(
TestVirtualHardDriveUrl
):
__partition_reference__
=
'vhdug'
kvm_instance_partition_reference
=
'vhdug0'
@
classmethod
def
getInstanceParameterDict
(
cls
):
return
{
"virtual-hard-drive-url"
:
cls
.
real_gzip
,
"virtual-hard-drive-md5sum"
:
cls
.
real_gzip_md5sum
,
"virtual-hard-drive-gzipped"
:
True
}
@
skipUnlessKvm
@
skipUnlessKvm
class
TestBootImageUrlList
(
KVMTestCase
,
FakeImageServerMixin
):
class
TestBootImageUrlList
(
KVMTestCase
,
FakeImageServerMixin
):
__partition_reference__
=
'biul'
__partition_reference__
=
'biul'
...
@@ -976,20 +1066,6 @@ class TestBootImageUrlList(KVMTestCase, FakeImageServerMixin):
...
@@ -976,20 +1066,6 @@ class TestBootImageUrlList(KVMTestCase, FakeImageServerMixin):
cls
.
fake_image2_md5sum
)
cls
.
fake_image2_md5sum
)
}
}
@
classmethod
def
setUpClass
(
cls
):
try
:
cls
.
startImageHttpServer
()
super
().
setUpClass
()
except
BaseException
:
cls
.
stopImageHttpServer
()
raise
@
classmethod
def
tearDownClass
(
cls
):
super
().
tearDownClass
()
cls
.
stopImageHttpServer
()
def
tearDown
(
self
):
def
tearDown
(
self
):
# clean up the instance for other tests
# clean up the instance for other tests
# 1st remove all images...
# 1st remove all images...
...
...
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