From 193e2124469c19e6abf1e69a4eab745cdc0a01c6 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Fri, 7 Nov 2014 09:26:48 -0600
Subject: [PATCH 23/26] Move mediaPresent out of Device and into StorageDevice.

mediaPresent indicates whether a device node is backed by
readable/writeable media. It is generally only meaningful for root devices
(devices with no parents). There are only a few instances in which this
is relevant: cdrom/dvd, card readers, md containers, and some goofy raid
hardware that creates a zero-size block device node.
---
 blivet/devices/device.py  | 5 -----
 blivet/devices/md.py      | 9 ++-------
 blivet/devices/storage.py | 5 +++++
 tests/devices_test.py     | 6 ++----
 4 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/blivet/devices/device.py b/blivet/devices/device.py
index a28cc0d..d768f75 100644
--- a/blivet/devices/device.py
+++ b/blivet/devices/device.py
@@ -312,11 +312,6 @@ class Device(LockedObjectID):
 
         return services
 
-    @property
-    def mediaPresent(self):
-        """ True if this device contains usable media. """
-        return True
-
     @classmethod
     def isNameValid(cls, name): # pylint: disable=unused-argument
         """Is the device name valid for the device type?"""
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index e7fc900..9658919 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -565,15 +565,10 @@ class MDRaidArrayDevice(ContainerDevice, RaidDevice):
 
     @property
     def mediaPresent(self):
-        # Containers should not get any format handling done
-        # (the device node does not allow read / write calls)
+        # Containers effectively have no media since their device nodes do not
+        # allow read / write calls.
         if self.type == "mdcontainer":
             return False
-        # BIOS RAID sets should show as present even when teared down
-        elif self.type == "mdbiosraidarray":
-            return True
-        elif flags.testing:
-            return True
         else:
             return super(MDRaidArrayDevice, self).mediaPresent
 
diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index d8182a5..9203580 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -588,6 +588,11 @@ class StorageDevice(Device):
         return self.alignTargetSize(self.format.maxSize) if self.resizable else self.currentSize
 
     @property
+    def mediaPresent(self):
+        """ True if this device contains usable media. """
+        return True
+
+    @property
     def status(self):
         """ This device's status.
 
diff --git a/tests/devices_test.py b/tests/devices_test.py
index ba61068..44ecb2d 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -64,7 +64,7 @@ class DeviceStateTestCase(unittest.TestCase):
            "isleaf" : xform(self.assertTrue),
            "major" : xform(lambda x, m: self.assertEqual(x, 0, m)),
            "maxSize" : xform(lambda x, m: self.assertEqual(x, Size(0), m)),
-           "mediaPresent" : xform(self.assertFalse),
+           "mediaPresent" : xform(self.assertTrue),
            "minor" : xform(lambda x, m: self.assertEqual(x, 0, m)),
            "parents" : xform(lambda x, m: self.assertEqual(len(x), 0, m) and
                                     self.assertIsInstance(x, ParentList, m)),
@@ -373,6 +373,7 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
            devices=xform(lambda x, m: self.assertEqual(len(x), 1, m)),
            level=xform(lambda x, m: self.assertEqual(x.name, "container", m)),
            parents=xform(lambda x, m: self.assertEqual(len(x), 1, m)),
+           mediaPresent=xform(self.assertFalse),
            type=xform(lambda x, m: self.assertEqual(x, "mdcontainer", m)))
         self.stateCheck(self.dev2,
            createBitmap=xform(self.assertFalse),
@@ -417,7 +418,6 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
            devices=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
            isDisk=xform(self.assertTrue),
            level=xform(lambda x, m: self.assertEqual(x.number, 0, m)),
-           mediaPresent=xform(self.assertTrue),
            memberDevices=xform(lambda x, m: self.assertEqual(x, 2, m)),
            parents=xform(lambda x, m: self.assertNotEqual(x, [], m)),
            partitionable=xform(self.assertTrue),
@@ -438,7 +438,6 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
            devices=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
            isDisk=xform(self.assertTrue),
            level=xform(lambda x, m: self.assertEqual(x.number, 1, m)),
-           mediaPresent=xform(self.assertTrue),
            memberDevices=xform(lambda x, m: self.assertEqual(x, 2, m)),
            parents=xform(lambda x, m: self.assertNotEqual(x, [], m)),
            partitionable=xform(self.assertTrue),
@@ -450,7 +449,6 @@ class MDRaidArrayDeviceTestCase(DeviceStateTestCase):
            devices=xform(lambda x, m: self.assertEqual(len(x), 2, m)),
            isDisk=xform(self.assertTrue),
            level=xform(lambda x, m: self.assertEqual(x.number, 1, m)),
-           mediaPresent=xform(self.assertTrue),
            memberDevices=xform(lambda x, m: self.assertEqual(x, 2, m)),
            parents=xform(lambda x, m: self.assertNotEqual(x, [], m)),
            partitionable=xform(self.assertTrue),
-- 
1.9.3

