コード例 #1
0
    def _start_das(self):
        # target_override_filepath = _construct_override_file(test_scenario=test_scenario, overrides=overrides)

        if self.immortals_root is None:
            immortals_root = get_configuration().globals.immortalsRoot
        else:
            immortals_root = os.path.abspath(self.immortals_root)
            print(immortals_root)

        self.das_stdout = open(
            os.path.join(
                get_configuration().globals.globalLogDirectory,
                self._current_test_scenario.scenarioIdentifier +
                '-start-stdout.txt'), 'a')
        self.das_stderr = open(
            os.path.join(
                get_configuration().globals.globalLogDirectory,
                self._current_test_scenario.scenarioIdentifier +
                '-start-stderr.txt'), 'a')
        try:
            self.das_process = Popen([
                'bash',
                os.path.join(immortals_root, 'das/start.sh'), "-v", "DEBUG"
            ],
                                     cwd=os.path.abspath(
                                         os.path.join(immortals_root,
                                                      'harness')),
                                     stdin=PIPE,
                                     stderr=self.das_stderr,
                                     stdout=self.das_stdout)
        except ResourceWarning:
            # Ignore this...
            pass
コード例 #2
0
    def start(self, test_suite_identifier: str, test_identifier: str = None):
        """
        :param test_suite_identifier: The test suite to execute
        :param test_identifier: THe test to execute from the test suite. If None, all test suite tests are run
        """
        try:
            self.harness = LLHarness(host=get_configuration().testHarness.url,
                                     port=get_configuration().testHarness.port,
                                     done_listener=self.done_listener)

            initial_test_scenario = self.harness.load_test(
                test_suite_identifier=test_suite_identifier,
                test_identifier=test_identifier)

            ig.add_exit_handler(self.exit_handler)

            self._current_test_scenario = initial_test_scenario
            self._start_das()

            self.harness.start()
            ig.force_exit()
            sys.exit(ig.get_exit_code())
        except Exception as e:
            traceback.print_exc()
            sys.exit(1)
コード例 #3
0
def immortals_assert(assertion: bool, msg: Optional[str] = None):
    # noinspection PyBroadException
    try:
        global keep_going
        if not assertion:
            keep_going = False
            if ig.get_configuration().debug.forceTestingSystemExitWithoutKillingServer:
                ig.set_exit_code(-1)
                ig.force_exit()
            assert assertion, msg
    except Exception as e:
        if ig.get_configuration().debug.haltTestingOnFailure:
            ig.set_exit_code(-1)
            ig.exception_handler(*sys.exc_info())
        else:
            raise e
コード例 #4
0
    def __init__(self, command_processor: 'ImmortalsSubprocess' or None,
                 log_tag: str, log_dirpath: str = None):
        self.__command_processor = command_processor if command_processor is not None else subprocess

        if log_dirpath is None:
            log_dirpath = ig.get_configuration().globals.globalLogDirectory

        endpoint = get_std_endpoint(log_dirpath=log_dirpath, file_tag=log_tag)
        self.__err = endpoint.err
        self.__out = endpoint.out
コード例 #5
0
def run_test_scenario(test_suite_identifier: str, test_identifier: str = None):
    config = get_configuration().testHarness

    harness = LLHarness(host=config.url,
                        port=config.port,
                        done_listener=None,
                        done_listener_is_self=True)

    harness.load_test(test_suite_identifier=test_suite_identifier,
                      test_identifier=test_identifier)
    ig.add_exit_handler(harness.stop)
    harness.start()
コード例 #6
0
def send_cp3(submission_model: Optional[SubmissionModel] = None):
    if submission_model is None:
        body = None
    else:
        body = submission_model.to_dict(include_metadata=False,
                                        strip_nulls=True)
        submission_model.to_file_pretty(os.path.join(
            get_configuration().globals.immortalsRoot,
            'DAS_DEPLOYMENT/input.json'),
                                        include_metadata=False)
    tpr.start_thread(thread_method=post,
                     thread_args=[TestAdapterEndpoint.CP3, body])
コード例 #7
0
    def done_listener(self, next_test_scenario: Phase2TestScenario):
        self._stop_das()

        if not get_configuration().debug.useMockDas and \
                self._current_test_scenario.submissionFlow is not Phase2SubmissionFlow.BaselineA:
            ir = get_configuration().globals.immortalsRoot
            results = subprocess.run(['bash', 'setup.sh', '--unattended'],
                                     cwd=os.path.join(ir, 'database/server'),
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
            results.check_returncode()

            if self._current_test_scenario.perturbationScenario == PerturbationScenario.P2CP1DatabaseSchema and \
                    (self._current_test_scenario.submissionFlow == Phase2SubmissionFlow.BaselineB or
                     self._current_test_scenario.submissionFlow == Phase2SubmissionFlow.Challenge):
                cwd = os.path.join(ir, 'das/das-service')
                results = subprocess.run([
                    'java', '-jar',
                    os.path.join(cwd, 'das.jar'), '--perform-schema-analysis'
                ],
                                         cwd=cwd,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.STDOUT)
                results.check_returncode()

            gradle_original = os.path.join(ir, 'settings.gradle.original')
            if os.path.exists(gradle_original):
                shutil.copy2(gradle_original,
                             os.path.join(ir, 'settings.gradle'))

        if next_test_scenario is not None:
            self.harness.reset_sequence_counter()
            self._current_test_scenario = next_test_scenario
            self._start_das()

        else:
            ig.force_exit()
コード例 #8
0
    def receiving_post_listener(self, endpoint: TestHarnessEndpoint, body_str: str):
        with self._lock:
            body_dict = self.parse_posted_data(endpoint=endpoint, body_str=body_str)
            if endpoint == TestHarnessEndpoint.DONE:
                with open(os.path.join(ig.get_configuration().globals.immortalsRoot,
                                       'DAS_DEPLOYMENT/result.json'), 'w') as out:
                    out.write(body_str)
            self._scenario_executions[0].receiving_post_listener(
                endpoint=endpoint,
                body_str=(None if body_dict is None else json.dumps(body_dict)))
            # self._scenario_executions[0].receive_post(endpoint=endpoint, body_str=json.dumps(body_dict))

            if self._scenario_executions[0].finished:
                self._scenario_executions.pop(0)
                self._done_listener(self.get_current_test_scenario())
コード例 #9
0
import json
import logging
import os
import time
from typing import List, Callable, Union, Optional

import requests

from integrationtest.immortalsglobals import get_configuration
from integrationtest.datatypes.testing import Phase2SubmissionFlow, PerturbationScenario
from integrationtest.generated.mil.darpa.immortals.core.api.ll.phase2.enabledas import EnableDas
from integrationtest.generated.mil.darpa.immortals.core.api.ll.phase2.submissionmodel import SubmissionModel
from integrationtest.generated.mil.darpa.immortals.core.api.ll.phase2.testadapterendpoint import TestAdapterEndpoint
from integrationtest import threadprocessrouter as tpr

_URL_TEMPLATE = get_configuration().testAdapter.protocol + '://' + \
                get_configuration().testAdapter.url + \
                ':' + str(get_configuration().testAdapter.port) + '{path}'

JSON_HEADERS = {'Content-Type': 'application/json'}

_logger = logging.getLogger()


def set_logger(logger):
    global _logger
    _logger = logger


def post(endpoint: TestAdapterEndpoint, body: dict):
    global _logger