type should be required for v2.0 service create

Bug #1404073 reported by Lin Hua Cheng on 2014-12-19
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Lin Hua Cheng
Fix Released
Lin Hua Cheng

Bug Description

For v2.0, the API says the following, but is unclear about what is required vs. optional


    "OS-KSADM:service": {
        "id": "123",
        "name": "nova",
        "type": "compute",
        "description": "OpenStack Compute Service"

Based on the v3 API, type should be the only argument that is required.

However, looking at what is implemented, there is very little validation going on. 'id' is assigned set at the controller level:

And 'enabled' which is missing from the API is set at the manager level:

There is no validation performed at any level, leaving it up to the backends, for the SQL backend for instance, only 'enabled' is required:
class Service(sql.ModelBase, sql.DictBase):
    __tablename__ = 'service'
    attributes = ['id', 'type', 'enabled']
    id = sql.Column(sql.String(64), primary_key=True)
    type = sql.Column(sql.String(255))
    enabled = sql.Column(sql.Boolean, nullable=False, default=True,
    extra = sql.Column(sql.JsonBlob())
    endpoints = sqlalchemy.orm.relationship("Endpoint", backref="service")

Which means the following call works, and is very useless:
$ http post http://localhost:35357/v2.0/OS-KSADM/services '{"OS-KSADM:service": {}}' --x-auth-token=ADMIN
  "OS-KSADM:service": {
    "type": null,
    "enabled": true,
    "id": "fe937fd1152f494d88edd89e3adbfe1f"

Keystoneclient requires name, type and description.

It should probably at least default some of those to None.

Lastly OpenstackClient has only 'name' as a required argument.
$ openstack service create --type service_type_1
usage: openstack service create [-h] [-f {html,json,shell,table,value,yaml}]
                                [-c COLUMN] [--max-width <integer>]
                                [--prefix PREFIX] --type <service-type>
                                [--description <service-description>]
openstack service create: error: too few arguments

We should probably make this similar to v3, where the only required argument is 'type', and name/description are optional.

Changed in python-openstackclient:
assignee: nobody → Lin Hua Cheng (lin-hua-cheng)
Steve Martinelli (stevemar) wrote :

You are looking at the v2.0 code.

Compared to the v3 code, which seems to agree with the API

Try setting:
$ export OS_AUTH_URL=http://localhost:5000/v3

And adding:
$ export OS_PROJECT_DOMAIN_ID=default
$ export OS_USER_DOMAIN_ID=default

To get the actual v3 command for service create.

Lin Hua Cheng (lin-hua-cheng) wrote :

Ah, I didn't notice that I have to manually set the version.

 I have pointed OSC to a V3 endpoint and assumed it would be smart enough to figure out the version.

I guess the bug is just for fixing the V2 client.

Thanks for checking it out.

summary: - name should be optional for service-create
+ type should be required for v2.0 service create
Steve Martinelli (stevemar) wrote :

Changed up the description

description: updated
Changed in python-keystoneclient:
assignee: nobody → Lin Hua Cheng (lin-hua-cheng)

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

Changed in python-openstackclient:
status: New → In Progress
Changed in python-keystoneclient:
status: New → In Progress

Reviewed: https://review.openstack.org/143242
Committed: https://git.openstack.org/cgit/openstack/python-openstackclient/commit/?id=4a07e63e7ea4b99b10e4a3fd9ed06c0cf6ee905f
Submitter: Jenkins
Branch: master

commit 4a07e63e7ea4b99b10e4a3fd9ed06c0cf6ee905f
Author: lin-hua-cheng <email address hidden>
Date: Fri Dec 19 18:40:40 2014 -0800

    type should be required for v2.0 service create

    Updated the service name to be optional, mostly matching the cli arguments
    with v3 service create.
    Implemented the following changes on service create:
    - if only a single positional is present, it's a <type>.
      This is not currently legal so it is considered a new case.
    - if --type option is present the positional is handled as <name>;
      display deprecation message
    - if --name option is present the positional is handled as <type>.
      Making --type optional is new, but back-compatible
    - Made --name and --type mutually exclusive.
    - only '--name <service-name> <type>' shall appear in the help output

    Change-Id: I8fd4adba3d8cd00d5a8cacc2c494d99d492c45a3
    Closes-Bug: #1404073

Changed in python-openstackclient:
status: In Progress → Fix Committed
Dean Troyer (dtroyer) on 2015-01-12
Changed in python-openstackclient:
milestone: none → m7
Dean Troyer (dtroyer) on 2015-01-19
Changed in python-openstackclient:
status: Fix Committed → Fix Released

Reviewed: https://review.openstack.org/143223
Committed: https://git.openstack.org/cgit/openstack/python-keystoneclient/commit/?id=1b8c3c8cb90c03881e0a648f247a186fe4b494de
Submitter: Jenkins
Branch: master

commit 1b8c3c8cb90c03881e0a648f247a186fe4b494de
Author: lin-hua-cheng <email address hidden>
Date: Fri Dec 19 16:15:13 2014 -0800

    Updated service name to be optional in CLI

    Service name is optional in the API, updating the CLI
    for consistency.

    Change-Id: I94f0eb248a39d2f59edd00a5f90125a5c42525ed
    Closes-Bug: #1393977
    Closes-Bug: #1404073

Changed in python-keystoneclient:
status: In Progress → Fix Committed
Morgan Fainberg (mdrnstm) wrote :

While the resulting service is not very useful I don't want to change the behavior of the V2 API itself. Unless there is a very very compelling reason, I'm going to leave this as "wont fix" since the V2 api is frozen *and* is really only open for security fixes.

Changed in keystone:
status: New → Won't Fix
Changed in python-keystoneclient:
milestone: none → 1.1.0
importance: Undecided → Low
Changed in python-keystoneclient:
status: Fix Committed → Fix Released

Reviewed: https://review.openstack.org/158204
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=28a12d51b4e3a1458e3f0663a882b82129d1db7f
Submitter: Jenkins
Branch: master

commit 28a12d51b4e3a1458e3f0663a882b82129d1db7f
Author: Steve Martinelli <email address hidden>
Date: Mon Feb 23 02:04:01 2015 -0500

    Update `os service create` examples in config services

    OSC was updated to make type a mandatory field, and a service name
    made optional. Though the current examples still work, OSC will
    deprecate the supported syntax eventually. Update the docs now
    before I forget to do it later.

    Change-Id: I56f3e3e8601b2df488e8a45015a53f184d107b3a
    Related-Bug: #1404073

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

Other bug subscribers