def test_configparsers_equal(self, tidy_writer, stub_create):
     rf = RepoFile()
     other = RawConfigParser()
     for parser in [rf, other]:
         parser.add_section('test')
         parser.set('test', 'key', 'val')
     self.assertTrue(rf._configparsers_equal(other))
Example #2
0
 def test_configparsers_equal(self, tidy_writer, stub_create):
     rf = RepoFile()
     other = RawConfigParser()
     for parser in [rf, other]:
         parser.add_section('test')
         parser.set('test', 'key', 'val')
     self.assertTrue(rf._configparsers_equal(other))
 def test_configparsers_diff_items(self, tidy_writer, stub_create):
     rf = RepoFile()
     other = RawConfigParser()
     for parser in [rf, other]:
         parser.add_section("test")
         parser.set("test", "key", "val")
     rf.set("test", "somekey", "val")
     self.assertFalse(rf._configparsers_equal(other))
 def test_configparsers_equal_int(self, tidy_writer, stub_create):
     rf = RepoFile()
     other = RawConfigParser()
     for parser in [rf, other]:
         parser.add_section("test")
         parser.set("test", "key", "val")
     rf.set("test", "k", 1)
     other.set("test", "k", "1")
     self.assertTrue(rf._configparsers_equal(other))
Example #5
0
def _set_enable_for_yum_repositories(setting, *repo_ids):
    invoker = RepoActionInvoker()
    repos = invoker.get_repos()
    repos_to_change = []

    for r in repo_ids:
        matches = set([repo for repo in repos if fnmatch.fnmatch(repo.id, r)])
        repos_to_change.extend(matches)

    if len(repos_to_change) == 0:
        return 0

    # The cache should be primed at this point by the invoker.get_repos()
    cache = inj.require(inj.OVERRIDE_STATUS_CACHE)
    identity = inj.require(inj.IDENTITY)
    cp_provider = inj.require(inj.CP_PROVIDER)

    if identity.is_valid() and cp_provider.get_consumer_auth_cp(
    ).supports_resource('content_overrides'):
        overrides = [{
            'contentLabel': repo.id,
            'name': 'enabled',
            'value': setting
        } for repo in repos_to_change]
        cp = cp_provider.get_consumer_auth_cp()
        results = cp.setContentOverrides(identity.uuid, overrides)

        cache = inj.require(inj.OVERRIDE_STATUS_CACHE)

        # Update the cache with the returned JSON
        cache.server_status = results
        cache.write_cache()

        invoker.update()
    else:
        for repo in repos_to_change:
            repo['enabled'] = setting

        repo_file = RepoFile()
        repo_file.read()
        for repo in repos_to_change:
            repo_file.update(repo)
        repo_file.write()

    return len(repos_to_change)
Example #6
0
def _set_enable_for_yum_repositories(setting, *repo_ids):
    invoker = RepoActionInvoker()
    repos = invoker.get_repos()
    repos_to_change = []

    for r in repo_ids:
        matches = set([repo for repo in repos if fnmatch.fnmatch(repo.id, r)])
        repos_to_change.extend(matches)

    if len(repos_to_change) == 0:
        return 0

    # The cache should be primed at this point by the invoker.get_repos()
    cache = inj.require(inj.OVERRIDE_STATUS_CACHE)
    identity = inj.require(inj.IDENTITY)
    cp_provider = inj.require(inj.CP_PROVIDER)

    if identity.is_valid() and cp_provider.get_consumer_auth_cp().supports_resource('content_overrides'):
        overrides = [{'contentLabel': repo.id, 'name': 'enabled', 'value': setting} for repo in repos_to_change]
        cp = cp_provider.get_consumer_auth_cp()
        results = cp.setContentOverrides(identity.uuid, overrides)

        cache = inj.require(inj.OVERRIDE_STATUS_CACHE)

        # Update the cache with the returned JSON
        cache.server_status = results
        cache.write_cache()

        invoker.update()
    else:
        for repo in repos_to_change:
            repo['enabled'] = setting

        repo_file = RepoFile()
        repo_file.read()
        for repo in repos_to_change:
            repo_file.update(repo)
        repo_file.write()

    return len(repos_to_change)
Example #7
0
    def test_repo_file(self):
        # Fake that the redhat.repo exists:

        Path.ROOT = '/mnt/sysimage'
        rf = RepoFile()
        self.assertEquals("/mnt/sysimage/etc/yum.repos.d/redhat.repo", rf.path)