Commit 4736ed35 authored by Spiros Koulouzis's avatar Spiros Koulouzis

changed playbook to save results

parent ad821dc7
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
<h1 class="page-header">Files and Libraries</h1> <h1 class="page-header">Files and Libraries</h1>
<h3 id="artifact_gwt_json_overlay">GWT JSON Overlay</h3> <h3 id="artifact_gwt_json_overlay">GWT JSON Overlay</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p> <p> <p> <p>
The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> JSON Overlay library provides the JSON Overlays that The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> JSON Overlay library provides the JSON Overlays that
can be used to access the Web service API for this application. can be used to access the Web service API for this application.
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_java_json_client_library">Java JSON Client Library</h3> <h3 id="artifact_java_json_client_library">Java JSON Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The Java client-side library is used to provide the set of Java objects that can be serialized The Java client-side library is used to provide the set of Java objects that can be serialized
to/from JSON using <a href="http://jackson.codehaus.org/">Jackson</a>. This is useful for accessing the to/from JSON using <a href="http://jackson.codehaus.org/">Jackson</a>. This is useful for accessing the
...@@ -127,7 +127,7 @@ ...@@ -127,7 +127,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_java_xml_client_library">Java XML Client Library</h3> <h3 id="artifact_java_xml_client_library">Java XML Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The Java client-side library is used to access the Web service API for this application using Java. The Java client-side library is used to access the Web service API for this application using Java.
</p> </p>
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_js_client_library">JavaScript Client Library</h3> <h3 id="artifact_js_client_library">JavaScript Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The JavaScript client-side library defines classes that can be (de)serialized to/from JSON. The JavaScript client-side library defines classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only This is useful for accessing the resources that are published by this application, but only
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_php_json_client_library">PHP JSON Client Library</h3> <h3 id="artifact_php_json_client_library">PHP JSON Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The PHP JSON client-side library defines the PHP classes that can be (de)serialized to/from JSON. The PHP JSON client-side library defines the PHP classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only This is useful for accessing the resources that are published by this application, but only
...@@ -219,7 +219,7 @@ ...@@ -219,7 +219,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_php_xml_client_library">PHP XML Client Library</h3> <h3 id="artifact_php_xml_client_library">PHP XML Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The PHP client-side library defines the PHP classes that can be (de)serialized to/from XML. The PHP client-side library defines the PHP classes that can be (de)serialized to/from XML.
This is useful for accessing the resources that are published by this application, but only This is useful for accessing the resources that are published by this application, but only
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
</tbody> </tbody>
</table> </table>
<h3 id="artifact_ruby_json_client_library">Ruby JSON Client Library</h3> <h3 id="artifact_ruby_json_client_library">Ruby JSON Client Library</h3>
<p class="lead">Created March 28, 2017</p> <p class="lead">Created March 31, 2017</p>
<p><p> <p><p>
The Ruby JSON client-side library defines the Ruby classes that can be (de)serialized to/from JSON. The Ruby JSON client-side library defines the Ruby classes that can be (de)serialized to/from JSON.
This is useful for accessing the REST endpoints that are published by this application, but only This is useful for accessing the REST endpoints that are published by this application, but only
......
...@@ -23,7 +23,7 @@ from results_collector import ResultsCollector ...@@ -23,7 +23,7 @@ from results_collector import ResultsCollector
hosts='172.17.0.2,172.17.0.3,' hosts='172.17.0.2,'
playbook_path = 'playbook.yml' playbook_path = 'playbook.yml'
if not os.path.exists(playbook_path): if not os.path.exists(playbook_path):
print '[ERROR] The playbook does not exist' print '[ERROR] The playbook does not exist'
...@@ -31,7 +31,7 @@ if not os.path.exists(playbook_path): ...@@ -31,7 +31,7 @@ if not os.path.exists(playbook_path):
user='vm_user' user='vm_user'
ssh_key_file='id_ras' ssh_key_file='id_ras'
extra_vars = {'resultslocation':'/tmp/res'} extra_vars = {} #{'resultslocation':'/tmp/res','ansible_sudo_pass':'123'}
variable_manager = VariableManager() variable_manager = VariableManager()
...@@ -63,35 +63,23 @@ results = pbex.run() ...@@ -63,35 +63,23 @@ results = pbex.run()
ok = results_callback.host_ok ok = results_callback.host_ok
count=0; answer = []
for res in ok: for res in ok:
re = json.dumps(res['result']._result) resp = json.dumps({"host":res['ip'], "result":res['result']._result})
++count answer.append({"host":res['ip'], "result":res['result']._result})
target = open("ok"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
count=0;
unreachable = results_callback.host_unreachable unreachable = results_callback.host_unreachable
for res in unreachable: for res in unreachable:
re = json.dumps(res['result']._result) resp = json.dumps({"host":res['ip'], "result":res['result']._result})
++count answer.append({"host":res['ip'], "result":res['result']._result})
target = open("unreachable"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
count=0;
host_failed = results_callback.host_failed host_failed = results_callback.host_failed
for res in host_failed: for res in host_failed:
re = json.dumps(res['result']._result) resp = json.dumps({"host":res['ip'], "result":res['result']._result})
++count answer.append({"host":res['ip'], "result":res['result']._result})
target = open("host_failed"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
print json.dumps(answer,indent=4)
\ No newline at end of file
...@@ -21,6 +21,25 @@ import paramiko, os ...@@ -21,6 +21,25 @@ import paramiko, os
import threading import threading
import ansible.runner import ansible.runner
from results_collector import ResultsCollector from results_collector import ResultsCollector
import json
from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
from ansible.inventory import Inventory
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
import ansible.executor.task_queue_manager
import ansible.inventory
import ansible.parsing.dataloader
import ansible.playbook.play
import ansible.plugins.callback
import ansible.vars
from ansible.executor.playbook_executor import PlaybookExecutor
from ansible.plugins import callback_loader
import logging
import yaml
import sys
def install_prerequisites(vm): def install_prerequisites(vm):
try: try:
...@@ -39,15 +58,66 @@ def install_prerequisites(vm): ...@@ -39,15 +58,66 @@ def install_prerequisites(vm):
return "ERROR:"+vm.ip+" "+str(e) return "ERROR:"+vm.ip+" "+str(e)
ssh.close() ssh.close()
return "SUCCESS" return "SUCCESS"
def execute_playbook(hosts, playbook_path,user,ssh_key_file,extra_vars,passwords):
if not os.path.exists(playbook_path):
print '[ERROR] The playbook does not exist'
return '[ERROR] The playbook does not exist'
variable_manager = VariableManager()
loader = DataLoader()
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=hosts)
Options = namedtuple('Options', ['listtags', 'listtasks', 'listhosts', 'syntax', 'connection','module_path', 'forks', 'remote_user', 'private_key_file', 'ssh_common_args', 'ssh_extra_args', 'sftp_extra_args', 'scp_extra_args', 'become', 'become_method', 'become_user', 'verbosity', 'check'])
options = Options(listtags=False, listtasks=False, listhosts=False, syntax=False, connection='smart', module_path=None, forks=None, remote_user=user, private_key_file=ssh_key_file, ssh_common_args=None, ssh_extra_args=None, sftp_extra_args=None, scp_extra_args=None, become=True, become_method='sudo', become_user='root', verbosity=None, check=False)
variable_manager.extra_vars = extra_vars
pbex = PlaybookExecutor(playbooks=[playbook_path],
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
options=options,
passwords=passwords,
)
results_callback = ResultsCollector()
pbex._tqm._stdout_callback = results_callback
results = pbex.run()
ok = results_callback.host_ok
answer = []
for res in ok:
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
unreachable = results_callback.host_unreachable
for res in unreachable:
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
host_failed = results_callback.host_failed
for res in host_failed:
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
return json.dumps(answer)
def run(vm_list,playbook): def run(vm_list,playbook_path):
ips="" hosts=""
privatekey="" ssh_key_file=""
for vm in vm_list: for vm in vm_list:
ret = install_prerequisites(vm) ret = install_prerequisites(vm)
ips+=vm.ip+"," hosts+=vm.ip+","
privatekey = vm.key ssh_key_file = vm.key
user = vm.user user = vm.user
if "ERROR" in ret: return ret if "ERROR" in ret: return ret
return "SUCCESS" extra_vars = {}
\ No newline at end of file passwords = {}
return execute_playbook(hosts,playbook_path,user,ssh_key_file,extra_vars,passwords)
\ No newline at end of file
#! /bin/bash #! /bin/bash
apt-get update apt-get update
apt-get upgrade apt-get upgrade
apt-get -y install software-properties-common python apt-get -y install software-properties-common python openssh-server sudo
service ssh restart service ssh restart
\ No newline at end of file
{
"host": "172.17.0.2",
"result": {
"_ansible_parsed": false,
"_ansible_no_log": false,
"module_stderr": "Shared connection to 172.17.0.2 closed.\r\n",
"changed": false,
"module_stdout": "/bin/sh: 1: sudo: not found\r\n",
"failed": true,
"invocation": {
"module_name": "setup"
},
"msg": "MODULE FAILURE"
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -25,40 +25,43 @@ ...@@ -25,40 +25,43 @@
become: true become: true
- name: Count vCPU #- name: Count vCPU
command: nproc #command: nproc
register: vcpunumber #register: vcpunumber
become: true #become: true
#- debug: msg="{{ vcpunumber.stdout }}"
- debug: msg="{{ vcpunumber.stdout }}"
- name: Run sysbench #- name: Run sysbench
command: sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run #command: sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run
register: sysbenchoutput #register: sysbenchoutput
become: true #become: true
#- debug: msg="{{ sysbenchoutput.stdout }}"
- debug: msg="{{ sysbenchoutput.stdout }}" #- local_action: copy content="{{ sysbenchoutput.stdout }}" dest="{{ resultslocation }}sysbench"
- local_action: copy content="{{ sysbenchoutput.stdout }}" dest="{{ resultslocation }}sysbench"
- name: Run stream - name: Run stream
command: expect -c "spawn phoronix-test-suite run-test stream; expect \"Type:\"; send \"4\n\"; expect \"\(Y/n\):\"; send \"n\n\"; interact;" command: expect -c "spawn phoronix-test-suite run-test stream; expect \"Type:\"; send \"4\n\"; expect \"\(Y/n\):\"; send -- \"y\r\"; expect \"Enter a name to save these results under: \"; send -- \"out\r\"; expect \"Enter a unique name to describe this test run / configuration:\"; send -- \"unique\r\"; expect \"New Description:\"; send \"\r\";interact;"
#command: ls -all
register: streamoutput register: streamoutput
become: true become: true
- debug: msg="{{ streamoutput.stdout }}" - debug: msg="{{ streamoutput.stdout }}"
- local_action: copy content="{{ streamoutput.stdout }}" dest="{{ resultslocation }}stream"
- name: Run iozone - name: Get stream results
command: expect -c "spawn phoronix-test-suite run-test iozone; expect \"Record Size:\"; send \"2\n\"; expect \"File Size:\"; send \"2\n\"; expect \"Disk Test:\"; send \"3\n\"; expect \"\(Y/n\):\"; send \"n\n\"; interact;" command: expect -c ""
register: iozoneoutput register: streamoutput
become: true become: true
- debug: msg="{{ streamoutput.stdout }}"
#- name: Run iozone
#command: expect -c "spawn phoronix-test-suite run-test iozone; expect \"Record Size:\"; send \"2\n\"; expect \"File Size:\"; send \"2\n\"; expect \"Disk Test:\"; send \"3\n\"; expect \"\(Y/n\):\"; send \"n\n\"; interact;"
#register: iozoneoutput
#become: true
- debug: msg="{{ iozoneoutput.stdout }}" #- debug: msg="{{ iozoneoutput.stdout }}"
- local_action: copy content="{{ iozoneoutput.stdout }}" dest="{{ resultslocation }}iozone" #- local_action: copy content="{{ iozoneoutput.stdout }}" dest="{{ resultslocation }}iozone"
{
"host": "172.17.0.3",
"result": {
"msg": "Failed to connect to the host via ssh: ssh: connect to host 172.17.0.3 port 22: No route to host\r\n",
"unreachable": true,
"changed": false
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment