Merge "Supprt version discovery"

This commit is contained in:
Zuul 2018-01-25 03:27:14 +00:00 committed by Gerrit Code Review
commit 9a51618f48
8 changed files with 146 additions and 1 deletions

View File

@ -30,7 +30,9 @@ if not LOG.handlers:
HEADER_NAME = "OpenStack-API-Version"
SERVICE_TYPE = "container"
DEFAULT_API_VERSION = '1.12'
MIN_API_VERSION = '1.1'
MAX_API_VERSION = '1.12'
DEFAULT_API_VERSION = MAX_API_VERSION
_SUBSTITUTIONS = {}

View File

@ -57,6 +57,9 @@ class FakeAPI(object):
response = self._request(*args, **kwargs)
return FakeResponse(response[0]), response[1]
def get_endpoint(self, *args, **kwargs):
return '/v1'
class FakeConnection(object):
def __init__(self, response=None):

View File

@ -0,0 +1,50 @@
# 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.
import testtools
from testtools import matchers
from zunclient.tests.unit import utils
from zunclient.v1 import versions
VERSION1 = {'status': 'CURRENT',
'min_version': '1.1',
'max_version': '1.12',
'id': 'v1',
}
fake_responses = {
'/':
{
'GET': (
{},
{'versions': [VERSION1]},
),
},
}
class VersionManagerTest(testtools.TestCase):
def setUp(self):
super(VersionManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses)
self.mgr = versions.VersionManager(self.api)
def test_version_list(self):
versions = self.mgr.list()
expect = [
('GET', '/', {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertThat(versions, matchers.HasLength(1))

View File

@ -0,0 +1,31 @@
# Copyright 2015 NEC Corporation. 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.
import mock
from zunclient.tests.unit.v1 import shell_test_base
class ShellTest(shell_test_base.TestCommandLineArgument):
@mock.patch('zunclient.v1.versions.VersionManager.list')
def test_zun_version_list_success(self, mock_list):
self._test_arg_success('version-list')
self.assertTrue(mock_list.called)
@mock.patch('zunclient.v1.versions.VersionManager.list')
def test_zun_version_list_failure(self, mock_list):
self._test_arg_failure('version-list --wrong',
self._unrecognized_arg_error)
self.assertFalse(mock_list.called)

View File

@ -21,6 +21,7 @@ from zunclient.v1 import containers
from zunclient.v1 import hosts
from zunclient.v1 import images
from zunclient.v1 import services
from zunclient.v1 import versions
class Client(object):
@ -123,6 +124,7 @@ class Client(object):
self.images = images.ImageManager(self.http_client)
self.services = services.ServiceManager(self.http_client)
self.hosts = hosts.HostManager(self.http_client)
self.versions = versions.VersionManager(self.http_client)
@property
def api_version(self):

View File

@ -17,10 +17,12 @@ from zunclient.v1 import containers_shell
from zunclient.v1 import hosts_shell
from zunclient.v1 import images_shell
from zunclient.v1 import services_shell
from zunclient.v1 import versions_shell
COMMAND_MODULES = [
containers_shell,
images_shell,
services_shell,
hosts_shell,
versions_shell,
]

27
zunclient/v1/versions.py Normal file
View File

@ -0,0 +1,27 @@
# 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.
from zunclient.common import base
class Version(base.Resource):
def __repr__(self):
return "<Version>"
class VersionManager(base.Manager):
resource_class = Version
def list(self):
url = "%s" % self.api.get_endpoint()
url = "%s/" % url.rsplit("/", 1)[0]
return self._list(url, "versions")

View File

@ -0,0 +1,28 @@
# 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.
from zunclient import api_versions
from zunclient.common import cliutils as utils
def do_version_list(cs, args):
"""List all API versions."""
print("Client supported API versions:")
print("Minimum version %(v)s" %
{'v': api_versions.MIN_API_VERSION})
print("Maximum version %(v)s" %
{'v': api_versions.MAX_API_VERSION})
print("\nServer supported API versions:")
result = cs.versions.list()
columns = ["Id", "Status", "Min Version", "Max Version"]
utils.print_list(result, columns)