示例#1
0
 def setUp(self, **kwargs):
     super(HintDefinitionTests, self).setUp(**kwargs)
     if not self.configs:
         config_file = os.path.join(CHECKS_DIR, "sw.yaml")
         cfg = yaml.ReadFromPath(config_file)
     chk = checks.Check(**cfg)
     self.lin_method, self.win_method, self.foo_method = list(chk.method)
示例#2
0
 def setUp(self, **kwargs):
   super(HintDefinitionTests, self).setUp(**kwargs)
   if not self.configs:
     config_file = os.path.join(CHECKS_DIR, "sw.yaml")
     with open(config_file, "rb") as data:
       cfg = yaml.safe_load(data)
   chk = checks.Check(**cfg)
   self.lin_method, self.win_method, self.foo_method = list(chk.method)
示例#3
0
 def testGenerateTriggerMap(self):
   chk = checks.Check(**self.cfg)
   expect = [TRIGGER_1, TRIGGER_3]
   result = [c.attr for c in chk.triggers.Search("DebianPackagesStatus")]
   self.assertItemsEqual(expect, result)
   expect = [TRIGGER_2]
   result = [c.attr for c in chk.triggers.Search("WMIInstalledSoftware")]
   self.assertItemsEqual(expect, result)
示例#4
0
 def testParseCheckFromConfig(self):
   chk = checks.Check(**self.cfg)
   # Triggers 1 (linux packages) & 2 (windows software) should return results.
   # Trigger 3 should not return results as no host data has the label 'foo'.
   result_1 = chk.Parse([TRIGGER_1], self.host_data)
   result_2 = chk.Parse([TRIGGER_2], self.host_data)
   result_3 = chk.Parse([TRIGGER_3], self.host_data)
   self.assertTrue(result_1)
   self.assertTrue(result_2)
   self.assertFalse(result_3)
示例#5
0
 def GetCheckErrors(self, check_spec):
   """Collect errors generated by host checking tools."""
   errors = []
   try:
     check = checks.Check(**check_spec)
     check.Validate()
   except (checks.Error, filters.Error, hints.Error, type_info.Error) as e:
     errors.append(str(e))
   except Exception as e:  # pylint: disable=broad-except
     # TODO(user): More granular exception handling.
     errors.append("Unknown error %s: %s" % (type(e), e))
   return errors
示例#6
0
 def testInitializeCheck(self):
   chk = checks.Check(**self.cfg)
   self.assertEqual("SW-CHECK", chk.check_id)
   self.assertItemsEqual(["ANY"], [str(c) for c in chk.match])
示例#7
0
 def _LoadCheck(self, cfg_file, check_id):
   configs = checks.LoadConfigsFromFile(os.path.join(CHECKS_DIR, cfg_file))
   cfg = configs.get(check_id)
   return checks.Check(**cfg)