From 99e22d627c039c910ebe3531ea94b193fe602f4e Mon Sep 17 00:00:00 2001 From: Brian Bouterse Date: Tue, 29 Oct 2019 14:54:32 -0400 Subject: [PATCH] Introduce CONTENT_ORIGIN setting This also adds a check that the user specified CONTENT_ORIGIN at startup. Pulp refuses to start if it is not set with an error message for the user. Required PR: https://github.com/PulpQE/pulp-smash/pull/1227 Required PR: https://github.com/pulp/ansible-pulp/pull/185 Required PR: https://github.com/pulp/pulp_file/pull/303 https://pulp.plan.io/issues/5629 re #5629 --- .travis/install.sh | 3 ++- .travis/script.sh | 4 ++++ CHANGES/5629.feature | 1 + CHANGES/plugin_api/5629.feature | 2 ++ docs/installation/configuration.rst | 9 +++++++++ pulpcore/app/serializers/fields.py | 4 ++-- pulpcore/app/settings.py | 10 ++++++++++ .../api/using_plugin/test_content_promotion.py | 3 +-- .../functional/api/using_plugin/test_distributions.py | 11 ++++------- template_config.yml | 2 +- 10 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 CHANGES/5629.feature create mode 100644 CHANGES/plugin_api/5629.feature diff --git a/.travis/install.sh b/.travis/install.sh index 21204e3fbc2..fe041592925 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -92,7 +92,8 @@ spec: password: pulp admin_password: pulp pulp_settings: - content_host: $(hostname):24816 + content_origin: http://$(hostname):24816 + CRYAML # Install k3s, lightweight Kubernetes diff --git a/.travis/script.sh b/.travis/script.sh index 90801eff22f..ddb633d4069 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -20,6 +20,10 @@ export FUNC_TEST_SCRIPT=$TRAVIS_BUILD_DIR/.travis/func_test_script.sh export DJANGO_SETTINGS_MODULE=pulpcore.app.settings if [ "$TEST" = 'docs' ]; then + + # Set CONTENT_ORIGIN for docs environments + echo 'CONTENT_ORIGIN=http://$(hostname):24816' >> $TRAVIS_BUILD_DIR/pulpcore/app/settings.py + cd docs make html cd .. diff --git a/CHANGES/5629.feature b/CHANGES/5629.feature new file mode 100644 index 00000000000..5468207c236 --- /dev/null +++ b/CHANGES/5629.feature @@ -0,0 +1 @@ +Added ``CONTENT_ORIGIN`` setting, which is now required. diff --git a/CHANGES/plugin_api/5629.feature b/CHANGES/plugin_api/5629.feature new file mode 100644 index 00000000000..e2366f74e1b --- /dev/null +++ b/CHANGES/plugin_api/5629.feature @@ -0,0 +1,2 @@ +Added the ``CONTENT_ORIGIN`` setting which can be used to reliably know the scheme+host+port to the +pulp content app. diff --git a/docs/installation/configuration.rst b/docs/installation/configuration.rst index 5266c85b217..74bfe2937e4 100644 --- a/docs/installation/configuration.rst +++ b/docs/installation/configuration.rst @@ -209,6 +209,15 @@ CONTENT_HOST This defaults to ``None`` which returns relative urls. +CONTENT_ORIGIN +^^^^^^^^^^^^^^ + + A required string containing the protocol, fqdn, and port where the content app is reachable by + users. This is used by ``pulpcore`` and various plugins when referring users to the content app. + For example if the API should refer users to content at using http to pulp.example.com on port + 24816, (the content default port), you would set: ``https://pulp.example.com:24816``. + + .. _content-path-prefix: CONTENT_PATH_PREFIX diff --git a/pulpcore/app/serializers/fields.py b/pulpcore/app/serializers/fields.py index 72bc11a318b..f60eff03e89 100644 --- a/pulpcore/app/serializers/fields.py +++ b/pulpcore/app/serializers/fields.py @@ -241,11 +241,11 @@ class BaseURLField(serializers.CharField): def to_representation(self, value): base_path = value - host = settings.CONTENT_HOST + origin = settings.CONTENT_ORIGIN prefix = settings.CONTENT_PATH_PREFIX return '/'.join( ( - host.strip('/'), + origin.strip('/'), prefix.strip('/'), base_path.lstrip('/') )) diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index d34179e7aaa..f6c3563fc20 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -10,9 +10,13 @@ import os from contextlib import suppress +from gettext import gettext as _ from importlib import import_module from pkg_resources import iter_entry_points +from django.core.exceptions import ImproperlyConfigured + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -234,3 +238,9 @@ ENVVAR_FOR_DYNACONF='PULP_SETTINGS', ) # HERE ENDS DYNACONF EXTENSION LOAD (No more code below this line) + + +try: + CONTENT_ORIGIN +except NameError: + raise ImproperlyConfigured(_('You must specify the CONTENT_ORIGIN setting.')) diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py index 112e7bcbc38..fafbda23ea9 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_promotion.py @@ -79,8 +79,7 @@ def test_all(self): unit_urls = [] unit_path = get_added_content(repo)[FILE_CONTENT_NAME][0]['relative_path'] for distribution in distributions: - unit_url = cfg.get_hosts('api')[0].roles['api']['scheme'] - unit_url += '://' + distribution['base_url'] + '/' + unit_url = distribution['base_url'] + '/' unit_urls.append(urljoin(unit_url, unit_path)) client.response_handler = api.safe_handler diff --git a/pulpcore/tests/functional/api/using_plugin/test_distributions.py b/pulpcore/tests/functional/api/using_plugin/test_distributions.py index b22add3d2f6..b91c822318b 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_distributions.py +++ b/pulpcore/tests/functional/api/using_plugin/test_distributions.py @@ -305,12 +305,11 @@ def test_content_served(self): added_content = get_added_content(repo) unit_path = added_content[FILE_CONTENT_NAME][0]['relative_path'] - unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme'] - unit_url += '://' + distribution['base_url'] + '/' + unit_url = distribution['base_url'] + '/' unit_url = urljoin(unit_url, unit_path) pulp_hash = hashlib.sha256( - self.client.using_handler(api.safe_handler).get(unit_url).content + self.client.get(unit_url).content ).hexdigest() fixtures_hash = hashlib.sha256( utils.http_get(urljoin(FILE_URL, unit_path)) @@ -323,12 +322,10 @@ def download_pulp_manifest(self, distribution): unit_url = reduce( urljoin, ( - self.cfg.get_content_host_base_url(), - '//' + distribution['base_url'] + '/', - 'PULP_MANIFEST' + distribution['base_url'] + '/', 'PULP_MANIFEST' ), ) - return self.client.using_handler(api.safe_handler).get(unit_url) + return self.client.get(unit_url) def parse_pulp_manifest(pulp_manifest): diff --git a/template_config.yml b/template_config.yml index 78ce673ab8a..c93138ee873 100644 --- a/template_config.yml +++ b/template_config.yml @@ -21,7 +21,7 @@ plugin_dash_short: pulpcore plugin_name: pulpcore plugin_snake: pulpcore pulp_settings: - content_host: $(hostname):24816 + content_origin: http://$(hostname):24816 pydocstyle: true pypi_username: pulp test_bindings: true