def test_translate_bad_unit_id(self): bad_unit = Unit("BAD_UNIT_ID", {"id":"bad_id"}, {}, None) prof = RPMErrataProfiler() caught_exception = False try: applicable_rpms = prof.translate(bad_unit, self.test_consumer, conduit) except: caught_exception = True self.assertTrue(caught_exception)
def test_unit_applicable_updated_rpm_already_installed(self): # Errata refers to RPMs already installed, i.e. the consumer has these exact NEVRA already errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA} prof = RPMErrataProfiler() report = prof.unit_applicable(self.test_consumer_been_updated, example_errata, None, conduit) self.assertFalse(report.applicable)
def test_unit_applicable_false(self): # Errata refers to RPMs which are NOT part of our test consumer's profile errata_obj = self.get_test_errata_object_unrelated() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA} prof = RPMErrataProfiler() report = prof.unit_applicable(self.test_consumer, example_errata, None, conduit) self.assertFalse(report.applicable)
def test_unit_applicable_true(self): # Errata refers to RPMs which ARE part of our test consumer's profile errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = [errata_unit.unit_key] prof = RPMErrataProfiler() report_list = prof.units_applicable(self.test_consumer, ["test_repo_id"], TYPE_ID_ERRATA, example_errata, None, conduit) self.assertFalse(report_list == [])
def test_unit_applicable_same_name_diff_arch(self): # Errata refers to RPMs that are x86_64, the test consumer is i386 # the rpms installed share the same name as the errata, but the client arch is different # so this errata is marked as unapplicable errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA} prof = RPMErrataProfiler() report = prof.unit_applicable(self.test_consumer_i386, example_errata, None, conduit) self.assertFalse(report.applicable)
def test_translate(self): # Setup test data errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA} # Test prof = RPMErrataProfiler() applicable_rpms, upgrade_details = prof.translate(example_errata, self.test_consumer, conduit) self.assertEqual(len(applicable_rpms), 2) self.assertEqual(len(upgrade_details), 2)
def test_metadata(self): data = RPMErrataProfiler.metadata() self.assertTrue(data.has_key("id")) self.assertEquals(data['id'], TYPE_ID_PROFILER_RPM_ERRATA) self.assertTrue(data.has_key("display_name")) self.assertTrue(data.has_key("types")) self.assertTrue(TYPE_ID_ERRATA in data["types"])
def test_install_units(self): errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) existing_units = [errata_unit] test_repo = profiler_mocks.get_repo("test_repo_id") conduit = profiler_mocks.get_profiler_conduit(existing_units=existing_units, repo_bindings=[test_repo]) example_errata = {"unit_key":errata_unit.unit_key, "type_id":TYPE_ID_ERRATA} prof = RPMErrataProfiler() translated_units = prof.install_units(self.test_consumer, [example_errata], None, None, conduit) self.assertEqual(len(translated_units), 2) expected = [] for r in self.test_consumer.profiles[TYPE_ID_RPM]: expected_name = "%s.%s" % (r["name"], r["arch"]) expected.append(expected_name) for u in translated_units: rpm_name = u["unit_key"]["name"] self.assertTrue(rpm_name in expected)
def test_rpms_applicable_to_consumer(self): errata_rpms = [] prof = RPMErrataProfiler() applicable_rpms, old_rpms = prof.rpms_applicable_to_consumer(Consumer("test", {}), errata_rpms) self.assertEqual(applicable_rpms, []) self.assertEqual(old_rpms, {}) # # Get rpm dictionaries embedded in an errata # errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) errata_rpms = prof.get_rpms_from_errata(errata_unit) # Test with 2 newer RPMs in the test errata # The consumer has already been configured with a profile containing 'emoticons' and 'patb' rpms applicable_rpms, old_rpms = prof.rpms_applicable_to_consumer(self.test_consumer, errata_rpms) self.assertTrue(applicable_rpms) self.assertTrue(old_rpms) self.assertEqual(len(applicable_rpms), 2) self.assertTrue(old_rpms.has_key("emoticons x86_64")) self.assertEqual("emoticons", old_rpms["emoticons x86_64"]["installed"]["name"]) self.assertEqual("0.0.1", old_rpms["emoticons x86_64"]["installed"]["version"])
def test_get_rpms_from_errata(self): errata_obj = self.get_test_errata_object() errata_unit = Unit(TYPE_ID_ERRATA, {"id":errata_obj["id"]}, errata_obj, None) prof = RPMErrataProfiler() rpms = prof.get_rpms_from_errata(errata_unit) # Expected data: # [{'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'emoticons', # 'sum': ('md5', '366bb5e73a5905eacb82c96e0578f92b'), # 'filename': 'emoticons-0.1-2.x86_64.rpm', 'epoch': '0', # 'version': '0.1', 'release': '2', 'arch': 'x86_64'}, # {'src': 'xen-3.0.3-80.el5_3.3.src.rpm', 'name': 'patb', # 'sum': ('md5', 'f3c197a29d9b66c5b65c5d62b25db5b4'), # 'filename': 'patb-0.1-2.x86_64.rpm', 'epoch': '0', # 'version': '0.1', 'release': '2', 'arch': 'x86_64'}] self.assertEqual(len(rpms), 2) self.assertTrue(rpms[0]["name"] in ['emoticons', 'patb']) self.assertTrue(rpms[1]["name"] in ['emoticons', 'patb']) for r in rpms: for key in ["name", "filename", "epoch", "version", "release"]: self.assertTrue(r.has_key(key)) self.assertTrue(r[key])