Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test__init__(self, default_schema):
        """Test the creation of the CCCL service config validator."""

        # Test a schema that does not exist.
        with pytest.raises(F5CcclSchemaError) as e:
            validator = ServiceConfigValidator(schema="test_schema.json")
        assert str(
            e.value) == ("F5CcclSchemaError - Schema provided is invalid: " +
                         "CCCL API schema could not be read.")

        bad_schema = 'f5_cccl/service/test/bad_schema.json'
        with pytest.raises(F5CcclSchemaError) as e:
            validator = ServiceConfigValidator(schema=bad_schema)
        assert str(
            e.value) == ("F5CcclSchemaError - Schema provided is invalid: " +
                         "Invalid API schema")

        bad_schema = 'f5_cccl/service/test/bad_decode_schema.json'
        with pytest.raises(F5CcclSchemaError) as e:
            validator = ServiceConfigValidator(schema=bad_schema)
        assert str(
            e.value) == ("F5CcclSchemaError - Schema provided is invalid: " +
                         "CCCL API schema could not be decoded.")

        validator = ServiceConfigValidator()
        assert validator.validator
        assert validator.validator.META_SCHEMA == Draft4Validator.META_SCHEMA
        assert validator.validator.schema == default_schema
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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._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