Update Tuskar Contribution Guidelines

Change-Id: I82f7a46095db6669ed0f32bc1101de560e53b06a
This commit is contained in:
Dougal Matthews 2014-10-02 14:07:56 +01:00
parent bd1fb8ec1e
commit 3f72cb5ffb

View File

@ -2,19 +2,24 @@
Contributing to Tuskar Contributing to Tuskar
====================== ======================
Tuskar follows the OpenStack processes when it comes to code, communication, Tuskar follows the OpenStack development processes for code and
etc. The `repositories are hosted on git.openstack.org communication. The `repository is hosted on git.openstack.org
<http://git.openstack.org/cgit/openstack/tuskar>`_, <http://git.openstack.org/cgit/openstack/tuskar>`_, `bugs and
`bugs and blueprints are on Launchpad blueprints are on Launchpad <https://launchpad.net/tuskar>`_ and
<https://launchpad.net/tuskar>`_ and we use the openstack-dev mailing list we use the openstack-dev mailing list (subject `[tuskar]`) and
(subject `[tuskar]`) and the `#tuskar` IRC channel for communication. the `#tripleo` IRC channel for communication.
As Tuskar is under the TripleO umbrella of projects you will also
want to look at the `TripleO contributing guidelines
<http://docs.openstack.org/developer/tripleo-
incubator/CONTRIBUTING.html>`_.
Coding Standards Coding Standards
---------------- ----------------
We attempt to comply with the OpenStack coding standards, defined in We comply with the `OpenStack coding standards
http://docs.openstack.org/developer/hacking/ <http://docs.openstack.org/developer/hacking/>`_.
Be sure to familiarise yourself with `OpenStack's Gerrit Workflow Be sure to familiarise yourself with `OpenStack's Gerrit Workflow
<https://wiki.openstack.org/wiki/Gerrit_Workflow>`_. <https://wiki.openstack.org/wiki/Gerrit_Workflow>`_.
@ -22,40 +27,40 @@ Be sure to familiarise yourself with `OpenStack's Gerrit Workflow
Before submitting your code, please make sure you have completed Before submitting your code, please make sure you have completed
the following checklist: the following checklist:
1. Update tools/sample\_data.py (if needed) #. Update the API docs (if needed)
2. Update the API docs (if needed) #. Update the tests (if needed)
3. Update the tests (if needed)
4. Update
`cURL commands <docs/api/curl.rst>`_
page (if needed)
Finding your way around Finding your way around
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
There are various pieces of the codebase that may not be immediately There are various pieces of the codebase that may not be
obvious to a newcomer to the project, so we attempt to explain some of immediately obvious to a newcomer to the project, so we attempt
that in this section. to explain some of that in this section.
* Where do the tuskar commands come from? (tuskar-api, tuskar-dbsync, etc) Where do the tuskar commands come from? (tuskar-api, tuskar-dbsync, etc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The project-specific commands live in tuskar/cmd, and are The project-specific commands live in tuskar/cmd, and are
implementations that use the oslo.config project as a base. They are implementations that use the oslo.config project as a base. They
generated and put into your venv when you run 'python setup.py are generated and put into your venv when you run 'python
develop'. Adding a new one consists of: setup.py develop'. Adding a new one consists of:
1. Creating a new file in tuskar/cmd #. Creating a new file in tuskar/cmd
2. Adding the appropriate name and package reference to the #. Adding the appropriate name and package reference to the
entry\_points section of setup.cfg entry\_points section of setup.cfg
* How do I add a new controller? How do I add a new controller?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Controllers are contained in tuskar/api/controllers/v1.py. To add a Controllers are contained in tuskar/api/controllers/v2.py. To add
new controller, you need to add an 'HTTP Representation' of whatever a new controller, you need to add an 'HTTP Representation' of
model you wish to expose with this controller. This is a simple whatever model you wish to expose with this controller. This is a
python object that extends Base, and describes the key and value simple python object that extends Base, and describes the key and
types that the object will return. For example, say there is a Foo value types that the object will return. For example, say there
model object you wish to return:: is a Foo model object you wish to return.
.. code-block:: python
class Foo(Base): class Foo(Base):
id = int id = int
@ -63,7 +68,9 @@ that in this section.
fred = Fred # Fred is another object defined in this file fred = Fred # Fred is another object defined in this file
Then add a controller for it (anywhere above the Controller class, Then add a controller for it (anywhere above the Controller class,
which is the last in the file. For example:: which is the last in the file. For example:
.. code-block:: python
class FoosController(rest.RestController): class FoosController(rest.RestController):
@wsme_pecan.wsexpose([Foo]) @wsme_pecan.wsexpose([Foo])
@ -73,50 +80,54 @@ that in this section.
return result return result
Lastly, add a reference to the controller in the Controller class at Lastly, add a reference to the controller in the Controller class at
the bottom of the file as so:: the bottom of the file as so.
.. code-block:: python
class Controller(object): class Controller(object):
foos = FoosController() foos = FoosController()
The name you give the controller above will be how it is accessed by The name you give the controller above will be how it is accessed by
the client, so in the above case, you could get the list of foos the client, so in the above case, you could get the list of foos
with:: with.
.. code-block:: bash
curl http://0.0.0.0:8585/v1/foos curl http://0.0.0.0:8585/v1/foos
For doing something simple, like a poc controller that doesn't For doing something simple, like a poc controller that doesn't
return any objects, you can return plain text as so:: return any objects, you can return plain text as so
.. code-block:: python
class FarkleController(rest.RestController): class FarkleController(rest.RestController):
@wsme_pecan.wsexpose(None, wtypes.text) @wsme_pecan.wsexpose(None, wtypes.text)
def get_all(self): def get_all(self):
return "Hi, I am farkle!" return "Hi, I am farkle!"
* Where are my changes to the app? Where are my changes to the app?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are two possible answers: You may make a change to, say, a controller, and wonder why your
1. You may make a change to, say, a controller, and wonder why your
change does not seem to happen when you call your curl command on change does not seem to happen when you call your curl command on
that resource. This is because, at least at the current time, you that resource. This is because, at least at the current time, you
must -c to kill the tuskar-api server, and then start it again to must ctrl+c to kill the tuskar-api server, and then restart it
pick up your changes. again to pick up your changes.
2. You may have changed something that requires you to rerun 'python
setup.py develop', such as changing or adding a new command in
the cmd dir described above
* How do I create a new model? How do I create a new model?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Models live in tuskar/db/sqlalchemy/. There are two files here of Models live in tuskar/db/sqlalchemy/. There are two files here of
relevance for describing the model (we will get to defining the relevance for describing the model (we will get to defining the
table in the next section), api.py and models.py. The models.py file table in the next section), api.py and models.py. The models.py
contains the definition of the columns to expose to the client for file contains the definition of the columns to expose to the
the model objects, as well as a mapping of the object in this file client for the model objects, as well as a mapping of the object
to the tablename define in the migration (below). In api.py, we have in this file to the tablename define in the migration (below). In
utility methods, as well as validation rules and other custom api.py, we have utility methods, as well as validation rules and
methods for interacting with the models. other custom methods for interacting with the models.
* How do I define the table for my new model? How do I define the table for my new model?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is described in a migration file, located in This is described in a migration file, located in
tuskar/db/sqlalchemy/migrate\_repo/versions/. Each new table or tuskar/db/sqlalchemy/migrate\_repo/versions/. Each new table or
@ -135,18 +146,12 @@ Writing and Running tests
We use testtools for our unit tests, and mox for mock objects. We use testtools for our unit tests, and mox for mock objects.
You can run tests using Tox: :: You can run tests using Tox:
.. code-block:: bash
$ tox $ tox
This will run tests under Python 2.6, 2.7 and verify `PEP 8 This will run tests under Python 2.6, 2.7 and verify `PEP 8
<http://www.python.org/dev/peps/pep-0008/>`_ compliance. The identical test <http://www.python.org/dev/peps/pep-0008/>`_ compliance. The identical test
suite is run by OpenStack's Jenkins whenever you send a patch. suite is run by OpenStack's Jenkins whenever you send a patch.
PEP8 check runs ::
$ ./tools/requirements_style_check.sh requirements.txt test-requirements.txt
as last check. This can fail on Fedora 20 due to `sort bug <https://bugzilla.redhat.com/show_bug.cgi?id=1055597>`_.
Additional details forthcoming.