Commit 0983f1ca authored by Łukasz Nowak's avatar Łukasz Nowak

kvm: Fix disk wipe if many disks are used

parent 43b029e1
Pipeline #15004 failed with stage
...@@ -19,7 +19,7 @@ md5sum = 0d34ff81779115bf899f7bc752877b70 ...@@ -19,7 +19,7 @@ md5sum = 0d34ff81779115bf899f7bc752877b70
[template-kvm] [template-kvm]
filename = instance-kvm.cfg.jinja2 filename = instance-kvm.cfg.jinja2
md5sum = 4c5d8c723b6adb96fcac9690c0c900f7 md5sum = 9d0980144f91d10d8a5cee041f385d34
[template-kvm-cluster] [template-kvm-cluster]
filename = instance-kvm-cluster.cfg.jinja2.in filename = instance-kvm-cluster.cfg.jinja2.in
......
...@@ -1031,11 +1031,13 @@ context = ...@@ -1031,11 +1031,13 @@ context =
{% do part_list.append('wipe-disk-device-wrapper') -%} {% do part_list.append('wipe-disk-device-wrapper') -%}
[wipe-disk-device-wrapper] [wipe-disk-device-wrapper]
recipe = slapos.cookbook:wrapper recipe = slapos.recipe.template:jinja2
wrapper-path = ${directory:prerm}/slapos_wipe_device_disk template = inline:
command-line = {%- for disk_device in disk_device_path.split() %}
dd if=/dev/zero of={{disk_device_path}} bs=4096 count=500k dd if=/dev/zero of={{ disk_device }} bs=4096 count=500k
{%- endfor %}
rendered = ${directory:prerm}/slapos_wipe_device_disk
mode = 0700
{% endif -%} {% endif -%}
{% do part_list.append('whitelist-firewall') -%} {% do part_list.append('whitelist-firewall') -%}
......
...@@ -127,6 +127,20 @@ class KvmMixin(object): ...@@ -127,6 +127,20 @@ class KvmMixin(object):
if q['name'] != 'watchdog' and q['group'] != 'watchdog'])) if q['name'] != 'watchdog' and q['group'] != 'watchdog']))
return running_process_info.replace(hash_value, '{hash}') return running_process_info.replace(hash_value, '{hash}')
def raising_waitForInstance(self, max_retry):
with self.assertRaises(SlapOSNodeCommandError):
self.slap.waitForInstance(max_retry=max_retry)
def rerequestInstance(self, parameter_dict, state='started'):
software_url = self.getSoftwareURL()
software_type = self.getInstanceSoftwareType()
return self.slap.request(
software_release=software_url,
software_type=software_type,
partition_reference=self.default_partition_reference,
partition_parameter_kw=parameter_dict,
state=state)
@skipUnlessKvm @skipUnlessKvm
class TestInstance(InstanceTestCase, KvmMixin): class TestInstance(InstanceTestCase, KvmMixin):
...@@ -582,17 +596,7 @@ class FakeImageHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): ...@@ -582,17 +596,7 @@ class FakeImageHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return return
class FakeImageServerMixin(object): class FakeImageServerMixin(KvmMixin):
def rerequestInstance(self, parameter_dict, state='started'):
software_url = self.getSoftwareURL()
software_type = self.getInstanceSoftwareType()
return self.slap.request(
software_release=software_url,
software_type=software_type,
partition_reference=self.default_partition_reference,
partition_parameter_kw=parameter_dict,
state=state)
def startImageHttpServer(self): def startImageHttpServer(self):
self.image_source_directory = tempfile.mkdtemp() self.image_source_directory = tempfile.mkdtemp()
server = SocketServer.TCPServer( server = SocketServer.TCPServer(
...@@ -689,10 +693,6 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin): ...@@ -689,10 +693,6 @@ class TestBootImageUrlList(InstanceTestCase, FakeImageServerMixin):
self.stopImageHttpServer() self.stopImageHttpServer()
super(InstanceTestCase, self).tearDown() super(InstanceTestCase, self).tearDown()
def raising_waitForInstance(self, max_retry):
with self.assertRaises(SlapOSNodeCommandError):
self.slap.waitForInstance(max_retry=max_retry)
def test(self): def test(self):
partition_parameter_kw = { partition_parameter_kw = {
self.key: self.test_input % ( self.key: self.test_input % (
...@@ -1270,3 +1270,31 @@ class TestWhitelistFirewallRequestCluster(TestWhitelistFirewallRequest): ...@@ -1270,3 +1270,31 @@ class TestWhitelistFirewallRequestCluster(TestWhitelistFirewallRequest):
} }
} }
})} })}
@skipUnlessKvm
class TestDiskDevicePathWipeDiskOndestroy(InstanceTestCase, KvmMixin):
__partition_reference__ = 'ddpwdo'
kvm_instance_partition_reference = 'ddpwdo0'
def test(self):
self.rerequestInstance({
'disk-device-path': '/dev/virt0 /dev/virt1',
'wipe-disk-ondestroy': True
})
self.slap.waitForInstance(max_retry=2)
instance_path = os.path.join(
self.slap.instance_directory, self.kvm_instance_partition_reference)
slapos_wipe_device_disk = os.path.join(
instance_path, 'etc', 'prerm', 'slapos_wipe_device_disk')
# check prerm script, it's trusted that prerm manager really works
self.assertTrue(os.path.exists(slapos_wipe_device_disk))
with open(slapos_wipe_device_disk) as fh:
self.assertEqual(
fh.read().strip(),
r"""dd if=/dev/zero of=/dev/virt0 bs=4096 count=500k
dd if=/dev/zero of=/dev/virt1 bs=4096 count=500k"""
)
self.assertTrue(os.access(slapos_wipe_device_disk, os.X_OK))
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