[node-patches] Change in ovirt-node[master]: Improve utils.system.LVM().vgs()

fabiand at fedoraproject.org fabiand at fedoraproject.org
Fri Jun 27 08:47:41 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: Improve utils.system.LVM().vgs()
......................................................................

Improve utils.system.LVM().vgs()

Add some documentation.

Change-Id: I0e04564256a10ab6434117de3b585396d599c503
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/Makefile.check
M src/ovirt/node/installer/core/confirmation_page.py
M src/ovirt/node/installer/core/welcome_page.py
M src/ovirt/node/utils/system.py
4 files changed, 28 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/28/29328/1

diff --git a/src/Makefile.check b/src/Makefile.check
index e6f87b9..ea009fd 100644
--- a/src/Makefile.check
+++ b/src/Makefile.check
@@ -22,7 +22,7 @@
 	@echo Passed $@
 
 %.doctest:
-	if grep -q ">>>" "$*"; then python -m doctest "$*" ; else : ; fi
+	@if grep -q ">>>" "$*" ; then set -x ; python -m doctest "$*" ; fi ;
 
 check-static-pep8: $(PYTHONSOURCES:%=%.pep8)
 	@echo Passed $@
diff --git a/src/ovirt/node/installer/core/confirmation_page.py b/src/ovirt/node/installer/core/confirmation_page.py
index c018864..a54eabe 100644
--- a/src/ovirt/node/installer/core/confirmation_page.py
+++ b/src/ovirt/node/installer/core/confirmation_page.py
@@ -123,8 +123,8 @@
     def _storage_tagged(self, dev):
         found = False
         for vg in LVM().vgs():
-            if dev in LVM.VG(vg).pv_names and "storage_domain" in \
-                    " ".join(LVM.VG(vg).tags):
+            if dev in vg.pv_names and "storage_domain" in \
+                    " ".join(vg.tags):
                 found = True
         return found
 
diff --git a/src/ovirt/node/installer/core/welcome_page.py b/src/ovirt/node/installer/core/welcome_page.py
index f19d13b..0d439fc 100644
--- a/src/ovirt/node/installer/core/welcome_page.py
+++ b/src/ovirt/node/installer/core/welcome_page.py
@@ -91,8 +91,8 @@
 
         media = utils.system.InstallationMedia()
         installed = utils.system.InstalledMedia()
-        if (installed.available()
-            and (media.version_major != installed.version_major)):
+        is_installed = installed.available()
+        if is_installed and (media.version_major != installed.version_major):
             block_upgrade = True
         elif utils.system.has_hostvg():
             has_hostvg = True
diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index 42412f7..4c44680 100644
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -939,27 +939,39 @@
     """
 
     def vgs(self):
-        return self._query_lvm("vg_name") if "No volume groups found" not in \
-            self._query_lvm("vg_name") else []
+        """Return a list of VG instances for each VG on the host
+        """
+        return [LVM.VG(n) for n in self._query_vgs("vg_name")]
 
     class VG(base.Base):
+        """Wrapper around the 'lvm vgs' command
+        """
         def __init__(self, name):
             self.name = name
 
         @property
         def tags(self):
-            return LVM._query_lvm("tags", self.name)
+            """Retrieve all tags associated to a VG
+            """
+            return LVM._query_vgs("tags", self.name)
 
         @property
         def pv_names(self):
-            return LVM._query_lvm("pv_name", self.name)
+            """Rerieve all PV names of a VG
+            """
+            return LVM._query_vgs("pv_name", self.name)
 
     @classmethod
-    def _query_lvm(self, option, pv=None):
+    def _query_vgs(self, option, pv=None):
+        cmd = ["lvm", "vgs", "--noheadings", "-o", option]
+
         if pv:
-            return [x.strip() for x in process.check_output(["lvm",
-                    "vgs", "--noheadings", "-o", option, pv]).strip().split(
-                    "\n")]
-        else:
-            return [x.strip() for x in process.check_output(["lvm",
-                    "vgs", "--noheadings", "-o", option]).strip().split("\n")]
+            cmd.append(pv)
+
+        out = process.check_output(cmd).strip()
+
+        # If not VGs are found, just simulate an empty list of VGs
+        if "No volume groups found" in out:
+            out = []
+
+        return [x.strip() for x in out.split("\n")]


-- 
To view, visit http://gerrit.ovirt.org/29328
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e04564256a10ab6434117de3b585396d599c503
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
Gerrit-Reviewer: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list