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