Chaos
Chaos is the web service which can feed Navitia with real-time disruptions. It can work together with Kirin which can feed Navitia with real-time delays.
Installation
The hard way
Clone the Chaos repository
git clone [email protected]:CanalTP/Chaos.git
cd Chaos
Requirements
- PostgreSQL 9.6
sudo apt-get install postgresql-9.6 postgresql-server-dev-9.6 libpq-dev
- RabbitMQ
Python
-
Install Python2.7
sudo apt-get install python2.7 python2.7-dev
or
sudo apt install python2 python2-dev
on recent linux release -
Install pip
-
Install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
Install & build protobuf
- Install protobuf
You can use sudo apt-get install protobuf-compiler
if you're sure it won't install version 3.x.x (incompatible).
Or install protoc building it from source : protobuf v2.6.1. After download, from inside the unziped folder :
./configure
make
make install
ldconfig
make clean
Check your version
protoc --version
- Build protobuf, back into Chaos project folder
git submodule init
git submodule update
./setup.py build_pbf
Create the database
sudo -i -u postgres
# Create a user
createuser -P navitia
(password "navitia")
# Create database
createdb -O navitia chaos
# Create database for tests
createdb -O navitia chaos_testing
ctrl + d
Cache configuration
To improve its performance Chaos can use Redis.
Install Redis
Using Chaos without Redis
You can deactivate Redis usage in default_settings.py by changing 'CACHE_TYPE' to 'simple'
Using Chaos without cache
For development purpose you can deactivate cache usage in default_settings.py by forcing 'CACHE_TYPE' to 'null'
Run Chaos with honcho (optional)
Install honcho
You can use honcho for managing Procfile-based applications.
pip install honcho
Upgrade database
honcho run ./manage.py db upgrade
RabbitMQ (optional)
RabbitMQ is optional and you can deactivate it if you don't want to send disruptions to a queue.
# chaos/default_settings.py
ENABLE_RABBITMQ = False
Run Chaos
honcho start
The easy way (with Docker)
git clone [email protected]:CanalTP/Chaos.git
cd Chaos
git submodule init
git submodule update
docker-compose up -d
To watch logs output:
docker-compose logs -f
Chaos will be accessible on http://chaos_ws_1.docker if you are using the docker-gen-hosts tool, it will also be accessible on http://chaos-ws.local.canaltp.fr
The database will be accessible at 'chaos_database_1.docker' and default RabbitMQ interface at 'http://chaos_rabbitmq_1.docker:15672'.
Security (optional)
If you want to add more security, you can add a file chaos/clients_tokens.json with the client code and navitia tokens like:
{
"client_code": [
"navitia_token1",
"navitia_token2"
]
}
client_code should be the same as the value of X-Customer-Id header in HTTP request and token should be the same as the value of Authorization header in HTTP request
If the file doesn't exist, the security will be disabled.
You can add a 'master' key in the file. It will allow you to access all resources for all clients.
Tests
Unit tests
cd tests
honcho run nosetests
Functional tests
cd tests
honcho run lettuce
To stop directly on faulty test
cd tests
honcho run lettuce --failfast
With docker
docker-compose -f docker-compose.test.yml build --pull
docker-compose -f docker-compose.test.yml up -d
docker-compose -f docker-compose.test.yml exec -T chaos /bin/sh ./docker/tests.sh
docker-compose -f docker-compose.test.yml down --remove-orphans