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

changed playbook to save results

parent ad821dc7
......@@ -72,7 +72,7 @@
<h1 class="page-header">Files and Libraries</h1>
<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>
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.
......@@ -97,7 +97,7 @@
</tbody>
</table>
<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>
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
......@@ -127,7 +127,7 @@
</tbody>
</table>
<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>
The Java client-side library is used to access the Web service API for this application using Java.
</p>
......@@ -155,7 +155,7 @@
</tbody>
</table>
<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>
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
......@@ -190,7 +190,7 @@
</tbody>
</table>
<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>
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
......@@ -219,7 +219,7 @@
</tbody>
</table>
<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>
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
......@@ -251,7 +251,7 @@
</tbody>
</table>
<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>
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
......
......@@ -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'
if not os.path.exists(playbook_path):
print '[ERROR] The playbook does not exist'
......@@ -31,7 +31,7 @@ if not os.path.exists(playbook_path):
user='vm_user'
ssh_key_file='id_ras'
extra_vars = {'resultslocation':'/tmp/res'}
extra_vars = {} #{'resultslocation':'/tmp/res','ansible_sudo_pass':'123'}
variable_manager = VariableManager()
......@@ -63,35 +63,23 @@ results = pbex.run()
ok = results_callback.host_ok
count=0;
answer = []
for res in ok:
re = json.dumps(res['result']._result)
++count
target = open("ok"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
count=0;
unreachable = results_callback.host_unreachable
for res in unreachable:
re = json.dumps(res['result']._result)
++count
target = open("unreachable"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
count=0;
host_failed = results_callback.host_failed
for res in host_failed:
re = json.dumps(res['result']._result)
++count
target = open("host_failed"+str(count)+".json", 'w')
target.write(re)
target.close()
print re
resp = json.dumps({"host":res['ip'], "result":res['result']._result})
answer.append({"host":res['ip'], "result":res['result']._result})
print json.dumps(answer,indent=4)
\ No newline at end of file
......@@ -21,6 +21,25 @@ import paramiko, os
import threading
import ansible.runner
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):
try:
......@@ -39,15 +58,66 @@ def install_prerequisites(vm):
return "ERROR:"+vm.ip+" "+str(e)
ssh.close()
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):
ips=""
privatekey=""
def run(vm_list,playbook_path):
hosts=""
ssh_key_file=""
for vm in vm_list:
ret = install_prerequisites(vm)
ips+=vm.ip+","
privatekey = vm.key
hosts+=vm.ip+","
ssh_key_file = vm.key
user = vm.user
if "ERROR" in ret: return ret
return "SUCCESS"
\ No newline at end of file
extra_vars = {}
passwords = {}
return execute_playbook(hosts,playbook_path,user,ssh_key_file,extra_vars,passwords)
\ No newline at end of file
#! /bin/bash
apt-get update
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
\ 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 @@
become: true
- name: Count vCPU
command: nproc
register: vcpunumber
become: true
- debug: msg="{{ vcpunumber.stdout }}"
#- name: Count vCPU
#command: nproc
#register: vcpunumber
#become: true
#- debug: msg="{{ vcpunumber.stdout }}"
- name: Run sysbench
command: sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run
register: sysbenchoutput
become: true
- debug: msg="{{ sysbenchoutput.stdout }}"
- local_action: copy content="{{ sysbenchoutput.stdout }}" dest="{{ resultslocation }}sysbench"
#- name: Run sysbench
#command: sysbench --test=cpu --cpu-max-prime=100000 --num-threads={{ vcpunumber.stdout }} run
#register: sysbenchoutput
#become: true
#- debug: msg="{{ sysbenchoutput.stdout }}"
#- local_action: copy content="{{ sysbenchoutput.stdout }}" dest="{{ resultslocation }}sysbench"
- 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: ls -all
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;"
register: streamoutput
become: true
- debug: msg="{{ streamoutput.stdout }}"
- local_action: copy content="{{ streamoutput.stdout }}" dest="{{ resultslocation }}stream"
- 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
- name: Get stream results
command: expect -c ""
register: streamoutput
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 }}"
- local_action: copy content="{{ iozoneoutput.stdout }}" dest="{{ resultslocation }}iozone"
#- debug: msg="{{ iozoneoutput.stdout }}"
#- 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