Skip to content

Commit

Permalink
Remove the dependency on WhiteNoise since the documentation has moved…
Browse files Browse the repository at this point in the history
… to Github

Also add a redirection to preserve links.

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
  • Loading branch information
abompard committed Jun 8, 2022
1 parent 844ad14 commit b539600
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 62 deletions.
10 changes: 6 additions & 4 deletions bodhi-server/bodhi/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""Initialize the Bodhi server."""
from collections import defaultdict
import importlib.metadata
import logging as python_logging

from cornice.validators import DEFAULT_FILTERS
Expand All @@ -26,18 +27,16 @@
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.renderers import JSONP
from pyramid.session import SignedCookieSessionFactory, PickleSerializer
from pyramid.session import PickleSerializer, SignedCookieSessionFactory
from pyramid.tweens import EXCVIEW
from sqlalchemy import engine_from_config, event
from sqlalchemy.orm import scoped_session, sessionmaker
from whitenoise import WhiteNoise
import pkg_resources

from bodhi.server import bugs, buildsys
from bodhi.server.config import config as bodhi_config


import importlib.metadata
METADATA = importlib.metadata.metadata('bodhi-server')
__version__ = METADATA['version']

Expand Down Expand Up @@ -336,6 +335,10 @@ def main(global_config, testing=None, session=None, **settings):
config.add_route('liveness', '/healthz/live')
config.add_route('readyness', '/healthz/ready')

# Legacy: Redirect the previously self-hosted documentation
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hybrid.html#using-subpath-in-a-route-pattern
config.add_route("docs", "/docs/*subpath")

config.scan('bodhi.server.views')
config.scan('bodhi.server.services')
config.scan('bodhi.server.webapp')
Expand Down Expand Up @@ -371,5 +374,4 @@ def main(global_config, testing=None, session=None, **settings):

log.info('Bodhi ready and at your service!')
app = config.make_wsgi_app()
app = WhiteNoise(app, root=bodhi_config["docs_path"], prefix="/docs", index_file=True)
return app
3 changes: 0 additions & 3 deletions bodhi-server/bodhi/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,6 @@ class BodhiConfig(dict):
'Bodhi is disabling automatic push to stable due to negative karma. The '
'maintainer may push manually if they determine that the issue is not severe.'),
'validator': str},
'docs_path': {
'value': '/usr/share/doc/bodhi-docs/html/',
'validator': str},
'dogpile.cache.arguments.filename': {
'value': '/var/cache/bodhi-dogpile-cache.dbm',
'validator': str},
Expand Down
13 changes: 11 additions & 2 deletions bodhi-server/bodhi/server/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

from prometheus_client import CONTENT_TYPE_LATEST, generate_latest, REGISTRY
from pyramid.exceptions import HTTPBadRequest, HTTPForbidden
from pyramid.httpexceptions import HTTPUnauthorized
from pyramid.httpexceptions import HTTPMovedPermanently, HTTPUnauthorized
from pyramid.response import Response
from pyramid.settings import asbool
from pyramid.view import notfound_view_config, view_config
import cornice.errors
import sqlalchemy as sa

from bodhi.server import log, models
from bodhi.server import log, METADATA, models
from bodhi.server.config import config
import bodhi.server.util

Expand Down Expand Up @@ -608,3 +608,12 @@ def exception_json_view(exc, request):
request.errors = errors

return bodhi.server.services.errors.json_handler(request)


@view_config(route_name='docs')
def docs(request):
"""Legacy: Redirect the previously self-hosted documentation."""
major_minor_version = ".".join(METADATA["version"].split(".")[:2])
subpath = "/".join(request.subpath)
url = f"https://fedora-infra.github.io/bodhi/{major_minor_version}/{subpath}"
raise HTTPMovedPermanently(url)
22 changes: 1 addition & 21 deletions bodhi-server/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions bodhi-server/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,6 @@ cache.long_term.expire = 3600
# Celery configuration file
celery_config = /etc/bodhi/celeryconfig.py

# Documentation
docs_path = /usr/share/doc/bodhi-docs/html/


[server:main]
use = egg:waitress#main
Expand Down
3 changes: 1 addition & 2 deletions bodhi-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ click = ">=7.1.2"
colander = "^1.8.3"
cornice = ">=5.0.3"
"dogpile.cache" = "^1.1.2"
pyasn1-modules = "^0.2.8" # Due to an unfortunate dash in its name, installs break if pyasn1 is installed first
pyasn1-modules = "^0.2.8" # Due to an unfortunate dash in its name, installs break if pyasn1 is installed first
fedora-messaging = "^3.0.0"
feedgen= "^0.9.0"
Jinja2 = ">=2.11.3"
Expand All @@ -110,7 +110,6 @@ requests = "^2.25.1"
simplemediawiki = {version = "^1.2.0b2", allow-prereleases = true}
SQLAlchemy = "^1.3.24"
waitress = ">=1.4.4"
whitenoise = ">=5.1.0"

[tool.pytest.ini_options]
addopts = "--cov-config .coveragerc --cov=bodhi --cov-report term --cov-report xml --cov-report html"
Expand Down
2 changes: 1 addition & 1 deletion bodhi-server/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _setup_method(self):
with mock.patch('bodhi.server.Session.remove'):
_app = TestApp(main({}, testing='guest', session=self.db, **self.app_settings))
self.app = _app
self.registry = self.app.app.application.registry
self.registry = self.app.app.registry

# ensure a clean state of the dev build system
buildsys.DevBuildsys.clear()
Expand Down
18 changes: 9 additions & 9 deletions bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def test_koji_config_url(self, *args):
"""
Test html rendering of default build link
"""
self.app.app.application.registry.settings['koji_web_url'] = \
self.registry.settings['koji_web_url'] = \
'https://koji.fedoraproject.org/koji/'
nvr = 'bodhi-2.0.0-2.fc17'
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
Expand All @@ -490,7 +490,7 @@ def test_koji_config_url_without_trailing_slash(self, *args):
"""
Test html rendering of default build link without trailing slash
"""
self.app.app.application.registry.settings['koji_web_url'] = \
self.registry.settings['koji_web_url'] = \
'https://koji.fedoraproject.org/koji'
nvr = 'bodhi-2.0.0-2.fc17'
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
Expand All @@ -507,7 +507,7 @@ def test_koji_config_mock_url_without_trailing_slash(self, *args):
Test html rendering of build link using a mock config variable 'koji_web_url'
without a trailing slash in it
"""
self.app.app.application.registry.settings['koji_web_url'] = 'https://host.org'
self.registry.settings['koji_web_url'] = 'https://host.org'
nvr = 'bodhi-2.0.0-2.fc17'
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
resp = self.app.post_json('/updates/', self.get_update(nvr))
Expand Down Expand Up @@ -1388,7 +1388,7 @@ def test_decision_context_testing(self):
def test_home_html_legal(self):
"""Test the home page HTML when a legal link is configured."""
with mock.patch.dict(
self.app.app.application.registry.settings,
self.registry.settings,
{'legal_link': 'http://loweringthebar.net/'}):
resp = self.app.get('/', headers={'Accept': 'text/html'})

Expand All @@ -1399,7 +1399,7 @@ def test_home_html_legal(self):

def test_home_html_no_legal(self):
"""Test the home page HTML when no legal link is configured."""
with mock.patch.dict(self.app.app.application.registry.settings, {'legal_link': ''}):
with mock.patch.dict(self.registry.settings, {'legal_link': ''}):
resp = self.app.get('/', headers={'Accept': 'text/html'})

assert 'Fedora Updates System' in resp
Expand Down Expand Up @@ -1936,7 +1936,7 @@ def test_get_single_update_html_no_privacy_link(self):
"""Test getting a single update via HTML when no privacy link is configured."""
update = Build.query.filter_by(nvr='bodhi-2.0-1.fc17').one().update

with mock.patch.dict(self.app.app.application.registry.settings, {'privacy_link': ''}):
with mock.patch.dict(self.registry.settings, {'privacy_link': ''}):
resp = self.app.get(f'/updates/{update.alias}',
headers={'Accept': 'text/html'})

Expand All @@ -1952,7 +1952,7 @@ def test_get_single_update_html_privacy_link(self):
update = Build.query.filter_by(nvr='bodhi-2.0-1.fc17').one().update

with mock.patch.dict(
self.app.app.application.registry.settings,
self.registry.settings,
{'privacy_link': 'https://privacyiscool.com'}):
resp = self.app.get(f'/updates/{update.alias}',
headers={'Accept': 'text/html'})
Expand Down Expand Up @@ -5388,7 +5388,7 @@ def test_push_to_stable_button_not_present_when_test_gating_status_failed(self,
update.comment(self.db, 'works', 1, 'bowlofeggs')
# Let's clear any messages that might get sent
self.db.info['messages'] = []
self.app.app.application.registry.settings['test_gating.required'] = True
self.registry.settings['test_gating.required'] = True

resp = self.app.get(f'/updates/{update.alias}', headers={'Accept': 'text/html'})

Expand Down Expand Up @@ -5417,7 +5417,7 @@ def test_push_to_stable_button_present_when_test_gating_status_passed(self, upda
update.comment(self.db, 'works', 1, 'bowlofeggs')
# Let's clear any messages that might get sent
self.db.info['messages'] = []
self.app.app.application.registry.settings['test_gating.required'] = True
self.registry.settings['test_gating.required'] = True

resp = self.app.get(f'/updates/{update.alias}', headers={'Accept': 'text/html'})

Expand Down
1 change: 0 additions & 1 deletion bodhi-server/tests/testing.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ resultsdb_api_url = whatever
sqlalchemy.url = sqlite:///%(here)s/../bodhi-tests.sqlite
# waiverdb_api_url = http://bodhi_user:pass@localhost:6544/api/v1.0
# greenwave_api_url = http://localhost:6545/api/v1.0
docs_path = %(here)s/../docs/_build/html/

[server:main]
use = egg:waitress#main
Expand Down
8 changes: 7 additions & 1 deletion bodhi-server/tests/views/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pytest
import webtest

from bodhi.server import main, util
from bodhi.server import __version__, main, util
from bodhi.server.models import Release, ReleaseState, Update, UpdateStatus

from .. import base
Expand Down Expand Up @@ -500,6 +500,12 @@ def test_api_version(self):
res = self.app.get('/api_version')
assert str(util.version()) in res

def test_docs(self):
"""Test the docs redirection."""
res = self.app.get('/docs/some/where.html', status=301)
ver = ".".join(__version__.split(".")[:2])
assert res.location == f"https://fedora-infra.github.io/bodhi/{ver}/some/where.html"


class TestNotfoundView(base.BasePyTestCase):
"""Test the notfound_view() handler."""
Expand Down
2 changes: 0 additions & 2 deletions devel/ansible/roles/bodhi/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
- python3-sqlalchemy
- python3-sqlalchemy_schemadisplay
- python3-webtest
- python3-whitenoise
- redhat-rpm-config
- screen
- skopeo
Expand Down Expand Up @@ -196,7 +195,6 @@
loop:
- {key: "celery_config", value: "%(here)s/bodhi/bodhi-server/celeryconfig.py"}
- {key: "pungi.basepath", value: "%(here)s/bodhi/devel/ci/integration/bodhi/"}
- {key: "docs_path", value: "%(here)s/bodhi/docs/_build/html/"}

- name: Change development.ini to make bodhi use the staging infrastructure
import_tasks: configure_stg.yml
Expand Down
1 change: 0 additions & 1 deletion devel/ci/Dockerfile-f35
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ RUN dnf install -y \
python3-waitress \
python3-webtest \
python3-wheel \
python3-whitenoise \
python3-yaml \
rpm-build \
rpmdevtools \
Expand Down
1 change: 0 additions & 1 deletion devel/ci/Dockerfile-f36
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ RUN dnf install -y \
python3-waitress \
python3-webtest \
python3-wheel \
python3-whitenoise \
python3-yaml \
rpm-build \
rpmdevtools \
Expand Down
1 change: 0 additions & 1 deletion devel/ci/Dockerfile-pip
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ RUN dnf install -y \
python3-gssapi \
python3-pip \
python3-wheel \
python3-whitenoise \
python3-prometheus_client \
pre-commit

Expand Down
1 change: 0 additions & 1 deletion devel/ci/Dockerfile-rawhide
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ RUN dnf install -y \
python3-waitress \
python3-webtest \
python3-wheel \
python3-whitenoise \
python3-yaml \
rpm-build \
rpmdevtools \
Expand Down
6 changes: 0 additions & 6 deletions devel/ci/integration/bodhi/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ MaxRequestWorkers 100
<Location />
Require all granted
</Location>
<Location /docs/>
Header set Cache-Control public
ExpiresDefault "access plus 1 month"
Header unset ETag
</Location>
<Location /static/>
Header set Cache-Control public
ExpiresDefault "access plus 1 month"
Expand All @@ -55,7 +50,6 @@ LogLevel info
TypesConfig /etc/mime.types
AddDefaultCharset UTF-8
CoreDumpDirectory /tmp
Alias /docs /usr/share/doc/bodhi-docs/html/
Alias /static /usr/lib/python3.7/site-packages/bodhi/server/static/
WSGIDaemonProcess bodhi display-name=bodhi processes=2 threads=2 maximum-requests=1000 home=/httpdir
WSGIApplicationGroup %{GLOBAL}
Expand Down
3 changes: 0 additions & 3 deletions devel/development.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ test_gating.required = True
waiverdb_api_url = http://bodhi_user:pass@localhost:6544/api/v1.0
greenwave_api_url = http://localhost:6545/api/v1.0

# Documentation
docs_path = %(here)s/../docs/_build/html/

[server:main]
use = egg:waitress#main
host = 0.0.0.0
Expand Down
1 change: 1 addition & 0 deletions news/PR4555.dependency
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the dependency on WhiteNoise since the documentation has moved to Github

0 comments on commit b539600

Please sign in to comment.