diff --git a/zunclient/api_versions.py b/zunclient/api_versions.py index 318b146a..c427f998 100644 --- a/zunclient/api_versions.py +++ b/zunclient/api_versions.py @@ -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 = {} diff --git a/zunclient/tests/unit/utils.py b/zunclient/tests/unit/utils.py index 56a695da..8e1fbf1f 100644 --- a/zunclient/tests/unit/utils.py +++ b/zunclient/tests/unit/utils.py @@ -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): diff --git a/zunclient/tests/unit/v1/test_versions.py b/zunclient/tests/unit/v1/test_versions.py new file mode 100644 index 00000000..e22168b0 --- /dev/null +++ b/zunclient/tests/unit/v1/test_versions.py @@ -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)) diff --git a/zunclient/tests/unit/v1/test_versions_shell.py b/zunclient/tests/unit/v1/test_versions_shell.py new file mode 100644 index 00000000..3160f1db --- /dev/null +++ b/zunclient/tests/unit/v1/test_versions_shell.py @@ -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) diff --git a/zunclient/v1/client.py b/zunclient/v1/client.py index a9713250..f1efb74e 100644 --- a/zunclient/v1/client.py +++ b/zunclient/v1/client.py @@ -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): diff --git a/zunclient/v1/shell.py b/zunclient/v1/shell.py index e3fcca28..c05d66be 100644 --- a/zunclient/v1/shell.py +++ b/zunclient/v1/shell.py @@ -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, ] diff --git a/zunclient/v1/versions.py b/zunclient/v1/versions.py new file mode 100644 index 00000000..ba5d45c2 --- /dev/null +++ b/zunclient/v1/versions.py @@ -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 "" + + +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") diff --git a/zunclient/v1/versions_shell.py b/zunclient/v1/versions_shell.py new file mode 100644 index 00000000..21c4ad41 --- /dev/null +++ b/zunclient/v1/versions_shell.py @@ -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)