Example #1
0
    def test_create_security_group(self):
        """
        Tests create security group.
        """
        management_security_group_name = 'temp_unittest-mngt-sg'
        agent_security_group_name = 'temp_unittest-agent-sg'
        provider_config = _read_config(None)

        # change security-group name so test will not affect production
        provider_config['networking']['management_security_group'][
            'name'] = management_security_group_name
        provider_config['networking']['agents_security_group'][
            'name'] = agent_security_group_name

        self.cloud_driver = ExoscaleConnector(provider_config).create()

        try:
            sg_creator = ExoscaleSecurityGroupCreator(self.cloud_driver,
                                                      provider_config)
            sg_creator.create_security_groups()

            if sg_creator.get_security_group(
                    management_security_group_name) is None:
                raise AssertionError(
                    'expecting to find security group {0}'.format(
                        management_security_group_name))
            if sg_creator.get_security_group(
                    agent_security_group_name) is None:
                raise AssertionError(
                    'expecting to find security group {0}'.format(
                        agent_security_group_name))

            sg_creator.delete_security_groups()

            if sg_creator.get_security_group(
                    management_security_group_name):
                raise AssertionError(
                    'expecting security group {0} to be deleted'.format(
                        management_security_group_name))
            if sg_creator.get_security_group(agent_security_group_name):
                raise AssertionError(
                    'expecting security group {0} to be deleted'.format(
                        agent_security_group_name))
        finally:
            try:
                self.cloud_driver.ex_delete_security_group(
                    management_security_group_name)
            except:
                pass

            try:
                self.cloud_driver.ex_delete_security_group(
                    agent_security_group_name)
            except:
                pass
    def test_create_security_group(self):
        """
        Tests create security group.
        """
        management_security_group_name = 'temp_unittest-mngt-sg'
        agent_security_group_name = 'temp_unittest-agent-sg'
        provider_config = _read_config(None)

        #change security-group name so test will not affect production
        provider_config['networking']['management_security_group'][
            'name'] = management_security_group_name
        provider_config['networking']['agents_security_group'][
            'name'] = agent_security_group_name

        self.cloud_driver = ExoscaleConnector(provider_config).create()

        try:
            sg_creator = ExoscaleSecurityGroupCreator(self.cloud_driver,
                                                      provider_config)
            sg_creator.create_security_groups()

            if sg_creator.get_security_group(
                    management_security_group_name) is None:
                raise AssertionError(
                    'expecting to find security group {0}'.format(
                        management_security_group_name))
            if sg_creator.get_security_group(agent_security_group_name) is None:
                raise AssertionError(
                    'expecting to find security group {0}'.format(
                        agent_security_group_name))

            sg_creator.delete_security_groups()

            if sg_creator.get_security_group(
                    management_security_group_name):
                raise AssertionError(
                    'expecting security group {0} to be deleted'.format(
                    management_security_group_name))
            if sg_creator.get_security_group(agent_security_group_name):
                raise AssertionError(
                    'expecting security group {0} to be deleted'.format(
                    agent_security_group_name))
        finally:
            try:
                self.cloud_driver.ex_delete_security_group(
                    management_security_group_name)
            except:
                pass

            try:
                self.cloud_driver.ex_delete_security_group(
                    agent_security_group_name)
            except:
                pass
    def test_use_existing_security_group_not_found(self):
        """
        Tests create security group with 'use_existing' property set to true
        """
        provider_config = _read_config(None)

        #security-group use_existing=True
        provider_config['networking']['management_security_group'][
            'use_existing'] = True
        provider_config['networking']['management_security_group'][
            'name'] = 'non-existing-sg'

        cloud_driver = ExoscaleConnector(provider_config).create()
        sg_creator = ExoscaleSecurityGroupCreator(cloud_driver, provider_config)
        try:
            sg_creator.create_security_groups()
            raise AssertionError(
                'Security-group validation failed. Non existing group did not '
                'raise an error as expected')
        except ExoscaleLogicError:
            pass
Example #4
0
    def test_use_existing_security_group_not_found(self):
        """
        Tests create security group with 'use_existing' property set to true
        """
        provider_config = _read_config(None)

        # security-group use_existing=True
        provider_config['networking']['management_security_group'][
            'use_existing'] = True
        provider_config['networking']['management_security_group'][
            'name'] = 'non-existing-sg'

        cloud_driver = ExoscaleConnector(provider_config).create()
        sg_creator = ExoscaleSecurityGroupCreator(
            cloud_driver, provider_config)
        try:
            sg_creator.create_security_groups()
            raise AssertionError(
                'Security-group validation failed. Non existing group did not '
                'raise an error as expected')
        except ExoscaleLogicError:
            pass
    def test_security_group_does_not_exist(self):
        """
        Tests create security group with use_existing=True expecting an error
        """
        existing_sg_name = 'temp-unittest-security-group'
        provider_config = _read_config(None)

        provider_config['networking']['management_security_group'][
            'use_existing'] = True
        provider_config['networking']['management_security_group'][
            'name'] = existing_sg_name

        cloud_driver = ExoscaleConnector(provider_config).create()
        sg_creator = ExoscaleSecurityGroupCreator(cloud_driver,
                                                  provider_config)
        try:
            sg_creator.create_security_groups()
            raise AssertionError(
                'Security-group validation failed. '
                'use_existing flag did not '
                'raise an error as expected')
        except ExoscaleLogicError:
            pass
Example #6
0
    def test_security_group_does_not_exist(self):
        """
        Tests create security group with use_existing=True expecting an error
        """
        existing_sg_name = 'temp-unittest-security-group'
        provider_config = _read_config(None)

        provider_config['networking']['management_security_group'][
            'use_existing'] = True
        provider_config['networking']['management_security_group'][
            'name'] = existing_sg_name

        cloud_driver = ExoscaleConnector(provider_config).create()
        sg_creator = ExoscaleSecurityGroupCreator(cloud_driver,
                                                  provider_config)
        try:
            sg_creator.create_security_groups()
            raise AssertionError(
                'Security-group validation failed. '
                'use_existing flag did not '
                'raise an error as expected')
        except ExoscaleLogicError:
            pass