def test_pssh_client_hosts_list_part_failure(self): """Test getting output for remainder of host list in the case where one host in the host list has a failure""" hosts = [self.host, '127.1.1.100'] client = ParallelSSHClient(hosts, port=self.port, pkey=self.user_key, num_retries=1) output = client.run_command(self.cmd, stop_on_errors=False) self.assertFalse(client.finished(output)) client.join(output, consume_output=True) self.assertTrue(client.finished(output)) self.assertTrue( hosts[0] in output, msg="Successful host does not exist in output - output is %s" % (output, )) self.assertTrue( hosts[1] in output, msg="Failed host does not exist in output - output is %s" % (output, )) self.assertTrue('exception' in output[hosts[1]], msg="Failed host %s has no exception in output - %s" % ( hosts[1], output, )) self.assertTrue(output[hosts[1]].exception is not None) self.assertEqual(output[hosts[1]].exception.host, hosts[1]) try: raise output[hosts[1]]['exception'] except ConnectionErrorException: pass else: raise Exception("Expected ConnectionError, got %s instead" % (output[hosts[1]]['exception'], ))
def test_join_timeout(self): client = ParallelSSHClient([self.host], port=self.port, pkey=self.user_key) output = client.run_command('echo me; sleep 1.5') self.assertRaises(Timeout, client.join, output, timeout=1) self.assertFalse(output[0].client.finished(output[0].channel)) self.assertFalse(output[0].channel.is_eof()) client.join(output, timeout=2) self.assertTrue(output[0].channel.is_eof()) self.assertTrue(client.finished(output))
def test_join_timeout(self): client = ParallelSSHClient([self.host], port=self.port, pkey=self.user_key) output = client.run_command('echo me; sleep 2') # Wait for long running command to start to avoid race condition time.sleep(.1) self.assertRaises(Timeout, client.join, output, timeout=1) self.assertFalse(output[self.host].channel.is_eof()) # Ensure command has actually finished - avoid race conditions time.sleep(2) client.join(output, timeout=3) self.assertTrue(output[self.host].channel.is_eof()) self.assertTrue(client.finished(output))
def test_default_finished(self): client = ParallelSSHClient([self.host], port=self.port, pkey=self.user_key) self.assertTrue(client.finished())