type should be required for v2.0 service create

Bug #1404073 reported by Lin Hua Cheng
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Won't Fix
Undecided
Unassigned
python-keystoneclient
Fix Released
Low
Lin Hua Cheng
python-openstackclient
Fix Released
Undecided
Lin Hua Cheng

Bug Description

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

http://developer.openstack.org/api-ref-identity-v2.html

{
    "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:
https://github.com/openstack/keystone/blob/master/keystone/catalog/controllers.py#L53-L60

And 'enabled' which is missing from the API is set at the manager level:
https://github.com/openstack/keystone/blob/master/keystone/catalog/core.py#L145-L147

There is no validation performed at any level, leaving it up to the backends, for the SQL backend for instance, only 'enabled' is required:
https://github.com/openstack/keystone/blob/master/keystone/catalog/backends/sql.py#L57-L65
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,
                         server_default=sqlalchemy.sql.expression.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.
https://github.com/openstack/python-keystoneclient/blob/master/keystoneclient/v2_0/services.py#L38-L43

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>]
                                <service-name>
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)
Revision history for this message
Steve Martinelli (stevemar) wrote :

You are looking at the v2.0 code.
https://github.com/openstack/python-openstackclient/blob/master/openstackclient/identity/v2_0/service.py#L36-L54

Compared to the v3 code, which seems to agree with the API
https://github.com/openstack/python-openstackclient/blob/master/openstackclient/identity/v3/service.py#L34-L57

Try setting:
$ export OS_IDENTITY_API_VERSION=3
$ 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.

Revision history for this message
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
Revision history for this message
Steve Martinelli (stevemar) wrote :

Changed up the description

description: updated
Changed in python-keystoneclient:
assignee: nobody → Lin Hua Cheng (lin-hua-cheng)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-openstackclient (master)

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
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstackclient (master)

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)
Changed in python-openstackclient:
milestone: none → m7
Dean Troyer (dtroyer)
Changed in python-openstackclient:
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-keystoneclient (master)

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
Revision history for this message
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
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to keystone (master)

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

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

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  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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