Commit 37cb0fff authored by Julien Muchembled's avatar Julien Muchembled

kvm: small cleanup before further changes about iso image path

parent 840f25fb
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
[template] [template]
filename = instance.cfg.in filename = instance.cfg.in
md5sum = 0d34ff81779115bf899f7bc752877b70 md5sum = 0d9d24ef59248da8fa47535f54b83ba8
[template-kvm] [template-kvm]
filename = instance-kvm.cfg.jinja2 filename = instance-kvm.cfg.jinja2
......
...@@ -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}
......
...@@ -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()
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment