Ship the default metadata schema in the client

Now the help message of namespace and resource_type are wrong,
we could see a <unavailable> error when try to get the help
information, such as "glance help md-namespace-create".

See the patch[1] to get more information. the patch[1] added
image schema, but the metadata schema are needed as well.

This patch adds the current metadata schema into client, so that
help text can't be rendered when there schema is not available in
the system.

[1]: https://review.openstack.org/#/c/209536/3

Change-Id: I2ab94d8768114a7e5c475310ba094af653627658
Closes-Bug: #1536430
This commit is contained in:
wangxiyuan 2016-01-19 16:31:36 +08:00
parent 14b9ba2981
commit d3de9ed16a
4 changed files with 330 additions and 0 deletions

View File

@ -178,6 +178,20 @@ class ShellTest(testutils.TestCase):
self.assertNotIn('<unavailable>', actual)
self.assertFalse(et_mock.called)
argstr = '--os-image-api-version 2 help md-namespace-create'
with mock.patch.object(shell, '_get_keystone_session') as et_mock:
actual = shell.main(argstr.split())
self.assertEqual(0, actual)
self.assertNotIn('<unavailable>', actual)
self.assertFalse(et_mock.called)
argstr = '--os-image-api-version 2 help md-resource-type-associate'
with mock.patch.object(shell, '_get_keystone_session') as et_mock:
actual = shell.main(argstr.split())
self.assertEqual(0, actual)
self.assertNotIn('<unavailable>', actual)
self.assertFalse(et_mock.called)
def test_get_base_parser(self):
test_shell = openstack_shell.OpenStackImagesShell()
actual_parser = test_shell.get_base_parser()

View File

@ -0,0 +1,243 @@
# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(flaper87): Keep a copy of the current default schema so that
# we can react on cases where there's no connection to an OpenStack
# deployment. See #1481729
BASE_SCHEMA = {
"additionalProperties": False,
"definitions": {
"positiveInteger": {
"minimum": 0,
"type": "integer"
},
"positiveIntegerDefault0": {
"allOf": [
{"$ref": "#/definitions/positiveInteger"},
{"default": 0}
]
},
"stringArray": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": True
},
"property": {
"type": "object",
"additionalProperties": {
"type": "object",
"required": ["title", "type"],
"properties": {
"name": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"operators": {
"type": "array",
"items": {
"type": "string"
}
},
"type": {
"type": "string",
"enum": [
"array",
"boolean",
"integer",
"number",
"object",
"string",
None
]
},
"required": {
"$ref": "#/definitions/stringArray"
},
"minimum": {
"type": "number"
},
"maximum": {
"type": "number"
},
"maxLength": {
"$ref": "#/definitions/positiveInteger"
},
"minLength": {
"$ref": "#/definitions/positiveIntegerDefault0"
},
"pattern": {
"type": "string",
"format": "regex"
},
"enum": {
"type": "array"
},
"readonly": {
"type": "boolean"
},
"default": {},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"array",
"boolean",
"integer",
"number",
"object",
"string",
None
]
},
"enum": {
"type": "array"
}
}
},
"maxItems": {
"$ref": "#/definitions/positiveInteger"
},
"minItems": {
"$ref": "#/definitions/positiveIntegerDefault0"
},
"uniqueItems": {
"type": "boolean",
"default": False
},
"additionalItems": {
"type": "boolean"
},
}
}
}
},
"required": ["namespace"],
"name": "namespace",
"properties": {
"namespace": {
"type": "string",
"description": "The unique namespace text.",
"maxLength": 80
},
"display_name": {
"type": "string",
"description": "The user friendly name for the namespace. Used by "
"UI if available.",
"maxLength": 80
},
"description": {
"type": "string",
"description": "Provides a user friendly description of the "
"namespace.",
"maxLength": 500
},
"visibility": {
"enum": [
"public",
"private"
],
"type": "string",
"description": "Scope of namespace accessibility."
},
"protected": {
"type": "boolean",
"description": "If true, namespace will not be deletable."
},
"owner": {
"type": "string",
"description": "Owner of the namespace.",
"maxLength": 255
},
"created_at": {
"type": "string",
"readOnly": True,
"description": "Date and time of namespace creation.",
"format": "date-time"
},
"updated_at": {
"type": "string",
"readOnly": True,
"description": "Date and time of the last namespace modification.",
"format": "date-time"
},
"schema": {
"readOnly": True,
"type": "string"
},
"self": {
"readOnly": True,
"type": "string"
},
"resource_type_associations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"prefix": {
"type": "string"
},
"properties_target": {
"type": "string"
}
}
}
},
"properties": {
"$ref": "#/definitions/property"
},
"objects": {
"items": {
"type": "object",
"properties": {
"required": {
"$ref": "#/definitions/stringArray"
},
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"properties": {
"$ref": "#/definitions/property"
}
}
},
"type": "array"
},
"tags": {
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"type": "array"
},
}
}

View File

@ -0,0 +1,67 @@
# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(flaper87): Keep a copy of the current default schema so that
# we can react on cases where there's no connection to an OpenStack
# deployment. See #1481729
BASE_SCHEMA = {
"additionalProperties": False,
"required": ["name"],
"name": "resource_type_association",
"properties": {
"name": {
"type": "string",
"description": "Resource type names should be aligned with Heat "
"resource types whenever possible: http://docs."
"openstack.org/developer/heat/template_guide/"
"openstack.html",
"maxLength": 80
},
"prefix": {
"type": "string",
"description": "Specifies the prefix to use for the given resource"
" type. Any properties in the namespace should be"
" prefixed with this prefix when being applied to"
" the specified resource type. Must include prefix"
" separator (e.g. a colon :).",
"maxLength": 80
},
"properties_target": {
"type": "string",
"description": "Some resource types allow more than one key / "
"value pair per instance. For example, Cinder "
"allows user and image metadata on volumes. Only "
"the image properties metadata is evaluated by Nova"
" (scheduling or drivers). This property allows a "
"namespace target to remove the ambiguity.",
"maxLength": 80
},
"created_at": {
"type": "string",
"readOnly": True,
"description": "Date and time of resource type association.",
"format": "date-time"
},
"updated_at": {
"type": "string",
"readOnly": True,
"description": "Date and time of the last resource type "
"association modification.",
"format": "date-time"
}
}
}

View File

@ -22,6 +22,8 @@ from glanceclient import exc
from glanceclient.v2 import image_members
from glanceclient.v2 import image_schema
from glanceclient.v2 import images
from glanceclient.v2 import namespace_schema
from glanceclient.v2 import resource_type_schema
from glanceclient.v2 import tasks
import json
import os
@ -454,6 +456,8 @@ def get_namespace_schema():
with open(schema_path, "r") as f:
schema_raw = f.read()
NAMESPACE_SCHEMA = json.loads(schema_raw)
else:
return namespace_schema.BASE_SCHEMA
return NAMESPACE_SCHEMA
@ -601,6 +605,8 @@ def get_resource_type_schema():
with open(schema_path, "r") as f:
schema_raw = f.read()
RESOURCE_TYPE_SCHEMA = json.loads(schema_raw)
else:
return resource_type_schema.BASE_SCHEMA
return RESOURCE_TYPE_SCHEMA