from calyptos.plugins.validator.validatorplugin import ValidatorPlugin
import os

class PingHosts(ValidatorPlugin):
    def validate(self):
        for host in self.component_deployer.all_hosts:
            if self._ping(host, count=3):
                self.success('Ping to ' + host)
            else:
                self.failure('Ping to ' + host)
                raise AssertionError('Unable to ping host: ' + host)

    def _ping(self, host, count=1):
        exit_code = os.system('ping -c {0} {1}'.format(count, host))
        if exit_code != 0:
            return False
        else:
            return True

@@ -71,18 +71,44 @@
 %0Aimport 
-os
+threading%0Aimport subprocess%0A
 %0A%0Aclass 
@@ -143,123 +143,575 @@
     
-def validate(self):%0A        for host in self.component_deployer.all_hosts:%0A            if self._ping(host, count=3)
+hostlock = threading.Lock()%0A%0A    def validate(self):%0A        results = %7B%7D%0A        threads = %5B%5D%0A%0A        def results_ping(host, count, hostlock):%0A            res = self.ping_ip(host, count=count)%0A            with hostlock:%0A                results%5Bhost%5D = res%0A        for host in self.component_deployer.all_hosts:%0A            t = threading.Thread(target=results_ping, args=(host, 3, self.hostlock))%0A            threads.append(t)%0A            t.start()%0A        for t in threads:%0A            t.join()%0A        for host, result in results.iteritems():%0A            if result
 :%0A  
@@ -900,21 +900,23 @@
     def 
-_
 ping
+_ip
 (self, h
@@ -926,17 +926,17 @@
 , count=
-1
+3
 ):%0A     
@@ -942,35 +942,25 @@
     
-exit_code = os.system('ping
+args = 'ping -W 3
  -c 
@@ -987,17 +987,16 @@
 t, host)
-)
 %0A       
@@ -1000,26 +1000,280 @@
     
-if exit_
+process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,%0A                                   bufsize=4096, shell=True)%0A        output, unused_err = process.communicate()%0A        ret
 code 
-!
 = 
-0:
+process.poll()%0A        if retcode:%0A            print output
 %0A   
@@ -1294,34 +1294,16 @@
 n False%0A
-        else:%0A    
         

Improve pinghost performance