Example #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()
Example #2
0
    def tearDown(self):
        """
        Cleans the remote OpenStack objects
        """
        if self.project:
            neutron = neutron_utils.neutron_client(self.os_creds,
                                                   self.os_session)
            default_sec_grp = neutron_utils.get_security_group(
                neutron,
                self.keystone,
                sec_grp_name='default',
                project_name=self.os_creds.project_name)
            if default_sec_grp:
                try:
                    neutron_utils.delete_security_group(
                        neutron, default_sec_grp)
                except:
                    pass

            keystone_utils.delete_project(self.keystone, self.project)

        if self.user:
            keystone_utils.delete_user(self.keystone, self.user)

        if self.role:
            keystone_utils.delete_role(self.keystone, self.role)

        super(self.__class__, self).__clean__()
Example #3
0
    def delete_all_security_groups(self):
        '''
        Deletes all the available security groups

        Needed until this bug is fixed:
        https://bugs.launchpad.net/networking-odl/+bug/1763705
        '''
        sec_groups = neutron_utils.list_security_groups(self.neutron)
        for sg in sec_groups:
            neutron_utils.delete_security_group(self.neutron, sg)
Example #4
0
    def clean(self):
        """
        Cleanse environment of all artifacts
        :return: void
        """
        if self.__project:
            # Delete security group 'default' if exists
            neutron = neutron_utils.neutron_client(self._os_creds,
                                                   self._os_session)
            try:
                default_sec_grp = neutron_utils.get_security_group(
                    neutron,
                    self._keystone,
                    sec_grp_name='default',
                    project_name=self.__project.name)
                if default_sec_grp:
                    try:
                        neutron_utils.delete_security_group(
                            neutron, default_sec_grp)
                    except:
                        pass
            finally:
                neutron.httpclient.session.session.close()

            # Delete Project
            try:
                keystone_utils.delete_project(self._keystone, self.__project)
            except NotFound:
                pass
            self.__project = None

        if self.__role:
            try:
                keystone_utils.delete_role(self._keystone, self.__role)
            except NotFound:
                pass
            self.__project = None

        # Final role check in case init was done from an existing instance
        role = keystone_utils.get_role_by_name(self._keystone,
                                               self.__role_name)
        if role:
            keystone_utils.delete_role(self._keystone, role)

        super(self.__class__, self).clean()
Example #5
0
    def clean(self):
        """
        Removes and deletes the rules then the security group.
        """
        for setting, rule in self.__rules.items():
            try:
                neutron_utils.delete_security_group_rule(self._neutron, rule)
            except NotFound as e:
                logger.warning('Rule not found, cannot delete - ' + str(e))
                pass
        self.__rules = dict()

        if self.__security_group:
            try:
                neutron_utils.delete_security_group(self._neutron,
                                                    self.__security_group)
            except NotFound as e:
                logger.warning(
                    'Security Group not found, cannot delete - ' + str(e))

            self.__security_group = None

        super(self.__class__, self).clean()