Esempio n. 1
0
    def test_common_lib_path_not_in_pythonpath_env_var(self, mock_create_token, mock_subproc_popen):
        process_mock = Mock()
        attrs = {'communicate.return_value': ('output', 'error')}
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock

        mock_create_token = Mock()
        mock_create_token.return_value = 'WHOLETTHEDOGSOUT'

        mock_dispatcher = Mock()
        process_container = ProcessSensorContainer(None, poll_interval=0.1,
                                                   dispatcher=mock_dispatcher)
        sensor = {
            'class_name': 'wolfpack.StupidSensor',
            'ref': 'wolfpack.StupidSensor',
            'id': '567890',
            'trigger_types': ['some_trigga'],
            'pack': 'wolfpack',
            'file_path': '/opt/stackstorm/packs/wolfpack/sensors/stupid_sensor.py',
            'poll_interval': 5
        }

        process_container._enable_common_pack_libs = False
        process_container._sensors = {'pack.StupidSensor': sensor}
        process_container._spawn_sensor_process(sensor)

        _, call_kwargs = mock_subproc_popen.call_args
        actual_env = call_kwargs['env']
        self.assertTrue('PYTHONPATH' in actual_env)
        pack_common_lib_path = '/opt/stackstorm/packs/wolfpack/lib'
        self.assertTrue(pack_common_lib_path not in actual_env['PYTHONPATH'])
Esempio n. 2
0
    def test_common_lib_path_not_in_pythonpath_env_var(self, mock_create_token,
                                                       mock_subproc_popen):
        process_mock = Mock()
        attrs = {'communicate.return_value': ('output', 'error')}
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock

        mock_create_token = Mock()
        mock_create_token.return_value = 'WHOLETTHEDOGSOUT'

        mock_dispatcher = Mock()
        process_container = ProcessSensorContainer(None,
                                                   poll_interval=0.1,
                                                   dispatcher=mock_dispatcher)
        sensor = {
            'class_name': 'wolfpack.StupidSensor',
            'ref': 'wolfpack.StupidSensor',
            'id': '567890',
            'trigger_types': ['some_trigga'],
            'pack': 'wolfpack',
            'file_path':
            '/opt/stackstorm/packs/wolfpack/sensors/stupid_sensor.py',
            'poll_interval': 5
        }

        process_container._enable_common_pack_libs = False
        process_container._sensors = {'pack.StupidSensor': sensor}
        process_container._spawn_sensor_process(sensor)

        _, call_kwargs = mock_subproc_popen.call_args
        actual_env = call_kwargs['env']
        self.assertIn('PYTHONPATH', actual_env)
        pack_common_lib_path = '/opt/stackstorm/packs/wolfpack/lib'
        self.assertNotIn(pack_common_lib_path, actual_env['PYTHONPATH'])
Esempio n. 3
0
    def test_common_lib_path_in_pythonpath_env_var(self, mock_create_token,
                                                   mock_subproc_popen):
        process_mock = Mock()
        attrs = {"communicate.return_value": ("output", "error")}
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock

        mock_create_token = Mock()
        mock_create_token.return_value = "WHOLETTHEDOGSOUT"

        mock_dispatcher = Mock()
        process_container = ProcessSensorContainer(None,
                                                   poll_interval=0.1,
                                                   dispatcher=mock_dispatcher)
        sensor = {
            "class_name": "wolfpack.StupidSensor",
            "ref": "wolfpack.StupidSensor",
            "id": "567890",
            "trigger_types": ["some_trigga"],
            "pack": "wolfpack",
            "file_path":
            "/opt/stackstorm/packs/wolfpack/sensors/stupid_sensor.py",
            "poll_interval": 5,
        }

        process_container._enable_common_pack_libs = True
        process_container._sensors = {"pack.StupidSensor": sensor}
        process_container._spawn_sensor_process(sensor)

        _, call_kwargs = mock_subproc_popen.call_args
        actual_env = call_kwargs["env"]
        self.assertIn("PYTHONPATH", actual_env)
        pack_common_lib_path = "/opt/stackstorm/packs/wolfpack/lib"
        self.assertIn(pack_common_lib_path, actual_env["PYTHONPATH"])