예제 #1
0
    def test_exception_logging(self):
        executor = Executor()
        executor._log = Mock()

        with patch.object(Runnable, 'run', side_effect=Exception):
            executor.run(Runnable)
        executor.wait()

        self.assertEqual(1, executor._log.error.call_count)
예제 #2
0
    def test_exception_logging(self):
        executor = Executor()
        executor._log = Mock()

        with patch.object(Runnable, 'run', side_effect=Exception):
            executor.run(Runnable)
        executor.wait()

        self.assertEqual(1, executor._log.error.call_count)
예제 #3
0
    def test_runnable_output(self):
        executor = Executor()

        with patch.object(Runnable, 'run', return_value=TestExecutor.output):
            executor.run(Runnable())
        executor.wait()
        results = executor.results

        self.assertEqual(1, len(results))
        self.assertEqual(TestExecutor.output, results[0])
예제 #4
0
    def test_calledprocesserror_logging(self):
        executor = Executor()
        executor._log = Mock()
        exception = CalledProcessError(returncode=1, cmd='command')

        with patch.object(Runnable, 'run', side_effect=exception):
            executor.run(Runnable)
        executor.wait()

        self.assertEqual(1, executor._log.error.call_count)
예제 #5
0
    def test_calledprocesserror_logging(self):
        executor = Executor()
        executor._log = Mock()
        exception = CalledProcessError(returncode=1, cmd='command')

        with patch.object(Runnable, 'run', side_effect=exception):
            executor.run(Runnable)
        executor.wait()

        self.assertEqual(1, executor._log.error.call_count)
예제 #6
0
    def test_runnable_output(self):
        executor = Executor()

        with patch.object(Runnable, 'run', return_value=TestExecutor.output):
            executor.run(Runnable())
        executor.wait()
        results = executor.results

        self.assertEqual(1, len(results))
        self.assertEqual(TestExecutor.output, results[0])
예제 #7
0
    def test_function_outputs(self):
        executor = Executor()
        runnable = Runnable()

        with patch.object(Runnable, 'run', side_effect=TestExecutor.outputs):
            executor.run(runnable)
            executor.run(runnable)
        executor.wait()
        results = executor.results

        self.assertListEqual(TestExecutor.outputs, results)
예제 #8
0
    def test_function_outputs(self):
        executor = Executor()
        runnable = Runnable()

        with patch.object(Runnable, 'run', side_effect=TestExecutor.outputs):
            executor.run(runnable)
            executor.run(runnable)
        executor.wait()
        results = executor.results

        self.assertListEqual(TestExecutor.outputs, results)
예제 #9
0
    def test_logged_title_when_it_differs_from_command(self):
        command, title = 'command', 'title'

        runnable = Runnable()
        runnable.title = title
        exception = CalledProcessError(returncode=1, cmd=command)
        runnable.run = Mock(side_effect=exception)

        executor = Executor()
        executor._log = Mock()
        executor.run(runnable)
        executor.wait()

        executor._log.error.assert_called_once_with(Matcher(has_title))
예제 #10
0
    def test_logged_title_when_it_differs_from_command(self):
        command, title = 'command', 'title'

        runnable = Runnable()
        runnable.title = title
        exception = CalledProcessError(returncode=1, cmd=command)
        runnable.run = Mock(side_effect=exception)

        executor = Executor()
        executor._log = Mock()
        executor.run(runnable)
        executor.wait()

        executor._log.error.assert_called_once_with(Matcher(has_title))
예제 #11
0
    def test_if_logged_title_is_hidden_if_it_equals_command(self):
        command = 'command'

        runnable = Runnable()
        runnable.title = command
        exception = CalledProcessError(returncode=1, cmd=command)
        runnable.run = Mock(side_effect=exception)

        executor = Executor()
        executor._log = Mock()
        executor.run(runnable)
        executor.wait()

        executor._log.error.assert_called_once_with(Matcher(has_not_title))
예제 #12
0
    def test_if_logged_title_is_hidden_if_it_equals_command(self):
        command = 'command'

        runnable = Runnable()
        runnable.title = command
        exception = CalledProcessError(returncode=1, cmd=command)
        runnable.run = Mock(side_effect=exception)

        executor = Executor()
        executor._log = Mock()
        executor.run(runnable)
        executor.wait()

        executor._log.error.assert_called_once_with(Matcher(has_not_title))
예제 #13
0
#!/usr/bin/env python3
from expyrimenter import SSH, Executor


# Suppose we have a cluster with hostnames vm0, vm1 and vm2
cluster = ['hdpd%d' % i for i in range(0, 3)]

# Let's run the command below in all VMs:
cmd = 'echo "$(date +%S) Hello by $(hostname)"'

# Blocking version
print('Serial execution\n================')
for vm in cluster:
    output = SSH(vm, cmd, stdout=True).run()
    print(output)

# Create a pool for parallel execution
pool = Executor()

# Non-blocking version
print('\nParallel execution\n==================')
for vm in cluster:
    ssh = SSH(vm, cmd, stdout=True, stderr=False)
    pool.run(ssh)

# Block until all parallel calls are done
# and then print the results
pool.wait()
for result in pool.results:
    print(result)
예제 #14
0
 def test_against_function_memory_leak(self):
     executor = Executor()
     executor.run_function(test_function)
     executor.wait()
     self.assertEqual(0, len(executor._function_titles))
예제 #15
0
 def test_against_runnable_memory_leak(self):
     executor = Executor()
     with patch.object(Runnable, 'run'):
         executor.run(Runnable())
     executor.wait()
     self.assertEqual(0, len(executor._future_runnables))
예제 #16
0
 def test_function_output(self):
     executor = Executor()
     executor.run_function(test_function)
     executor.wait()
     output = executor.results[0]
     self.assertEqual(TestExecutor.output, output)
예제 #17
0
#!/usr/bin/env python3
from expyrimenter import SSH, Executor

# Suppose we have a cluster with hostnames vm0, vm1 and vm2
cluster = ['vm%d' % i for i in range(0, 3)]

# Let's run the command below in all VMs:
cmd = 'echo "$(date +%S) Hello by $(hostname)"'

# Blocking version, serial execution
print('Serial execution\n================')
for vm in cluster:
    output = SSH(vm, cmd, stdout=True).run()
    print(output)

# Create a pool for parallel execution
pool = Executor()

# Non-blocking version, parallel execution
print('\nParallel execution\n==================')
for vm in cluster:
    ssh = SSH(vm, cmd, stdout=True, stderr=False)
    pool.run(ssh)

# Block until all parallel calls are done
# and then print the results
pool.wait()
for result in pool.results:
    print(result)
예제 #18
0
 def test_function_output(self):
     executor = Executor()
     executor.run_function(background_function)
     executor.wait()
     output = executor.results[0]
     self.assertEqual(TestExecutor.output, output)
예제 #19
0
 def test_against_function_memory_leak(self):
     executor = Executor()
     executor.run_function(background_function)
     executor.wait()
     self.assertEqual(0, len(executor._function_titles))
예제 #20
0
 def test_against_runnable_memory_leak(self):
     executor = Executor()
     with patch.object(Runnable, 'run'):
         executor.run(Runnable())
     executor.wait()
     self.assertEqual(0, len(executor._future_runnables))