From 22d784fe117d67215e379bc0698c4ca33da7007b Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Fri, 6 Mar 2015 14:20:20 -0600
Subject: [PATCH 18/19] Add some console print statements and one safety
 measure for debugging.

---
 blivet/actionlist.py     | 2 ++
 blivet/event.py          | 2 ++
 blivet/flags.py          | 1 +
 blivet/handler.py        | 7 +++++++
 examples/factory.py      | 2 ++
 examples/lvm.py          | 2 ++
 examples/partitioning.py | 2 ++
 7 files changed, 18 insertions(+)

diff --git a/blivet/actionlist.py b/blivet/actionlist.py
index 48cad7c..b1920e1 100644
--- a/blivet/actionlist.py
+++ b/blivet/actionlist.py
@@ -276,6 +276,8 @@ class ActionList(object):
         self._preProcess(devices=devices)
 
         for action in self._actions[:]:
+            if flags.console_debug:
+                print action
             log.info("executing action: %s", action)
             if dryRun:
                 continue
diff --git a/blivet/event.py b/blivet/event.py
index 50595a2..69789b7 100644
--- a/blivet/event.py
+++ b/blivet/event.py
@@ -280,6 +280,8 @@ class UdevEventManager(EventManager):
 
     def enqueue_event(self, *args, **kwargs):
         event = UdevEvent(args[0], args[1])
+        if flags.console_debug:
+            print "->", event
         log.debug("-> %s", event)
         self._queue.enqueue(event)
 
diff --git a/blivet/flags.py b/blivet/flags.py
index 3d7fb6d..92f6639 100644
--- a/blivet/flags.py
+++ b/blivet/flags.py
@@ -74,6 +74,7 @@ class Flags(object):
         self.update_from_boot_cmdline()
         self.allow_imperfect_devices = True
         self.debug_threads = False
+        self.console_debug = True
 
     def get_boot_cmdline(self):
         buf = open("/proc/cmdline").read().strip()
diff --git a/blivet/handler.py b/blivet/handler.py
index d4a4653..f97bc72 100644
--- a/blivet/handler.py
+++ b/blivet/handler.py
@@ -28,6 +28,7 @@ from six import add_metaclass
 
 from . import udev
 from .errors import DeviceError, EventQueueEmptyError
+from .flags import flags
 from .formats import getFormat
 from .storage_log import log_method_call
 from .threads import SynchronizedMeta
@@ -51,6 +52,8 @@ class EventHandler(object):
             log.debug("uevent queue is empty")
             return
 
+        if flags.console_debug:
+            print event
         currentThread().name = "Event%d" % event.id
         log.debug("event: %s", event)
         if event.action == "add":
@@ -567,6 +570,10 @@ class EventHandler(object):
         if expected:
             return
 
+        if not expected:
+            log.error("unexpected change event on %s", name)
+            return
+
         if reformatted:
             log.info("%s was reformatted from outside of blivet", device.name)
             self.devicetree.cancelDiskActions(device.disks)
diff --git a/examples/factory.py b/examples/factory.py
index 7c9cd83..e745250 100644
--- a/examples/factory.py
+++ b/examples/factory.py
@@ -3,6 +3,7 @@ import os
 from examples.common import print_devices
 
 import blivet
+from blivet.flags import flags
 from blivet.size import Size
 from blivet.util import set_up_logging, create_sparse_tempfile
 
@@ -15,6 +16,7 @@ b.config.diskImages["disk1"] = disk1_file
 disk2_file = create_sparse_tempfile("disk2", Size("100GiB"))
 b.config.diskImages["disk2"] = disk2_file
 
+flags.console_debug = True
 b.reset()
 
 try:
diff --git a/examples/lvm.py b/examples/lvm.py
index 90208be..ad201bf 100644
--- a/examples/lvm.py
+++ b/examples/lvm.py
@@ -3,6 +3,7 @@ import os
 from examples.common import print_devices
 
 import blivet
+from blivet.flags import flags
 from blivet.size import Size
 from blivet.util import set_up_logging, create_sparse_tempfile
 
@@ -13,6 +14,7 @@ b = blivet.Blivet()   # create an instance of Blivet (don't add system devices)
 disk1_file = create_sparse_tempfile("disk1", Size("100GiB"))
 b.config.diskImages["disk1"] = disk1_file
 
+flags.console_debug = True
 b.reset()
 
 try:
diff --git a/examples/partitioning.py b/examples/partitioning.py
index 1e4f0db..1a75a6c 100644
--- a/examples/partitioning.py
+++ b/examples/partitioning.py
@@ -3,6 +3,7 @@ import os
 from examples.common import print_devices
 
 import blivet
+from blivet.flags import flags
 from blivet.size import Size
 from blivet.util import set_up_logging, create_sparse_tempfile
 
@@ -15,6 +16,7 @@ b.config.diskImages["disk1"] = disk1_file
 disk2_file = create_sparse_tempfile("disk2", Size("100GiB"))
 b.config.diskImages["disk2"] = disk2_file
 
+flags.console_debug = True
 b.reset()
 
 try:
-- 
1.9.3

