Beispiel #1
0
    def run_job(self):
        """
        Tests image with img-proof and update status and results.
        """
        self.status = SUCCESS
        self.log_callback.info(
            'Running img-proof tests against image with '
            'type: {inst_type}.'.format(inst_type=self.instance_type))

        self.request_credentials([self.account])
        credentials = self.credentials[self.account]

        self.cloud_image_name = self.status_msg['cloud_image_name']
        self.object_name = self.status_msg['object_name']
        image_id = self.status_msg['source_regions'][self.region]

        with setup_key_pair(credentials['access_key'], self.region,
                            credentials['access_secret'],
                            self.ssh_private_key_file) as key_pair_name:
            try:
                result = img_proof_test(
                    cloud=self.cloud,
                    access_key=credentials['access_key'],
                    access_secret=credentials['access_secret'],
                    description=self.description,
                    distro=self.distro,
                    image_id=image_id,
                    instance_type=self.instance_type,
                    img_proof_timeout=self.img_proof_timeout,
                    region=self.region,
                    ssh_key_name=key_pair_name,
                    ssh_private_key_file=self.ssh_private_key_file,
                    ssh_user=self.ssh_user,
                    tests=self.tests,
                    security_group_id=self.security_group_id,
                    vswitch_id=self.vswitch_id,
                    log_callback=self.log_callback)
            except Exception as error:
                self.add_error_msg(str(error))
                result = {
                    'status': EXCEPTION,
                    'msg': str(traceback.format_exc())
                }

        self.status = process_test_result(result, self.log_callback,
                                          self.region, self.status_msg)

        if self.status != SUCCESS:
            self.add_error_msg(
                'Image failed img-proof test suite. '
                'See "mash job test-results --job-id {GUID} -v" '
                'for details on the failing tests.')

        if self.cleanup_images or \
                (self.status != SUCCESS and self.cleanup_images is not False):
            self.cleanup_image(credentials)
Beispiel #2
0
    def run_job(self):
        """
        Tests image with img-proof and update status and results.
        """
        self.status = SUCCESS
        self.log_callback.info(
            'Running img-proof tests against image with '
            'type: {inst_type}.'.format(inst_type=self.instance_type))

        # Get all account credentials in one request
        accounts = []
        for region, info in self.test_regions.items():
            accounts.append(get_testing_account(info))

        self.request_credentials(accounts)

        for region, info in self.test_regions.items():
            account = get_testing_account(info)
            credentials = self.credentials[account]

            if info['partition'] in ('aws-cn', 'aws-us-gov') and \
                    self.cloud_architecture == 'aarch64':
                # Skip test aarch64 images in China and GovCloud.
                # There are no aarch64 based instance types available.
                continue

            with setup_ec2_networking(
                    credentials['access_key_id'],
                    region,
                    credentials['secret_access_key'],
                    self.ssh_private_key_file,
                    subnet_id=info.get('subnet')) as network_details:
                try:
                    result = img_proof_test(
                        access_key_id=credentials['access_key_id'],
                        cloud=self.cloud,
                        description=self.description,
                        distro=self.distro,
                        image_id=self.status_msg['source_regions'][region],
                        instance_type=self.instance_type,
                        img_proof_timeout=self.img_proof_timeout,
                        region=region,
                        secret_access_key=credentials['secret_access_key'],
                        security_group_id=network_details['security_group_id'],
                        ssh_key_name=network_details['ssh_key_name'],
                        ssh_private_key_file=self.ssh_private_key_file,
                        ssh_user=self.ssh_user,
                        subnet_id=network_details['subnet_id'],
                        tests=self.tests,
                        log_callback=self.log_callback)
                except Exception as error:
                    self.add_error_msg(str(error))
                    result = {
                        'status': EXCEPTION,
                        'msg': str(traceback.format_exc())
                    }

                status = process_test_result(result, self.log_callback, region,
                                             self.status_msg)

                instance_id = result.get('instance_id')
                if instance_id:
                    # Wait until instance is terminated to exit
                    # context manager and cleanup resources.
                    wait_for_instance_termination(
                        credentials['access_key_id'], instance_id, region,
                        credentials['secret_access_key'])

                if status != SUCCESS:
                    self.status = status
                    self.add_error_msg(
                        'Image failed img-proof test suite. '
                        'See "mash job test-results --job-id {GUID} -v" '
                        'for details on the failing tests.')
                    break  # Fail eagerly, if the image fails in any partition.

        if self.cleanup_images or (self.status != SUCCESS and
                                   self.cleanup_images is not False):  # noqa
            for region, info in self.test_regions.items():
                credentials = self.credentials[info['account']]

                cleanup_ec2_image(
                    credentials['access_key_id'],
                    credentials['secret_access_key'],
                    self.log_callback,
                    region,
                    image_id=self.status_msg['source_regions'][region])
Beispiel #3
0
    def run_job(self):
        """
        Tests image with img-proof and update status and results.
        """
        self.status = SUCCESS

        accounts = [self.account]
        if self.testing_account:
            # Get both sets of credentials in case cleanup method is run.
            accounts.append(self.testing_account)

        self.request_credentials(accounts)
        credentials = self.credentials[self.testing_account or self.account]
        project = credentials.get('project_id')
        compute_driver = get_gce_compute_driver(credentials)

        if self.test_fallback_regions == []:
            # fallback testing explicitly disabled
            fallback_regions = set()
        elif self.test_fallback_regions is None:
            fallback_regions = get_region_list(compute_driver, project)
        else:
            fallback_regions = set(self.test_fallback_regions)

        fallback_regions.add(self.region)

        self.cloud_image_name = self.status_msg['cloud_image_name']

        with create_json_file(credentials) as auth_file:
            for firmware in self.boot_firmware:
                self.log_callback.info(
                    'Running img-proof tests against image with '
                    'type: {inst_type}. Using boot firmware setting: '
                    '{firmware}.'.format(inst_type=self.instance_type,
                                         firmware=firmware))

                if self.test_gvnic_with == firmware:
                    test_gvnic = True
                else:
                    test_gvnic = False

                retry_region = self.region
                while fallback_regions:
                    try:
                        result = img_proof_test(
                            cloud=self.cloud,
                            description=self.description,
                            distro=self.distro,
                            image_id=self.cloud_image_name,
                            instance_type=self.instance_type,
                            img_proof_timeout=self.img_proof_timeout,
                            region=retry_region,
                            service_account_file=auth_file,
                            ssh_private_key_file=self.ssh_private_key_file,
                            ssh_user=self.ssh_user,
                            tests=self.tests,
                            boot_firmware=firmware,
                            image_project=self.image_project,
                            log_callback=self.log_callback,
                            sev_capable=self.sev_capable,
                            use_gvnic=test_gvnic)
                    except IpaRetryableError as error:
                        result = {'status': EXCEPTION, 'msg': str(error)}
                        fallback_regions.remove(retry_region)

                        if fallback_regions:
                            retry_region = random.choice(fallback_regions)
                    except Exception as error:
                        self.add_error_msg(str(error))
                        result = {
                            'status': EXCEPTION,
                            'msg': str(traceback.format_exc())
                        }
                        break
                    else:
                        break

                self.status = process_test_result(result, self.log_callback,
                                                  self.region, self.status_msg)

                if self.status != SUCCESS:
                    self.add_error_msg(
                        'Image failed img-proof test suite. '
                        'See "mash job test-results --job-id {GUID} -v" '
                        'for details on the failing tests.')
                    break

        if self.cleanup_images or \
                (self.status != SUCCESS and self.cleanup_images is not False):
            self.cleanup_image()
Beispiel #4
0
    def run_job(self):
        """
        Tests image with img-proof and update status and results.
        """
        self.status = SUCCESS
        self.log_callback.info(
            'Running img-proof tests against image with '
            'type: {inst_type}.'.format(
                inst_type=self.instance_type
            )
        )

        self.request_credentials([self.account])
        credentials = self.credentials[self.account]

        self.cloud_image_name = self.status_msg['cloud_image_name']
        image_id = self.status_msg['image_id']

        with create_key_file(credentials['signing_key']) as signing_key_file:
            try:
                result = img_proof_test(
                    availability_domain=self.availability_domain,
                    cloud=self.cloud,
                    compartment_id=self.compartment_id,
                    description=self.description,
                    distro=self.distro,
                    image_id=image_id,
                    instance_type=self.instance_type,
                    img_proof_timeout=self.img_proof_timeout,
                    oci_user_id=self.oci_user_id,
                    region=self.region,
                    signing_key_file=signing_key_file,
                    signing_key_fingerprint=credentials['fingerprint'],
                    ssh_private_key_file=self.ssh_private_key_file,
                    ssh_user=self.ssh_user,
                    tenancy=self.tenancy,
                    tests=self.tests,
                    log_callback=self.log_callback
                )
            except Exception as error:
                self.add_error_msg(str(error))
                result = {
                    'status': EXCEPTION,
                    'msg': str(traceback.format_exc())
                }

        self.status = process_test_result(
            result,
            self.log_callback,
            self.region,
            self.status_msg
        )

        if self.status != SUCCESS:
            self.add_error_msg(
                'Image failed img-proof test suite. '
                'See "mash job test-results --job-id {GUID} -v" '
                'for details on the failing tests.'
            )

        if self.cleanup_images or \
                (self.status != SUCCESS and self.cleanup_images is not False):
            self.cleanup_image(credentials, image_id)