File: development.environment.rst

package info (click to toggle)
zaqar 21.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,964 kB
  • sloc: python: 28,819; sh: 513; java: 135; makefile: 63; javascript: 50
file content (306 lines) | stat: -rw-r--r-- 8,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
..
      Licensed under the Apache License, Version 2.0 (the "License"); you may
      not use this file except in compliance with the License. You may obtain
      a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
      WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
      License for the specific language governing permissions and limitations
      under the License.

====================================
Setting up a development environment
====================================

This section describes how to setup a working Python development environment
that you can use in developing Zaqar on Ubuntu or Fedora. These instructions
assume that you are familiar with Git. Refer to GettingTheCode_ for
additional information.

.. _GettingTheCode: https://wiki.openstack.org/wiki/Getting_The_Code


Virtual environments
--------------------

Use virtualenv_ to track and manage Python dependencies for developing and
testing Zaqar.
Using virtualenv_ enables you to install Python dependencies in an isolated
virtual environment, instead of installing the packages at the system level.

.. _virtualenv: https://pypi.org/project/virtualenv

.. note::

   Virtualenv is useful for development purposes, but is not typically used for
   full integration testing or production usage. If you want to learn about
   production best practices, check out the `OpenStack Operations Guide`_.

   .. _`OpenStack Operations Guide`: https://wiki.openstack.org/wiki/OpsGuide

Install GNU/Linux system dependencies
#####################################

.. note::

  This section is tested for Zaqar on Ubuntu 14.04 (Trusty) and Fedora-based
  (RHEL 6.1) distributions. Feel free to add notes and change according to your
  experiences or operating system. Learn more about contributing to Zaqar
  documentation in the :doc:`welcome` manual.

Install the prerequisite packages.

On Ubuntu:

.. code-block:: console

  $ sudo apt-get install gcc python-pip libxml2-dev libxslt1-dev python-dev zlib1g-dev

On Fedora-based distributions (e.g., Fedora/RHEL/CentOS):

.. code-block:: console

  $ sudo dnf install gcc python-pip libxml2-devel libxslt-devel python3-devel

Install MongoDB
###############

You also need to have MongoDB_ installed and running.

.. _MongoDB: http://www.mongodb.org

On Ubuntu, follow the instructions in the
`MongoDB on Ubuntu Installation Guide`_.

.. _`MongoDB on Ubuntu installation guide`: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

On Fedora-based distributions, follow the instructions in the
`MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon Linux
Installation Guide`_.

.. _`MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon Linux installation guide`: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/

.. note::

  If you are Contributor and plan to run Unit tests on Zaqar, you may want to
  add this line to mongodb configuration file (``etc/mongod.conf`` or
  ``etc/mongodb.conf`` depending on distribution):

  .. code-block:: ini

    smallfiles = true

  Many Zaqar's Unit tests do not clean up their testing databases after
  executing. And database files consume much disk space even if they do not
  contain any records. This behavior will be fixed soon.

Getting the code
################

Get the code from git.openstack.org to create a local repository with Zaqar:

.. code-block:: console

  $ git clone https://git.openstack.org/openstack/zaqar.git

Configuration
#############

#. From your home folder create the ``~/.zaqar`` folder. This directory holds
   the configuration files for Zaqar:

   .. code-block:: console

     $ mkdir ~/.zaqar

#. Generate the sample configuration file ``zaqar/etc/zaqar.conf.sample``:

   .. code-block:: console

     $ pip install tox
     $ cd zaqar
     $ tox -e genconfig

#. Copy the Zaqar configuration samples to the directory ``~/.zaqar/``:

   .. code-block:: console

     $ cp etc/zaqar.conf.sample ~/.zaqar/zaqar.conf
     $ cp etc/logging.conf.sample ~/.zaqar/logging.conf

#. Find the ``[drivers]`` section in ``~/.zaqar/zaqar.conf`` and specify
   ``mongodb`` as the message store:

   .. code-block:: ini

     message_store = mongodb
     management_store = mongodb

#. Then find ``[drivers:message_store:mongodb]`` and
   ``[drivers:management_store:mongodb]`` sections and specify the
   :samp:`{URI}` to point to your local mongodb instance by adding this line
   to both the sections:

   .. code-block:: ini

     uri = mongodb://$MONGODB_HOST:$MONGODB_PORT

   By default you will have:

   .. code-block:: ini

     uri = mongodb://127.0.0.1:27017

   This :samp:`{URI}` points to single mongodb node which of course is not
   reliable, so you need to set in the ``[default]`` section of configuration
   file:

   .. code-block:: ini

     unreliable = True

   For your reference, you can omit this parameter or set it to False only
   if the provided :samp:`{URI}` to your mongodb is actually the URI to mongodb
   Replica Set or Mongos. Also it must have "Write concern" parameter set to
   ``majority`` or to a number more than ``1``.

   For example, :samp:`{URI}` to reliable mongodb can look like this:

   .. code-block:: ini

     uri = mongodb://mydb0,mydb1,mydb2:27017/?replicaSet=foo&w=2

   Where ``mydb0``, ``mydb1``, ``mydb2`` are addresses of the configured
   mongodb Replica Set nodes, ``replicaSet`` (Replica Set name) parameter is
   set to ``foo``, ``w`` (Write concern) parameter is set to ``2``.

#. For logging, find the ``[handler_file]`` section in
   ``~/.zaqar/logging.conf`` and modify as desired:

   .. code-block:: ini

     args=('zaqar.log', 'w')

Installing and using virtualenv
###############################

#. Install virtualenv by running:

   .. code-block:: console

     $ pip install virtualenv

#. Create and activate a virtual environment:

   .. code-block:: console

     $ virtualenv zaqarenv
     $ source zaqarenv/bin/activate

#. Install Zaqar:

   .. code-block:: console

     $ pip install -e .

#. Install the required Python binding for MongoDB:

   .. code-block:: console

     $ pip install pymongo

#. Start Zaqar server in ``info`` logging mode:

   .. code-block:: console

     $ zaqar-server -v

   Or you can start Zaqar server in ``debug`` logging mode:

   .. code-block:: console

     $ zaqar-server -d

#. Verify Zaqar is running by creating a queue via curl. In a separate
   terminal run:

   .. code-block:: console

     $ curl -i -X PUT http://localhost:8888/v2/queues/samplequeue -H "Content-type: application/json" -H 'Client-ID: 123e4567-e89b-12d3-a456-426655440000' -H 'X-PROJECT-ID: 12345'

   .. note::

     ``Client-ID`` expects a valid UUID.

     ``X-PROJECT-ID`` expects a user-defined project identifier.


#. Get ready to code!

.. note::

  You can run the Zaqar server in the background by passing the
  ``--daemon`` flag:

  .. code-block:: console

    $ zaqar-server -v --daemon

  But with this method you will not get immediate visual feedback and it will
  be harder to kill and restart the process.

Troubleshooting
^^^^^^^^^^^^^^^

No handlers found for zaqar.client (...)
""""""""""""""""""""""""""""""""""""""""

This happens because the current user cannot create the log file (for the
default configuration in ``/var/log/zaqar/server.log``). To solve it, create
the folder:

.. code-block:: console

  $ sudo mkdir /var/log/zaqar

Create the file:

.. code-block:: console

  $ sudo touch /var/log/zaqar/server.log

And try running the server again.

DevStack
--------

If you want to use Zaqar in an integrated OpenStack developing environment, you
can add it to your DevStack_ deployment.

To do this, you first need to add the following setting to your ``local.conf``:

.. code-block:: bash

  enable_plugin zaqar https://git.openstack.org/openstack/zaqar

Then run the ``stack.sh`` script as usual.

.. _DevStack: https://docs.openstack.org/devstack/latest/

Running tests
-------------

See :doc:`running_tests` for details.

Running the benchmarking tool
-----------------------------

See :doc:`../admin/running_benchmark` for details.

Contributing your work
----------------------

See :doc:`welcome` and :doc:`first_patch` for details.