class OverrideTests(SubManFixture): def setUp(self): SubManFixture.setUp(self) self.overrides = Overrides() def test_add_function(self): repos = ['x', 'y'] override_props = {'a': 'b', 'c': 'd'} overrides = [Override(repo, name, value) for repo in repos for name, value in list(override_props.items())] expected = [ {'contentLabel': 'x', 'name': 'a', 'value': 'b'}, {'contentLabel': 'x', 'name': 'c', 'value': 'd'}, {'contentLabel': 'y', 'name': 'a', 'value': 'b'}, {'contentLabel': 'y', 'name': 'c', 'value': 'd'}, ] result = self.overrides._add(overrides) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_function(self): repos = ['x', 'y'] props_to_remove = ['a', 'b'] removes = [Override(repo, name) for repo in repos for name in props_to_remove] expected = [ {'contentLabel': 'x', 'name': 'a'}, {'contentLabel': 'x', 'name': 'b'}, {'contentLabel': 'y', 'name': 'a'}, {'contentLabel': 'y', 'name': 'b'}, ] result = self.overrides._remove(removes) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all(self): repos = ['x', 'y'] expected = [ {'contentLabel': 'x'}, {'contentLabel': 'y'}, ] result = self.overrides._remove_all(repos) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all_with_no_repos_given(self): repos = [] result = self.overrides._remove_all(repos) self.assertEqual(None, result)
def create_uep(self): # Re-initialize our connection: self.cp_provider.set_connection_info() # These objects hold a reference to the old uep and must be updated: # FIXME: We should find a way to update the connection so that the # conncection objects are refreshed rather than recreated. self.certlib = EntCertActionInvoker() self.overrides = Overrides()
def __init__(self): self.identity = require(IDENTITY) self.cp_provider = require(CP_PROVIDER) self.update() self.product_dir = inj.require(inj.PROD_DIR) self.entitlement_dir = inj.require(inj.ENT_DIR) self.certlib = EntCertActionInvoker() self.overrides = Overrides() self.cs = require(CERT_SORTER)
def setUp(self): SubManFixture.setUp(self) self.overrides = Overrides()
class OverrideTests(SubManFixture): def setUp(self): SubManFixture.setUp(self) self.overrides = Overrides() def test_add_function(self): repos = ["x", "y"] override_props = {"a": "b", "c": "d"} overrides = [ Override(repo, name, value) for repo in repos for name, value in list(override_props.items()) ] expected = [ { "contentLabel": "x", "name": "a", "value": "b" }, { "contentLabel": "x", "name": "c", "value": "d" }, { "contentLabel": "y", "name": "a", "value": "b" }, { "contentLabel": "y", "name": "c", "value": "d" }, ] result = self.overrides._add(overrides) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_function(self): repos = ["x", "y"] props_to_remove = ["a", "b"] removes = [ Override(repo, name) for repo in repos for name in props_to_remove ] expected = [ { "contentLabel": "x", "name": "a" }, { "contentLabel": "x", "name": "b" }, { "contentLabel": "y", "name": "a" }, { "contentLabel": "y", "name": "b" }, ] result = self.overrides._remove(removes) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all(self): repos = ["x", "y"] expected = [ { "contentLabel": "x" }, { "contentLabel": "y" }, ] result = self.overrides._remove_all(repos) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all_with_no_repos_given(self): repos = [] result = self.overrides._remove_all(repos) self.assertEqual(None, result)
def _do_command(self): self._validate_options() # Abort if not registered self.assert_should_be_registered() supported_resources = get_supported_resources() if "content_overrides" not in supported_resources: system_exit( os.EX_UNAVAILABLE, _("Error: The 'repo-override' command is not supported by the server." )) # update entitlement certificates if necessary. If we do have new entitlements # CertLib.update() will call RepoActionInvoker.update(). self.entcertlib.update() # make sure the EntitlementDirectory singleton is refreshed self._request_validity_check() overrides = Overrides() if not manage_repos_enabled(): print(_("Repositories disabled by configuration.")) if self.options.list: results = overrides.get_overrides(self.identity.uuid) if results: self._list(results, self.options.repos) else: print( _("This system does not have any content overrides applied to it." )) return if self.options.additions: repo_ids = [ repo.id for repo in overrides.repo_lib.get_repos(apply_overrides=False) ] to_add = [ Override(repo, name, value) for repo in self.options.repos for name, value in list(self.options.additions.items()) ] try: results = overrides.add_overrides(self.identity.uuid, to_add) except connection.RestlibException as ex: if ex.code == 400: # blocklisted overrides specified. # Print message and return a less severe code. mapped_message: str = ExceptionMapper().get_message(ex) system_exit(1, mapped_message) else: raise ex # Print out warning messages if the specified repo does not exist in the repo file. for repo in self.options.repos: if repo not in repo_ids: print( _("Repository '{repo}' does not currently exist, but the override has been added." ).format(repo=repo)) if self.options.removals: to_remove = [ Override(repo, item) for repo in self.options.repos for item in self.options.removals ] results = overrides.remove_overrides(self.identity.uuid, to_remove) if self.options.remove_all: results = overrides.remove_all_overrides(self.identity.uuid, self.options.repos) # Update the cache and refresh the repo file. overrides.update(results)
class OverrideTests(SubManFixture): def setUp(self): SubManFixture.setUp(self) self.overrides = Overrides() def test_add_function(self): repos = ['x', 'y'] override_props = {'a': 'b', 'c': 'd'} overrides = [ Override(repo, name, value) for repo in repos for name, value in list(override_props.items()) ] expected = [ { 'contentLabel': 'x', 'name': 'a', 'value': 'b' }, { 'contentLabel': 'x', 'name': 'c', 'value': 'd' }, { 'contentLabel': 'y', 'name': 'a', 'value': 'b' }, { 'contentLabel': 'y', 'name': 'c', 'value': 'd' }, ] result = self.overrides._add(overrides) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_function(self): repos = ['x', 'y'] props_to_remove = ['a', 'b'] removes = [ Override(repo, name) for repo in repos for name in props_to_remove ] expected = [ { 'contentLabel': 'x', 'name': 'a' }, { 'contentLabel': 'x', 'name': 'b' }, { 'contentLabel': 'y', 'name': 'a' }, { 'contentLabel': 'y', 'name': 'b' }, ] result = self.overrides._remove(removes) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all(self): repos = ['x', 'y'] expected = [ { 'contentLabel': 'x' }, { 'contentLabel': 'y' }, ] result = self.overrides._remove_all(repos) self.assertTrue(self.assert_items_equals(expected, result)) def test_remove_all_with_no_repos_given(self): repos = [] result = self.overrides._remove_all(repos) self.assertEqual(None, result)