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