From 0b6f818f46e3b7c5b9be33216ef8438f59d7bcf1 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Thu, 18 Oct 2018 10:07:31 -0400
Subject: [PATCH] Wipe all stale metadata after creating md array. (#1639682)
---
blivet/devices/md.py | 4 ++++
tests/devices_test/device_methods_test.py | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index dad099e8..6a837df0 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -31,6 +31,7 @@
from ..devicelibs import mdraid, raid
from .. import errors
+from ..formats import DeviceFormat
from .. import util
from ..static_data import pvs_info
from ..storage_log import log_method_call
@@ -563,6 +564,9 @@ def remove_stale_lvm():
remove_stale_lvm()
+ # remove any other stale metadata before proceeding
+ DeviceFormat(device=self.path, exists=True).destroy()
+
def _create(self):
""" Create the device. """
log_method_call(self, self.name, status=self.status)
diff --git a/tests/devices_test/device_methods_test.py b/tests/devices_test/device_methods_test.py
index 8e40e6b6..12d5f7d8 100644
--- a/tests/devices_test/device_methods_test.py
+++ b/tests/devices_test/device_methods_test.py
@@ -404,6 +404,7 @@ def test_setup(self):
self.assertTrue(self.patches["md"].activate.called)
def test_create(self):
- super(MDRaidArrayDeviceMethodsTestCase, self).test_create()
+ with patch("blivet.devices.md.DeviceFormat"):
+ super(MDRaidArrayDeviceMethodsTestCase, self).test_create()
self.device._create()
self.assertTrue(self.patches["md"].create.called)