예제 #1
0
    def test_create_delete_group(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(name=self.sec_grp_name,
                                               description='hello group')
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        created_sec_grp = self.sec_grp_creator.create()
        self.assertIsNotNone(created_sec_grp)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group()))

        neutron_utils.delete_security_group(self.neutron, created_sec_grp)
        self.assertIsNone(
            neutron_utils.get_security_group(
                self.neutron,
                self.keystone,
                sec_grp_settings=self.sec_grp_creator.sec_grp_settings))

        self.sec_grp_creator.clean()
예제 #2
0
    def test_create_group_with_one_simple_rule(self):
        """
        Tests the creation of an OpenStack Security Group with one simple
        custom rule.
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))
예제 #3
0
    def test_create_group_new_user_to_admin_project(self):
        """
        Tests the creation of an OpenStack Security Group without custom rules.
        """
        # Create Security Group
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            project_name=self.os_creds.project_name)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.admin_os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        self.assertIsNotNone(sec_grp)

        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)
        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))
예제 #4
0
    def test_remove_rule_by_setting(self):
        """
        Tests the creation of an OpenStack Security Group with two simple
        custom rules then removes one by the rule setting object
        """
        # Create Security Group
        sec_grp_rule_settings = list()
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.ingress,
                                    description='test_rule_1'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv6,
                                    description='test_rule_2'))
        sec_grp_rule_settings.append(
            SecurityGroupRuleConfig(sec_grp_name=self.sec_grp_name,
                                    direction=Direction.egress,
                                    protocol=Protocol.udp,
                                    ethertype=Ethertype.IPv4,
                                    port_range_min=10,
                                    port_range_max=20,
                                    description='test_rule_3'))
        sec_grp_settings = SecurityGroupConfig(
            name=self.sec_grp_name,
            description='hello group',
            rule_settings=sec_grp_rule_settings)
        self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
            self.os_creds, sec_grp_settings)
        self.sec_grp_creator.create()

        sec_grp = neutron_utils.get_security_group(
            self.neutron, self.keystone, sec_grp_settings=sec_grp_settings)
        validation_utils.objects_equivalent(
            self.sec_grp_creator.get_security_group(), sec_grp)

        rules = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
        validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
                                            rules)

        self.assertTrue(
            validate_sec_grp(self.neutron, self.keystone,
                             self.sec_grp_creator.sec_grp_settings,
                             self.sec_grp_creator.get_security_group(), rules))

        self.sec_grp_creator.remove_rule(rule_setting=sec_grp_rule_settings[0])
        rules_after_del = neutron_utils.get_rules_by_security_group(
            self.neutron, self.sec_grp_creator.get_security_group())
        self.assertEqual(len(rules) - 1, len(rules_after_del))