Beispiel #1
0
    def test_dict_valid(self):
        uuid = uuidutils.generate_uuid()

        @args.validate(foo=args.dict_valid(
            bar=args.uuid
        ))
        def doit(foo):
            return foo

        # validate passes
        doit(foo={'bar': uuid})

        # tolerate other keys
        doit(foo={'bar': uuid, 'baz': 'baz'})

        # key missing
        doit({})

        # value fails validation
        e = self.assertRaises(exception.InvalidParameterValue,
                              doit, {'bar': uuid + 'XXX'})
        self.assertIn('Expected UUID for bar:', str(e))

        # not a dict
        e = self.assertRaises(exception.InvalidParameterValue,
                              doit, 'asdf')
        self.assertIn("Expected types <class 'dict'> for foo: asdf", str(e))
Beispiel #2
0
    def test_dict_valid_colon_key_name(self):
        uuid = uuidutils.generate_uuid()

        @args.validate(foo=args.dict_valid(**{
            'bar:baz': args.uuid
        }
        ))
        def doit(foo):
            return foo

        # validate passes
        doit(foo={'bar:baz': uuid})

        # value fails validation
        e = self.assertRaises(exception.InvalidParameterValue,
                              doit, {'bar:baz': uuid + 'XXX'})
        self.assertIn('Expected UUID for bar:', str(e))
Beispiel #3
0
        'volume_id': {
            'type': 'string'
        },
        'volume_type': {
            'type': 'string'
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'required': ['boot_index', 'node_uuid', 'volume_id', 'volume_type'],
    'additionalProperties': False,
}

TARGET_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

TARGET_VALIDATOR = args.and_valid(args.schema(TARGET_SCHEMA),
                                  TARGET_VALIDATOR_EXTRA)

PATCH_ALLOWED_FIELDS = [
    'boot_index', 'extra', 'node_uuid', 'properties', 'volume_id',
    'volume_type'
]


def convert_with_links(rpc_target, fields=None, sanitize=True):
    target = api_utils.object_to_dict(rpc_target,
                                      link_resource='volume/targets',
                                      fields=('boot_index', 'extra',
Beispiel #4
0
        'standalone_ports_supported': {
            'type': ['string', 'boolean', 'null']
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'required': ['node_uuid'],
    'additionalProperties': False,
}

PORTGROUP_PATCH_SCHEMA = PORTGROUP_SCHEMA

PORTGROUP_VALIDATOR_EXTRA = args.dict_valid(
    address=args.mac_address,
    node_uuid=args.uuid,
    standalone_ports_supported=args.boolean,
    uuid=args.uuid)
PORTGROUP_VALIDATOR = args.and_valid(args.schema(PORTGROUP_SCHEMA),
                                     PORTGROUP_VALIDATOR_EXTRA)

PORTGROUP_PATCH_VALIDATOR = args.and_valid(args.schema(PORTGROUP_PATCH_SCHEMA),
                                           PORTGROUP_VALIDATOR_EXTRA)

PATCH_ALLOWED_FIELDS = [
    'address', 'extra', 'mode', 'name', 'node_uuid', 'properties',
    'standalone_ports_supported'
]


def convert_with_links(rpc_portgroup, fields=None, sanitize=True):
Beispiel #5
0
PATCH_ALLOWED_FIELDS = [
    'address',
    'extra',
    'is_smartnic',
    'local_link_connection',
    'node_uuid',
    'physical_network',
    'portgroup_uuid',
    'pxe_enabled'
]

PORT_VALIDATOR_EXTRA = args.dict_valid(
    address=args.mac_address,
    node_uuid=args.uuid,
    is_smartnic=args.boolean,
    local_link_connection=api_utils.LOCAL_LINK_VALIDATOR,
    portgroup_uuid=args.uuid,
    pxe_enabled=args.boolean,
    uuid=args.uuid,
)

PORT_VALIDATOR = args.and_valid(
    args.schema(PORT_SCHEMA),
    PORT_VALIDATOR_EXTRA
)

PORT_PATCH_VALIDATOR = args.and_valid(
    args.schema(PORT_PATCH_SCHEMA),
    PORT_VALIDATOR_EXTRA
)
Beispiel #6
0
            'type': ['string', 'null'],
            'maxLength': 80
        },
        'traits': {
            'type': ['array', 'null'],
            'items': api_utils.TRAITS_SCHEMA
        },
        'uuid': {
            'type': ['string', 'null']
        },
    },
    'additionalProperties': False,
}

ALLOCATION_VALIDATOR = args.and_valid(args.schema(ALLOCATION_SCHEMA),
                                      args.dict_valid(uuid=args.uuid))

PATCH_ALLOWED_FIELDS = ['name', 'extra']


def hide_fields_in_newer_versions(allocation):
    # if requested version is < 1.60, hide owner field
    if not api_utils.allow_allocation_owner():
        allocation.pop('owner', None)


def convert_with_links(rpc_allocation, fields=None, sanitize=True):

    allocation = api_utils.object_to_dict(
        rpc_allocation,
        link_resource='allocations',
Beispiel #7
0
CONNECTOR_SCHEMA = {
    'type': 'object',
    'properties': {
        'connector_id': {'type': 'string'},
        'extra': {'type': ['object', 'null']},
        'node_uuid': {'type': 'string'},
        'type': {'type': 'string'},
        'uuid': {'type': ['string', 'null']},
    },
    'required': ['connector_id', 'node_uuid', 'type'],
    'additionalProperties': False,
}

CONNECTOR_VALIDATOR_EXTRA = args.dict_valid(
    node_uuid=args.uuid,
    uuid=args.uuid,
)

CONNECTOR_VALIDATOR = args.and_valid(
    args.schema(CONNECTOR_SCHEMA),
    CONNECTOR_VALIDATOR_EXTRA
)

PATCH_ALLOWED_FIELDS = [
    'connector_id',
    'extra',
    'node_uuid',
    'type'
]

Beispiel #8
0
                'type': ['string', 'null']
            },
            'binding:host_id': {
                'type': ['string', 'null']
            },
            'binding:vnic_type': {
                'type': ['string', 'null']
            },
        },
        'required': ['event', 'port_id', 'mac_address', 'status'],
        'additionalProperties': False,
    }),
    args.dict_valid(
        **{
            'port_id': args.uuid,
            'mac_address': args.mac_address,
            'device_id': args.uuid,
            'binding:host_id': args.uuid
        }))

EVENT_VALIDATORS = {
    'network.bind_port': NETWORK_EVENT_VALIDATOR,
    'network.unbind_port': NETWORK_EVENT_VALIDATOR,
    'network.delete_port': NETWORK_EVENT_VALIDATOR,
}

EVENTS_SCHEMA = {
    'type': 'object',
    'properties': {
        'events': {
            'type': 'array',