misleading "key_name" API validation message complains about "name"

Bug #1700825 reported by Ken Dreyer (Red Hat)
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
In Progress
Medium
jichenjc

Bug Description

I think this was working in Kilo but broken in Newton.

When I submit a POST to create a new node, and the POST JSON has "key_name": null, I get an HTTP 400 error.

For example:

curl -i -X POST -H 'Host: example.com:13774' -H 'X-LC-Request-ID: 139827913935568' -H 'Accept-Encoding: gzip,deflate' -H 'X-Auth-Token: <mytoken>' -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json' -H 'User-Agent: libcloud/2.0.0 (OpenStack) ' --data-binary '{"server": {"name": "kdreyer-test", "imageRef": "ac47d004-c15c-4eb5-a205-ec8beda806e5", "key_name": null, "flavorRef": "2", "metadata": {}, "personality": []}}' --compress https://example.com:13774/v2.1/servers

400 Bad Request
Openstack-Api-Version: compute 2.1
X-Openstack-Nova-Api-Version: 2.1
Vary: OpenStack-API-Version, X-OpenStack-Nova-API-Version
Content-Type: application/json; charset=UTF-8
Content-Length: 159
X-Compute-Request-Id: req-de6f1fc0-f403-4579-bfa3-e4ce031bcd91
Date: Tue, 27 Jun 2017 18:56:28 GMT

{"badRequest": {"message": "An invalid 'name' value was provided. The name must be: printable characters. Can not start or end with whitespace.", "code": 400}}

Omitting the key_name parameter entirely allows the request to succeed.

The problem is that the API error from Nova is complaining about "name", when it should be "key_name" instead. I spent a long time wondering what was wrong with my innocuous node name there.

tags: added: api openstack-version.newton
Revision history for this message
Sean Dague (sdague) wrote :

This is going to take some unwinding of the schema validation code. The level of reuse there definitely doesn't make it clear how you'd specify which name in a big object is failing.

Changed in nova:
status: New → Confirmed
tags: added: has.reproduce
Changed in nova:
importance: Undecided → Medium
Revision history for this message
Tim S (timss) wrote :

Recently upgraded to Mitaka from Kilo and encountered this bug which broke a few of my apache-libcloud scripts. Ignoring the "name/key_name" naming issue, should key_name be allowed to be null to begin with?

It's pretty handy to default to `ex_keyname=None` in libcloud when creating servers where keypair is optional, or when using cloud-config to specify keys instead of the compute API.

jichenjc (jichenjc)
Changed in nova:
assignee: nobody → jichenjc (jichenjc)
Revision history for this message
jichenjc (jichenjc) wrote :

key_name is defined
https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/schemas/keypairs.py#L87

and name is
https://github.com/openstack/nova/blob/master/nova/api/validation/parameter_types.py#L238

so give a null is allowed

maybe we can consider following as reference.....

description = {
    'type': ['string', 'null'], 'minLength': 0, 'maxLength': 255,
    'pattern': valid_description_regex,
}

Revision history for this message
jichenjc (jichenjc) wrote :

sorry, a typo, null is not allowed

Revision history for this message
jichenjc (jichenjc) wrote :

from compute/api.py, looks like key_name is None is valid..... we just set it to None

 805 if key_data is None and key_name is not None:
 806 key_pair = objects.KeyPair.get_by_name(context,
 807 context.user_id,
 808 key_name)
 809 key_data = key_pair.public_key
 810 else:
 811 key_pair = None

Revision history for this message
jichenjc (jichenjc) wrote :

 390 class InvalidName(Invalid):
 391 msg_fmt = _("An invalid 'name' value was provided. "
 392 "The name must be: %(reason)s")
 393

this is where the confusing info comes from, it should be enhanced....

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to nova (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/489519

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Related fix proposed to branch: master
Review: https://review.openstack.org/489525

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to nova (master)

Reviewed: https://review.openstack.org/489525
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=9a36e7cda45f8b35f6d5325c3b9c77b80d7e1847
Submitter: Jenkins
Branch: master

commit 9a36e7cda45f8b35f6d5325c3b9c77b80d7e1847
Author: jichenjc <email address hidden>
Date: Fri Jul 28 01:48:56 2017 +0800

    add description about key_name

    add description about key_name, which tells user 'null' is not
    accepted parameter.

    this is ths solution that other than change the code.

    Change-Id: Id84c7803fdd44961497cd35c15ece98e2852d4f6
    Related-Bug: 1700825

Revision history for this message
jichenjc (jichenjc) wrote :

latest master fbdefacc1d7be98d9b34a2fb7f35aada33611604

stack@k8s:~/devstack$ curl -g -i -X POST http://192.168.122.143/compute/v2.1/servers -H "Accept: application/json" -H "User-Agent: python-novaclient" -H "OpenStack-API-Version: compute 2.53" -H "X-OpenStack-Nova-API-Version: 2.53" -H "X-Auth-Token: gAAAAABag6IHNMfcnPiz2MKUy7xmqMTMUo2H_KH1No43_phnt0J8tX8e6-2kXsF1-YalmXUG7huoOf866_S6jlwINAbOSXzlGoyRfXUIKZe17Hw-gN04lxCGFv3-JkK3Abrsd1FMD-qC4pPgzZ_NkyEYCe9biGn5AmMCCRs0G11w9EQARMzzAOs" -H "Content-Type: application/json" -d '{"server": {"name": "ji3", "imageRef": "5ba4945d-d190-4205-b50c-3c957410061b", "flavorRef": "1", "max_count": 1, "min_count": 1, "networks": "auto", "key_name": "null", "security_groups": [{"name": "webservers"}]}}'
HTTP/1.1 400 Bad Request
Date: Wed, 14 Feb 2018 02:44:21 GMT
Server: Apache/2.4.18 (Ubuntu)
OpenStack-API-Version: compute 2.53
X-OpenStack-Nova-API-Version: 2.53
Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version
Content-Type: application/json; charset=UTF-8
Content-Length: 70
x-openstack-request-id: req-a0908397-4174-4d21-9959-0b05ea4f2db4
x-compute-request-id: req-a0908397-4174-4d21-9959-0b05ea4f2db4
Connection: close

{"badRequest": {"message": "Invalid key_name provided.", "code": 400}}stack@k8s:~/devstack$

Revision history for this message
jichenjc (jichenjc) wrote :

oops incorrect input, still a valid bug

}stack@k8s:~/devstack$ curl -g -i -X POST http://192.168.122.143/compute/vlient" -H "OpenStack-API-Version: compute 2.1" -H "X-OpenStack-Nova-API-Version: 2.1" -H "X-Auth-Token: gAAAAABag6IHNMfcnPiz2MKUy7xmqMTMUo2H_KH1No43_phnt0J8tX8e6-2kXsF1-YalmXUG7huoOf866_S6jlwINAbOSXzlGoyRfXUIKZe17Hw-gN04lxCGFv3-JkK3Abrsd1FMD-qC4pPgzZ_NkyEYCe9biGn5AmMCCRs0G11w9EQARMzzAOs" -H "Content-Type: application/json" -d '{"server": {"name": "ji3", "imageRef": "5ba4945d-d190-4205-b50c-3c957410061b", "flavorRef": "1", "max_count": 1, "min_count": 1, "key_name": null, "security_groups": [{"name": "webservers"}]}}'
HTTP/1.1 400 Bad Request
Date: Wed, 14 Feb 2018 02:49:59 GMT
Server: Apache/2.4.18 (Ubuntu)
OpenStack-API-Version: compute 2.1
X-OpenStack-Nova-API-Version: 2.1
Vary: OpenStack-API-Version,X-OpenStack-Nova-API-Version
Content-Type: application/json; charset=UTF-8
Content-Length: 159
x-openstack-request-id: req-802d410a-2c6c-4a1e-ae73-e2f818023f3f
x-compute-request-id: req-802d410a-2c6c-4a1e-ae73-e2f818023f3f
Connection: close

{"badRequest": {"message": "An invalid 'name' value was provided. The name must be: printable characters. Can not start or end with whitespace.", "code": 400}}stack@k8s:~/devstack$

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/544163

Changed in nova:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on nova (master)

Change abandoned by jichenjc (<email address hidden>) on branch: master
Review: https://review.openstack.org/489519

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by jichenjc (<email address hidden>) on branch: master
Review: https://review.openstack.org/544163

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.