def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=False) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEqual(expected, sorter.get_system_status())
def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock(return_value=None) self.status_mgr.server_status = None sorter = CertSorter() sorter.is_registered = Mock(return_value=False) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEqual(expected, sorter.get_system_status())
def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock(return_value=None) self.status_mgr.server_status = None sorter = CertSorter() sorter.is_registered = Mock(return_value=False) status_map = subscription_manager.cert_sorter.ComplianceManager.get_status_map( ) expected = status_map[subscription_manager.cert_sorter.UNKNOWN] self.assertEqual(expected, sorter.get_system_status())
class CertSorterTests(SubManFixture): @patch('subscription_manager.cache.InstalledProductsManager.update_check') def setUp(self, mock_update): SubManFixture.setUp(self) # Setup mock product and entitlement certs: self.prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2, INST_PID_3, INST_PID_4]) self.ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(PROD_2, ent_id=ENT_ID_2), StubEntitlementCertificate(PROD_1, ent_id=ENT_ID_1), StubEntitlementCertificate(product=PROD_4, stacking_id=STACK_1, ent_id=ENT_ID_4), # entitled, but not installed StubEntitlementCertificate(StubProduct('not_installed_product', name="Some Product"), ent_id="SomeSubId"), ]) self.mock_uep = StubUEP() self.status_mgr = EntitlementStatusCache() self.status_mgr.load_status = Mock( return_value=SAMPLE_COMPLIANCE_JSON) self.status_mgr.write_cache = Mock() inj.provide(inj.ENTITLEMENT_STATUS_CACHE, self.status_mgr) inj.provide(inj.PROD_DIR, self.prod_dir) inj.provide(inj.ENT_DIR, self.ent_dir) self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_unregistered_status(self, mock_update): sorter = CertSorter() sorter.is_registered = Mock(return_value=False) self.assertEqual(UNKNOWN, sorter.get_status(INST_PID_1)) # Server doesn't support compliance API, or server is unreachable and # we cannot use the cache for some reason. @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_no_usable_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=True) self.assertEqual(UNKNOWN, sorter.get_status(INST_PID_1)) # Consumer has been deleted, overall status should be unknown @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_deleted_consumer_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=True) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEqual(expected, sorter.get_system_status()) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=False) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEqual(expected, sorter.get_system_status()) def test_unentitled_products(self): self.assertEqual(1, len(self.sorter.unentitled_products)) self.assertTrue(INST_PID_3 in self.sorter.unentitled_products) def test_valid_products(self): self.assertEqual(1, len(self.sorter.valid_products)) self.assertTrue(INST_PID_1 in self.sorter.valid_products) def test_partially_valid_products(self): self.assertEqual(2, len(self.sorter.partially_valid_products)) self.assertTrue(INST_PID_2 in self.sorter.partially_valid_products) self.assertTrue(INST_PID_4 in self.sorter.partially_valid_products) def test_installed_products(self): self.assertEqual(4, len(self.sorter.installed_products)) self.assertTrue(INST_PID_1 in self.sorter.installed_products) self.assertTrue(INST_PID_2 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) def test_partial_stack(self): self.assertEqual(1, len(self.sorter.partial_stacks)) self.assertTrue(PARTIAL_STACK_ID in self.sorter.partial_stacks) def test_reasons(self): self.assertEqual(5, len(self.sorter.reasons.reasons)) expected_keys = ['NOTCOVERED', 'CORES', 'SOCKETS', 'RAM', 'ARCH'] result_keys = [reason['key'] for reason in self.sorter.reasons.reasons] self.assertEqual(sorted(expected_keys), sorted(result_keys)) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_installed_mismatch_unentitled(self, mock_update): # Use a different product directory with something not present # in the response from the server as an unentitled product: prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertFalse(INST_PID_3 in sorter.installed_products) # Should get filtered out of unentitled products even though # server reported it here: self.assertFalse(INST_PID_3 in sorter.unentitled_products) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_missing_installed_product(self, mock_update): # Add a new installed product server doesn't know about: prod_dir = StubProductDirectory(pids=[INST_PID_1, INST_PID_2, INST_PID_3, "product4"]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertTrue('product4' in sorter.unentitled_products) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_no_compliant_until(self, mock_update): # don't want to munge the module scope version of this because # setup will load it for later tests no_compliance_until = copy.deepcopy(SAMPLE_COMPLIANCE_JSON) no_compliance_until['compliantUntil'] = None # build and inject a status cache with new values status_mgr = EntitlementStatusCache() status_mgr.load_status = Mock(return_value=no_compliance_until) status_mgr.write_cache = Mock() inj.provide(inj.ENTITLEMENT_STATUS_CACHE, status_mgr) self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) self.assertTrue(self.sorter.compliant_until is None) def test_compliant_until(self): compliant_until = self.sorter.compliant_until self.assertEqual(2013, compliant_until.year) self.assertEqual(4, compliant_until.month) self.assertEqual(26, compliant_until.day) self.assertEqual(13, compliant_until.hour) self.assertEqual(43, compliant_until.minute) self.assertEqual(12, compliant_until.second) def test_scan_for_expired_or_future_products(self): prod_dir = StubProductDirectory(pids=["a", "b", "c", "d", "e"]) ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(StubProduct("a")), StubEntitlementCertificate(StubProduct("b")), StubEntitlementCertificate(StubProduct("c")), StubEntitlementCertificate(StubProduct("d"), start_date=datetime.now() - timedelta(days=365), end_date=datetime.now() - timedelta(days=2)), StubEntitlementCertificate(StubProduct("e"), start_date=datetime.now() + timedelta(days=365), end_date=datetime.now() + timedelta(days=730)), ]) inj.provide(inj.PROD_DIR, prod_dir) inj.provide(inj.ENT_DIR, ent_dir) sorter = StubCertSorter() sorter.valid_products = {"a": StubProduct("a")} sorter.partially_valid_products = {"b": StubProduct("b")} sorter._scan_entitlement_certs() self.assertEqual(["d"], list(sorter.expired_products.keys())) self.assertEqual(["e"], list(sorter.future_products.keys())) self.assertEqual(3, len(sorter.valid_entitlement_certs)) def test_get_system_status(self): self.assertEqual('Invalid', self.sorter.get_system_status()) self.sorter.system_status = 'valid' self.assertEqual('Current', self.sorter.get_system_status()) self.sorter.system_status = 'partial' self.assertEqual('Insufficient', self.sorter.get_system_status())
class CertSorterTests(SubManFixture): @patch("subscription_manager.cache.InstalledProductsManager.update_check") def setUp(self, mock_update): SubManFixture.setUp(self) # Setup mock product and entitlement certs: self.prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2, INST_PID_3, INST_PID_4]) self.ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(PROD_2, ent_id=ENT_ID_2), StubEntitlementCertificate(PROD_1, ent_id=ENT_ID_1), StubEntitlementCertificate(product=PROD_4, stacking_id=STACK_1, ent_id=ENT_ID_4), # entitled, but not installed StubEntitlementCertificate(StubProduct("not_installed_product", name="Some Product"), ent_id="SomeSubId"), ]) self.mock_uep = StubUEP() self.status_mgr = EntitlementStatusCache() self.status_mgr.load_status = Mock(return_value=SAMPLE_COMPLIANCE_JSON) self.status_mgr.write_cache = Mock() inj.provide(inj.ENTITLEMENT_STATUS_CACHE, self.status_mgr) inj.provide(inj.PROD_DIR, self.prod_dir) inj.provide(inj.ENT_DIR, self.ent_dir) self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_unregistered_status(self, mock_update): sorter = CertSorter() sorter.is_registered = Mock(return_value=False) self.assertEqual(UNKNOWN, sorter.get_status(INST_PID_1)) # Server doesn't support compliance API, or server is unreachable and # we cannot use the cache for some reason. @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_no_usable_status(self, mock_update): self.status_mgr.load_status = Mock(return_value=None) self.status_mgr.server_status = None sorter = CertSorter() sorter.is_registered = Mock(return_value=True) self.assertEqual(UNKNOWN, sorter.get_status(INST_PID_1)) # Consumer has been deleted, overall status should be unknown @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_deleted_consumer_status(self, mock_update): self.status_mgr.load_status = Mock(return_value=None) self.status_mgr.server_status = None sorter = CertSorter() sorter.is_registered = Mock(return_value=True) status_map = subscription_manager.cert_sorter.ComplianceManager.get_status_map( ) expected = status_map[subscription_manager.cert_sorter.UNKNOWN] self.assertEqual(expected, sorter.get_system_status()) @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock(return_value=None) self.status_mgr.server_status = None sorter = CertSorter() sorter.is_registered = Mock(return_value=False) status_map = subscription_manager.cert_sorter.ComplianceManager.get_status_map( ) expected = status_map[subscription_manager.cert_sorter.UNKNOWN] self.assertEqual(expected, sorter.get_system_status()) def test_unentitled_products(self): self.assertEqual(1, len(self.sorter.unentitled_products)) self.assertTrue(INST_PID_3 in self.sorter.unentitled_products) def test_valid_products(self): self.assertEqual(1, len(self.sorter.valid_products)) self.assertTrue(INST_PID_1 in self.sorter.valid_products) def test_partially_valid_products(self): self.assertEqual(2, len(self.sorter.partially_valid_products)) self.assertTrue(INST_PID_2 in self.sorter.partially_valid_products) self.assertTrue(INST_PID_4 in self.sorter.partially_valid_products) def test_installed_products(self): self.assertEqual(4, len(self.sorter.installed_products)) self.assertTrue(INST_PID_1 in self.sorter.installed_products) self.assertTrue(INST_PID_2 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) def test_partial_stack(self): self.assertEqual(1, len(self.sorter.partial_stacks)) self.assertTrue(PARTIAL_STACK_ID in self.sorter.partial_stacks) def test_reasons(self): self.assertEqual(5, len(self.sorter.reasons.reasons)) expected_keys = ["NOTCOVERED", "CORES", "SOCKETS", "RAM", "ARCH"] result_keys = [reason["key"] for reason in self.sorter.reasons.reasons] self.assertEqual(sorted(expected_keys), sorted(result_keys)) @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_installed_mismatch_unentitled(self, mock_update): # Use a different product directory with something not present # in the response from the server as an unentitled product: prod_dir = StubProductDirectory(pids=[INST_PID_1, INST_PID_2]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertFalse(INST_PID_3 in sorter.installed_products) # Should get filtered out of unentitled products even though # server reported it here: self.assertFalse(INST_PID_3 in sorter.unentitled_products) @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_missing_installed_product(self, mock_update): # Add a new installed product server doesn't know about: prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2, INST_PID_3, "product4"]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertTrue("product4" in sorter.unentitled_products) @patch("subscription_manager.cache.InstalledProductsManager.update_check") def test_no_compliant_until(self, mock_update): # don't want to munge the module scope version of this because # setup will load it for later tests no_compliance_until = copy.deepcopy(SAMPLE_COMPLIANCE_JSON) no_compliance_until["compliantUntil"] = None # build and inject a status cache with new values status_mgr = EntitlementStatusCache() status_mgr.load_status = Mock(return_value=no_compliance_until) status_mgr.write_cache = Mock() inj.provide(inj.ENTITLEMENT_STATUS_CACHE, status_mgr) self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) self.assertTrue(self.sorter.compliant_until is None) def test_compliant_until(self): compliant_until = self.sorter.compliant_until self.assertEqual(2013, compliant_until.year) self.assertEqual(4, compliant_until.month) self.assertEqual(26, compliant_until.day) self.assertEqual(13, compliant_until.hour) self.assertEqual(43, compliant_until.minute) self.assertEqual(12, compliant_until.second) def test_scan_for_expired_or_future_products(self): prod_dir = StubProductDirectory(pids=["a", "b", "c", "d", "e"]) ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(StubProduct("a")), StubEntitlementCertificate(StubProduct("b")), StubEntitlementCertificate(StubProduct("c")), StubEntitlementCertificate( StubProduct("d"), start_date=datetime.now() - timedelta(days=365), end_date=datetime.now() - timedelta(days=2), ), StubEntitlementCertificate( StubProduct("e"), start_date=datetime.now() + timedelta(days=365), end_date=datetime.now() + timedelta(days=730), ), ]) inj.provide(inj.PROD_DIR, prod_dir) inj.provide(inj.ENT_DIR, ent_dir) sorter = StubCertSorter() sorter.valid_products = {"a": StubProduct("a")} sorter.partially_valid_products = {"b": StubProduct("b")} sorter._scan_entitlement_certs() self.assertEqual(["d"], list(sorter.expired_products.keys())) self.assertEqual(["e"], list(sorter.future_products.keys())) self.assertEqual(3, len(sorter.valid_entitlement_certs)) def test_get_system_status(self): self.assertEqual("Invalid", self.sorter.get_system_status()) self.sorter.system_status = "valid" self.assertEqual("Current", self.sorter.get_system_status()) self.sorter.system_status = "partial" self.assertEqual("Insufficient", self.sorter.get_system_status())
class CertSorterTests(SubManFixture): @patch('subscription_manager.cache.InstalledProductsManager.update_check') def setUp(self, mock_update): SubManFixture.setUp(self) # Setup mock product and entitlement certs: self.prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2, INST_PID_3, INST_PID_4]) self.ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(PROD_2, ent_id=ENT_ID_2), StubEntitlementCertificate(PROD_1, ent_id=ENT_ID_1), StubEntitlementCertificate(product=PROD_4, stacking_id=STACK_1, ent_id=ENT_ID_4), # entitled, but not installed StubEntitlementCertificate(StubProduct('not_installed_product', name="Some Product"), ent_id="SomeSubId"), ]) self.mock_uep = StubUEP() self.status_mgr = StatusCache() self.status_mgr.load_status = Mock( return_value=SAMPLE_COMPLIANCE_JSON) self.status_mgr.write_cache = Mock() inj.provide(inj.STATUS_CACHE, self.status_mgr) inj.provide(inj.PROD_DIR, self.prod_dir) inj.provide(inj.ENT_DIR, self.ent_dir) self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_unregistered_status(self, mock_update): sorter = CertSorter() sorter.is_registered = Mock(return_value=False) self.assertEquals(UNKNOWN, sorter.get_status(INST_PID_1)) # Server doesn't support compliance API, or server is unreachable and # we cannot use the cache for some reason. @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_no_usable_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=True) self.assertEquals(UNKNOWN, sorter.get_status(INST_PID_1)) # Consumer has been deleted, overall status should be unknown @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_deleted_consumer_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=True) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEquals(expected, sorter.get_system_status()) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_unregistered_system_status(self, mock_update): self.status_mgr.load_status = Mock( return_value=None) sorter = CertSorter() sorter.is_registered = Mock(return_value=False) expected = subscription_manager.cert_sorter.STATUS_MAP['unknown'] self.assertEquals(expected, sorter.get_system_status()) def test_unentitled_products(self): self.assertEquals(1, len(self.sorter.unentitled_products)) self.assertTrue(INST_PID_3 in self.sorter.unentitled_products) def test_valid_products(self): self.assertEquals(1, len(self.sorter.valid_products)) self.assertTrue(INST_PID_1 in self.sorter.valid_products) def test_partially_valid_products(self): self.assertEquals(2, len(self.sorter.partially_valid_products)) self.assertTrue(INST_PID_2 in self.sorter.partially_valid_products) self.assertTrue(INST_PID_4 in self.sorter.partially_valid_products) def test_installed_products(self): self.assertEquals(4, len(self.sorter.installed_products)) self.assertTrue(INST_PID_1 in self.sorter.installed_products) self.assertTrue(INST_PID_2 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) self.assertTrue(INST_PID_3 in self.sorter.installed_products) def test_partial_stack(self): self.assertEquals(1, len(self.sorter.partial_stacks)) self.assertTrue(PARTIAL_STACK_ID in self.sorter.partial_stacks) def test_reasons(self): self.assertEquals(5, len(self.sorter.reasons.reasons)) expected_keys = ['NOTCOVERED', 'CORES', 'SOCKETS', 'RAM', 'ARCH'] result_keys = [reason['key'] for reason in self.sorter.reasons.reasons] self.assertEquals(sorted(expected_keys), sorted(result_keys)) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_installed_mismatch_unentitled(self, mock_update): # Use a different product directory with something not present # in the response from the server as an unentitled product: prod_dir = StubProductDirectory( pids=[INST_PID_1, INST_PID_2]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertFalse(INST_PID_3 in sorter.installed_products) # Should get filtered out of unentitled products even though # server reported it here: self.assertFalse(INST_PID_3 in sorter.unentitled_products) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_missing_installed_product(self, mock_update): # Add a new installed product server doesn't know about: prod_dir = StubProductDirectory(pids=[INST_PID_1, INST_PID_2, INST_PID_3, "product4"]) inj.provide(inj.PROD_DIR, prod_dir) sorter = CertSorter() self.assertTrue('product4' in sorter.unentitled_products) @patch('subscription_manager.cache.InstalledProductsManager.update_check') def test_no_compliant_until(self, mock_update): SAMPLE_COMPLIANCE_JSON['compliantUntil'] = None self.sorter = CertSorter() self.sorter.is_registered = Mock(return_value=True) self.assertTrue(self.sorter.compliant_until is None) self.assertTrue(self.sorter.first_invalid_date is None) def test_compliant_until(self): compliant_until = self.sorter.compliant_until self.assertEquals(2013, compliant_until.year) self.assertEquals(4, compliant_until.month) self.assertEquals(26, compliant_until.day) self.assertEquals(13, compliant_until.hour) self.assertEquals(43, compliant_until.minute) self.assertEquals(12, compliant_until.second) def test_first_invalid_date(self): first_invalid = self.sorter.first_invalid_date self.assertEquals(2013, first_invalid.year) self.assertEquals(4, first_invalid.month) self.assertEquals(27, first_invalid.day) def test_scan_for_expired_or_future_products(self): prod_dir = StubProductDirectory(pids=["a", "b", "c", "d", "e"]) ent_dir = StubEntitlementDirectory([ StubEntitlementCertificate(StubProduct("a")), StubEntitlementCertificate(StubProduct("b")), StubEntitlementCertificate(StubProduct("c")), StubEntitlementCertificate(StubProduct("d"), start_date=datetime.now() - timedelta(days=365), end_date=datetime.now() - timedelta(days=2)), StubEntitlementCertificate(StubProduct("e"), start_date=datetime.now() + timedelta(days=365), end_date=datetime.now() + timedelta(days=730)), ]) inj.provide(inj.PROD_DIR, prod_dir) inj.provide(inj.ENT_DIR, ent_dir) sorter = StubCertSorter() sorter.valid_products = {"a": StubProduct("a")} sorter.partially_valid_products = {"b": StubProduct("b")} sorter._scan_entitlement_certs() self.assertEquals(["d"], sorter.expired_products.keys()) self.assertEquals(["e"], sorter.future_products.keys()) self.assertEquals(3, len(sorter.valid_entitlement_certs)) def test_get_system_status(self): self.assertEquals('Invalid', self.sorter.get_system_status()) self.sorter.system_status = 'valid' self.assertEquals('Current', self.sorter.get_system_status()) self.sorter.system_status = 'partial' self.assertEquals('Insufficient', self.sorter.get_system_status())