Jump to: navigation, search

NovaApiValidationFramework

Revision as of 06:36, 11 October 2013 by Ken1ohmichi (talk | contribs) (Migration plan)

Nova API Validation Framework

Discussion

https://etherpad.openstack.org/NovaApiValidationFramework

Introduction

Nova is a RESTful API based HTTP service.
These APIs allow for cloud managed server operations.
For example, we can create a virtual machine instance by sending the following POST request to Nova's URI: /servers.

{
   "server" : {
       "name" : "new-server-test",
       "imageRef" : "http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54",
       "flavorRef" : 1
   }
}

Nova contains many RESTful APIs to facilitate its many features.
Moreover, each RESTful API can be controlled flexibly through multiple parameters.
For example, the above "create a virtual machine instance" API has 19 parameters including "name", "imageRef", etc.

The HTTP service need to validate practically every API parameter in terms of acceptable type and minimum/maximum length and range.
Unnecessary workload can be avoided by validating API parameters before executing the API operation.
Moreover, API validation is an important feature from the viewpoint of HTTP service security.


As Nova is an HTTP service, it should be able to validate API parameters as follows:

  • Validate every API parameter.
  • Return an error response before API operation, if API parameter is invalid.
  • Unify the error message format of the response, if the cause is the same.
    (ex) ".. is too short.", ".. is too long.", ".. is not integer."

What is necessary for Nova-v3-API

This framework target is Nova-v3-API, because it is new and the API compatibility issues would not happen.
In Havana release, Nova-v3-API is experimental and the API will become generic in Icehouse.
In Icehouse development cycle, the web framework of Nova-v3-API will move to Pecan/WSME.
WSME has original API validation mechanism already, and we'd better to find good API validation feature based on current Nova-v3-API.

Investigation of Nova-v3-API

This investigation is based on the following commit of Nova source code:

commit 5f0591252dc5d6e3f49682f85dcdbd99f692c07a	
Merge: 0211752 a19d72b	
Author: Jenkins <jenkins@review.openstack.org>	
Date:   Mon Oct 7 03:14:43 2013 +0000	

    Merge "Fixes rescue doesn't honor enable password conf for v3"

The table of Appendix: Nova-v3-API_parameters shows all parameters of Nova-v3-API.

Proposal

Basic validation feature

WSME

OpenStack common validation feature

Oslo

Appendix: Nova-v3-API parameters

This investigation is based on the following commit of Nova source code:

commit 5f0591252dc5d6e3f49682f85dcdbd99f692c07a	
Merge: 0211752 a19d72b	
Author: Jenkins <jenkins@review.openstack.org>	
Date:   Mon Oct 7 03:14:43 2013 +0000	

    Merge "Fixes rescue doesn't honor enable password conf for v3"	

The source files of Nova-v3-API are put under ./nova/api/openstack/compute/plugins/v3/, and there are 79 API methods.
In these APIs, 49 APIs use API parameters of a request body, and they have 146 API parameters.
The following table shows all API parameters and each API validating implementation.

  • NV: any elements are not validated
Class API method API parameter Required/Optional Type Length/Range Data format
AdminActionsController _create_backup() name Required NV
backup_type Required NV
rotation Required int >= 0
metadata Optional dict "{key: value} 1 < len(key) < 255"
AdminActionsController _migrate_live() block_migration Required NV
disk_over_commit Required NV
host Required NV
AdminActionsController _reset_state() state Required str "active"or "error"
AdminPasswordController change_password() admin_password Required str
AgentController create() hypervisor Required NV
os Required NV
architecture Required NV
version Required NV
url Required NV
md5hash Required NV
AgentController update() url Required NV
md5hash Required NV
version Required NV
AggregateController create() name Required str 1 - 255
availability_zone Required None or str
AggregateController update() name Required if not specifying availability_zone str 1 - 255
availability_zone Required if not specifying name None or str
AggregateController _add_host() host Required str
AggregateController _remove_host() host Required str
AggregateController _set_metadata() metadata Required dict
InterfaceAttachmentController create() net_id Optional, Should not specify both net_id and port_id NV
port_id Optional, Should not specify both net_id and port_id NV
ip_address Optional, Should specify both req_ip and net_id NV
CellsController create() name Required str not "!" and "."
type Optional str "parent" or "child"
CellsController update() name Optional str not "!" and "."
type Optional str "parent" or "child"
CellsController sync_instances() project_id Optional NV
deleted Optional NV
updated_since Optional NV
ConsoleOutputController get_console_output() length Optional int Cast by int(str(length))
CoverageController _start_coverage() combine Optional bool Cast by bool()
CoverageController _report_coverage() file Optional str filename (if path != os.path.basename(path): Error)
xml Optional bool
html Optional bool
ServerDiskConfigController create() os-disk-config:disk_config Optional str "MANUAL" or "AUTO"
ServerDiskConfigController update() os-disk-config:disk_config Optional str "MANUAL" or "AUTO"
ServerDiskConfigController _action_rebuild() os-disk-config:disk_config Required str "MANUAL" or "AUTO"
ServerDiskConfigController _action_resize() os-disk-config:disk_config Required str "MANUAL" or "AUTO"
EvacuateController _evacuate() host Required NV
on_shared_storage Required str boolean
admin_password Optional NV
ExtendedVolumesController swap() old_volume_id Required str uuid
new_volume_id Required str uuid
ExtendedVolumesController attach() volume_id Required str uuid
device Required NV
ExtendedVolumesController detach() volume_id Required str uuid
FlavorActionController _add_tenant_access() tenant_id Required NV
FlavorActionController _remove_tenant_access() tenant_id Required NV
FlavorManageController _create() name Required str 1 - 255 names can only contain [a-zA-Z0-9_.- ]
id Required int or str 1 - 255 id can only contain [a-zA-Z0-9_.-]
ram Required int > 0
vcpus Required int > 0
disk Required int >= 0
ephemeral Optional int >= 0
swap Optional int >= 0
rxtx_factor Optional float > 0
os-flavor-access:is_public Optional str '1', 't', 'true', 'on', 'y', 'yes', '0', 'f', 'false', 'off', 'n', 'no'
FlavorExtraSpecsController create() extra_specs Optional dict
FlavorExtraSpecsController update() Optional dict
HostController update() status Required if not specifying maintenance_mode str "enable" or "disable"
maintenance_mode Required if not specifying status str "enable" or "disable"
KeypairController create() name Required str? (not type checked) 1 - 255
public_key Optional NV
MultinicController _add_fixed_ip() network_id Required NV
MultinicController _remove_fixed_ip() address Required NV
QuotaClassSetsController update() instances Optional int
cores Optional int
ram Optional int
security_groups Optional int
floating_ips Optional int
fixed_ips Optional int
metadata_items Optional int
injected_files Optional int
injected_file_content_bytes Optional int
injected_file_path_bytes Optional int
security_group_rules Optional int
key_pairs Optional int
QuotaSetsController update() instances Optional int
cores Optional int
ram Optional int
security_groups Optional int
floating_ips Optional int
fixed_ips Optional int
metadata_items Optional int
injected_files Optional int
injected_file_content_bytes Optional int
injected_file_path_bytes Optional int
security_group_rules Optional int
key_pairs Optional int
force Optional str boolean
RescueController _rescue() admin_pass Optional NV
SchedulerHintsController create() os-scheduler-hints:scheduler_hints Optional NV
ServerMetadataController create() metadata Required dict
ServerMetadataController update() metadata Required dict len(dict) == 1
ServerMetadataController update_all() metadata Required dict
ServersController create() admin_pass Optional str validated with only Type
name Required str 1 - 255
image_ref Required if not specifying os-block-device-mapping:block_device_mapping str uuid or ".*/<uuid>"
os-block-device-mapping:block_device_mapping Required if not specifying image_ref dict
source_type Required str 'volume', 'image', 'snapshot', 'blank'
uuid Required if source_type is not 'blank' NV
os-availability-zone:availability_zone Optional NV
os-config-drive:config_drive Optional NV
auto_disk_config Optional NV
key_name Optional NV
os-multiple-create:min_count Optional int >= 1
os-multiple-create:max_count Optional int >= 1
os-multiple-create:return_reservation_id Optional bool
personality Optional dict
path Required NV
contents Required str base64 encoded
scheduler_hints Optional NV
os-security-groups:security_groups Optional list
name Optional str
os-user-data:user_data Optional NV
networks Optional list of dict
fixed_ip Optional, Should not specify both fixed_ip and port validated by netaddr.valid_ipv4()
port Optional, Should not specify both fixed_ip and port uuid
access_ip_v4 Optional validated by netaddr.valid_ipv4()
access_ip_v6 Optional validated by netaddr.valid_ipv6()
flavor_ref Required NV
metadata Optional {key: value}, 1 < len(key) < 255, len(value) < 255"
ServersController update() name Optional str 1 - 255
access_ip_v4 Optional validated by netaddr.valid_ipv4()
access_ip_v6 Optional validated by netaddr.valid_ipv6()
auto_disk_config Optional NV
ServersController _action_reboot() type Required str "HARD" or "SOFT", not allowed lower case.
ServersController _action_resize() flavor_ref Required NV validated with the existing flavors.
ServersController _action_rebuild() image_ref Required str uuid or ".*/<uuid>"
admin_pass Optional NV
name Optional str 1 - 255
access_ip_v4 Optional validated by netaddr.valid_ipv4()
access_ip_v6 Optional validated by netaddr.valid_ipv6()
auto_disk_config Optional NV
personality Optional NV
path Required NV
contents Required str base64encoded
ServersController _action_create_image() name Required NV
metadata Optional dict
ServiceController update() host Required NV
binary Required NV
disabled_reason Required if id is disable-log-reason str 1 - 255

Appendix: URL