Setting up Environment

Setting up Environment

For information on how to get source code see Getting the Source Code.

Preparing Development Environment

Warning

Nailgun requires Python 2.7. Please check installed Python version using python --version.

  1. Nailgun can be found in fuel-web/nailgun

  2. Install and configure PostgreSQL database. Please note that Ubuntu 12.04 requires postgresql-server-dev-9.1 while Ubuntu 14.04 requires postgresql-server-dev-9.3:

    sudo apt-get install --yes postgresql postgresql-server-dev-all
    
    sudo sed -ir 's/peer/trust/' /etc/postgresql/9.*/main/pg_hba.conf
    sudo service postgresql restart
    
    sudo -u postgres psql -c "CREATE ROLE nailgun WITH LOGIN PASSWORD 'nailgun'"
    sudo -u postgres createdb nailgun
    

    If required, you can specify Unix-domain socket in ‘host’ settings to connect to PostgreSQL database:

    DATABASE:
         engine: "postgresql"
         name: "nailgun"
         host: "/var/run/postgresql"
         port: ""
         user: "nailgun"
         passwd: "nailgun"
    
  3. Install pip and development tools:

    sudo apt-get install --yes python-dev python-pip
    
  4. Install virtualenv. This step increases flexibility when dealing with environment settings and package installation:

    sudo pip install virtualenv virtualenvwrapper
    . /usr/local/bin/virtualenvwrapper.sh  # you can save this to .bashrc
    mkvirtualenv fuel # you can use any name instead of 'fuel'
    workon fuel  # command selects the particular environment
    
  5. Install Python dependencies. This section assumes that you use virtual environment. Otherwise, you must install all packages globally. You can install pip and use it to require all the other packages at once:

    sudo apt-get install --yes git
    git clone https://github.com/openstack/fuel-web.git
    cd fuel-web
    pip install --allow-all-external -r nailgun/test-requirements.txt
    
  6. Install Nailgun in the developers mode by running the command below in the nailgun folder. Thanks to that, Nailgun extensions will be discovered:

    python setup.py develop
    

    Or if you are using pip:

    pip install -e .
    
  7. Create required folder for log files:

    sudo mkdir /var/log/nailgun
    sudo chown -R `whoami`.`whoami` /var/log/nailgun
    sudo chmod -R a+w /var/log/nailgun
    

Setup for Nailgun Unit Tests

  1. Nailgun unit tests use Tox for generating test environments. This means that you don’t need to install all Python packages required for the project to run them, because Tox does this by itself.

  2. First, create a virtualenv the way it’s described in previous section. Then, install the Tox package:

    workon fuel #activate virtual environment created in the previous section
    pip install tox
    
  3. Run the Nailgun backend unit tests and flake8 test:

    sudo apt-get install puppet-common #install missing package required by tasklib tests
    ./run_tests.sh
    
  4. You can also run the same tests by hand, using tox itself:

    cd nailgun
    tox -epy26 -- -vv nailgun/test
    tox -epep8
    
  5. Tox reuses the previously created environment. After making some changes with package dependencies, tox should be run with -r option to recreate existing virtualenvs:

    tox -r -epy26 -- -vv nailgun/test
    tox -r -epep8
    

Running Nailgun Performance Tests

Now you can run performance tests using -x option:

./run_tests.sh -x

If -x is not specified, run_tests.sh will not run performance tests.

The -n or -N option works exactly as before: it states whether tests should be launched or not.

For example:

  • run_tests.sh -n -x - run both regular and performance Nailgun tests.
  • run_tests.sh -x - run nailgun performance tests only, do not run regular Nailgun tests.
  • run_tests.sh -n - run regular Naigun tests only.
  • run_tests.sh -N - run all tests except for Nailgun regular and performance tests.

Running parallel tests with py.test

Now tests can be run over several processes in a distributed manner; each test is executed within an isolated database.

Prerequisites

  • Nailgun user requires createdb permission.

  • Postgres database is used for initial connection.

  • If createdb cannot be granted for the environment, then several databases should be created. The number of databases should be equal to TEST_WORKERS variable. The createdb permission should have the following format: nailgun0, nailgun1.

  • If no TEST_WORKERS variable is provided, then a default database name will be used. Often it is nailgun, but you can overwrite it with TEST_NAILGUN_DB environment variable.

  • To execute parallel tests on your local environment, run the following command from fuel-web/nailgun:

    py.test -n 4 nailgun/test
    

    You can also run the it from fuel-web:

    py.test -n 4 nailgun/nailgun/test
    

Running Nailgun in Fake Mode

  1. Switch to virtual environment:

    workon fuel
    
  2. Populate the database from fixtures:

    cd nailgun
    ./manage.py syncdb
    ./manage.py loaddefault # It loads all basic fixtures listed in settings.yaml
    ./manage.py loaddata nailgun/fixtures/sample_environment.json  # Loads fake nodes
    
  3. Start application in “fake” mode, when no real calls to orchestrator are performed:

    python manage.py run -p 8000 --fake-tasks | egrep --line-buffered -v '^$|HTTP' >> /var/log/nailgun.log 2>&1 &
    
  4. (optional) You can also use –fake-tasks-amqp option if you want to make fake environment use real RabbitMQ instead of fake one:

    python manage.py run -p 8000 --fake-tasks-amqp | egrep --line-buffered -v '^$|HTTP' >> /var/log/nailgun.log 2>&1 &
    

Nailgun in fake mode is usually used for Fuel UI development and Fuel UI functional tests. For more information, please check out README file in the fuel-ui repo.

Note: Diagnostic Snapshot is not available in a Fake mode.

Running the Fuel System Tests

For fuel-devops configuration info please refer to Devops Guide article.

  1. Run the integration test:

    cd fuel-main
    make test-integration
    
  2. To save time, you can execute individual test cases from the integration test suite like this (nice thing about TestAdminNode is that it takes you from nothing to a Fuel master with 9 blank nodes connected to 3 virtual networks):

    cd fuel-main
    export PYTHONPATH=$(pwd)
    export ENV_NAME=fuelweb
    export PUBLIC_FORWARD=nat
    export ISO_PATH=`pwd`/build/iso/fuelweb-centos-6.5-x86_64.iso
    ./fuelweb_tests/run_tests.py --group=test_cobbler_alive
    
  3. The test harness creates a snapshot of all nodes called ‘empty’ before starting the tests, and creates a new snapshot if a test fails. You can revert to a specific snapshot with this command:

    dos.py revert --snapshot-name <snapshot_name> <env_name>
    
  4. To fully reset your test environment, tell the Devops toolkit to erase it:

    dos.py list
    dos.py erase <env_name>
    

Flushing database before/after running tests

The database should be cleaned after running tests; before parallel tests were enabled, you could only run dropdb with ./run_tests.sh script.

Now you need to run dropdb for each slave node: the py.test –cleandb <path to the tests> command is introduced for this purpose.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

Contents