diff --git a/fuelclient/__init__.py b/fuelclient/__init__.py index 8e69a48..2b93cd6 100644 --- a/fuelclient/__init__.py +++ b/fuelclient/__init__.py @@ -49,8 +49,9 @@ def get_client(resource, version='v1'): version_map = { 'v1': { 'environment': v1.environment, + 'fuel-version': v1.fuelversion, 'node': v1.node, - 'task': v1.task + 'task': v1.task, } } diff --git a/fuelclient/cli/actions/__init__.py b/fuelclient/cli/actions/__init__.py index f4242d0..6e30ec6 100644 --- a/fuelclient/cli/actions/__init__.py +++ b/fuelclient/cli/actions/__init__.py @@ -38,6 +38,7 @@ from fuelclient.cli.actions.snapshot import SnapshotAction from fuelclient.cli.actions.task import TaskAction from fuelclient.cli.actions.user import UserAction from fuelclient.cli.actions.plugins import PluginAction +from fuelclient.cli.actions.fuelversion import FuelVersionAction actions_tuple = ( ReleaseAction, @@ -62,6 +63,7 @@ actions_tuple = ( NotifyAction, TokenAction, GraphAction, + FuelVersionAction, ) actions = dict( diff --git a/fuelclient/cli/actions/fuelversion.py b/fuelclient/cli/actions/fuelversion.py new file mode 100644 index 0000000..bc9d051 --- /dev/null +++ b/fuelclient/cli/actions/fuelversion.py @@ -0,0 +1,42 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 fuelclient.cli.arguments as Args + +from fuelclient.cli.actions.base import Action +from fuelclient.objects.fuelversion import FuelVersion + + +class FuelVersionAction(Action): + """Show Fuel server's version + """ + + action_name = "fuel-version" + + def __init__(self): + super(FuelVersionAction, self).__init__() + + self.args = [ + Args.get_list_arg("Show fuel version"), + ] + self.flag_func_map = ( + (None, self.version), + ) + + def version(self, params): + """To show fuel version data: + fuel fuel-version + """ + version = FuelVersion.get_all_data() + print(self.serializer.serialize(version)) diff --git a/fuelclient/cli/arguments.py b/fuelclient/cli/arguments.py index 52b6483..0911b98 100644 --- a/fuelclient/cli/arguments.py +++ b/fuelclient/cli/arguments.py @@ -133,7 +133,9 @@ def get_fuel_version_arg(): "args": ["--fuel-version"], "params": { "action": fuel_version.FuelVersionAction, - "help": "show Fuel server's version number and exit" + "help": "show Fuel server's version number and exit. " + "WARNING: deprecated since 7.0 release. " + "Please use fuel-version command instead" } } diff --git a/fuelclient/commands/fuelversion.py b/fuelclient/commands/fuelversion.py new file mode 100644 index 0000000..95a7525 --- /dev/null +++ b/fuelclient/commands/fuelversion.py @@ -0,0 +1,28 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 fuelclient.cli.serializers import Serializer +from fuelclient.commands import base + + +class FuelVersion(base.BaseCommand): + """Show fuel version.""" + + entity_name = 'fuel-version' + + def take_action(self, parsed_args): + version = self.client.get_all() + serializer = Serializer.from_params(parsed_args) + msg = serializer.serialize(version) + self.app.stdout.write(msg) diff --git a/fuelclient/main.py b/fuelclient/main.py index 40cdc7b..659651c 100644 --- a/fuelclient/main.py +++ b/fuelclient/main.py @@ -43,8 +43,9 @@ class FuelClient(app.App): parser.add_argument( '--fuel-version', action=fuel_version.FuelVersionAction, - help="show Fuel server's version number and exit" - ) + help=("show Fuel server's version number and exit. " + "WARNING: deprecated since 7.0 release. " + "Please use fuel-version command instead")) return parser diff --git a/fuelclient/objects/__init__.py b/fuelclient/objects/__init__.py index 0917a76..aaf01c1 100644 --- a/fuelclient/objects/__init__.py +++ b/fuelclient/objects/__init__.py @@ -24,3 +24,4 @@ from fuelclient.objects.release import Release from fuelclient.objects.task import DeployTask from fuelclient.objects.task import SnapshotTask from fuelclient.objects.task import Task +from fuelclient.objects.fuelversion import FuelVersion diff --git a/fuelclient/objects/fuelversion.py b/fuelclient/objects/fuelversion.py new file mode 100644 index 0000000..3e67f34 --- /dev/null +++ b/fuelclient/objects/fuelversion.py @@ -0,0 +1,20 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 fuelclient.objects.base import BaseObject + + +class FuelVersion(BaseObject): + + class_api_path = "version/" diff --git a/fuelclient/tests/utils/__init__.py b/fuelclient/tests/utils/__init__.py index 210f49b..1c3ad0b 100644 --- a/fuelclient/tests/utils/__init__.py +++ b/fuelclient/tests/utils/__init__.py @@ -19,10 +19,12 @@ from fuelclient.tests.utils.fake_net_conf import get_fake_interface_config from fuelclient.tests.utils.fake_net_conf import get_fake_network_config from fuelclient.tests.utils.fake_node import get_fake_node from fuelclient.tests.utils.fake_env import get_fake_env +from fuelclient.tests.utils.fake_fuel_version import get_fake_fuel_version __all__ = (get_fake_env, get_fake_node, random_string, get_fake_interface_config, - get_fake_network_config) + get_fake_network_config, + get_fake_fuel_version) diff --git a/fuelclient/tests/utils/fake_fuel_version.py b/fuelclient/tests/utils/fake_fuel_version.py new file mode 100644 index 0000000..9b79857 --- /dev/null +++ b/fuelclient/tests/utils/fake_fuel_version.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2015 Mirantis, Inc. +# +# 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. + + +def get_fake_fuel_version(): + """Creates a fake fuel version + + Returns the serialized and parametrized representation of a dumped Fuel + environment. Represents the average amount of data. + + """ + return { + "astute_sha": "16b252d93be6aaa73030b8100cf8c5ca6a970a91", + "release": "6.0", + "build_id": "2014-12-26_14-25-46", + "build_number": "58", + "auth_required": True, + "fuellib_sha": "fde8ba5e11a1acaf819d402c645c731af450aff0", + "production": "docker", + "nailgun_sha": "5f91157daa6798ff522ca9f6d34e7e135f150a90", + "release_versions": { + "2014.2-6.0": { + "VERSION": { + "ostf_sha": "a9afb68710d809570460c29d6c3293219d3624d4", + "astute_sha": "16b252d93be6aaa73030b8100cf8c5ca6a970a91", + "release": "6.0", + "build_id": "2014-12-26_14-25-46", + "build_number": "58", + "fuellib_sha": "fde8ba5e11a1acaf819d402c645c731af450aff0", + "production": "docker", + "nailgun_sha": "5f91157daa6798ff522ca9f6d34e7e135f150a90", + "api": "1.0", + "fuelmain_sha": "81d38d6f2903b5a8b4bee79ca45a54b76c1361b8", + "feature_groups": [ + "mirantis" + ] + } + } + }, + "api": "1.0", + "fuelmain_sha": "81d38d6f2903b5a8b4bee79ca45a54b76c1361b8", + "feature_groups": [ + "mirantis" + ] + } diff --git a/fuelclient/tests/v1/unit/test_base_action.py b/fuelclient/tests/v1/unit/test_base_action.py index 38ebd3a..ef8848c 100644 --- a/fuelclient/tests/v1/unit/test_base_action.py +++ b/fuelclient/tests/v1/unit/test_base_action.py @@ -23,6 +23,7 @@ import yaml from fuelclient.cli.actions import base from fuelclient.cli import error from fuelclient.tests import base as base_tests +from fuelclient.tests.utils import fake_fuel_version class TestBaseAction(base_tests.UnitTestCase): @@ -71,40 +72,7 @@ class TestBaseAction(base_tests.UnitTestCase): @requests_mock.mock() class TestFuelVersion(base_tests.UnitTestCase): - VERSION = { - "astute_sha": "16b252d93be6aaa73030b8100cf8c5ca6a970a91", - "release": "6.0", - "build_id": "2014-12-26_14-25-46", - "build_number": "58", - "auth_required": True, - "fuellib_sha": "fde8ba5e11a1acaf819d402c645c731af450aff0", - "production": "docker", - "nailgun_sha": "5f91157daa6798ff522ca9f6d34e7e135f150a90", - "release_versions": { - "2014.2-6.0": { - "VERSION": { - "ostf_sha": "a9afb68710d809570460c29d6c3293219d3624d4", - "astute_sha": "16b252d93be6aaa73030b8100cf8c5ca6a970a91", - "release": "6.0", - "build_id": "2014-12-26_14-25-46", - "build_number": "58", - "fuellib_sha": "fde8ba5e11a1acaf819d402c645c731af450aff0", - "production": "docker", - "nailgun_sha": "5f91157daa6798ff522ca9f6d34e7e135f150a90", - "api": "1.0", - "fuelmain_sha": "81d38d6f2903b5a8b4bee79ca45a54b76c1361b8", - "feature_groups": [ - "mirantis" - ] - } - } - }, - "api": "1.0", - "fuelmain_sha": "81d38d6f2903b5a8b4bee79ca45a54b76c1361b8", - "feature_groups": [ - "mirantis" - ] - } + VERSION = fake_fuel_version.get_fake_fuel_version() def test_return_yaml(self, mrequests): mrequests.get('/api/v1/version', json=self.VERSION) diff --git a/fuelclient/tests/v1/unit/test_fuel_version.py b/fuelclient/tests/v1/unit/test_fuel_version.py new file mode 100644 index 0000000..e2473c8 --- /dev/null +++ b/fuelclient/tests/v1/unit/test_fuel_version.py @@ -0,0 +1,50 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 json +import mock +import requests_mock +import yaml + +from fuelclient.tests import base +from fuelclient.tests.utils import fake_fuel_version + + +@requests_mock.mock() +class TestFuelVersion(base.UnitTestCase): + + def test_return_yaml(self, mrequests): + mrequests.get('/api/v1/version/', + json=fake_fuel_version.get_fake_fuel_version()) + + with mock.patch('sys.stdout') as mstdout: + self.execute(['fuel', 'fuel-version', '--yaml']) + args, _ = mstdout.write.call_args_list[0] + with self.assertRaisesRegexp( + ValueError, 'No JSON object could be decoded'): + json.loads(args[0]) + self.assertEqual( + fake_fuel_version.get_fake_fuel_version(), + yaml.safe_load(args[0])) + + def test_return_json(self, mrequests): + mrequests.get('/api/v1/version/', + json=fake_fuel_version.get_fake_fuel_version()) + + with mock.patch('sys.stdout') as mstdout: + self.execute(['fuel', 'fuel-version', '--json']) + args, _ = mstdout.write.call_args_list[0] + self.assertEqual( + fake_fuel_version.get_fake_fuel_version(), + json.loads(args[0])) diff --git a/fuelclient/tests/v2/unit/cli/test_fuel_version.py b/fuelclient/tests/v2/unit/cli/test_fuel_version.py new file mode 100644 index 0000000..9e838a6 --- /dev/null +++ b/fuelclient/tests/v2/unit/cli/test_fuel_version.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2015 Mirantis, Inc. +# +# 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 cStringIO +import mock +import yaml + +from fuelclient.tests.utils import fake_fuel_version +from fuelclient.tests.v2.unit.cli import test_engine + + +class TestFuelVersionCommand(test_engine.BaseCLITest): + """Tests for fuel2 version * commands.""" + + def setUp(self): + super(TestFuelVersionCommand, self).setUp() + self.m_client.get_all.return_value = \ + fake_fuel_version.get_fake_fuel_version() + + def test_fuel_version(self): + args = 'fuel-version' + + with mock.patch('sys.stdout', new=cStringIO.StringIO()) as m_stdout: + self.exec_command(args) + self.assertEqual(fake_fuel_version.get_fake_fuel_version(), + yaml.safe_load(m_stdout.getvalue())) diff --git a/fuelclient/tests/v2/unit/lib/test_fuel_version.py b/fuelclient/tests/v2/unit/lib/test_fuel_version.py new file mode 100644 index 0000000..27bc1af --- /dev/null +++ b/fuelclient/tests/v2/unit/lib/test_fuel_version.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2015 Mirantis, Inc. +# +# 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 requests_mock as rm + +import fuelclient +from fuelclient.tests.v2.unit.lib import test_api + + +class TestFuelVersionFacade(test_api.BaseLibTest): + + def setUp(self): + super(TestFuelVersionFacade, self).setUp() + + self.version = 'v1' + self.res_uri = '/api/{version}/version/'.format(version=self.version) + + self.client = fuelclient.get_client('fuel-version', self.version) + + def test_fuel_version(self): + self.client.get_all() + + self.assertEqual(rm.GET, self.session_adapter.last_request.method) + self.assertEqual(self.res_uri, self.session_adapter.last_request.path) diff --git a/fuelclient/v1/__init__.py b/fuelclient/v1/__init__.py index 820f8f0..4506390 100644 --- a/fuelclient/v1/__init__.py +++ b/fuelclient/v1/__init__.py @@ -12,13 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -from fuelclient. v1 import environment -from fuelclient. v1 import node -from fuelclient. v1 import task +from fuelclient.v1 import environment +from fuelclient.v1 import fuelversion +from fuelclient.v1 import node +from fuelclient.v1 import task -__all__ = ( - 'environment', - 'node', - 'task' -) +# Please keeps the list in alphabetical order +__all__ = ('environment', + 'fuelversion', + 'node', + 'task') diff --git a/fuelclient/v1/fuelversion.py b/fuelclient/v1/fuelversion.py new file mode 100644 index 0000000..87c2263 --- /dev/null +++ b/fuelclient/v1/fuelversion.py @@ -0,0 +1,25 @@ +# Copyright 2015 Mirantis, Inc. +# +# 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 fuelclient import objects +from fuelclient.v1 import base_v1 + + +class FuelVersionClient(base_v1.BaseV1Client): + + _entity_wrapper = objects.FuelVersion + + +def get_client(): + return FuelVersionClient() diff --git a/setup.cfg b/setup.cfg index f8c6015..22af400 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,7 @@ fuelclient = node_update=fuelclient.commands.node:NodeUpdate task_list=fuelclient.commands.task:TaskList task_show=fuelclient.commands.task:TaskShow + fuel-version=fuelclient.commands.fuelversion:FuelVersion [global] setup-hooks =