[7541] | 1 | #!/usr/bin/env python |
---|
| 2 | # |
---|
| 3 | # Copyright (c) 2010 Corey Goldberg (corey@goldb.org) |
---|
| 4 | # License: GNU LGPLv3 |
---|
| 5 | # |
---|
| 6 | # This file is part of Multi-Mechanize | Performance Test Framework |
---|
| 7 | # |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | """ |
---|
| 11 | Multi-Mechanize Grid Controller |
---|
| 12 | sample gui application for controlling multi-mechanize instances via the remote management api |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | import socket |
---|
| 17 | import ScrolledText |
---|
| 18 | import Tkinter |
---|
| 19 | import tkFileDialog |
---|
| 20 | import xmlrpclib |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | # list of hosts:ports where multi-mechanize is listening |
---|
| 25 | NODES = [ |
---|
| 26 | '192.168.1.2:9001', |
---|
| 27 | '192.168.1.3:9001', |
---|
| 28 | ] |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | class Application: |
---|
| 33 | def __init__(self, root, hosts): |
---|
| 34 | self.hosts = hosts |
---|
| 35 | self.root = root |
---|
| 36 | self.root.geometry('%dx%d%+d%+d' % (600, 400, 100, 100)) |
---|
| 37 | self.root.title('Multi-Mechanize Grid Controller') |
---|
| 38 | |
---|
| 39 | Tkinter.Button(self.root, text='List Nodes', command=self.list_nodes, width=15,).place(x=5, y=5) |
---|
| 40 | Tkinter.Button(self.root, text='Check Tests', command=self.check_servers, width=15,).place(x=5, y=35) |
---|
| 41 | Tkinter.Button(self.root, text='Get Project Names', command=self.get_project_names, width=15).place(x=5, y=65) |
---|
| 42 | Tkinter.Button(self.root, text='Get Configs', command=self.get_configs, width=15).place(x=5, y=95) |
---|
| 43 | Tkinter.Button(self.root, text='Update Configs', command=self.update_configs, width=15).place(x=5, y=125) |
---|
| 44 | Tkinter.Button(self.root, text='Get Results', command=self.get_results, width=15).place(x=5, y=155) |
---|
| 45 | Tkinter.Button(self.root, text='Run Tests', command=self.run_tests, width=15).place(x=5, y=185) |
---|
| 46 | |
---|
| 47 | self.text_box = ScrolledText.ScrolledText(self.root, width=59, height=24, font=('Helvetica', 9)) |
---|
| 48 | self.text_box.place(x=162, y=5) |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def clear_window(self): |
---|
| 52 | self.text_box.delete(1.0, Tkinter.END) |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | def list_nodes(self): |
---|
| 56 | self.clear_window() |
---|
| 57 | for host, port in self.hosts: |
---|
| 58 | self.text_box.insert(Tkinter.END, '%s:%s\n' % (host, port)) |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | def run_tests(self): |
---|
| 62 | self.clear_window() |
---|
| 63 | for host, port in self.hosts: |
---|
| 64 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 65 | try: |
---|
| 66 | status = server.run_test() |
---|
| 67 | self.text_box.insert(Tkinter.END, '%s:%s:\n%s\n\n\n' % (host, port, status)) |
---|
| 68 | except socket.error: |
---|
| 69 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | def get_configs(self): |
---|
| 73 | self.clear_window() |
---|
| 74 | for host, port in self.hosts: |
---|
| 75 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 76 | try: |
---|
| 77 | config = server.get_config() |
---|
| 78 | self.text_box.insert(Tkinter.END, '%s:%s config:\n%s\n\n\n' % (host, port, config)) |
---|
| 79 | except socket.error: |
---|
| 80 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | def update_configs(self): |
---|
| 84 | self.clear_window() |
---|
| 85 | f = tkFileDialog.askopenfile(parent=self.root, initialdir='./', title='Select a Config File') |
---|
| 86 | for host, port in self.hosts: |
---|
| 87 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 88 | try: |
---|
| 89 | status = server.update_config(f.read()) |
---|
| 90 | self.text_box.insert(Tkinter.END, '%s:%s config updated:\n%s\n\n' % (host, port, status)) |
---|
| 91 | except socket.error: |
---|
| 92 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | def get_results(self): |
---|
| 96 | self.clear_window() |
---|
| 97 | for host, port in self.hosts: |
---|
| 98 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 99 | try: |
---|
| 100 | results = server.get_results() |
---|
| 101 | self.text_box.insert(Tkinter.END, '%s:%s results:\n%s\n\n\n' % (host, port, results)) |
---|
| 102 | except socket.error: |
---|
| 103 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | def get_project_names(self): |
---|
| 107 | self.clear_window() |
---|
| 108 | for host, port in self.hosts: |
---|
| 109 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 110 | try: |
---|
| 111 | name = server.get_project_name() |
---|
| 112 | self.text_box.insert(Tkinter.END, '%s:%s project name:\n%s\n\n' % (host, port, name)) |
---|
| 113 | except socket.error: |
---|
| 114 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | def check_servers(self): |
---|
| 118 | self.clear_window() |
---|
| 119 | for host, port in self.hosts: |
---|
| 120 | server = xmlrpclib.ServerProxy('http://%s:%s' % (host, port)) |
---|
| 121 | try: |
---|
| 122 | is_running = server.check_test_running() |
---|
| 123 | self.text_box.insert(Tkinter.END, '%s:%s test running:\n%s\n\n' % (host, port, is_running)) |
---|
| 124 | except socket.error: |
---|
| 125 | self.text_box.insert(Tkinter.END, 'can not make connection to: %s:%s\n' % (host, port)) |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | def main(): |
---|
| 130 | hosts = [(host_port.split(':')[0], host_port.split(':')[1]) for host_port in NODES] |
---|
| 131 | root = Tkinter.Tk() |
---|
| 132 | app = Application(root, hosts) |
---|
| 133 | root.mainloop() |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | if __name__ == '__main__': |
---|
| 137 | main() |
---|