Fuel version as full action instead of option
Implementation for both cases: - as action for fuel v1; - as command for fuel v2. Add deprecation message for --fuel-version in 7.0 release. Also solved several problems: - support custom credential; - support interective mode; - support unified scheme of api queries. Change-Id: I915d3b5ff265883883fbf92786c3cbc860ec4128 Closes-Bug: #1474767 Closes-Bug: #1399608 DocImpact
This commit is contained in:
parent
7a29d1ac9b
commit
6deb1c7daf
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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))
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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/"
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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]))
|
|
@ -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()))
|
|
@ -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)
|
|
@ -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')
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue