XiVO confd
==========

[![Build Status](https://travis-ci.org/xivo-pbx/xivo-confd.png?branch=master)](https://travis-ci.org/xivo-pbx/xivo-confd)

XiVO CONFD is a web server that provides a [RESTful](http://en.wikipedia.org/wiki/Representational_state_transfer)
service for configuring and managing a XiVO server.


Installing xivo-confd
---------------------

The server is already provided as a part of [XiVO](http://documentation.xivo.solutions).
Please refer to [the documentation](https://documentation.xivo.solutions/en/stable/xivo/installation/installation.html) for
further details on installing one.


Running unit tests
------------------

We used  to do :
```
apt-get install libpq-dev python-dev libffi-dev libyaml-dev
pip install tox
tox --recreate -e py27
```

But now we can do :
1) Run the latest version of the debian-builder container mounting the project directories (HOME by default)
``` 
docker run --rm -it --user "`id -u`:`id -g`" \
 -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro \
 -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:rw \
 -v /etc/shadow:/etc/shadow:ro -v "$HOME":"$HOME" \
 -w "`pwd`" -e HOME=$HOME xivoxc/debian-builder:2021.13.latestdev
```
2) Launch all of them with tox :
```
tox --recreate -e py37
```

Running integration tests
-------------------------

Below the new procedure to run integration tests :
1) go to the integration-tests folder
2) Clone a copy of the required projects in that folder :
```   
rm -rf xivo-provisioning xivo-manage-db xivo-db xivo-config rabbitmq
git clone --depth 1 -b master "git@gitlab.com:xivo.solutions/xivo-provisioning.git"
git clone --depth 1 -b master "git@gitlab.com:xivo.solutions/xivo-db.git"
git clone --depth 1 -b master "git@gitlab.com:xivo.solutions/xivo-config.git"
git clone --depth 1 "git@gitlab.com:xivo.solutions/rabbitmq.git"
cp xivo-config/etc/xivo/default_french_configuration.sql ../
```
3) run an instance of the debian-builder container, mounting the docker socket, the network and the project directories (HOME by default)

```
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro \
--network host \
-v /etc/shadow:/etc/shadow:ro -v "$HOME":"$HOME" -w "`pwd`" xivoxc/debian-builder:2021.13.latestdev
```
4) You are now in a docker. Let's create a virtualenv and install the test requirements :
```
python3 -m venv /tmp/venv && source /tmp/venv/bin/activate
pip install pip==20.3.4
pip install -r test-requirements.txt
make distclean
make test-setup-local \
    PROVD_DIR=./xivo-provisioning \
    DB_DIR=./xivo-db \
    DB_VERSION=2021.11.latest \
    RABBITMQ_DIR=./rabbitmq
```
5) Run the tests just like before :

```
make test
```
and you're done ! Below is how we used to run them, including some more information to run specific tests.

You need Docker installed and the package libpq-dev.

You need the repos xivo-db, xivo-provisioning and rabbitmq.

To clone them:

```
git clone https://gitlab.com/xivo.solutions/xivo-db.git
git clone https://gitlab.com/xivo.solutions/xivo-provisioning.git
git clone https://gitlab.com/xivo.solutions/rabbitmq.git
```

If you already have them, you can use them. In this case:

1. ensure they are on the right branch and up-to-date
2. edit ``integration_tests/Makefile``
3. update ``PROVD_DIR``, ``DB_DIR``, ``DB_VERSION`` and other for the ``make test-setup`` command

Alternatively you can clone them to the ``integration_tests`` directory
and then override the paths in the make command. E.g.: ``make test-setup DB_DIR=./xivo-db``

Run the tests:

```
cd integration_tests
pip install -U -r test-requirements.txt
make test-setup
make test
```

Run only selected tests:

```
nosetests suite/base/test_users.py
nosetests suite/base/test_users.py:test_create_user_with_all_parameters
```

Note: if you are modifying the dao, you will probably need to modify the requirements.txt of xivo-db project to point towards your working xivo-dao branch.


Development
-----------

### xivo-dao

In case you need to mount xivo_dao inside the xivo-confd container, add the
following line in confd volumes in
integration_tests/assets/base/docker-compose.yml

```
- "/path/to/xivo_dao:/usr/local/lib/python2.7/site-packages/xivo_dao"
```

### Modified database

If you need to run tests against a modified database schema, run:

```
make update-db DB_DIR=../../xivo-db DB_VERSION=2019.12.latest
```

### Quick multiple runs

If you need to run tests more than once (e.g. when developing):

```
make stop
make start
DOCKER=0 nosetests suite
```

You can also just run one test suite:
```
cd integration_tests
nosetests suite/base/test_users.py
```
