Exemplo n.º 1
0
    def test_subnet_without_security_groups(self):
        """ Test that we create the temporary security group in the subnet
        that the user specified.
        """
        self.security_group_was_created = False

        def create_security_group_callback(vpc_id):
            self.security_group_was_created = True
            self.assertEqual('vpc-1', vpc_id)

        aws_svc, encryptor_image, guest_image = build_aws_service()
        aws_svc.create_security_group_callback = \
            create_security_group_callback

        subnet = Subnet()
        subnet.id = 'subnet-1'
        subnet.vpc_id = 'vpc-1'
        aws_svc.subnets = {subnet.id: subnet}

        encrypt_ami.encrypt(
            aws_svc=aws_svc,
            enc_svc_cls=DummyEncryptorService,
            image_id=guest_image.id,
            encryptor_ami=encryptor_image.id,
            subnet_id='subnet-1'
        )
        self.assertTrue(self.security_group_was_created)
Exemplo n.º 2
0
    def test_subnet_without_security_groups(self):
        """ Test that we create the temporary security group in the subnet
        that the user specified.
        """
        self.security_group_was_created = False

        def create_security_group_callback(vpc_id):
            self.security_group_was_created = True
            self.assertEqual('vpc-1', vpc_id)

        aws_svc, encryptor_image, guest_image = build_aws_service()
        aws_svc.create_security_group_callback = \
            create_security_group_callback

        subnet = Subnet()
        subnet.id = 'subnet-1'
        subnet.vpc_id = 'vpc-1'
        aws_svc.subnets = {subnet.id: subnet}

        encrypt_ami.encrypt(aws_svc=aws_svc,
                            enc_svc_cls=DummyEncryptorService,
                            image_id=guest_image.id,
                            encryptor_ami=encryptor_image.id,
                            subnet_id='subnet-1')
        self.assertTrue(self.security_group_was_created)
Exemplo n.º 3
0
    def test_validate_subnet_and_security_groups(self):
        aws_svc, encryptor_image, guest_image = build_aws_service()

        # Subnet, no security groups.
        subnet = Subnet()
        subnet.id = 'subnet-1'
        subnet.vpc_id = 'vpc-1'
        aws_svc.subnets[subnet.id] = subnet

        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, subnet_id=subnet.id)

        # Security groups, no subnet.
        sg1 = aws_svc.create_security_group('test1', 'test')
        sg2 = aws_svc.create_security_group('test2', 'test')
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, security_group_ids=[sg1.id, sg2.id]
        )

        # Security group and subnet.
        sg3 = aws_svc.create_security_group(
            'test3', 'test', vpc_id=subnet.vpc_id)
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, subnet_id=subnet.id, security_group_ids=[sg3.id])

        # Security groups in different VPCs.
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, security_group_ids=[sg1.id, sg2.id, sg3.id])

        # Security group not in default subnet.
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, security_group_ids=[sg3.id])

        # Security group and subnet in different VPCs.
        sg4 = aws_svc.create_security_group(
            'test4', 'test', vpc_id='vpc-2')
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, subnet_id=subnet.id, security_group_ids=[sg4.id])

        # We don't validate security groups that have no vpc_id.
        sg5 = aws_svc.create_security_group('test5', 'test', vpc_id='vpc-2')
        sg5.vpc_id = None
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, security_group_ids=[sg5.id])
Exemplo n.º 4
0
    def test_validate_subnet_and_security_groups(self):
        aws_svc, encryptor_image, guest_image = build_aws_service()

        # Subnet, no security groups.
        subnet = Subnet()
        subnet.id = 'subnet-1'
        subnet.vpc_id = 'vpc-1'
        aws_svc.subnets[subnet.id] = subnet

        brkt_cli.aws._validate_subnet_and_security_groups(aws_svc,
                                                          subnet_id=subnet.id)

        # Security groups, no subnet.
        sg1 = aws_svc.create_security_group('test1', 'test')
        sg2 = aws_svc.create_security_group('test2', 'test')
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, security_group_ids=[sg1.id, sg2.id])

        # Security group and subnet.
        sg3 = aws_svc.create_security_group('test3',
                                            'test',
                                            vpc_id=subnet.vpc_id)
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, subnet_id=subnet.id, security_group_ids=[sg3.id])

        # Security groups in different VPCs.
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, security_group_ids=[sg1.id, sg2.id, sg3.id])

        # Security group not in default subnet.
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, security_group_ids=[sg3.id])

        # Security group and subnet in different VPCs.
        sg4 = aws_svc.create_security_group('test4', 'test', vpc_id='vpc-2')
        with self.assertRaises(ValidationError):
            brkt_cli.aws._validate_subnet_and_security_groups(
                aws_svc, subnet_id=subnet.id, security_group_ids=[sg4.id])

        # We don't validate security groups that have no vpc_id.
        sg5 = aws_svc.create_security_group('test5', 'test', vpc_id='vpc-2')
        sg5.vpc_id = None
        brkt_cli.aws._validate_subnet_and_security_groups(
            aws_svc, security_group_ids=[sg5.id])