Пример #1
0
    def _make_observer(self):
        """Implements BaseScenarioPlatformSupport interface."""
        bindings = self.scenario.bindings
        profile = bindings.get('AWS_PROFILE')
        if not profile:
            raise ValueError('An AWS Observer requires an AWS_PROFILE')

        return aws.AwsAgent(profile, bindings['TEST_AWS_REGION'])
Пример #2
0
    def __init_aws_bindings(self):
        context = ExecutionContext()
        bindings = self.bindings  # base class made a copy
        if not bindings['TEST_AWS_ZONE']:
            bindings['TEST_AWS_ZONE'] = bindings['AWS_ZONE']
        if not bindings.get('TEST_AWS_REGION', ''):
            bindings['TEST_AWS_REGION'] = bindings['TEST_AWS_ZONE'][:-1]

        if bindings.get('AWS_PROFILE'):
            self.__aws_observer = aws.AwsAgent(bindings['AWS_PROFILE'],
                                               bindings['TEST_AWS_REGION'])
            if not bindings.get('TEST_AWS_VPC_ID', ''):
                # We need to figure out a specific aws vpc id to use.
                logger = logging.getLogger(__name__)
                logger.info('Determine default AWS VpcId...')
                vpc_list = self.__aws_observer.get_resource_list(
                    context,
                    root_key='Vpcs',
                    aws_command='describe-vpcs',
                    args=['--filters', 'Name=tag:Name,Values=defaultvpc'],
                    region=bindings['TEST_AWS_REGION'],
                    aws_module='ec2',
                    profile=self.__aws_observer.profile)
                if not vpc_list:
                    raise ValueError('There is no vpc tagged as "defaultvpc"')
                bindings['TEST_AWS_VPC_ID'] = vpc_list[0]['VpcId']
                logger.info('Using discovered default VpcId=%s',
                            str(bindings['TEST_AWS_VPC_ID']))

            if not bindings.get('TEST_AWS_SECURITY_GROUP', ''):
                # We need to figure out a specific security group that is compatable
                # with the VpcId we are using.
                logger = logging.getLogger(__name__)
                logger.info('Determine default AWS SecurityGroupId...')
                sg_list = self.__aws_observer.get_resource_list(
                    context,
                    root_key='SecurityGroups',
                    aws_command='describe-security-groups',
                    args=[],
                    region=bindings['TEST_AWS_REGION'],
                    aws_module='ec2',
                    profile=self.__aws_observer.profile)
                for entry in sg_list:
                    if entry.get('VpcId', None) == bindings['TEST_AWS_VPC_ID']:
                        bindings['TEST_AWS_SECURITY_GROUP_ID'] = entry[
                            'GroupId']
                        break
                logger.info('Using discovered default SecurityGroupId=%s',
                            str(bindings['TEST_AWS_SECURITY_GROUP_ID']))
        else:
            self.__aws_observer = None
            logger = logging.getLogger(__name__)
            logger.warning(
                '--aws_profile was not set.'
                ' Therefore, we will not be able to observe Amazon Web Services.'
            )