From b4ca952461a432b3dca4c47ad0b3e0ab108a5d7c Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Wed, 23 Oct 2019 03:02:44 -0400 Subject: [PATCH] Depend on pulpcore directly instead of pulpcore-plugin Required PR: https://github.com/pulp/pulpcore/pull/347 re: #5580 https://pulp.plan.io/issues/5580 --- .travis.yml | 15 +-- .travis/before_install.sh | 52 +++++----- .travis/install.sh | 6 -- CHANGES/5580.misc | 1 + README.md | 5 + pulp_rpm/app/settings.py | 6 ++ .../functional/api/test_crud_publishers.py | 97 +++++++++++++++++++ pulp_rpm/tests/unit/test_serializers.py | 40 ++++++++ 8 files changed, 182 insertions(+), 40 deletions(-) create mode 100644 CHANGES/5580.misc create mode 100644 README.md create mode 100644 pulp_rpm/app/settings.py create mode 100644 pulp_rpm/tests/functional/api/test_crud_publishers.py create mode 100644 pulp_rpm/tests/unit/test_serializers.py diff --git a/.travis.yml b/.travis.yml index 22f71276cb..312756f81e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,15 +16,15 @@ python: - "3.7" env: matrix: - - DB=postgres TEST=pulp - - DB=postgres TEST=docs - - DB=postgres TEST=bindings + - TEST=pulp + - TEST=docs + - TEST=bindings matrix: exclude: - python: '3.6' - env: DB=postgres TEST=bindings + env: TEST=bindings - python: '3.6' - env: DB=postgres TEST=docs + env: TEST=docs fast_finish: true services: - postgresql @@ -61,30 +61,25 @@ jobs: - stage: publish-daily-client-gem script: bash .travis/publish_client_gem.sh env: - - DB=postgres - TEST=bindings if: type = cron - stage: publish-daily-client-pypi script: bash .travis/publish_client_pypi.sh env: - - DB=postgres - TEST=bindings if: type = cron - stage: publish-client-gem script: bash .travis/publish_client_gem.sh env: - - DB=postgres - TEST=bindings if: tag IS present - stage: publish-client-pypi script: bash .travis/publish_client_pypi.sh env: - - DB=postgres - TEST=bindings if: tag IS present - stage: daily-performance-test env: - - DB=postgres - TEST=performance if: type = cron notifications: None diff --git a/.travis/before_install.sh b/.travis/before_install.sh index 325d42f9f5..57bc674a16 100755 --- a/.travis/before_install.sh +++ b/.travis/before_install.sh @@ -24,12 +24,20 @@ if [[ -n $(echo -e $COMMIT_MSG | grep -P "Required PR:.*" | grep -v "https") ]]; exit 1 fi -export PULP_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore\/pull\/(\d+)' | awk -F'/' '{print $7}') -export PULP_PLUGIN_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore-plugin\/pull\/(\d+)' | awk -F'/' '{print $7}') -export PULP_SMASH_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/PulpQE\/pulp-smash\/pull\/(\d+)' | awk -F'/' '{print $7}') -export PULP_ROLES_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/ansible-pulp\/pull\/(\d+)' | awk -F'/' '{print $7}') -export PULP_BINDINGS_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-openapi-generator\/pull\/(\d+)' | awk -F'/' '{print $7}') -export PULP_OPERATOR_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-operator\/pull\/(\d+)' | awk -F'/' '{print $7}') +if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ -z "$TRAVIS_TAG" -a "$TRAVIS_BRANCH" != "master"] +then + export PULP_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore\/pull\/(\d+)' | awk -F'/' '{print $7}') + export PULP_SMASH_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/PulpQE\/pulp-smash\/pull\/(\d+)' | awk -F'/' '{print $7}') + export PULP_ROLES_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/ansible-pulp\/pull\/(\d+)' | awk -F'/' '{print $7}') + export PULP_BINDINGS_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-openapi-generator\/pull\/(\d+)' | awk -F'/' '{print $7}') + export PULP_OPERATOR_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-operator\/pull\/(\d+)' | awk -F'/' '{print $7}') +else + export PULP_PR_NUMBER= + export PULP_SMASH_PR_NUMBER= + export PULP_ROLES_PR_NUMBER= + export PULP_BINDINGS_PR_NUMBER= + export PULP_OPERATOR_PR_NUMBER= +fi # test_requirements contains tools needed for flake8, etc. # So install them here rather than in install.sh @@ -58,6 +66,10 @@ if [ -n "$PULP_OPERATOR_PR_NUMBER" ]; then cd pulp-operator git fetch --depth=1 origin +refs/pull/$PULP_OPERATOR_PR_NUMBER/merge git checkout FETCH_HEAD + RELEASE_VERSION=v0.9.0 + curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu + chmod +x operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu && sudo mkdir -p /usr/local/bin/ && sudo cp operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu /usr/local/bin/operator-sdk && rm operator-sdk-${RELEASE_VERSION}-x86_64-linux-gnu + sudo operator-sdk build --image-builder=docker quay.io/pulp/pulp-operator:latest cd .. fi @@ -76,29 +88,21 @@ fi # build (they will be installed as dependencies of the plugin). if [ -z "$TRAVIS_TAG" ]; then - git clone --depth=1 https://github.com/pulp/pulpcore-plugin.git - - if [ -n "$PULP_PLUGIN_PR_NUMBER" ]; then - cd pulpcore-plugin - git fetch --depth=1 origin +refs/pull/$PULP_PLUGIN_PR_NUMBER/merge - git checkout FETCH_HEAD - cd .. - fi +git clone --depth=1 https://github.com/PulpQE/pulp-smash.git +if [ -n "$PULP_SMASH_PR_NUMBER" ]; then + cd pulp-smash + git fetch --depth=1 origin +refs/pull/$PULP_SMASH_PR_NUMBER/merge + git checkout FETCH_HEAD + cd .. +fi - git clone --depth=1 https://github.com/PulpQE/pulp-smash.git - - if [ -n "$PULP_SMASH_PR_NUMBER" ]; then - cd pulp-smash - git fetch --depth=1 origin +refs/pull/$PULP_SMASH_PR_NUMBER/merge - git checkout FETCH_HEAD - cd .. - fi +# pulp-smash already got installed via test_requirements.txt +pip install --upgrade --force-reinstall ./pulp-smash - # pulp-smash already got installed via test_requirements.txt - pip install --upgrade --force-reinstall ./pulp-smash fi + pip install ansible cd pulp_rpm diff --git a/.travis/install.sh b/.travis/install.sh index e33accc7ef..638ab17ff5 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -52,8 +52,6 @@ PLUGIN=pulp_rpm # For pulpcore, and any other repo that might check out some plugin PR - - if [ -n "$TRAVIS_TAG" ]; then # Install the plugin only and use published PyPI packages for the rest cat > vars/vars.yaml << VARSYAML @@ -64,7 +62,6 @@ images: tag: $TAG plugins: - ./$PLUGIN - VARSYAML else cat > vars/vars.yaml << VARSYAML @@ -74,13 +71,10 @@ images: image_name: $PLUGIN tag: $TAG pulpcore: ./pulpcore - pulpcore_plugin: ./pulpcore-plugin plugins: - ./$PLUGIN - VARSYAML fi - ansible-playbook build.yaml cd $TRAVIS_BUILD_DIR/../pulp-operator diff --git a/CHANGES/5580.misc b/CHANGES/5580.misc new file mode 100644 index 0000000000..6db2c40fdf --- /dev/null +++ b/CHANGES/5580.misc @@ -0,0 +1 @@ +Depend on pulpcore, directly, instead of pulpcore-plugin. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000..ce8adc1190 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# pulp-rpm + +A Pulp plugin to support hosting your own rpm. + +For more information, please see the [documentation](docs/index.rst) or the [Pulp project page](https://pulpproject.org/). diff --git a/pulp_rpm/app/settings.py b/pulp_rpm/app/settings.py new file mode 100644 index 0000000000..282e113f4a --- /dev/null +++ b/pulp_rpm/app/settings.py @@ -0,0 +1,6 @@ +""" +Check `Plugin Writer's Guide`_ for more details. + +.. _Plugin Writer's Guide: + http://docs.pulpproject.org/en/3.0/nightly/plugins/plugin-writer/index.html +""" diff --git a/pulp_rpm/tests/functional/api/test_crud_publishers.py b/pulp_rpm/tests/functional/api/test_crud_publishers.py new file mode 100644 index 0000000000..9d70dfbc91 --- /dev/null +++ b/pulp_rpm/tests/functional/api/test_crud_publishers.py @@ -0,0 +1,97 @@ +# coding=utf-8 +"""Tests that CRUD content_unit publishers.""" +import unittest + +from requests.exceptions import HTTPError + +from pulp_smash import api, config +from pulp_smash.pulp3.constants import REPO_PATH +from pulp_smash.pulp3.utils import gen_repo + +from pulp_rpm.tests.functional.constants import RPM_PUBLISHER_PATH +from pulp_rpm.tests.functional.utils import gen_rpm_publisher, skip_if +from pulp_rpm.tests.functional.utils import set_up_module as setUpModule # noqa:F401 + + +class CRUDPublishersTestCase(unittest.TestCase): + """CRUD publishers.""" + + @classmethod + def setUpClass(cls): + """Create class-wide variables. + + In order to create a publisher a repository has to be created first. + """ + cls.cfg = config.get_config() + cls.client = api.Client(cls.cfg, api.json_handler) + cls.publisher = {} + cls.repo = cls.client.post(REPO_PATH, gen_repo()) + + @classmethod + def tearDownClass(cls): + """Clean class-wide variable.""" + cls.client.delete(cls.repo["pulp_href"]) + + def test_01_create_publisher(self): + """Create a publisher.""" + body = gen_rpm_publisher() + type(self).publisher = self.client.post(RPM_PUBLISHER_PATH, body) + for key, val in body.items(): + with self.subTest(key=key): + self.assertEqual(self.publisher[key], val) + + @skip_if(bool, "publisher", False) + def test_02_create_same_name(self): + """Try to create a second publisher with an identical name. + + See: `Pulp Smash #1055 + `_. + """ + body = gen_rpm_publisher() + body["name"] = self.publisher["name"] + with self.assertRaises(HTTPError): + self.client.post(RPM_PUBLISHER_PATH, body) + + @skip_if(bool, "publisher", False) + def test_02_read_publisher(self): + """Read a publisher by its href.""" + publisher = self.client.get(self.publisher["pulp_href"]) + for key, val in self.publisher.items(): + with self.subTest(key=key): + self.assertEqual(publisher[key], val) + + @skip_if(bool, "publisher", False) + def test_02_read_publishers(self): + """Read a publisher by its name.""" + page = self.client.get(RPM_PUBLISHER_PATH, params={"name": self.publisher["name"]}) + self.assertEqual(len(page["results"]), 1) + for key, val in self.publisher.items(): + with self.subTest(key=key): + self.assertEqual(page["results"][0][key], val) + + @skip_if(bool, "publisher", False) + def test_03_partially_update(self): + """Update a publisher using HTTP PATCH.""" + body = gen_rpm_publisher() + self.client.patch(self.publisher["pulp_href"], body) + type(self).publisher = self.client.get(self.publisher["pulp_href"]) + for key, val in body.items(): + with self.subTest(key=key): + self.assertEqual(self.publisher[key], val) + + @skip_if(bool, "publisher", False) + def test_04_fully_update(self): + """Update a publisher using HTTP PUT.""" + body = gen_rpm_publisher() + self.client.put(self.publisher["pulp_href"], body) + type(self).publisher = self.client.get(self.publisher["pulp_href"]) + for key, val in body.items(): + with self.subTest(key=key): + self.assertEqual(self.publisher[key], val) + + @skip_if(bool, "publisher", False) + def test_05_delete(self): + """Delete a publisher.""" + self.client.delete(self.publisher["pulp_href"]) + with self.assertRaises(HTTPError): + self.client.get(self.publisher["pulp_href"]) diff --git a/pulp_rpm/tests/unit/test_serializers.py b/pulp_rpm/tests/unit/test_serializers.py new file mode 100644 index 0000000000..e33c514e40 --- /dev/null +++ b/pulp_rpm/tests/unit/test_serializers.py @@ -0,0 +1,40 @@ +import unittest +from django.test import TestCase + +from pulp_rpm.app.serializers import RpmContentSerializer +from pulp_rpm.app.models import RpmContent + +from pulpcore.plugin.models import Artifact + + +# Fill data with sufficient information to create RpmContent +# Provide sufficient parameters to create the RpmContent object +# Depending on the base class of the serializer, provide either "_artifact" or "_artifacts" +@unittest.skip("FIXME: plugin writer action required") +class TestRpmContentSerializer(TestCase): + """Test RpmContentSerializer.""" + + def setUp(self): + """Set up the RpmContentSerializer tests.""" + self.artifact = Artifact.objects.create( + md5="ec0df26316b1deb465d2d18af7b600f5", + sha1="cf6121b0425c2f2e3a2fcfe6f402d59730eb5661", + sha224="9a6297eb28d91fad5277c0833856031d0e940432ad807658bd2b60f4", + sha256="c8ddb3dcf8da48278d57b0b94486832c66a8835316ccf7ca39e143cbfeb9184f", + sha384="53a8a0cebcb7780ed7624790c9d9a4d09ba74b47270d397f5ed7bc1c46777a0fbe362aaf2bbe7f0966a350a12d76e28d", # noqa + sha512="a94a65f19b864d184a2a5e07fa29766f08c6d49b6f624b3dd3a36a98267b9137d9c35040b3e105448a869c23c2aec04c9e064e3555295c1b8de6515eed4da27d", # noqa + size=1024, + ) + + def test_valid_data(self): + """Test that the RpmContentSerializer accepts valid data.""" + data = {"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk)} + serializer = RpmContentSerializer(data=data) + self.assertTrue(serializer.is_valid()) + + def test_duplicate_data(self): + """Test that the RpmContentSerializer does not accept data.""" + RpmContent.objects.create(artifact=artifact) + data = {"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk)} + serializer = RpmContentSerializer(data=data) + self.assertFalse(serializer.is_valid())