def test_create_group_rules_ruleset(self):

        ctx = self.mock_cloudify_context(
            'test_create_group_rules_ruleset')
        ctx.node.properties['rules'] = [
            {
                'ip_protocol': 'tcp',
                'from_port': 22,
                'to_port': 22,
                'cidr_ip': '0.0.0.0/0'
            }
        ]

        current_ctx.set(ctx=ctx)

        client = self._get_ec2_client()
        group = client.create_security_group(
            'test_create_group_rules',
            'some description')
        self.addCleanup(group.delete)
        securitygroup._create_group_rules(group)
        groups_from_test = \
            client.get_all_security_groups(groupnames=[group.name])
        self.assertEqual(group.id, groups_from_test[0].id)
        self.assertEqual(
            str(groups_from_test[0].rules[0]),
            'IPPermissions:tcp(22-22)'
        )
    def test_create_group_rules(self):
        """ This tests that _create_group_rules creates
        the rules and that they match on the way out
        to what when in.
        """

        test_properties = self.get_mock_properties()
        ctx = self.security_group_mock(
            'test_create_group_rules', test_properties)
        current_ctx.set(ctx=ctx)
        ec2_client = connection.EC2ConnectionClient().client()
        group = ec2_client.create_security_group('test_create_group_rules',
                                                 'this is test')
        securitygroup._create_group_rules(group)
        self.assertEqual(
            str(group.rules),
            str(ec2_client.get_all_security_groups(
                groupnames='test_create_group_rules')[0].rules))
    def test_create_group_rules_ruleset(self):

        ctx = self.mock_cloudify_context('test_create_group_rules_ruleset')
        ctx.node.properties['rules'] = [{
            'ip_protocol': 'tcp',
            'from_port': 22,
            'to_port': 22,
            'cidr_ip': '0.0.0.0/0'
        }]

        current_ctx.set(ctx=ctx)

        client = self._get_ec2_client()
        group = client.create_security_group('test_create_group_rules',
                                             'some description')
        self.addCleanup(group.delete)
        securitygroup._create_group_rules(group)
        groups_from_test = \
            client.get_all_security_groups(groupnames=[group.name])
        self.assertEqual(group.id, groups_from_test[0].id)
        self.assertEqual(str(groups_from_test[0].rules[0]),
                         'IPPermissions:tcp(22-22)')
Exemple #4
0
    def test_create_group_rules_src_group(self):
        """ This tests that _create_group_rules creates
        the rules and that they match on the way out
        to what when in.
        """

        ec2_client = connection.EC2ConnectionClient().client()
        test_properties = self.get_mock_properties()
        ctx = self.security_group_mock('test_create_group_rules_src_group',
                                       test_properties)
        group_object = ec2_client.create_security_group(
            'dummy', 'this is test')
        ctx.node.properties['rules'][0]['src_group_id'] = group_object.id
        del ctx.node.properties['rules'][0]['cidr_ip']
        current_ctx.set(ctx=ctx)
        group = ec2_client.create_security_group(
            'test_create_group_rules_src_group', 'this is test')
        securitygroup._create_group_rules(group)
        self.assertEqual(
            str(group.rules),
            str(
                ec2_client.get_all_security_groups(
                    groupnames='test_create_group_rules_src_group')[0].rules))
    def test_create_group_rules_src_group(self):
        """ This tests that _create_group_rules creates
        the rules and that they match on the way out
        to what when in.
        """

        ec2_client = connection.EC2ConnectionClient().client()
        test_properties = self.get_mock_properties()
        ctx = self.security_group_mock(
            'test_create_group_rules_src_group', test_properties)
        group_object = ec2_client.create_security_group(
            'dummy',
            'this is test')
        ctx.node.properties['rules'][0]['src_group_id'] = group_object.id
        del ctx.node.properties['rules'][0]['cidr_ip']
        current_ctx.set(ctx=ctx)
        group = ec2_client.create_security_group(
            'test_create_group_rules_src_group',
            'this is test')
        securitygroup._create_group_rules(group)
        self.assertEqual(
            str(group.rules),
            str(ec2_client.get_all_security_groups(
                groupnames='test_create_group_rules_src_group')[0].rules))