Example #1
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("GGBREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)
        if enable and entry.enabled:
            raise InvalidOperation("GGBREPOS0015E", {'repo_id': repo_id})

        if not enable and not entry.enabled:
            raise InvalidOperation("GGBREPOS0016E", {'repo_id': repo_id})

        gingerBaseLock.acquire()
        try:
            if enable:
                entry.enable()
            else:
                entry.disable()

            write_repo_to_file(entry)
        except:
            if enable:
                raise OperationFailed("GGBREPOS0020E", {'repo_id': repo_id})

            raise OperationFailed("GGBREPOS0021E", {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Example #2
0
    def toggleRepo(self, repo_id, enable):
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

        entry = repos.get(repo_id)
        if enable and entry.enabled:
            raise InvalidOperation('GGBREPOS0015E', {'repo_id': repo_id})

        if not enable and not entry.enabled:
            raise InvalidOperation('GGBREPOS0016E', {'repo_id': repo_id})

        gingerBaseLock.acquire()
        try:
            if enable:
                entry.enable()
            else:
                entry.disable()

            write_repo_to_file(entry)
        except Exception:
            if enable:
                raise OperationFailed('GGBREPOS0020E', {'repo_id': repo_id})

            raise OperationFailed('GGBREPOS0021E', {'repo_id': repo_id})
        finally:
            gingerBaseLock.release()

        return repo_id
Example #3
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError("GGBREPOS0012E", {'repo_id': repo_id})

        entry = repos.get(repo_id)

        baseurl = params.get('baseurl', None)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', None)
        metalink = config.get('metalink', None)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter("GGBREPOS0013E")

        if baseurl is not None:
            validate_repo_url(get_expanded_url(baseurl))
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(get_expanded_url(mirrorlist))
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(get_expanded_url(metalink))
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('GGBREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        gingerBaseLock.acquire()
        write_repo_to_file(entry)
        gingerBaseLock.release()
        return repo_id
Example #4
0
    def updateRepo(self, repo_id, params):
        """
        Update a given repository in repositories.Repositories() format
        """
        repos = self._get_repos('GGBREPOS0011E')
        if repo_id not in repos.keys():
            raise NotFoundError('GGBREPOS0012E', {'repo_id': repo_id})

        entry = repos.get(repo_id)

        baseurl = params.get('baseurl', entry.baseurl)
        config = params.get('config', {})
        mirrorlist = config.get('mirrorlist', entry.mirrorlist)
        metalink = config.get('metalink', entry.metalink)

        if baseurl is not None and len(baseurl.strip()) == 0:
            baseurl = None

        if mirrorlist is not None and len(mirrorlist.strip()) == 0:
            mirrorlist = None

        if metalink is not None and len(metalink.strip()) == 0:
            metalink = None

        if baseurl is None and mirrorlist is None and metalink is None:
            raise MissingParameter('GGBREPOS0013E')

        if baseurl is not None:
            validate_repo_url(get_expanded_url(baseurl))
            entry.baseurl = baseurl

        if mirrorlist is not None:
            validate_repo_url(get_expanded_url(mirrorlist))
            entry.mirrorlist = mirrorlist

        if metalink is not None:
            validate_repo_url(get_expanded_url(metalink))
            entry.metalink = metalink

        if mirrorlist and metalink:
            raise InvalidOperation('GGBREPOS0030E')

        entry.id = params.get('repo_id', repo_id)
        entry.name = config.get('repo_name', entry.name)
        entry.gpgcheck = config.get('gpgcheck', entry.gpgcheck)
        entry.gpgkey = config.get('gpgkey', entry.gpgkey)
        gingerBaseLock.acquire()
        write_repo_to_file(entry)
        gingerBaseLock.release()
        return repo_id
    def test_update_repo_attributes(self):
        repos = get_yum_repositories()
        fake_repo_2 = repos['fake-repo-2']
        fake_repo_2.disable()
        fake_repo_2.name = 'This is a fake repo'
        fake_repo_2.baseurl = 'http://a.fake.repo.url'
        fake_repo_2.gpgkey = 'file://a/fake/gpg/key.fake'
        fake_repo_2.gpgcheck = False
        fake_repo_2.metalink = 'this is not a true metalink'
        fake_repo_2.mirrorlist = 'fake mirrorlist'
        write_repo_to_file(fake_repo_2)

        repos = get_yum_repositories()
        fake_repo_2 = repos['fake-repo-2']
        self.assertEqual(False, fake_repo_2.enabled)
        self.assertEqual(False, fake_repo_2.gpgcheck)
        self.assertEqual('This is a fake repo', fake_repo_2.name)
        self.assertEqual('http://a.fake.repo.url', fake_repo_2.baseurl)
        self.assertEqual('file://a/fake/gpg/key.fake', fake_repo_2.gpgkey)
        self.assertEqual('this is not a true metalink', fake_repo_2.metalink)
        self.assertEqual('fake mirrorlist', fake_repo_2.mirrorlist)
Example #6
0
    def test_update_repo_attributes(self):
        repos = get_yum_repositories()
        fake_repo_2 = repos['fake-repo-2']
        fake_repo_2.disable()
        fake_repo_2.name = 'This is a fake repo'
        fake_repo_2.baseurl = 'http://a.fake.repo.url'
        fake_repo_2.gpgkey = 'file://a/fake/gpg/key.fake'
        fake_repo_2.gpgcheck = False
        fake_repo_2.metalink = 'this is not a true metalink'
        fake_repo_2.mirrorlist = 'fake mirrorlist'
        write_repo_to_file(fake_repo_2)

        repos = get_yum_repositories()
        fake_repo_2 = repos['fake-repo-2']
        self.assertEqual(False, fake_repo_2.enabled)
        self.assertEqual(False, fake_repo_2.gpgcheck)
        self.assertEqual('This is a fake repo', fake_repo_2.name)
        self.assertEqual('http://a.fake.repo.url', fake_repo_2.baseurl)
        self.assertEqual('file://a/fake/gpg/key.fake', fake_repo_2.gpgkey)
        self.assertEqual('this is not a true metalink', fake_repo_2.metalink)
        self.assertEqual('fake mirrorlist', fake_repo_2.mirrorlist)