Skip to content

Running tests on Travis CI

Xiaoqin Zhu edited this page Jul 14, 2016 · 4 revisions

To add/modify Travis CI sanity tests

Open the travis CI test script in an editor from the cloned ydk-gen repo (example: vi ydk-gen/test/travis_ci.sh) and edit the below lines to add/modify any build-time tests and/or run-time sanity tests:

# sanity tests
function run_sanity_tests {
    virtualenv myenv
    source myenv/bin/activate
    pip install gen-api/python/dist/ydk-0.4.0.tar.gz
    source gen-api/python/env.sh
    cd gen-api/python
    run_test python tests/test_sanity_codec.py
    run_test python tests/test_sanity_types.py
    run_test python tests/test_sanity_filters.py
    run_test python tests/test_sanity_levels.py
    run_test python tests/test_sanity_filter_read.py
    run_test python tests/test_sanity_netconf.py
    run_test python tests/test_sanity_rpc.py
    cd ydk/tests
    run_test python import_tests.py
}

Background

Sanity Tests with docker/confd

Travis CI has docker service, which could be used along with free version of confd to provide a sandbox like environment. And we can use this combination to replace the testVM/netsim environment used in gitlab. We can push the preconfigured docker image to docker hub and pull them when running test ci.

In an example travis.yml:

sudo: required
services:
    - docker
language: python
python:
    - "2.7"
before_install:
    - docker pull ydkdev/confd
script:
    - docker run ydkdev/confd /root/confd_all.sh -r https://github.com/$TRAVIS_REPO_SLUG.git -b $TRAVIS_BRANCH

When commits and pull requests come in, the travis ci worker will pull the image from docker hub repository ydkdev/confd, create and run the script /root/confd_all.sh in a container based on this image.

How to modify docker image

A docker hub account is needed to push changes to existing preconfigured image hosted on docker hub.

Install docker and pull the image

For OSX, please follow this tutorial. Note: docker will have timeout issue when using along with cisco anyconnect.

Open up a Dokcer Quickstart Terminal, it will take a few minutes for initializing:

                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/


docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

After this information is shown in the terminal, pull image from docker hub, run command below in the same terminal:

  $ docker pull ydkdev/confd

Create container and modify files

In the same terminal, run the command:

  $ docker run -it ydkdev/confd
  root@da1b0c5ff16f:~#

Then you will be logged into this container, with name da1b0c5ff16f for example. This is an image based on ubuntu, so feel free to use apt-get to install necessary softwares.

Commit your changes and push to docker hub

After modifying files in that container, open up another Docker Quickstart Terminal, and commit your changes:

  $ docker commit da1b0c5ff16f ydktest/confd
  sha256:a11ab3b501deb048fa616ce08abdbdead5cdbbaeb1f558c477bfb946c6f0fbf8

And push your changes to docker hub(a docker hub account is required and you need to be added to the ydkdev team. Please contact Xiaoqin if you need to be added):

  $ docker login --username=yourhubusername [email protected]
  Password:
  Login Succeeded
  $ docker push ydkdev/confd

How to add more models to confd

The way confd works is to first compile yang models to fxs files, then use those fxs files to start daemon. If for example one more yang model is needed, first compile it:

  $ source /root/confd/confdrc
  $ cd /path/to/yang
  $ confdc -c example.yang

Then you will get example.fxs compiled in /path/to/yang. To compile yang model with deviation, use:

  $ confdc -c example.yang --deviation example-devaition.yang --deviation example-deviation-1.yang

Copy those files to /root/confd/etc/confd. It is recommended to copy those fxs files at run time , for example(in /root/confd_install_ydktest.sh), instead of pushing changes to docker hub. So the image is kept clean.