Refactor dhrystone playbook 29/29629/3
authorwu.zhihui <wu.zhihui1@zte.com.cn>
Thu, 2 Mar 2017 10:40:11 +0000 (18:40 +0800)
committerzhihui wu <zhihui.wu2006+zte@gmail.com>
Fri, 3 Mar 2017 00:53:59 +0000 (00:53 +0000)
- Break previous one playbook into three playbooks:
    setup.yaml: setup test environment.
    run.yaml: execute test steps
    clean.yaml: cleanup test environment to restore
    environment
  The advantage is cleaning part will never be blocked by another.
- Just do testing on remote hosts, parse logfile on localhost.
- Use ansible module instead of shell command.
- Move up all files under /ansible and remove ansible directory.
  Under /ansible, ansible package cann't be imported.

Change-Id: I43c65be23869b7d42ca769994d4decb9a012d196
Signed-off-by: wu.zhihui <wu.zhihui1@zte.com.cn>
qtip/driver/ansible.py [moved from qtip/driver/ansible/ansible.py with 100% similarity]
qtip/driver/ansible/__init__.py [deleted file]
qtip/driver/playbook/bwn_ng.yaml [moved from qtip/driver/ansible/playbook/bwn_ng.yaml with 100% similarity]
qtip/driver/playbook/dhrystone/clean.yaml [new file with mode: 0644]
qtip/driver/playbook/dhrystone/run.yaml [new file with mode: 0644]
qtip/driver/playbook/dhrystone/setup.yaml [new file with mode: 0644]
qtip/driver/playbook/inxi.yaml [moved from qtip/driver/ansible/playbook/inxi.yaml with 100% similarity]
qtip/driver/playbook/prepare_env.yaml [moved from qtip/driver/ansible/playbook/prepare_env.yaml with 84% similarity]
qtip/driver/playbook/top.yaml [moved from qtip/driver/ansible/playbook/top.yaml with 100% similarity]

diff --git a/qtip/driver/ansible/__init__.py b/qtip/driver/ansible/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/qtip/driver/playbook/dhrystone/clean.yaml b/qtip/driver/playbook/dhrystone/clean.yaml
new file mode 100644 (file)
index 0000000..72bfab7
--- /dev/null
@@ -0,0 +1,27 @@
+##############################################################################
+# 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: hosts
+  become: yes
+  remote_user: root
+
+  tasks:
+    - name: Checking home directory
+      shell: echo $HOME
+      register: home_dir
+
+    - name: Cleaning tempT
+      file:
+        path: '{{ home_dir.stdout }}/tempT'
+        state: absent
+
+    - name: Cleaning qtip_result
+      file:
+        path: '{{ home_dir.stdout }}/qtip_result'
+        state: absent
diff --git a/qtip/driver/playbook/dhrystone/run.yaml b/qtip/driver/playbook/dhrystone/run.yaml
new file mode 100644 (file)
index 0000000..55de659
--- /dev/null
@@ -0,0 +1,63 @@
+##############################################################################
+# 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: hosts
+  become: yes
+  remote_user: root
+
+  tasks:
+    - name: Get current timestamp
+      set_fact:
+        timestamp: "{{ lookup('pipe', 'date +%Y-%m-%d-%H-%M') }}"
+
+    - name: Checking home directory
+      shell: echo $HOME
+      register: home_dir
+
+    - name: Fetch hostname
+      shell: hostname
+      register: host_name
+
+    - name: Make UnixBench
+      shell: make --directory $HOME/tempT/UnixBench/
+
+    - name: Make some directories needed
+      file:
+        path: '{{ home_dir.stdout }}/qtip_result/{{ timestamp }}/{{ host_name.stdout }}'
+        state: directory
+
+    - include: ../inxi.yaml
+
+    - include: ../top.yaml
+
+    - name: Run dhrystone
+      shell: ./Run -v dhrystone
+      args:
+        chdir: '{{ home_dir.stdout }}/tempT/UnixBench/'
+
+    - name: Copying result to qtip result directory
+      shell: cp -r $HOME/tempT/UnixBench/results/* ./
+      args:
+        chdir: '{{ home_dir.stdout }}/qtip_result/{{ timestamp }}/{{ host_name.stdout }}'
+
+    - name: Copy top log to qtip result directory
+      shell: mv $HOME/qtip_result/top.log ./
+      args:
+        chdir: '{{ home_dir.stdout }}/qtip_result/{{ timestamp }}/{{ host_name.stdout }}'
+
+    - name: Copy inxi log to qtip result directory
+      shell: mv $HOME/qtip_result/inxi.log ./
+      args:
+        chdir: '{{ home_dir.stdout }}/qtip_result/{{ timestamp }}/{{ host_name.stdout }}'
+
+    - name: Fetch result files to local manchine
+      synchronize:
+        mode: pull
+        src: '{{ home_dir.stdout }}/qtip_result/'
+        dest: '{{ result_dir }}/dhrystone/logs/'
diff --git a/qtip/driver/playbook/dhrystone/setup.yaml b/qtip/driver/playbook/dhrystone/setup.yaml
new file mode 100644 (file)
index 0000000..430670c
--- /dev/null
@@ -0,0 +1,66 @@
+##############################################################################
+# 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: localhost
+  connection: local
+  gather_facts: no
+
+  tasks:
+    - name: Making dhrystone directory
+      file:
+        path: '{{ result_dir }}/dhrystone/logs/'
+        state: directory
+
+- hosts: hosts
+  become: yes
+  remote_user: root
+
+  tasks:
+    - name: Checking home directory
+      shell: echo $HOME
+      register: home_dir
+
+    - name: Cleaning tempT directory
+      file:
+        path: '{{ home_dir.stdout }}/tempT'
+        state: absent
+
+    - name: Cleaning qtip_result directory
+      file:
+        path: '{{ home_dir.stdout }}/qtip_result'
+        state: absent
+
+    - include: ../prepare_env.yaml
+
+    - name: Installing UnixBench dependencies if CentOS
+      yum:
+        name: '{{ item }}'
+        state: present
+      when: ansible_os_family == "RedHat"
+      with_items:
+        - git
+        - gcc
+        - patch
+        - perl-Time-HiRes
+
+    - name: Installing UnixBench dependencies if Ubuntu
+      apt:
+        name: '{{ item }}'
+        state: present
+      when: ansible_os_family == "Debian"
+      with_items:
+        - git
+        - gcc
+        - patch
+        - perl
+
+    - name: Clone unixbench
+      git:
+        repo: https://github.com/kdlucas/byte-unixbench.git
+        dest: '{{ home_dir.stdout }}/tempT'
similarity index 84%
rename from qtip/driver/ansible/playbook/prepare_env.yaml
rename to qtip/driver/playbook/prepare_env.yaml
index 0595d98..1ec7152 100644 (file)
@@ -10,7 +10,7 @@
   yum:
     name: epel-release
     state: present
-   when: ansible_os_family == "RedHat"
+  when: ansible_os_family == "RedHat"
 
 - name: Software Properties Common
   apt:
     name: python-selinux
     state: present
   when: ansible_os_family == "Debian"
+
+- name: Install rsync when CentOS
+  yum:
+    name: rsync
+    state: present
+  when: ansible_os_family == "RedHat"
+
+- name: Install rsync when Ubuntu
+  apt:
+    name: rsync
+    state: present
+  when: ansible_os_family == "Debian"