diff options
author | Martin Sivak <msivak@redhat.com> | 2008-05-05 15:46:38 +0200 |
---|---|---|
committer | Martin Sivak <msivak@redhat.com> | 2008-05-05 15:46:38 +0200 |
commit | dda25ee4e1ca17cd333f10fcf0c825b60105da9c (patch) | |
tree | 38b57154fda72b4d2bf07bced54c3fe9be7924b3 /plugins | |
parent | c227496fa86c36762018c2a8219f2136ec63fa10 (diff) | |
download | firstaidkit-dda25ee4e1ca17cd333f10fcf0c825b60105da9c.tar.gz firstaidkit-dda25ee4e1ca17cd333f10fcf0c825b60105da9c.tar.xz firstaidkit-dda25ee4e1ca17cd333f10fcf0c825b60105da9c.zip |
Use Issue reporting in plugins
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/plugin_examples/dep1.py | 6 | ||||
-rw-r--r-- | plugins/plugin_examples/dep2.py | 6 | ||||
-rw-r--r-- | plugins/plugin_examples/dep3.py | 6 | ||||
-rw-r--r-- | plugins/plugin_examples/sample1Plugin.py | 6 | ||||
-rw-r--r-- | plugins/plugin_examples/sample2Plugin.py | 6 | ||||
-rw-r--r-- | plugins/plugin_examples/sample3Plugin/sample3Plugin.py | 7 | ||||
-rw-r--r-- | plugins/plugin_grub.py | 21 | ||||
-rw-r--r-- | plugins/xserver.py | 5 |
8 files changed, 62 insertions, 1 deletions
diff --git a/plugins/plugin_examples/dep1.py b/plugins/plugin_examples/dep1.py index 0fe673a..a39beda 100644 --- a/plugins/plugin_examples/dep1.py +++ b/plugins/plugin_examples/dep1.py @@ -17,6 +17,8 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * +from pyfirstaidkit.issue import SimpleIssue +from pyfirstaidkit.reporting import PLUGIN class Sample1Plugin(Plugin): """This plugin uses the predefined flow in the Plugin abstract class.""" @@ -25,6 +27,7 @@ class Sample1Plugin(Plugin): author = "Joel Andres Granados" def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) @classmethod def getDeps(cls): @@ -32,6 +35,7 @@ class Sample1Plugin(Plugin): def prepare(self): self._result=ReturnSuccess + self._issue.set(detected = False, reporting = self._reporting, origin = self, level = PLUGIN) def backup(self): self._result=ReturnSuccess @@ -42,9 +46,11 @@ class Sample1Plugin(Plugin): def diagnose(self): self._result=ReturnSuccess self.provide("sample_dependency2") + self._issue.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) def fix(self): self._result=ReturnFailure + self._issue.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) def clean(self): self._result=ReturnSuccess diff --git a/plugins/plugin_examples/dep2.py b/plugins/plugin_examples/dep2.py index e8e8f43..1a0e0fd 100644 --- a/plugins/plugin_examples/dep2.py +++ b/plugins/plugin_examples/dep2.py @@ -17,6 +17,8 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * +from pyfirstaidkit.reporting import PLUGIN +from pyfirstaidkit.issue import SimpleIssue class Sample1Plugin(Plugin): """This plugin uses the predefined flow in the Plugin abstract class.""" @@ -25,6 +27,7 @@ class Sample1Plugin(Plugin): author = "Joel Andres Granados" def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) @classmethod def getDeps(cls): @@ -32,6 +35,7 @@ class Sample1Plugin(Plugin): def prepare(self): self._result=ReturnSuccess + self._issue.set(detected = False, reporting = self._reporting, origin = self, level = PLUGIN) def backup(self): self._result=ReturnSuccess @@ -41,9 +45,11 @@ class Sample1Plugin(Plugin): def diagnose(self): self._result=ReturnSuccess + self._issue.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) def fix(self): self._result=ReturnFailure + self._issue.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) def clean(self): self._result=ReturnSuccess diff --git a/plugins/plugin_examples/dep3.py b/plugins/plugin_examples/dep3.py index 3da70ea..fb109c4 100644 --- a/plugins/plugin_examples/dep3.py +++ b/plugins/plugin_examples/dep3.py @@ -17,6 +17,8 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * +from pyfirstaidkit.reporting import PLUGIN +from pyfirstaidkit.issue import SimpleIssue class Sample1Plugin(Plugin): """This plugin uses the predefined flow in the Plugin abstract class.""" @@ -25,9 +27,11 @@ class Sample1Plugin(Plugin): author = "Joel Andres Granados" def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) def prepare(self): self._result=ReturnSuccess + self._issue.set(detected = False, reporting = self._reporting, origin = self, level = PLUGIN) def backup(self): self._result=ReturnSuccess @@ -38,9 +42,11 @@ class Sample1Plugin(Plugin): def diagnose(self): self._result=ReturnSuccess self.provide("sample_dependency") + self._issue.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) def fix(self): self._result=ReturnFailure + self._issue.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) def clean(self): self._result=ReturnSuccess diff --git a/plugins/plugin_examples/sample1Plugin.py b/plugins/plugin_examples/sample1Plugin.py index 90e9874..560f69d 100644 --- a/plugins/plugin_examples/sample1Plugin.py +++ b/plugins/plugin_examples/sample1Plugin.py @@ -18,7 +18,7 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.reporting import PLUGIN from pyfirstaidkit.returns import * - +from pyfirstaidkit.issue import SimpleIssue class Sample1Plugin(Plugin): """This plugin uses the predefined flow in the Plugin abstract class.""" @@ -27,9 +27,11 @@ class Sample1Plugin(Plugin): author = "Joel Andres Granados" def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) def prepare(self): self._result=ReturnSuccess + self._issue.set(reporting = self._reporting, origin = self, level = PLUGIN) self._reporting.info("Sample1Plugin in Prepare task", origin = self, level = PLUGIN) def backup(self): @@ -42,10 +44,12 @@ class Sample1Plugin(Plugin): def diagnose(self): self._result=ReturnSuccess + self._issue.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) self._reporting.info("Sample1Plugin in diagnose task", origin = self, level = PLUGIN) def fix(self): self._result=ReturnFailure + self._issue.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) self._reporting.info("Sample1Plugin in Fix task", origin = self, level = PLUGIN) def clean(self): diff --git a/plugins/plugin_examples/sample2Plugin.py b/plugins/plugin_examples/sample2Plugin.py index e48389a..aab679c 100644 --- a/plugins/plugin_examples/sample2Plugin.py +++ b/plugins/plugin_examples/sample2Plugin.py @@ -17,6 +17,8 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * +from pyfirstaidkit.issue import SimpleIssue +from pyfirstaidkit.reporting import PLUGIN class Sample2Plugin(Plugin): """This plugin will defin one more function and use it in a newly defined fix flow.""" @@ -41,8 +43,10 @@ class Sample2Plugin(Plugin): def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) def prepare(self): + self._issue.set(reporting = self._reporting, origin = self, level = PLUGIN) self._result=ReturnSuccess def clean(self): @@ -55,9 +59,11 @@ class Sample2Plugin(Plugin): self._result=ReturnSuccess def diagnose(self): + self._issue.set(detected = True, happened = True, reporting = self._reporting, origin = self, level = PLUGIN) self._result=ReturnFailure def fix(self): + self._issue.set(fixed = True, reporting = self._reporting, origin = self, level = PLUGIN) self._result=ReturnSuccess def extraStep(self): diff --git a/plugins/plugin_examples/sample3Plugin/sample3Plugin.py b/plugins/plugin_examples/sample3Plugin/sample3Plugin.py index cac5f70..d3a3f21 100644 --- a/plugins/plugin_examples/sample3Plugin/sample3Plugin.py +++ b/plugins/plugin_examples/sample3Plugin/sample3Plugin.py @@ -18,6 +18,8 @@ from pyfirstaidkit.returns import * from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit import Config +from pyfirstaidkit.issue import SimpleIssue +from pyfirstaidkit.reporting import PLUGIN import subprocess class Sample3Plugin(Plugin): @@ -28,9 +30,11 @@ class Sample3Plugin(Plugin): def __init__(self, *args, **kwargs): Plugin.__init__(self, *args, **kwargs) + self._issue = SimpleIssue(self.name, self.description) def prepare(self): # Prepare command line. + self._issue.set(detected = False, reporting = self._reporting, origin = self, level = PLUGIN) prepare = [self._path + "/plugin", "--task", "prepare"] proc = subprocess.Popen(prepare, stdout=subprocess.PIPE) (out, err) = proc.communicate() @@ -79,6 +83,7 @@ class Sample3Plugin(Plugin): self._result=ReturnFailure elif out[-4:] == "true": self._result=ReturnSuccess + self._issue.set(detected = True, happened = (self._result==ReturnFailure), reporting = self._reporting, origin = self, level = PLUGIN) def fix(self): fix = [self._path+"/plugin", "--task", "fix"] @@ -89,3 +94,5 @@ class Sample3Plugin(Plugin): self._result=ReturnFailure elif out[-4:] == "true": self._result=ReturnSuccess + self._issue.set(fixed = (self._result==ReturnSuccess), reporting = self._reporting, origin = self, level = PLUGIN) + diff --git a/plugins/plugin_grub.py b/plugins/plugin_grub.py index 8137bfb..e60cf48 100644 --- a/plugins/plugin_grub.py +++ b/plugins/plugin_grub.py @@ -20,6 +20,7 @@ from pyfirstaidkit.reporting import PLUGIN from pyfirstaidkit.returns import * from pyfirstaidkit.configuration import Config,getConfigBits from pyfirstaidkit.utils import spawnvch +from pyfirstaidkit.issue import SimpleIssue import os.path import difflib import re @@ -62,10 +63,18 @@ class Sample1Plugin(Plugin): self._grub_map = {} #mapping from linux device names to grub device names self._grub_mask = re.compile("""\(hd[0-9]*,[0-9]*\)""") + self._issue_boot_flag = SimpleIssue("Bootable partition", "No bootable partition found in partition table and GRUB is not MBR installed") + self._issue_grub_dir = SimpleIssue("GRUB directory", "No GRUB directory was not found") + self._issue_grub_installed = SimpleIssue("GRUB installed", "No GRUB was found in bootable partitions or MBR") + def prepare(self): from bootloaderInfo import x86BootloaderInfo self._bootloaderInfo = x86BootloaderInfo() self._result=ReturnSuccess + + self._issue_boot_flag.set(reporting = self._reporting, origin = self, level = PLUGIN) + self._issue_grub_dir.set(reporting = self._reporting, origin = self, level = PLUGIN) + self._issue_grub_installed.set(reporting = self._reporting, origin = self, level = PLUGIN) def backup(self): self._result=ReturnSuccess @@ -103,6 +112,9 @@ class Sample1Plugin(Plugin): self._linux.append(data[0][5:]) self._reporting.debug(origin = self, level = PLUGIN, message = "Linux partition found: %s" % (data[0][5:],)) + if len(self._bootable) == 0: + self._issue_boot_flag.set(detected = True, happened = True, reporting = self._reporting, origin = self, level = PLUGIN) + #Find grub directories self._reporting.debug(origin = self, level = PLUGIN, message = "Locating the grub directories") @@ -112,6 +124,9 @@ class Sample1Plugin(Plugin): if self._grub_mask.search(l): self._reporting.info(origin = self, level = PLUGIN, message = "Grub directory found at %s" % (l.strip(),)) self._grub_dir.add(l.strip()) + + if len(self._grub_dir) == 0: + self._issue_grub_dir.set(detected = True, happened = True, reporting = self._reporting, origin = self, level = PLUGIN) #TODO Mount the required partitions from self._grub_dir and read the important files from there for gdrive in self._grub_dir: @@ -150,12 +165,18 @@ class Sample1Plugin(Plugin): #if there is the grub configuration dir and the grub appears installed into MBR or bootable partition, then we are probably OK if len(self._grub_dir)>0 and len(self._grub)>0 and len(set(self._grub).intersection(set(self._bootable+self._drives)))>0: self._result=ReturnSuccess + self._issue_grub_installed.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) + self._issue_boot_flag.set(detected = True, happened = False, reporting = self._reporting, origin = self, level = PLUGIN) #if we can find bootable, than it didn't happen self._dependencies.provide("boot-grub") else: + self._issue_grub_installed.set(detected = True, happened = True, reporting = self._reporting, origin = self, level = PLUGIN) self._result=ReturnFailure def fix(self): self._result=ReturnFailure + self._issue_boot_flag.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) + self._issue_grub_dir.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) + self._issue_grub_installed.set(fixed = False, reporting = self._reporting, origin = self, level = PLUGIN) def install(self): #install the grub to Config.operation.params partition diff --git a/plugins/xserver.py b/plugins/xserver.py index 8b63113..0b2f238 100644 --- a/plugins/xserver.py +++ b/plugins/xserver.py @@ -19,6 +19,7 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * from pyfirstaidkit.utils import * from pyfirstaidkit.reporting import PLUGIN +from pyfirstaidkit.issue import SimpleIssue from pyfirstaidkit import Config import rhpxl.xserver @@ -42,10 +43,12 @@ class Xserver(Plugin): # Arbitrary test display self.display = ":10" self.confPath = "/etc/X11/xorg.conf" + self._issue = SimpleIssue(self.name, "X server didn't start") def prepare(self): # Nothing to prepare really. self._result = ReturnSuccess + self._issue.set(reporting = self._reporting, level = PLUGIN, origin = self) # If we cant start the server def diagnose(self): @@ -55,6 +58,7 @@ class Xserver(Plugin): else: self._reporting.info("X server is missconfigured.", level = PLUGIN, origin = self) self._result = ReturnFailure + self._issue.set(detected = True, happened = (self._result == ReturnFailure), reporting = self._reporting, level = PLUGIN, origin = self) # FIXME:Must change this when the backup utils is done. def backup(self): @@ -89,6 +93,7 @@ class Xserver(Plugin): else: self._reporting.info("X server is still missconfigured with new file.", level = PLUGIN, origin = self) self._result = ReturnFailure + self._issue.set(fixed = (self._result == ReturnSuccess), reporting = self._reporting, level = PLUGIN, origin = self) def restore(self): if os.path.isfile("%s.FAK-backup"%self.confPath): |