
# Copyright 2017-present Open Networking Foundation
#
# 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.


---
- name: Install Cord tester prerequisites
  become: yes
  apt: name={{ item }} state=latest force=yes
  with_items:
    - wget
    - python
    - python-dev
    - python-pip
    - python-setuptools
    - python-scapy
    - python-pexpect
    - openvswitch-switch
    - libssl-dev
    - libffi-dev

- name: Install Python Prerequisites for cord tester
  become: yes
  pip: name={{ item }} state=latest
  with_items:
    - nose
    - monotonic
    - configObj
    - pyyaml
    - nsenter
    - pyroute2
    - netaddr
    - python-daemon
    - robotframework
    - robotframework-requests
    - robotframework-sshlibrary

- name: Install scapy
  pip: name=scapy version=2.3.2 state=present

- name: Install scapy-ssl_tls
  pip: name=scapy-ssl_tls version=1.2.2 state=present

- name: Install docker-py
  pip: name=docker-py version=1.9.0 state=present

- name: Install paramiko
  pip: name=paramiko version=1.10.1 state=present

- name: Download Openvswitch {{ openvswitch_version }}
  become:  yes
  get_url:
    url: "{{ openvswitch_url }}/openvswitch-{{ openvswitch_version }}.tar.gz"
    dest: "/home/{{ ansible_user }}/openvswitch-{{ openvswitch_version }}.tar.gz"
    force: yes

- name:  Untar Openvswitch {{ openvswitch_version }}
  become: yes
  unarchive:
    src=openvswitch-{{ openvswitch_version }}.tar.gz
    dest=/home/{{ ansible_user }}

- name: Build Openvswitch {{ openvswitch_version }}
  become: yes
  shell: "{{ item }}"
  args:
    chdir: "/home/{{ ansible_user }}/openvswitch-{{ openvswitch_version }}"
  with_items:
    - ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl
    - make
    - make install

- name: Remove build files for Openvswitch {{ openvswitch_version }}
  file:
    path=/home/{{ ansible_user }}/{{ item }}
    state=absent
  with_items:
    - "openvswitch-{{ openvswitch_version }}.tar.gz"
    - "openvswitch-{{ openvswitch_version }}"

- name: install Pipework
  sudo: True
  get_url:
    url: "{{ docker_tools_pipework_exe_url }}"
    dest: "{{ docker_tools_path }}/pipework"
    force: yes
    mode: "a+x"

- name: Pull cord test container
  become: yes
  docker:
    name: cord-test
    image: "{{ docker.registry }}/cordtest/nose:{{ docker.image_version }}"
    pull: always
    state: absent

- name: Pull test radius container
  become: yes
  docker:
    name: cord-radius
    image: "{{ docker.registry }}/cordtest/radius:{{ docker.image_version }}"
    pull: always
    state: absent

- name: Pull test quagga container
  become: yes
  docker:
    name: cord-quagga
    image: "{{ docker.registry }}/cordtest/quagga:{{ docker.image_version }}"
    pull: always
    state: absent

- name: Pull onosproject
  become: yes
  docker:
    name: cord-test-onos
    image: "{{ docker.registry }}/onosproject/onos:{{ docker.image_version }}"
    pull: always
    state: absent
