Пример #1
0
    def test_env_variables_when_pty(self):
        test_utils.set_env_value('some_env', 'test')

        config = create_config_model(
            'config_x',
            script_command='tests/scripts/printenv.sh',
            requires_terminal=True,
            parameters=[
                create_script_param_config('id'),
                create_script_param_config('name',
                                           env_var='My_Name',
                                           param='-n'),
                create_script_param_config('verbose',
                                           param='--verbose',
                                           no_value=True),
            ])

        executor._process_creator = create_process_wrapper
        self.create_executor(config, {
            'id': '918273',
            'name': 'UserX',
            'verbose': True
        })
        self.executor.start()

        data = read_until_closed(self.executor.get_raw_output_stream(), 100)
        output = ''.join(data)

        variables = parse_env_variables(output)
        self.assertEqual('918273', variables.get('PARAM_ID'))
        self.assertEqual('UserX', variables.get('My_Name'))
        self.assertEqual('true', variables.get('PARAM_VERBOSE'))
        self.assertEqual('test', variables.get('some_env'))
Пример #2
0
    def test_replay_dispose_when_active(self):
        observable = self.create_replay_observable()
        observable.push('1')
        observable.dispose()

        self.assertTrue(observable.closed)
        self.assertEqual([], read_until_closed(observable, timeout=0.001))
Пример #3
0
    def _test_read_until_closed(self, source, observable, prewait_callback=None):
        early_messages = ['early 1', 'early 1']
        late_messages = ['lateX', 'lateY']

        for message in early_messages:
            source.push(message)

        def publish_async():
            time.sleep(0.1)

            for message in late_messages:
                source.push(message)

            source.close()

        thread = threading.Thread(target=publish_async, daemon=True)
        thread.start()

        if prewait_callback:
            prewait_callback()

        data = read_until_closed(observable, timeout=0.3)

        self.assertTrue(source.closed)
        self.assertTrue(observable.closed)

        return data, early_messages, late_messages
Пример #4
0
    def _execution_finished(self):
        output_stream_data = read_until_closed(self.output_stream)
        script_output = ''.join(output_stream_data)

        downloadable_files = self._prepare_downloadable_files(
            self.result_files_paths, self.config, script_output)

        self.result_files.extend(downloadable_files.values())
Пример #5
0
    def test_replay_dispose(self):
        observable = self.create_replay_observable()
        observable.push('1')
        observable.close()
        observable.dispose()

        data = read_until_closed(observable, 0.1)
        self.assertEqual([], data)
Пример #6
0
            def output_closed():
                output_stream_data = read_until_closed(output_stream)
                script_output = ''.join(output_stream_data)

                parameter_values = execution_service.get_parameter_values(
                    execution_id)
                owner = execution_service.get_owner(execution_id)

                downloadable_files = download_feature._prepare_downloadable_files(
                    config, script_output, parameter_values, owner)
                download_feature._execution_download_files[
                    execution_id] = downloadable_files
Пример #7
0
 def execute_and_get_passed_env(custom_variables):
     process_wrapper = PtyProcessWrapper('tests/scripts/printenv.sh', '.',
                                         custom_variables)
     process_wrapper.start()
     thread = threading.Thread(target=process_wrapper.wait_finish,
                               daemon=True)
     thread.start()
     thread.join(timeout=0.1)
     output = ''.join(read_until_closed(process_wrapper.output_stream))
     lines = output.split('\n')
     env_dict = {
         line.split('=', 2)[0]: line.split('=', 2)[1]
         for line in lines if '=' in line
     }
     return env_dict
Пример #8
0
    def test_pipe_replay_dispose_deferred_for_updates(self):
        observable = self.create_observable()
        replay = self.replay(observable)

        observer = _StoringObserver()
        replay.subscribe(observer)

        observable.push('1')
        replay.dispose()
        observable.push('2')

        self.assertEqual(['1', '2'], observer.data)

        observable.close()
        self.assertEqual([], read_until_closed(replay, timeout=0.001))
Пример #9
0
    def test_many_unicode_characters(self):
        long_unicode_text = ('ΩΨΔ\n' * 100000)
        test_utils.create_file('test.txt', text=long_unicode_text)

        process_wrapper = PtyProcessWrapper(['cat', 'test.txt'],
                                            test_utils.temp_folder, {})
        process_wrapper.start()

        thread = threading.Thread(target=process_wrapper.wait_finish,
                                  daemon=True)
        thread.start()
        thread.join(timeout=0.1)

        output = ''.join(read_until_closed(process_wrapper.output_stream))
        self.assertEqual(long_unicode_text, output)

        self.assertEqual(0, process_wrapper.get_return_code())
Пример #10
0
        def execution_finished(execution_id):
            config = execution_service.get_config(execution_id)
            if not download_feature._is_downloadable(config):
                return

            output_stream = execution_service.get_anonymized_output_stream(execution_id)

            output_stream_data = read_until_closed(output_stream)
            script_output = ''.join(output_stream_data)

            parameter_values = execution_service.get_user_parameter_values(execution_id)
            owner = execution_service.get_owner(execution_id)

            downloadable_files = download_feature._prepare_downloadable_files(
                config,
                script_output,
                parameter_values,
                owner)
            download_feature._execution_download_files[execution_id] = downloadable_files
Пример #11
0
        def finished(execution_id):
            return_code = execution_service.get_exit_code(execution_id)

            if return_code != 0:
                script_config = execution_service.get_config(execution_id)
                script = str(script_config.name)
                audit_name = execution_service.get_audit_name(execution_id)
                output_stream = execution_service.get_anonymized_output_stream(execution_id)

                title = script + ' FAILED'
                body = 'The script "' + script + '", started by ' + audit_name + \
                       ' exited with return code ' + str(return_code) + '.' + \
                       ' Usually this means an error, occurred during the execution.' + \
                       ' Please check the corresponding logs'

                output_stream_data = read_until_closed(output_stream)
                script_output = ''.join(output_stream_data)

                alert_service.send_alert(title, body, script_output)
Пример #12
0
        def finished(execution_id):
            return_code = execution_service.get_exit_code(execution_id)

            if return_code != 0:
                script_config = execution_service.get_config(execution_id)
                script = str(script_config.name)
                audit_name = execution_service.get_audit_name(execution_id)
                output_stream = execution_service.get_anonymized_output_stream(execution_id)

                title = script + ' FAILED'
                body = 'The script "' + script + '", started by ' + audit_name + \
                       ' exited with return code ' + str(return_code) + '.' + \
                       ' Usually this means an error, occurred during the execution.' + \
                       ' Please check the corresponding logs'

                output_stream_data = read_until_closed(output_stream)
                script_output = ''.join(output_stream_data)

                files = [File(filename='log.txt', content=script_output)]
                alert_service.send_alert(title, body, files)
Пример #13
0
    def test_mixed_encoding(self):
        file_path = os.path.join(test_utils.temp_folder, 'test.txt')
        file_utils.write_file(
            file_path,
            b'g\xc3\xbcltig\n l\xc3\xa4uft ver\xc3\xa4ndert f\xc3\xbcr '
            b'\xc4ndern \nPr\xfcfung g\xc3\xbcltig l\xc3\xa4uft \xe0\xa0\x80 \xf0\x92\x80\x80!',
            byte_content=True)

        process_wrapper = PtyProcessWrapper(['cat', 'test.txt'],
                                            test_utils.temp_folder, {})
        process_wrapper.start()

        thread = threading.Thread(target=process_wrapper.wait_finish,
                                  daemon=True)
        thread.start()
        thread.join(timeout=0.1)

        output = ''.join(read_until_closed(process_wrapper.output_stream))
        self.assertEqual(
            'gültig\n läuft verändert für Ändern \nPrüfung gültig läuft ࠀ 𒀀!',
            output)
Пример #14
0
 def get_finish_output(self):
     data = read_until_closed(self.executor.get_anonymized_output_stream(), timeout=BUFFER_FLUSH_WAIT_TIME)
     output = ''.join(data)
     return output
Пример #15
0
 def get_finish_output(self):
     data = read_until_closed(self.executor.get_anonymized_output_stream(),
                              timeout=0.1)
     output = ''.join(data)
     return output