Пример #1
0
 def get_test_details(self):
     test_details = {}
     test_details['sct_git_commit'] = get_git_commit_id()
     test_details['job_name'] = get_job_name()
     test_details['job_url'] = get_job_url()
     test_details['start_host'] = platform.node()
     test_details['test_duration'] = self.params.get(key='test_duration')
     test_details['start_time'] = time.time()
     test_details['grafana_snapshots'] = []
     test_details['grafana_screenshots'] = []
     test_details['grafana_annotations'] = []
     test_details['prometheus_data'] = ""
     test_details['test_id'] = self.test_config.test_id()
     test_details['log_files'] = {}
     return test_details
    def from_sct_config(cls, test_id: UUID, test_module_path: str,
                        sct_config: SCTConfiguration) -> TestRunWithHeartbeat:
        # pylint: disable=too-many-locals
        if cls.TESTRUN_INSTANCE:
            raise ArgusTestRunError("Instance already initialized")

        release_name = os.getenv("GIT_BRANCH", get_git_current_branch()).split("/")[-1]
        if release_name not in cls.AVAILABLE_RELEASES:
            raise ArgusTestRunError("Refusing to track a non-whitelisted branch", release_name, cls.AVAILABLE_RELEASES)
        LOGGER.info("Preparing Test Details...")
        test_group, *_ = test_module_path.split(".")
        config_files = sct_config.get("config_files")
        job_name = get_job_name()
        job_url = get_job_url()
        started_by = get_username()

        details = TestDetails(name=get_test_name(), scm_revision_id=get_git_commit_id(), started_by=started_by,
                              build_job_name=job_name, build_job_url=job_url,
                              yaml_test_duration=sct_config.get("test_duration"), start_time=int(time.time()),
                              config_files=config_files, packages=[])
        LOGGER.info("Preparing Resource Setup...")
        backend = sct_config.get("cluster_backend")
        raw_regions = sct_config.get("region_name") or sct_config.get("gce_datacenter") or "undefined_region"
        regions = raw_regions.split()
        primary_region = regions[0]

        sct_runner_info = CloudInstanceDetails(public_ip=get_sct_runner_ip(), provider=backend,
                                               region=primary_region, private_ip=get_my_ip())

        cloud_setup = cls.BACKEND_MAP.get(backend, _prepare_unknown_resource_setup)(sct_config)

        setup_details = TestResourcesSetup(sct_runner_host=sct_runner_info, region_name=regions,
                                           cloud_setup=cloud_setup)

        logs = TestLogs()
        resources = TestResources()
        results = TestResults(status=TestStatus.CREATED)

        run_info = TestRunInfo(details=details, setup=setup_details, resources=resources, logs=logs, results=results)
        LOGGER.info("Initializing TestRun...")
        cls.TESTRUN_INSTANCE = TestRunWithHeartbeat(test_id=test_id, group=test_group, release_name=release_name,
                                                    assignee="",
                                                    run_info=run_info,
                                                    config=cls.config())

        return cls.TESTRUN_INSTANCE
Пример #3
0
    def from_sct_config(cls, test_id: UUID,
                        sct_config: SCTConfiguration) -> TestRunWithHeartbeat:
        # pylint: disable=too-many-locals
        if cls.TESTRUN_INSTANCE:
            raise ArgusTestRunError("Instance already initialized")

        LOGGER.info("Preparing Test Details...")
        job_name = get_job_name()
        job_url = get_job_url()
        if job_name == "local_run":
            raise ArgusTestRunError("Will not track a locally run job")

        config_files = sct_config.get("config_files")
        started_by = get_username()

        details = TestDetails(
            scm_revision_id=get_git_commit_id(),
            started_by=started_by,
            build_job_url=job_url,
            yaml_test_duration=sct_config.get("test_duration"),
            start_time=datetime.utcnow().replace(microsecond=0),
            config_files=config_files,
            packages=[])

        LOGGER.info("Preparing Resource Setup...")
        backend = sct_config.get("cluster_backend")
        region_key = cls.REGION_PROPERTY_MAP.get(
            backend, cls.REGION_PROPERTY_MAP["default"])
        raw_regions = sct_config.get(region_key) or "undefined_region"
        regions = raw_regions.split() if isinstance(raw_regions,
                                                    str) else raw_regions
        primary_region = regions[0]

        sct_runner_info = CloudInstanceDetails(public_ip=get_sct_runner_ip(),
                                               provider=backend,
                                               region=primary_region,
                                               private_ip=get_my_ip())

        cloud_setup = cls.BACKEND_MAP.get(
            backend, _prepare_unknown_resource_setup)(sct_config)

        setup_details = TestResourcesSetup(sct_runner_host=sct_runner_info,
                                           region_name=regions,
                                           cloud_setup=cloud_setup)

        logs = TestLogs()
        resources = TestResources()
        results = TestResults(status=TestStatus.CREATED)

        run_info = TestRunInfo(details=details,
                               setup=setup_details,
                               resources=resources,
                               logs=logs,
                               results=results)
        LOGGER.info("Initializing TestRun...")
        cls.TESTRUN_INSTANCE = TestRunWithHeartbeat(test_id=test_id,
                                                    build_id=job_name,
                                                    assignee=None,
                                                    run_info=run_info,
                                                    config=cls.config())

        return cls.TESTRUN_INSTANCE