# http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-
-- name: prepare sample pcap file
-  get_url:
-    url: "http://artifacts.opnfv.org/qtip/utilities/test.pcap"
-    dest: "{{ qtip_cache }}/{{ nDPI_file }}"
-    # validate_certs: no  # required when using proxy for https
-  run_once: yes
-  delegate_to: localhost
+---
 
 - name: making nDPI temporary directory
   file:
-    path: "{{ nDPI_cwd }}"
+    path: "{{ workdir }}"
     state: directory
 
-- name: clone nDPI
-  git:
-    repo: https://github.com/ntop/nDPI.git
-    dest: "{{ nDPI_cwd }}"
-    depth: 1
-    update: no
+- name: downloading nDPI
+  get_url:
+    url: https://github.com/ntop/nDPI/archive/1.6.tar.gz
+    dest: "{{ workdir }}"
+    checksum: "sha256:0863c7096f70c785e1b27a34f7b40939ac1a0e3a734ea3dcaa5cf161360a2561"
+
+- name: extracting nDPI
+  command: "tar zxf nDPI-1.6.tar.gz"
+  args:
+    chdir: "{{ workdir }}"
+    creates: nDPI-1.6
 
 - name: build nDPI library
   command: '{{ item }}'
     - ./configure
     - make
   args:
-    chdir: "{{ nDPI_cwd }}"
+    chdir: "{{ workdir }}/nDPI-1.6"
     creates: example/ndpiReader
 
-- name: copy sample packet file
-  copy:
-    src: "{{ qtip_cache}}/{{ nDPI_file }}"
-    dest: "{{ nDPI_cwd }}/example/{{ nDPI_file }}"
+- name: downloading sample pcap file
+  get_url:
+    url: "https://build.opnfv.org/artifacts.opnfv.org/qtip/utilities/test.pcap"
+    dest: "{{ workdir }}/nDPI-1.6/example/{{ sample_pcap }}"
+    checksum: "sha256:ac5d1501d91a6d8a8d3bfcef6f74a87bf660cd2c2ab11b9791535aa5193e4f71"
+    validate_certs: no  # required when using proxy for https
 
 - name:
-  command: "./ndpiReader -i {{ nDPI_file }}"
+  command: "./ndpiReader -i {{ sample_pcap }}"
   args:
-    chdir: "{{ nDPI_cwd }}/example/"
-  register: nDPI_out
+    chdir: "{{ workdir }}/nDPI-1.6/example/"
+  register: ndpi_out
 
 - name: collect DPI metrics from nDPI
   collect:
-    string: "{{ nDPI_out.stdout }}"
+    string: "{{ ndpi_out.stdout }}"
     patterns:
       #        nDPI throughput:       1.46 M pps / 13.69 Gb/sec
       # TODO(yujunz) convert "M pps" and "K pps" to number
 
 #############################################################################
 
 ---
-nDPI_cwd: "{{ ansible_env.HOME }}/qtip/nDPI"
-nDPI_file: "dpi.pcap"
+workdir: "{{ qtip_workdir }}/ndpi"
+sample_pcap: "dpi.pcap"
 
 
 workspace: "workspace"
 qtip_package: ../../..
+qtip_cache: .qtip-cache
\ No newline at end of file
 
 # wanting to use, for example, IP information from one group of servers
 # without having to talk to them in the same playbook run to get their
 # current IP information.
-#fact_caching = memory
+fact_caching = jsonfile
+fact_caching_connection = {{ qtip_cache }}
+fact_caching_timeout = 86400
 
 
 # retry files
 
 qtip_results: results
 qtip_fixtures: fixtures
 qtip_dump: dump
-qtip_cache: .cache
+qtip_cache: "{{ qtip_cache }}"
+qtip_workdir: "qtip-workdir-{{ lookup('pipe', 'date +%Y%m%d-%H%M') }}"
 installer_master_group:
   fuel: fuel-masters
   apex: apex-underclouds
 
--- /dev/null
+##############################################################################
+# Copyright (c) 2017 ZTE Corporation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+- hosts: compute
+
+  vars_prompt:
+    - name: remove_workdir
+      prompt: "WARNING: remove work dir from system under test? (yes|no)"
+      default: no
+
+  roles:
+  # teardown environment
+  - { role: qtip, tasks: teardown }
 
     name: epel-release
     state: present
 
-- name: installing dependencis
+- name: installing dependencies
   yum:
     name: "{{ item }}"
     state: present
 
   set_fact:
     qtip_results: "{{ hostvars['localhost']['qtip_results_base']}}/{{ inventory_hostname }}"
 
-- name: create result directory
+- name: creating result directory
   file:
     path: "{{ qtip_results }}"
     state: directory
   delegate_to: localhost
 
+- name: creating work directory
+  file:
+    path: "{{ qtip_workdir }}"
+    state: directory
+
 - include: install-deps.yml
 
--- /dev/null
+##############################################################################
+# Copyright (c) 2017 ZTE Corporation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+---
+
+- name: removing work directory
+  file:
+    path: "{{ qtip_workdir }}"
+    state: absent
+  when: remove_workdir|bool
 
 
 - name: making ramspeed working directory
   file:
-    path: "{{ cwd }}"
+    path: "{{ workdir }}"
     state: directory
   tags: [setup]
 
-- name: download ramspeed/ramsmp
-  unarchive:
-    src: http://www.alasir.com/software/ramspeed/ramsmp-3.5.0.tar.gz
-    dest: "{{ cwd }}"
-    remote_src: yes
+- name: downloading ramsmp
+  get_url:
+    url: http://www.alasir.com/software/ramspeed/ramsmp-3.5.0.tar.gz
+    dest: "{{ workdir }}"
+    checksum: "sha256:39fb15493fb3c293575746d56f6ab9faaa1d876d8b1f0d8e5a4042d2ace95839"
   tags: [setup]
 
+- name: extracting ramsmp
+  # TODO(yujunz) unarchive may not work with long path (local: macOS, workdir: /root/qtip-workdir-20170423-0836/)
+  command: "tar zxf ramsmp-3.5.0.tar.gz"
+  args:
+    chdir: "{{ workdir }}"
+    creates: ramsmp-3.5.0
+
 - name: build ramsmp
   command: ./build.sh
   args:
-    chdir: "{{ cwd }}/ramsmp-3.5.0"
+    chdir: "{{ workdir }}/ramsmp-3.5.0"
     creates: ramsmp
   tags: [setup]
 
 - name: intmem benchmarking
   command: ./ramsmp -b 3 -l 5 -p 1
   args:
-    chdir: "{{ cwd }}/ramsmp-3.5.0"
+    chdir: "{{ workdir }}/ramsmp-3.5.0"
   register: ramsmp_intmem_out
   tags: [run]
 
 - name: floatmem benchmarking
   command: ./ramsmp -b 6 -l 5 -p 1
   args:
-    chdir: "{{ cwd }}/ramsmp-3.5.0"
+    chdir: "{{ workdir }}/ramsmp-3.5.0"
   register: ramsmp_floatmem_out
   tags: [run]
 
 
 #############################################################################
 
 ---
-cwd: "{{ ansible_env.HOME }}/qtip/ramspeed"
+workdir: "{{ qtip_workdir }}/ramspeed"
 
 
 - name: make unixbench working directory
   file:
-    path: "{{ cwd }}"
+    path: "{{ workdir }}"
     state: directory
 
-- name: download unixbench source code
-  unarchive:
-    src: https://github.com/kdlucas/byte-unixbench/archive/v5.1.3.tar.gz
-    dest: "{{ cwd }}"
-    remote_src: yes
+- name: downloading unixbench source code
+  get_url:
+    url: https://github.com/kdlucas/byte-unixbench/archive/v5.1.3.tar.gz
+    dest: "{{ workdir }}"
+    checksum: "sha256:3a6bb00f270a5329682dff20fd2c1ab5332ef046eb54a96a0d7bd371005d31a3"
+
+- name: extracting unixbench source code
+  # TODO(yujunz) unarchive may not work with long path (local: macOS, workdir: /root/qtip-workdir-20170423-0836/)
+  command: "tar zxf byte-unixbench-5.1.3.tar.gz"
+  args:
+    chdir: "{{ workdir }}"
+    creates: byte-unixbench-5.1.3
 
 - name: build UnixBench
   command: "make"
   args:
-    chdir: "{{ cwd }}/byte-unixbench-5.1.3/UnixBench"
+    chdir: "{{ workdir }}/byte-unixbench-5.1.3/UnixBench"
+    creates: Run
 
 - name: run whetstone and dhrystone
   shell: "./Run -i {{ iterations }} -c {{ parallel_copies }} dhrystone whetstone"
   args:
-    chdir: "{{ cwd }}/byte-unixbench-5.1.3/UnixBench"
+    chdir: "{{ workdir }}/byte-unixbench-5.1.3/UnixBench"
 
 - name: synchronize test results to local
   synchronize:
     mode: pull
-    src: "{{ cwd }}/byte-unixbench-5.1.3/UnixBench/results/"
+    src: "{{ workdir }}/byte-unixbench-5.1.3/UnixBench/results/"
     dest: "{{ qtip_results }}/unixbench"
     use_ssh_args: yes
 
 
 # http://www.apache.org/licenses/LICENSE-2.0
 #############################################################################
 
-cwd: "{{ ansible_env.HOME }}/qtip/unixbench"
+workdir: "{{ qtip_workdir }}/unixbench"
 iterations: 1
-parallel_copies: 1
\ No newline at end of file
+parallel_copies: 1