Ejemplo n.º 1
0
 def test_simple_action_fail(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     result = runner.run({'row_index': '4'})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(), ACTIONEXEC_STATUS_FAILED)
Ejemplo n.º 2
0
 def test_simple_action_no_file(self):
     runner = pythonrunner.get_runner()
     runner.entry_point = ''
     runner.container_service = service.RunnerContainerService()
     result = runner.run({})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(),
                      ACTIONEXEC_STATUS_FAILED)
Ejemplo n.º 3
0
 def test_simple_action_no_file(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.entry_point = ''
     runner.container_service = service.RunnerContainerService()
     result = runner.run({})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(), ACTIONEXEC_STATUS_FAILED)
Ejemplo n.º 4
0
 def test_simple_action(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     result = runner.run({'row_index': 4})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(), ACTIONEXEC_STATUS_SUCCEEDED)
     self.assertEqual(runner.container_service.get_result()['result'], '[1, 4, 6, 4, 1]')
Ejemplo n.º 5
0
    def test_simple_action_no_entry_point(self):
        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = ''
        runner.container_service = service.RunnerContainerService()

        expected_msg = 'Action .*? is missing entry_point attribute'
        self.assertRaisesRegexp(Exception, expected_msg, runner.run, {})
Ejemplo n.º 6
0
    def test_simple_action_no_entry_point(self):
        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = ''
        runner.container_service = service.RunnerContainerService()

        expected_msg = 'Action .*? is missing entry_point attribute'
        self.assertRaisesRegexp(Exception, expected_msg, runner.run, {})
Ejemplo n.º 7
0
 def test_exception_in_simple_action_with_invalid_status(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     self.assertRaises(ValueError,
                       runner.run, action_parameters={'row_index': 'd'})
Ejemplo n.º 8
0
    def test_stdout_interception_and_parsing(self, mock_popen):
        values = {'delimiter': ACTION_OUTPUT_RESULT_DELIMITER}

        # No output to stdout and no result (implicit None)
        mock_stdout = '%(delimiter)sNone%(delimiter)s' % values
        mock_stderr = 'foo stderr'
        mock_process = mock.Mock()
        mock_process.communicate.return_value = (mock_stdout, mock_stderr)
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, output, _) = runner.run({'row_index': 4})

        self.assertEqual(output['stdout'], '')
        self.assertEqual(output['stderr'], mock_stderr)
        self.assertEqual(output['result'], 'None')
        self.assertEqual(output['exit_code'], 0)

        # Output to stdout and no result (implicit None)
        mock_stdout = 'pre result%(delimiter)sNone%(delimiter)spost result' % values
        mock_stderr = 'foo stderr'
        mock_process = mock.Mock()
        mock_process.communicate.return_value = (mock_stdout, mock_stderr)
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, output, _) = runner.run({'row_index': 4})

        self.assertEqual(output['stdout'], 'pre resultpost result')
        self.assertEqual(output['stderr'], mock_stderr)
        self.assertEqual(output['result'], 'None')
        self.assertEqual(output['exit_code'], 0)
Ejemplo n.º 9
0
    def test_stdout_interception_and_parsing(self, mock_popen):
        values = {'delimiter': ACTION_OUTPUT_RESULT_DELIMITER}

        # No output to stdout and no result (implicit None)
        mock_stdout = '%(delimiter)sNone%(delimiter)s' % values
        mock_stderr = 'foo stderr'
        mock_process = mock.Mock()
        mock_process.communicate.return_value = (mock_stdout, mock_stderr)
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, output, _) = runner.run({'row_index': 4})

        self.assertEqual(output['stdout'], '')
        self.assertEqual(output['stderr'], mock_stderr)
        self.assertEqual(output['result'], 'None')
        self.assertEqual(output['exit_code'], 0)

        # Output to stdout and no result (implicit None)
        mock_stdout = 'pre result%(delimiter)sNone%(delimiter)spost result' % values
        mock_stderr = 'foo stderr'
        mock_process = mock.Mock()
        mock_process.communicate.return_value = (mock_stdout, mock_stderr)
        mock_process.returncode = 0
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, output, _) = runner.run({'row_index': 4})

        self.assertEqual(output['stdout'], 'pre resultpost result')
        self.assertEqual(output['stderr'], mock_stderr)
        self.assertEqual(output['result'], 'None')
        self.assertEqual(output['exit_code'], 0)
Ejemplo n.º 10
0
 def test_simple_action_no_file(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = 'foo.py'
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, result, _) = runner.run({})
     self.assertTrue(result is not None)
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
Ejemplo n.º 11
0
 def test_exception_in_simple_action_with_invalid_status(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     self.assertRaises(ValueError,
                       runner.run,
                       action_parameters={'row_index': 'd'})
Ejemplo n.º 12
0
 def test_simple_action_fail(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, result, _) = runner.run({'row_index': '4'})
     self.assertTrue(result is not None)
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
Ejemplo n.º 13
0
 def test_simple_action_no_file(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = 'foo.py'
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, result, _) = runner.run({})
     self.assertTrue(result is not None)
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
Ejemplo n.º 14
0
 def test_simple_action_fail(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, result, _) = runner.run({'row_index': '4'})
     self.assertTrue(result is not None)
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
Ejemplo n.º 15
0
 def test_simple_action(self):
     runner = pythonrunner.get_runner()
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     result = runner.run({'row_index': 4})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(),
                      ACTIONEXEC_STATUS_SUCCEEDED)
     self.assertEqual(runner.container_service.get_result(),
                      [1, 4, 6, 4, 1])
Ejemplo n.º 16
0
 def test_simple_action_with_status_succeeded(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 4})
     self.assertEqual(status, LIVEACTION_STATUS_SUCCEEDED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], [1, 4, 6, 4, 1])
Ejemplo n.º 17
0
 def test_action_with_same_module_name_as_module_in_stdlib(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = TEST_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({})
     self.assertEqual(status, LIVEACTION_STATUS_SUCCEEDED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], 'test action')
Ejemplo n.º 18
0
 def test_simple_action_with_status_succeeded(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 4})
     self.assertEqual(status, LIVEACTION_STATUS_SUCCEEDED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], [1, 4, 6, 4, 1])
Ejemplo n.º 19
0
 def test_action_with_same_module_name_as_module_in_stdlib(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = TEST_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({})
     self.assertEqual(status, LIVEACTION_STATUS_SUCCEEDED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], 'test action')
Ejemplo n.º 20
0
 def test_simple_action_with_status_failed(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 'a'})
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], "This is suppose to fail don't worry!!")
Ejemplo n.º 21
0
 def test_simple_action(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, result) = runner.run({'row_index': 4})
     self.assertEqual(status, ACTIONEXEC_STATUS_SUCCEEDED)
     self.assertTrue(result is not None)
     self.assertEqual(result['result'], [1, 4, 6, 4, 1])
Ejemplo n.º 22
0
 def test_simple_action_with_status_failed(self):
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 'a'})
     self.assertEqual(status, LIVEACTION_STATUS_FAILED)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'],
                      "This is suppose to fail don't worry!!")
Ejemplo n.º 23
0
 def test_simple_action_fail(self):
     runner = pythonrunner.get_runner()
     runner.entry_point = PACAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     result = runner.run({'row_index': '4'})
     self.assertTrue(result)
     self.assertEqual(runner.container_service.get_status(),
                      ACTIONEXEC_STATUS_FAILED)
     import json
     print '\n', json.dumps(runner.container_service.get_result(),
                            indent=4,
                            sort_keys=True)
Ejemplo n.º 24
0
 def test_simple_action_timeout(self):
     timeout = 0
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {pythonrunner.RUNNER_TIMEOUT: timeout}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 4})
     self.assertEqual(status, LIVEACTION_STATUS_TIMED_OUT)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], 'None')
     self.assertEqual(output['error'], 'Action failed to complete in 0 seconds')
     self.assertEqual(output['exit_code'], -9)
Ejemplo n.º 25
0
 def test_simple_action_timeout(self):
     timeout = 0
     runner = pythonrunner.get_runner()
     runner.action = self._get_mock_action_obj()
     runner.runner_parameters = {pythonrunner.RUNNER_TIMEOUT: timeout}
     runner.entry_point = PASCAL_ROW_ACTION_PATH
     runner.container_service = service.RunnerContainerService()
     runner.pre_run()
     (status, output, _) = runner.run({'row_index': 4})
     self.assertEqual(status, LIVEACTION_STATUS_TIMED_OUT)
     self.assertTrue(output is not None)
     self.assertEqual(output['result'], 'None')
     self.assertEqual(output['error'],
                      'Action failed to complete in 0 seconds')
     self.assertEqual(output['exit_code'], -9)
Ejemplo n.º 26
0
    def test_common_st2_env_vars_are_available_to_the_action(self, mock_popen):
        mock_process = mock.Mock()
        mock_process.communicate.return_value = ('', '')
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.auth_token = mock.Mock()
        runner.auth_token.token = 'ponies'
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, _, _) = runner.run({'row_index': 4})

        _, call_kwargs = mock_popen.call_args
        actual_env = call_kwargs['env']
        self.assertCommonSt2EnvVarsAvailableInEnv(env=actual_env)
Ejemplo n.º 27
0
    def test_common_st2_env_vars_are_available_to_the_action(self, mock_popen):
        mock_process = mock.Mock()
        mock_process.communicate.return_value = ('', '')
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.auth_token = mock.Mock()
        runner.auth_token.token = 'ponies'
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {}
        runner.entry_point = PASCAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, _, _) = runner.run({'row_index': 4})

        _, call_kwargs = mock_popen.call_args
        actual_env = call_kwargs['env']
        self.assertCommonSt2EnvVarsAvailableInEnv(env=actual_env)
Ejemplo n.º 28
0
    def test_action_with_user_supplied_env_vars(self, mock_popen):
        env_vars = {'key1': 'val1', 'key2': 'val2', 'PYTHONPATH': 'foobar'}

        mock_process = mock.Mock()
        mock_process.communicate.return_value = ('', '')
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {'env': env_vars}
        runner.entry_point = PASCAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, _, _) = runner.run({'row_index': 4})

        _, call_kwargs = mock_popen.call_args
        actual_env = call_kwargs['env']

        for key, value in env_vars.items():
            # Verify that a blacklsited PYTHONPATH has been filtered out
            if key == 'PYTHONPATH':
                self.assertTrue(actual_env[key] != value)
            else:
                self.assertEqual(actual_env[key], value)
Ejemplo n.º 29
0
    def test_action_with_user_supplied_env_vars(self, mock_popen):
        env_vars = {'key1': 'val1', 'key2': 'val2', 'PYTHONPATH': 'foobar'}

        mock_process = mock.Mock()
        mock_process.communicate.return_value = ('', '')
        mock_popen.return_value = mock_process

        runner = pythonrunner.get_runner()
        runner.action = self._get_mock_action_obj()
        runner.runner_parameters = {'env': env_vars}
        runner.entry_point = PACAL_ROW_ACTION_PATH
        runner.container_service = service.RunnerContainerService()
        runner.pre_run()
        (_, _, _) = runner.run({'row_index': 4})

        _, call_kwargs = mock_popen.call_args
        actual_env = call_kwargs['env']

        for key, value in env_vars.items():
            # Verify that a blacklsited PYTHONPATH has been filtered out
            if key == 'PYTHONPATH':
                self.assertTrue(actual_env[key] != value)
            else:
                self.assertEqual(actual_env[key], value)
Ejemplo n.º 30
0
 def test_runner_creation(self):
     runner = pythonrunner.get_runner()
     self.assertTrue(runner is not None, 'Creation failed. No instance.')
     self.assertEqual(type(runner), pythonrunner.PythonRunner, 'Creation failed. No instance.')
Ejemplo n.º 31
0
 def test_runner_creation(self):
     runner = pythonrunner.get_runner()
     self.assertTrue(runner is not None, 'Creation failed. No instance.')
     self.assertEqual(type(runner), pythonrunner.PythonRunner,
                      'Creation failed. No instance.')