예제 #1
0
    def test_validate_invalid_source_address_translation(
            self, valid_ltm_config):
        """Test the validation methods against invalid source address
        translation fields on virtual servers
        """
        invalid_sats = ["garbage",
                        1,
                        "automap",
                        "---\ntype: automap\npool: 1",
                        {},
                        {'type': 'garbage'},
                        {'garbage': 'automap'},
                        {'type': 'garbage', 'pool': 'snat-pool'},
                        {'type': 1},
                        {'type': 'automap', 'pool': 1},
                        {'type': 'garbage', 'pool': 'snat-pool', 'extra': 1}]
        ltm_validator = ServiceConfigValidator()

        try:
            ltm_validator.validate(valid_ltm_config)
        except F5CcclValidationError as e:
            assert False, "ValidationError raised for valid config"

        # Modify the source address translation to make it invalid
        invalid_config = copy.deepcopy(valid_ltm_config)
        for sat in invalid_sats:
            invalid_config['virtualServers'][0]['sourceAddressTranslation'] = \
                sat

            with pytest.raises(F5CcclValidationError):
                ltm_validator.validate(invalid_config)
예제 #2
0
class ServiceManager(object):
    """CCCL apply config implementation class."""
    def __init__(self, bigip, partition, schema, prefix=None):
        """Initialize the ServiceManager."""
        self._bigip = bigip
        self._partition = partition
        self._prefix = prefix
        self._config_validator = ServiceConfigValidator(schema)
        self._service_deployer = ServiceConfigDeployer(self._bigip)
        self._config_reader = ServiceConfigReader(self._partition)

    def get_partition(self):
        """Get the name of the managed partition."""
        return self._partition

    def apply_config(self, service_config):
        """Apply the desired service configuration."""
        # Validate the service configuration.
        self._config_validator.validate(service_config)

        # Read in the configuration
        desired_config = self._config_reader.read_config(service_config)

        # Refresh the BigIP state.
        self._bigip.refresh()

        # Deploy the service desired configuratio.
        return self._service_deployer.deploy(desired_config)
예제 #3
0
class ServiceManager(object):
    """CCCL apply config implementation class."""
    def __init__(self, bigip_proxy, partition, schema):
        """Initialize the ServiceManager.

        Args:
            bigip_proxy:  BigIPProxy object, f5_cccl.bigip.BigIPProxy.
            partition: The managed partition.
            schema: Schema that defines the structure of a service
            configuration.

        Raises:
            F5CcclError: Error initializing the validator or reading the
            API schema.
        """
        self._partition = partition
        self._config_validator = ServiceConfigValidator(schema)
        self._service_deployer = ServiceConfigDeployer(bigip_proxy)
        self._config_reader = ServiceConfigReader(self._partition)

    def get_partition(self):
        """Get the name of the managed partition."""
        return self._partition

    def apply_config(self, service_config):
        """Apply the desired service configuration.
        Args:
            service_config: The desired configuration state of the mananged
            partition.

        Returns:
            The number of resources that were not successfully deployed.

        Raises:
            F5CcclValidationError: Indicates that the service_configuration
            does not conform to the API schema.
        """

        LOGGER.debug("apply_config start")
        start_time = time()

        # Validate the service configuration.
        self._config_validator.validate(service_config)

        # Read in the configuration
        desired_config = self._config_reader.read_config(service_config)

        # Deploy the service desired configuratio.
        retval = self._service_deployer.deploy(desired_config)

        LOGGER.debug("apply_config took %.5f seconds.", (time() - start_time))

        return retval
예제 #4
0
    def test_validate(self, valid_ltm_config, valid_net_config):
        """Test the validation method."""
        ltm_validator = ServiceConfigValidator()
        net_validator = ServiceConfigValidator(
            schema="f5_cccl/schemas/cccl-net-api-schema.yml")

        try:
            ltm_validator.validate(valid_ltm_config)
            net_validator.validate(valid_net_config)
        except F5CcclValidationError as e:
            assert False, "ValidationError raised for valid config"

        # Modify the configuration to make invalid.
        invalid_config = copy.deepcopy(valid_ltm_config)
        virtuals = invalid_config['virtualServers']
        for virtual in virtuals:
            virtual.pop('destination', None)
            virtual.pop('name', None)

        with pytest.raises(F5CcclValidationError):
            ltm_validator.validate(invalid_config)

        invalid_config = copy.deepcopy(valid_net_config)
        arps = invalid_config['arps']
        for arp in arps:
            arp.pop('ipAddress', None)

        with pytest.raises(F5CcclValidationError):
            net_validator.validate(invalid_config)
예제 #5
0
    def test_validate(self, valid_ltm_config, valid_net_config):
        """Test the validation method."""
        ltm_validator = ServiceConfigValidator()
        net_validator = ServiceConfigValidator(
            schema="f5_cccl/schemas/cccl-net-api-schema.yml")

        try:
            ltm_validator.validate(valid_ltm_config)
            net_validator.validate(valid_net_config)
        except F5CcclValidationError as e:
            assert False, "ValidationError raised for valid config"

        # Modify the configuration to make invalid.
        invalid_config = copy.deepcopy(valid_ltm_config)
        virtuals = invalid_config['virtualServers']
        for virtual in virtuals:
            virtual.pop('destination', None)
            virtual.pop('name', None)

        with pytest.raises(F5CcclValidationError):
            ltm_validator.validate(invalid_config)

        invalid_config = copy.deepcopy(valid_net_config)
        arps = invalid_config['arps']
        for arp in arps:
            arp.pop('ipAddress', None)

        with pytest.raises(F5CcclValidationError):
            net_validator.validate(invalid_config)
예제 #6
0
    def test_validate(self, valid_config):
        """Test the validation method."""
        validator = ServiceConfigValidator()

        try:
            validator.validate(valid_config)
        except F5CcclValidationError as e:
            assert False, "ValidationError raised for valid config"

        # Modify the configuration to make invalid.
        invalid_config = copy.deepcopy(valid_config)
        virtuals = invalid_config['virtualServers']
        for virtual in virtuals:
            virtual.pop('destination', None)
            virtual.pop('name', None)

        with pytest.raises(F5CcclValidationError):
            validator.validate(invalid_config)
예제 #7
0
    def test_validate_invalid_source_address_translation(
            self, valid_ltm_config):
        """Test the validation methods against invalid source address
        translation fields on virtual servers
        """
        invalid_sats = [
            "garbage", 1, "automap", "---\ntype: automap\npool: 1", {}, {
                'type': 'garbage'
            }, {
                'garbage': 'automap'
            }, {
                'type': 'garbage',
                'pool': 'snat-pool'
            }, {
                'type': 1
            }, {
                'type': 'automap',
                'pool': 1
            }, {
                'type': 'garbage',
                'pool': 'snat-pool',
                'extra': 1
            }
        ]
        ltm_validator = ServiceConfigValidator()

        try:
            ltm_validator.validate(valid_ltm_config)
        except F5CcclValidationError as e:
            assert False, "ValidationError raised for valid config"

        # Modify the source address translation to make it invalid
        invalid_config = copy.deepcopy(valid_ltm_config)
        for sat in invalid_sats:
            invalid_config['virtualServers'][0]['sourceAddressTranslation'] = \
                sat

            with pytest.raises(F5CcclValidationError):
                ltm_validator.validate(invalid_config)
예제 #8
0
파일: manager.py 프로젝트: russokj/f5-cccl
class ServiceManager(object):
    """CCCL apply config implementation class."""

    def __init__(self, bigip_proxy, partition, schema):
        """Initialize the ServiceManager.

        Args:
            bigip_proxy:  BigIPProxy object, f5_cccl.bigip.BigIPProxy.
            partition: The managed partition.
            schema: Schema that defines the structure of a service
            configuration.

        Raises:
            F5CcclError: Error initializing the validator or reading the
            API schema.
        """
        self._partition = partition
        self._bigip = bigip_proxy
        self._config_validator = ServiceConfigValidator(schema)
        self._service_deployer = ServiceConfigDeployer(bigip_proxy)
        self._config_reader = ServiceConfigReader(self._partition)

    def get_partition(self):
        """Get the name of the managed partition."""
        return self._partition

    def apply_ltm_config(self, service_config, user_agent):
        """Apply the desired LTM service configuration.
        Args:
            service_config: The desired configuration state of the managed
            partition.

        Returns:
            The number of resources that were not successfully deployed.

        Raises:
            F5CcclValidationError: Indicates that the service_configuration
            does not conform to the API schema.
        """

        LOGGER.debug("apply_ltm_config start")
        start_time = time()

        # Validate the service configuration.
        self._config_validator.validate(service_config)

        # Determine the default route domain for the partition
        default_route_domain = self._bigip.get_default_route_domain()

        # Read in the configuration
        desired_config = self._config_reader.read_ltm_config(
            service_config, default_route_domain, user_agent)

        # Deploy the service desired configuration.
        retval = self._service_deployer.deploy_ltm(
            desired_config, default_route_domain)

        LOGGER.debug(
            "apply_ltm_config took %.5f seconds.", (time() - start_time))

        return retval

    def apply_net_config(self, service_config):
        """Apply the desired NET service configuration.
        Args:
            service_config: The desired configuration state of the managed
            partition.

        Returns:
            The number of resources that were not successfully deployed.

        Raises:
            F5CcclValidationError: Indicates that the service_configuration
            does not conform to the API schema.
        """

        LOGGER.debug("apply_net_config start")
        start_time = time()

        # Validate the service configuration.
        self._config_validator.validate(service_config)

        # Determine the default route domain for the partition
        default_route_domain = self._bigip.get_default_route_domain()

        # Read in the configuration
        desired_config = self._config_reader.read_net_config(
            service_config, default_route_domain)

        # Deploy the service desired configuration.
        retval = self._service_deployer.deploy_net(desired_config)

        LOGGER.debug(
            "apply_net_config took %.5f seconds.", (time() - start_time))

        return retval