Pulp 3 Developer Notes » History » Sprint/Milestone 13
bizhang, 07/25/2017 10:13 PM
1 | 1 | semyers | # Pulp 3 Developer Notes |
---|---|---|---|
2 | |||
3 | This wiki page is intended for use during early development of Pulp 3. Over time, as our development practices become standard, the contents of this page should be moved into the [Pulp Contributing Guide](https://docs.pulpproject.org/en/3.0/nightly/contributing/index.html) |
||
4 | |||
5 | 5 | semyers | Before reporting issues with the development environment, please ensure that you are using the latest version. |
6 | 4 | semyers | |
7 | 1 | semyers | ## Migrations |
8 | |||
9 | In both platform and plugins, the data model is not complete. As a result, committing migrations to the 3.0-dev branch will result in merge/migration conflicts from pull request to pull request. The simplest solution for now is not to commit migrations to the repository. |
||
10 | |||
11 | Because User model depends on Django's auth app having been migrated, this means that you currently need to run `python manage.py migrate auth` before running a general `python manage.py migrate` to set up the pulp database. |
||
12 | |||
13 | ### Making migrations during development |
||
14 | |||
15 | Tests require migrations to run, so while we should not *commit* migrations to the repositories just yet, we do still need to *make* them. This can be done with the `python manage.py makemigrations` command. Apps that depend on the platform migrations existing (such as plugins) may cause errors when making migrations. To avoid these errors, platform migrations should be made prior to installing any plugins. |
||
16 | |||
17 | Once the initial migrations are created, and model changes made thereafter will require `python manage.py makemigrations` to be run again, following by @python manage.py migrate" so Django can apply the model changes to the database. |
||
18 | |||
19 | 6 | amacdona@redhat.com | If you are using the vagrant environment this is done during provisioning. The `pclean` alias takes care of migrations after resting the db. |
20 | 1 | semyers | |
21 | 13 | bizhang | ### Debugging migrations |
22 | |||
23 | Migrate pulp_file |
||
24 | \<script\>python manage.py makemigrations pulp_file\</script\> |
||
25 | |||
26 | Migrate pulp_app first because (sometimes) makemigrations does not always create the initial migrations if they are not already there |
||
27 | \<script\>python manage.py makemigrations pulp_app\</script\> |
||
28 | |||
29 | 1 | semyers | ## Starting a Web Server |
30 | |||
31 | The Django development server can be started with `python manage.py runserver`. This will run a basic WSGI app that exposes the URLs routed in `urls.py`, allowing you to access the REST API. |
||
32 | |||
33 | If you're using the vagrant [hostmanager](https://rubygems.org/gems/vagrant-hostmanager) plugin, you can easily access the API from the host machine by explicitly binding the web server to all interfaces, e.g. `python manage.py runserver 0.0.0.0:8000`. This should make the API browseable at http://dev.example.com:8000/api/v3/ |
||
34 | |||
35 | ### Authentication |
||
36 | |||
37 | 6 | amacdona@redhat.com | We currently enable Basic HTTP Authentication on the REST API. This can be temporarily disabled by commenting out the `'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',)` line in the `REST_FRAMEWORK` section in `app/pulp/app/settings.py`. Note that this doesn't disable authentication, it just authorizes unauthenticated users to take any action. Basic Authentication should still work. |
38 | 2 | bizhang | |
39 | 6 | amacdona@redhat.com | ## Tasks |
40 | 1 | semyers | |
41 | 6 | amacdona@redhat.com | ### Starting Services |
42 | 1 | semyers | |
43 | 6 | amacdona@redhat.com | If using the vagrant environment, you can start the services with the alias `pstart`. Afterwards, use `prestart`. |
44 | |||
45 | To start the processes manually, if you are using a virtual environment, be sure that the path to celery matches the virtual environment that includes pulp, any plugins, and pulp dependencies. |
||
46 | |||
47 | 2 | bizhang | ~~~ |
48 | 9 | bizhang | sudo -u apache /usr/bin/celery beat --app=pulpcore.tasking.celery_app:celery --scheduler=pulpcore.tasking.services.scheduler.Scheduler -l=INFO --pidfile=/var/run/pulp/scheduler.pid |
49 | 2 | bizhang | |
50 | 9 | bizhang | sudo -u apache /usr/bin/celery worker -A pulpcore.tasking.celery_app:celery -n resource_manager@%%h\ |
51 | 2 | bizhang | -Q resource_manager -c 1 --events --umask 18 --pidfile=/var/run/pulp/resource_manager.pid\ |
52 | --heartbeat-interval=5 -l=INFO |
||
53 | |||
54 | sudo -u apache /usr/bin/celery worker -n reserved_resource_worker-123s@h\ |
||
55 | 9 | bizhang | -A pulpcore.tasking.celery_app:celery -c 1 --events --umask 18\ |
56 | 1 | semyers | --pidfile=/var/run/pulp/reserved_resource_worker-123s.pid\ |
57 | --heartbeat-interval=5 -l=INFO |
||
58 | 2 | bizhang | ~~~ |
59 | |||
60 | 6 | amacdona@redhat.com | ### Deploy tasks from shell |
61 | |||
62 | 2 | bizhang | apply_async and apply_async_with_reservation tasks can be tested from a django shell `python manage.py shell_plus` I usually do the following to test tasks |
63 | |||
64 | ~~~ |
||
65 | 9 | bizhang | from pulpcore.app.tasks import repository |
66 | from pulpcore.app.models import Repository |
||
67 | 2 | bizhang | import uuid |
68 | repo_uuid=str(uuid.uuid4()) |
||
69 | repo=Repository(name=repo_uuid) |
||
70 | repo.save() |
||
71 | 1 | semyers | |
72 | 11 | ttereshc | repository.delete.apply_async(kwargs={'repo_id':repo_uuid}) |
73 | repository.delete.apply_async_with_reservation("foo","bar",kwargs={'repo_id':repo_uuid}) |
||
74 | 1 | semyers | ~~~ |
75 | 6 | amacdona@redhat.com | |
76 | ### Deploy sync task from REST API |
||
77 | |||
78 | 1\. Make sure that you have the file plugin installed with a developer setup. |
||
79 | 2\. Define a `sync` method on the `FileImporter` model. |
||
80 | 3\. Create a repository on the browseable api: |
||
81 | 12 | ttereshc | `http://dev.example.com:8000/api/v3/repositories/` |
82 | 4\. Create an importer. Note, you must specify the repository and the plugin in the URL. |
||
83 | `http://dev.example.com:8000/api/v3/repositories/<repository_name>/importers/file/` |
||
84 | 5\. Sync at the importer's url `http://dev.example.com:8000/api/v3/repositories/<repository_name>importers/file/<importer_name>/sync` |
||
85 | 7 | bizhang | |
86 | ## PyPI |
||
87 | |||
88 | ### Publishing to PyPI |
||
89 | |||
90 | 8 | bizhang | `python setup.py sdist bdist_wheel --python-tag py3` |
91 | 7 | bizhang | `twine upload -s dist/{package}*` |
92 | |||
93 | ### Installing from PyPI |
||
94 | |||
95 | `pip3 install pulpcore` |
||
96 | `export DJANGO_SETTINGS_MODULE=pulpcore.app.settings` |
||
97 | *set up database and migrations* |
||
98 | `django-admin runserver` |
||
99 | 10 | bizhang | |
100 | ## Known Issues |
||
101 | |||
102 | - Creating a repo with notes/scratchpad and updating a repo does not work from the Crispy Forms UI because the UI does not send scratchpad and notes in a json object like the serializer expects. Calling the create/update from httpie or curl does work. `http --auth admin:admin --json PUT http://127.0.0.1:3000/api/v3/repositories/test/ name=test description=123456 scratchpad:='{"test": "asgfdds"}'` |