Compare commits
42 Commits
0.23.0
...
newton-eol
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6082163049 | ||
|
|
d4dfe32d0d | ||
|
|
63a319c1d6 | ||
|
|
6347775f6d | ||
|
|
0a5edb5852 | ||
|
|
77a6c9a6d9 | ||
|
|
465d0d46a3 | ||
|
|
6e858233dc | ||
|
|
522bc4374a | ||
|
|
c2b5eea3fb | ||
|
|
824017fa1f | ||
|
|
545f153bba | ||
|
|
008b50ea67 | ||
|
|
b836d83bc2 | ||
|
|
6fbcfc794a | ||
|
|
aa90c536b3 | ||
|
|
9c32e6e6dc | ||
|
|
7b55f92e11 | ||
|
|
daa4a88447 | ||
|
|
776a251d98 | ||
|
|
613810e43c | ||
|
|
df8997129e | ||
|
|
e2586130e1 | ||
|
|
ea455477a0 | ||
|
|
5b914e8877 | ||
|
|
918d2f0bbd | ||
|
|
91d1d8b0e1 | ||
|
|
3ffe4869f3 | ||
|
|
bde259e38c | ||
|
|
75dd8dc561 | ||
|
|
a6aed1772d | ||
|
|
63a1039fb2 | ||
|
|
9d3a6c51b1 | ||
|
|
8bcdf13d7f | ||
|
|
f9fb0875e0 | ||
|
|
d36d835d08 | ||
|
|
20931e2ce7 | ||
|
|
fb84ae9b25 | ||
|
|
e64e597aa6 | ||
|
|
f9aac4fc9f | ||
|
|
0f276e483b | ||
|
|
888a58fd2a |
@@ -2,3 +2,4 @@
|
||||
host=review.openstack.org
|
||||
port=29418
|
||||
project=openstack/python-watcherclient.git
|
||||
defaultbranch=stable/newton
|
||||
|
||||
176
LICENSE
Normal file
176
LICENSE
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
@@ -40,12 +40,4 @@ The preferred way to run the unit tests is using ``tox``.
|
||||
See `Consistent Testing Interface`_ for more details.
|
||||
|
||||
.. _Consistent Testing Interface: http://git.openstack.org/cgit/openstack/governance/tree/reference/project-testing-interface.rst
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
.. _Watcher: https://wiki.openstack.org/wiki/Watcher
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
Babel!=2.3.0,!=2.3.1,!=2.3.2,!=2.3.3,>=1.3 # BSD
|
||||
Babel>=2.3.4 # BSD
|
||||
cliff!=1.16.0,!=1.17.0,>=1.15.0 # Apache-2.0
|
||||
osc-lib>=1.0.2 # Apache-2.0
|
||||
oslo.i18n>=2.1.0 # Apache-2.0
|
||||
oslo.utils>=3.5.0 # Apache-2.0
|
||||
oslo.utils>=3.16.0 # Apache-2.0
|
||||
pbr>=1.6 # Apache-2.0
|
||||
PrettyTable>=0.7,<0.8 # BSD
|
||||
python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0
|
||||
python-openstackclient>=2.1.0 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7 # BSD
|
||||
python-keystoneclient!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
six>=1.9.0 # MIT
|
||||
|
||||
@@ -5,7 +5,7 @@ description-file =
|
||||
README.rst
|
||||
author = OpenStack
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://www.openstack.org/
|
||||
home-page = http://docs.openstack.org/developer/python-watcherclient
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
@@ -58,6 +58,9 @@ openstack.infra_optim.v1 =
|
||||
optimize_action_show = watcherclient.v1.action_shell:ShowAction
|
||||
optimize_action_list = watcherclient.v1.action_shell:ListAction
|
||||
|
||||
optimize_scoringengine_show = watcherclient.v1.scoring_engine_shell:ShowScoringEngine
|
||||
optimize_scoringengine_list = watcherclient.v1.scoring_engine_shell:ListScoringEngine
|
||||
|
||||
# The same as above but used by the 'watcher' command
|
||||
watcherclient.v1 =
|
||||
goal_show = watcherclient.v1.goal_shell:ShowGoal
|
||||
@@ -88,6 +91,9 @@ watcherclient.v1 =
|
||||
action_show = watcherclient.v1.action_shell:ShowAction
|
||||
action_list = watcherclient.v1.action_shell:ListAction
|
||||
|
||||
scoringengine_show = watcherclient.v1.scoring_engine_shell:ShowScoringEngine
|
||||
scoringengine_list = watcherclient.v1.scoring_engine_shell:ListScoringEngine
|
||||
|
||||
[pbr]
|
||||
autodoc_index_modules = True
|
||||
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
coverage>=3.6 # Apache-2.0
|
||||
discover # BSD
|
||||
hacking<0.11,>=0.10.2
|
||||
mock>=1.2 # BSD
|
||||
mock>=2.0 # BSD
|
||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
python-subunit>=0.0.18 # Apache-2.0/BSD
|
||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
|
||||
tempest-lib>=0.14.0 # Apache-2.0
|
||||
sphinx!=1.3b1,<1.3,>=1.2.1 # BSD
|
||||
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||
testscenarios>=0.4 # Apache-2.0/BSD
|
||||
testtools>=1.4.0 # MIT
|
||||
|
||||
9
tox.ini
9
tox.ini
@@ -1,15 +1,16 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
minversion = 1.8
|
||||
envlist = py34,py27,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
install_command = pip install -U {opts} {packages}
|
||||
install_command =
|
||||
constraints: pip install -U --force-reinstall -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/newton} {opts} {packages}
|
||||
pip install -U {opts} {packages}
|
||||
setenv =
|
||||
VIRTUAL_ENV={envdir}
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
commands = python setup.py testr --slowest --testr-args='{posargs}'
|
||||
|
||||
[testenv:pep8]
|
||||
|
||||
@@ -169,15 +169,18 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
for o in objs:
|
||||
row = []
|
||||
for field in fields:
|
||||
data = '-'
|
||||
if field in formatters:
|
||||
row.append(formatters[field](o))
|
||||
data = formatters[field](o)
|
||||
else:
|
||||
if field in mixed_case_fields:
|
||||
field_name = field.replace(' ', '_')
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
row.append(data)
|
||||
if data is None:
|
||||
data = '-'
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
if six.PY3:
|
||||
@@ -210,6 +213,8 @@ def print_dict(dct, dict_property="Property", wrap=0):
|
||||
pt.add_row([col1, line])
|
||||
col1 = ''
|
||||
else:
|
||||
if v is None:
|
||||
v = '-'
|
||||
pt.add_row([k, v])
|
||||
|
||||
if six.PY3:
|
||||
@@ -267,5 +272,5 @@ def pretty_choice_list(l):
|
||||
|
||||
def exit(msg=''):
|
||||
if msg:
|
||||
print (msg, file=sys.stderr)
|
||||
print(msg, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -165,7 +165,7 @@ class HTTPClient(object):
|
||||
url=url, e=e)
|
||||
except (socket.error, socket.timeout) as e:
|
||||
endpoint = self.endpoint
|
||||
raise exc.ConnectionRefused(
|
||||
raise exc.CommunicationError(
|
||||
_("Error communicating with %(endpoint)s %(e)s"),
|
||||
endpoint=endpoint, e=e)
|
||||
body_iter = ResponseBodyIterator(resp)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -39,12 +39,19 @@ def make_client(instance):
|
||||
interface=instance._interface,
|
||||
)
|
||||
|
||||
auth_url = instance._auth_url \
|
||||
if hasattr(instance, '_auth_url') else instance.auth.auth_url
|
||||
username = instance._username \
|
||||
if hasattr(instance, '_username') else instance.auth._username
|
||||
password = instance._password \
|
||||
if hasattr(instance, '_password') else instance.auth._password
|
||||
|
||||
client = watcher_client(
|
||||
endpoint=endpoint,
|
||||
session=instance.session,
|
||||
auth_url=instance._auth_url,
|
||||
username=instance._username,
|
||||
password=instance._password,
|
||||
auth_url=auth_url,
|
||||
username=username,
|
||||
password=password,
|
||||
region_name=instance._region_name,
|
||||
)
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ from keystoneclient.auth.identity import v3
|
||||
from keystoneclient import discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from keystoneclient import session
|
||||
from openstackclient.common import logs
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import logs
|
||||
from osc_lib import utils
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from watcherclient._i18n import _
|
||||
|
||||
@@ -28,18 +28,38 @@ from watcherclient.v1 import resource_fields
|
||||
ACTION_PLAN_1 = {
|
||||
'uuid': 'd9d9978e-6db5-4a05-8eab-1531795d7004',
|
||||
'audit_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'strategy_name': 'dummy',
|
||||
'state': 'RECOMMENDED',
|
||||
'efficacy_indicators': [{'description': 'Indicator 1',
|
||||
'name': 'indicator1',
|
||||
'unit': '%'}],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'global_efficacy': {
|
||||
"value": 99,
|
||||
"unit": "%",
|
||||
"name": "dummy_global_efficacy",
|
||||
"description": "Dummy Global Efficacy",
|
||||
},
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
ACTION_PLAN_2 = {
|
||||
'uuid': 'd6363285-5afa-4a26-96f2-89441e335765',
|
||||
'audit_uuid': '239f02a5-9649-4e14-9d33-ac2bf67cb755',
|
||||
'strategy_name': 'dummy',
|
||||
'state': 'RECOMMENDED',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'efficacy_indicators': [{'description': 'Indicator 2',
|
||||
'name': 'indicator2',
|
||||
'unit': '%'}],
|
||||
'updated_at': None,
|
||||
'global_efficacy': {
|
||||
"value": 87,
|
||||
"unit": "%",
|
||||
"name": "dummy_global_efficacy",
|
||||
"description": "Dummy Global Efficacy",
|
||||
},
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
|
||||
@@ -23,22 +23,26 @@ from testtools.matchers import HasLength
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.audit
|
||||
|
||||
|
||||
AUDIT1 = {
|
||||
'id': 1,
|
||||
'uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'uuid': '5869da81-4876-4687-a1ed-12cd64cf53d9',
|
||||
'deadline': None,
|
||||
'type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'goal': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
}
|
||||
|
||||
AUDIT2 = {
|
||||
'id': 2,
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'type': 'ONE_SHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588'
|
||||
'audit_type': 'ONE_SHOT',
|
||||
'goal': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy': None,
|
||||
}
|
||||
|
||||
|
||||
CREATE_AUDIT = copy.deepcopy(AUDIT1)
|
||||
del CREATE_AUDIT['id']
|
||||
del CREATE_AUDIT['uuid']
|
||||
@@ -125,19 +129,8 @@ fake_responses_sorting = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filters = {
|
||||
'/v1/audits/?audit_template=%s' % AUDIT2['audit_template_uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audits": [AUDIT2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class AuditManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuditManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
@@ -200,16 +193,6 @@ class AuditManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(audits))
|
||||
|
||||
def test_audits_list_filter_by_audit_template(self):
|
||||
self.api = utils.FakeAPI(fake_responses_filters)
|
||||
self.mgr = watcherclient.v1.audit.AuditManager(self.api)
|
||||
self.mgr.list(audit_template=AUDIT2['audit_template_uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/audits/?audit_template=%s' %
|
||||
AUDIT2['audit_template_uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
|
||||
def test_audits_show(self):
|
||||
audit = self.mgr.get(AUDIT1['uuid'])
|
||||
expect = [
|
||||
|
||||
@@ -31,8 +31,27 @@ AUDIT_TEMPLATE_1 = {
|
||||
'description': 'Audit Template 1 description',
|
||||
'host_aggregate': 5,
|
||||
'extra': {'automatic': False},
|
||||
'goal_uuid': '7568667b-51fe-4087-9eb1-29b26891036f',
|
||||
'strategy_uuid': 'bbe6b966-f98e-439b-a01a-17b9b3b8478b',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy_uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
GOAL_1 = {
|
||||
'uuid': "fc087747-61be-4aad-8126-b701731ae836",
|
||||
'name': "SERVER_CONSOLIDATION",
|
||||
'display_name': 'Server Consolidation',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
STRATEGY_1 = {
|
||||
'uuid': '2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
'name': 'basic',
|
||||
'display_name': 'Basic consolidation',
|
||||
'goal_uuid': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -41,25 +60,52 @@ AUDIT_TEMPLATE_1 = {
|
||||
AUDIT_1 = {
|
||||
'uuid': '5869da81-4876-4687-a1ed-12cd64cf53d9',
|
||||
'deadline': None,
|
||||
'type': 'ONESHOT',
|
||||
'audit_type': 'ONESHOT',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'host_aggregate': 5,
|
||||
'goal_name': 'SERVER_CONSOLIDATION',
|
||||
'strategy_name': 'basic',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
}
|
||||
|
||||
AUDIT_2 = {
|
||||
'uuid': 'a5199d0e-0702-4613-9234-5ae2af8dafea',
|
||||
'deadline': None,
|
||||
'type': 'ONESHOT',
|
||||
'audit_template_uuid': '770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
'audit_template_name': 'at2',
|
||||
'audit_type': 'ONESHOT',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'host_aggregate': None,
|
||||
'goal_name': 'fc087747-61be-4aad-8126-b701731ae836',
|
||||
'strategy_name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': None,
|
||||
}
|
||||
|
||||
AUDIT_3 = {
|
||||
'uuid': '43199d0e-0712-1213-9674-5ae2af8dhgte',
|
||||
'deadline': None,
|
||||
'audit_type': 'ONESHOT',
|
||||
'state': 'PENDING',
|
||||
'audit_template_uuid': 'f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
'audit_template_name': 'at1',
|
||||
'host_aggregate': 3,
|
||||
'goal_name': None,
|
||||
'strategy_name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters': None,
|
||||
'interval': 3600,
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +119,22 @@ class AuditShellTest(base.CommandTestCase):
|
||||
def setUp(self):
|
||||
super(self.__class__, self).setUp()
|
||||
|
||||
# goal mock
|
||||
p_goal_manager = mock.patch.object(resource, 'GoalManager')
|
||||
self.m_goal_mgr_cls = p_goal_manager.start()
|
||||
self.addCleanup(p_goal_manager.stop)
|
||||
|
||||
self.m_goal_mgr = mock.Mock()
|
||||
self.m_goal_mgr_cls.return_value = self.m_goal_mgr
|
||||
|
||||
# strategy mock
|
||||
p_strategy_manager = mock.patch.object(resource, 'StrategyManager')
|
||||
self.m_strategy_mgr_cls = p_strategy_manager.start()
|
||||
self.addCleanup(p_strategy_manager.stop)
|
||||
|
||||
self.m_strategy_mgr = mock.Mock()
|
||||
self.m_strategy_mgr_cls.return_value = self.m_strategy_mgr
|
||||
|
||||
p_audit_manager = mock.patch.object(resource, 'AuditManager')
|
||||
p_audit_template_manager = mock.patch.object(
|
||||
resource, 'AuditTemplateManager')
|
||||
@@ -87,6 +149,7 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.m_audit_mgr_cls.return_value = self.m_audit_mgr
|
||||
self.m_audit_template_mgr_cls.return_value = self.m_audit_template_mgr
|
||||
|
||||
# stdout mock
|
||||
self.stdout = six.StringIO()
|
||||
self.cmd = shell.WatcherShell(stdout=self.stdout)
|
||||
|
||||
@@ -129,7 +192,6 @@ class AuditShellTest(base.CommandTestCase):
|
||||
def test_do_audit_show_by_uuid(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.get.return_value = audit
|
||||
self.m_audit_template_mgr.get.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit show 5869da81-4876-4687-a1ed-12cd64cf53d9')
|
||||
@@ -213,7 +275,9 @@ class AuditShellTest(base.CommandTestCase):
|
||||
self.assertEqual('', result)
|
||||
|
||||
def test_do_audit_create_with_audit_template_uuid(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
@@ -225,10 +289,10 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_audit_template_name(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_3)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
@@ -241,39 +305,104 @@ class AuditShellTest(base.CommandTestCase):
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_deadline(self):
|
||||
def test_do_audit_create_with_goal(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -d 2016-04-28T10:48:32.064802')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT',
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
def test_do_audit_create_with_goal_and_strategy(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -s '
|
||||
'2cf86250-d309-4b81-818e-1537f3dba6e5')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
strategy='2cf86250-d309-4b81-818e-1537f3dba6e5',
|
||||
audit_type='ONESHOT'
|
||||
)
|
||||
|
||||
def test_do_audit_create_with_deadline(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -d '
|
||||
'2016-04-28T10:48:32.064802')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT',
|
||||
deadline='2016-04-28T10:48:32.064802')
|
||||
|
||||
def test_do_audit_create_with_type(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit_template = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
self.m_audit_template_mgr.get.return_value = audit_template
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -a at1 -t ONESHOT')
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -t ONESHOT')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
audit_template_uuid='f8e47706-efcf-49a4-a5c4-af604eb492f2',
|
||||
type='ONESHOT')
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT')
|
||||
|
||||
def test_do_audit_create_with_parameter(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 -p para1=10 '
|
||||
'-p para2=20')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='ONESHOT',
|
||||
parameters={'para1': 10, 'para2': 20})
|
||||
|
||||
def test_do_audit_create_with_type_continuous(self):
|
||||
audit = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
self.m_audit_mgr.create.return_value = audit
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'audit create -g fc087747-61be-4aad-8126-b701731ae836 '
|
||||
'-t CONTINUOUS -i 3600')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(audit, self.FIELDS, self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_audit_mgr.create.assert_called_once_with(
|
||||
goal='fc087747-61be-4aad-8126-b701731ae836',
|
||||
audit_type='CONTINUOUS',
|
||||
interval='3600')
|
||||
|
||||
@@ -28,6 +28,12 @@ GOAL_1 = {
|
||||
'uuid': "fc087747-61be-4aad-8126-b701731ae836",
|
||||
'name': "SERVER_CONSOLIDATION",
|
||||
'display_name': 'Server Consolidation',
|
||||
'efficacy_specification': [
|
||||
{'description': 'Indicator 1', 'name': 'indicator1',
|
||||
'schema': 'Range(min=0, max=100, min_included=True, '
|
||||
'max_included=True, msg=None)',
|
||||
'unit': '%'}
|
||||
],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -37,6 +43,12 @@ GOAL_2 = {
|
||||
'uuid': "407b03b1-63c6-49b2-adaf-4df5c0090047",
|
||||
'name': "COST_OPTIMIZATION",
|
||||
'display_name': 'Cost Optimization',
|
||||
'efficacy_specification': [
|
||||
{'description': 'Indicator 2', 'name': 'indicator2',
|
||||
'schema': 'Range(min=0, max=100, min_included=True, '
|
||||
'max_included=True, msg=None)',
|
||||
'unit': '%'}
|
||||
],
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
@@ -93,10 +105,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(goal1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
[self.resource_as_dict(goal1, self.FIELDS, self.FIELD_LABELS),
|
||||
self.resource_as_dict(goal2, self.FIELDS, self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_goal_mgr.list.assert_called_once_with(detail=True)
|
||||
@@ -109,8 +119,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(goal, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_goal_mgr.get.assert_called_once_with('SERVER_CONSOLIDATION')
|
||||
|
||||
@@ -123,8 +133,8 @@ class GoalShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(goal, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(goal, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_goal_mgr.get.assert_called_once_with(
|
||||
'fc087747-61be-4aad-8126-b701731ae836')
|
||||
|
||||
186
watcherclient/tests/v1/test_scoring_engine.py
Normal file
186
watcherclient/tests/v1/test_scoring_engine.py
Normal file
@@ -0,0 +1,186 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2016 Intel
|
||||
#
|
||||
# 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.matchers import HasLength
|
||||
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.scoring_engine
|
||||
|
||||
SE1 = {
|
||||
'uuid': '5b558998-57ed-11e6-9ca8-08002722cb22',
|
||||
'name': 'se-01',
|
||||
'description': 'Some Scoring Engine'
|
||||
}
|
||||
|
||||
SE2 = {
|
||||
'uuid': '1f856554-57ee-11e6-ac72-08002722cb22',
|
||||
'name': 'se-02',
|
||||
'description': 'Some Other Scoring Engine'
|
||||
}
|
||||
|
||||
fake_responses = {
|
||||
'/v1/scoring_engines':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1]},
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/detail':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1]},
|
||||
)
|
||||
},
|
||||
'/v1/scoring_engines/%s' % SE1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
SE1,
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/%s' % SE1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
SE1,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_pagination = {
|
||||
'/v1/scoring_engines':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1],
|
||||
"next": "http://127.0.0.1:6385/v1/scoring_engines/?limit=1"}
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/?limit=1':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_sorting = {
|
||||
'/v1/scoring_engines/?sort_key=id':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE1, SE2]}
|
||||
),
|
||||
},
|
||||
'/v1/scoring_engines/?sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"scoring_engines": [SE2, SE1]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ScoringEngineManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ScoringEngineManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
|
||||
def test_scoring_engines_list(self):
|
||||
scoring_engines = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_detail(self):
|
||||
scoring_engines = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/detail', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(limit=1)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?limit=1', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(scoring_engines, HasLength(1))
|
||||
|
||||
def test_scoring_engines_list_pagination_no_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(limit=0)
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines', {}, None),
|
||||
('GET', '/v1/scoring_engines/?limit=1', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(scoring_engines, HasLength(2))
|
||||
|
||||
def test_scoring_engines_list_sort_key(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(sort_key='id')
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?sort_key=id', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_list_sort_dir(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = \
|
||||
watcherclient.v1.scoring_engine.ScoringEngineManager(self.api)
|
||||
scoring_engines = self.mgr.list(sort_dir='desc')
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/?sort_dir=desc', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(scoring_engines))
|
||||
|
||||
def test_scoring_engines_show(self):
|
||||
scoring_engine = self.mgr.get(SE1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/%s' % SE1['uuid'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(SE1['uuid'], scoring_engine.uuid)
|
||||
|
||||
def test_scoring_engines_show_by_name(self):
|
||||
scoring_engine = self.mgr.get(SE1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/scoring_engines/%s' % SE1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(SE1['name'], scoring_engine.name)
|
||||
130
watcherclient/tests/v1/test_scoring_engine_shell.py
Normal file
130
watcherclient/tests/v1/test_scoring_engine_shell.py
Normal file
@@ -0,0 +1,130 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2016 Intel
|
||||
#
|
||||
# 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 datetime
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from watcherclient import shell
|
||||
from watcherclient.tests.v1 import base
|
||||
from watcherclient import v1 as resource
|
||||
from watcherclient.v1 import resource_fields
|
||||
|
||||
SCORING_ENGINE_1 = {
|
||||
'uuid': '5b558998-57ed-11e6-9ca8-08002722cb22',
|
||||
'name': 'se-01',
|
||||
'description': 'Scoring Engine 0.1',
|
||||
'metainfo': '{ "columns": ["cpu", "mem", "pci"] }',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
SCORING_ENGINE_2 = {
|
||||
'uuid': '1f856554-57ee-11e6-ac72-08002722cb22',
|
||||
'name': 'se-02',
|
||||
'description': 'Some other Scoring Engine',
|
||||
'metainfo': 'mode=simplified',
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
}
|
||||
|
||||
|
||||
class ScoringEngineShellTest(base.CommandTestCase):
|
||||
|
||||
SHORT_LIST_FIELDS = resource_fields.SCORING_ENGINE_SHORT_LIST_FIELDS
|
||||
SHORT_LIST_FIELD_LABELS = (
|
||||
resource_fields.SCORING_ENGINE_SHORT_LIST_FIELD_LABELS)
|
||||
FIELDS = resource_fields.SCORING_ENGINE_FIELDS
|
||||
FIELD_LABELS = resource_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
|
||||
def setUp(self):
|
||||
super(self.__class__, self).setUp()
|
||||
|
||||
p_se_manager = mock.patch.object(
|
||||
resource, 'ScoringEngineManager')
|
||||
self.m_se_mgr_cls = p_se_manager.start()
|
||||
self.addCleanup(p_se_manager.stop)
|
||||
|
||||
self.m_se_mgr = mock.Mock()
|
||||
self.m_se_mgr_cls.return_value = self.m_se_mgr
|
||||
|
||||
self.stdout = six.StringIO()
|
||||
self.cmd = shell.WatcherShell(stdout=self.stdout)
|
||||
|
||||
def test_do_scoringengine_list(self):
|
||||
se1 = resource.ScoringEngine(mock.Mock(), SCORING_ENGINE_1)
|
||||
se2 = resource.ScoringEngine(mock.Mock(), SCORING_ENGINE_2)
|
||||
self.m_se_mgr.list.return_value = [
|
||||
se1, se2]
|
||||
|
||||
exit_code, results = self.run_cmd('scoringengine list')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(se1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(se2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_se_mgr.list.assert_called_once_with(detail=False)
|
||||
|
||||
def test_do_scoringengine_list_detail(self):
|
||||
se1 = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
se2 = resource.Goal(mock.Mock(), SCORING_ENGINE_2)
|
||||
self.m_se_mgr.list.return_value = [
|
||||
se1, se2]
|
||||
|
||||
exit_code, results = self.run_cmd('scoringengine list --detail')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(se1, self.FIELDS, self.FIELD_LABELS),
|
||||
self.resource_as_dict(se2, self.FIELDS, self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_se_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
def test_do_scoringengine_show_by_name(self):
|
||||
scoringengine = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
self.m_se_mgr.get.return_value = scoringengine
|
||||
|
||||
exit_code, result = self.run_cmd('scoringengine show se-01')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(scoringengine, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_se_mgr.get.assert_called_once_with('se-01')
|
||||
|
||||
def test_do_scoringengine_show_by_uuid(self):
|
||||
scoringengine = resource.Goal(mock.Mock(), SCORING_ENGINE_1)
|
||||
self.m_se_mgr.get.return_value = scoringengine
|
||||
|
||||
exit_code, result = self.run_cmd(
|
||||
'scoringengine show 5b558998-57ed-11e6-9ca8-08002722cb22')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
self.resource_as_dict(scoringengine, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
result)
|
||||
self.m_se_mgr.get.assert_called_once_with(
|
||||
'5b558998-57ed-11e6-9ca8-08002722cb22')
|
||||
@@ -33,6 +33,7 @@ STRATEGY_1 = {
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters_spec': {},
|
||||
}
|
||||
|
||||
STRATEGY_2 = {
|
||||
@@ -44,6 +45,7 @@ STRATEGY_2 = {
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'parameters_spec': {},
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +98,10 @@ class StrategyShellTest(base.CommandTestCase):
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(strategy1, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
[self.resource_as_dict(strategy1, self.FIELDS,
|
||||
self.FIELD_LABELS),
|
||||
self.resource_as_dict(strategy2, self.FIELDS,
|
||||
self.FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_strategy_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
@@ -19,6 +19,7 @@ from watcherclient.v1 import action_plan
|
||||
from watcherclient.v1 import audit
|
||||
from watcherclient.v1 import audit_template
|
||||
from watcherclient.v1 import goal
|
||||
from watcherclient.v1 import scoring_engine
|
||||
from watcherclient.v1 import strategy
|
||||
|
||||
Action = action.Action
|
||||
@@ -31,10 +32,13 @@ AuditTemplate = audit_template.AuditTemplate
|
||||
AuditTemplateManager = audit_template.AuditTemplateManager
|
||||
Goal = goal.Goal
|
||||
GoalManager = goal.GoalManager
|
||||
ScoringEngine = scoring_engine.ScoringEngine
|
||||
ScoringEngineManager = scoring_engine.ScoringEngineManager
|
||||
Strategy = strategy.Strategy
|
||||
StrategyManager = strategy.StrategyManager
|
||||
|
||||
__all__ = (
|
||||
"Action", "ActionManager", "ActionPlan", "ActionPlanManager",
|
||||
"Audit", "AuditManager", "AuditTemplate", "AuditTemplateManager",
|
||||
"Goal", "GoalManager", "Strategy", "StrategyManager")
|
||||
"Goal", "GoalManager", "ScoringEngine", "ScoringEngineManager",
|
||||
"Strategy", "StrategyManager")
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from cliff.formatters import yaml_format
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@@ -24,6 +26,19 @@ from watcherclient import exceptions
|
||||
from watcherclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
def format_global_efficacy(global_efficacy):
|
||||
formatted_global_efficacy = None
|
||||
if (global_efficacy.get('value') is not None and
|
||||
global_efficacy.get('unit')):
|
||||
formatted_global_efficacy = "%(value)s %(unit)s" % dict(
|
||||
unit=global_efficacy.get('unit'),
|
||||
value=global_efficacy.get('value'))
|
||||
elif global_efficacy.get('value') is not None:
|
||||
formatted_global_efficacy = global_efficacy.get('value')
|
||||
|
||||
return formatted_global_efficacy
|
||||
|
||||
|
||||
class ShowActionPlan(command.ShowOne):
|
||||
"""Show detailed information about a given action plan."""
|
||||
|
||||
@@ -36,6 +51,20 @@ class ShowActionPlan(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_indicators(self, action_plan, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_indicators = action_plan.efficacy_indicators
|
||||
fields = ['name', 'description', 'value', 'unit']
|
||||
yaml_format.YAMLFormatter().emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_indicators],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -49,6 +78,15 @@ class ShowActionPlan(command.ShowOne):
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
# Update the raw efficacy indicators with the formatted ones
|
||||
action_plan.efficacy_indicators = (
|
||||
self._format_indicators(action_plan, parsed_args))
|
||||
|
||||
# Update the raw global efficacy with the formatted one
|
||||
action_plan.global_efficacy = format_global_efficacy(
|
||||
action_plan.global_efficacy)
|
||||
|
||||
columns = res_fields.ACTION_PLAN_FIELDS
|
||||
column_headers = res_fields.ACTION_PLAN_FIELD_LABELS
|
||||
return column_headers, utils.get_item_properties(action_plan, columns)
|
||||
@@ -88,6 +126,20 @@ class ListActionPlan(command.Lister):
|
||||
|
||||
return parser
|
||||
|
||||
def _format_indicators(self, action_plan, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_indicators = action_plan.efficacy_indicators
|
||||
fields = ['name', 'value', 'unit']
|
||||
yaml_format.YAMLFormatter().emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_indicators],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -106,6 +158,16 @@ class ListActionPlan(command.Lister):
|
||||
|
||||
data = client.action_plan.list(**params)
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
for action_plan in data:
|
||||
# Update the raw efficacy indicators with the formatted ones
|
||||
action_plan.efficacy_indicators = (
|
||||
self._format_indicators(action_plan, parsed_args))
|
||||
|
||||
# Update the raw global efficacy with the formatted one
|
||||
action_plan.global_efficacy = format_global_efficacy(
|
||||
action_plan.global_efficacy)
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
|
||||
@@ -127,9 +189,9 @@ class CreateActionPlan(command.ShowOne):
|
||||
metavar='<deadline>',
|
||||
help=_('Descrition of the audit.'))
|
||||
parser.add_argument(
|
||||
'-t', '--type',
|
||||
dest='type',
|
||||
metavar='<type>',
|
||||
'-t', '--audit_type',
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
help=_("ActionPlan type."))
|
||||
|
||||
@@ -138,7 +200,7 @@ class CreateActionPlan(command.ShowOne):
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'type', 'deadline']
|
||||
field_list = ['audit_template_uuid', 'audit_type', 'deadline']
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
if fields.get('audit_template_uuid'):
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
|
||||
@@ -18,7 +18,10 @@ from watcherclient.common import base
|
||||
from watcherclient.common import utils
|
||||
from watcherclient import exceptions as exc
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'deadline', 'type']
|
||||
|
||||
CREATION_ATTRIBUTES = ['audit_template_uuid', 'host_aggregate',
|
||||
'deadline', 'audit_type', 'interval',
|
||||
'parameters', 'goal', 'strategy']
|
||||
|
||||
|
||||
class Audit(base.Resource):
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
@@ -55,17 +55,22 @@ class ListAudit(command.Lister):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListAudit, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--audit-template',
|
||||
metavar='<audit_template>',
|
||||
dest='audit_template',
|
||||
help=_('Name or UUID of an audit template used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Show detailed information about audits."))
|
||||
parser.add_argument(
|
||||
'--goal',
|
||||
dest='goal',
|
||||
metavar='<goal>',
|
||||
help=_('UUID or name of the goal used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('UUID or name of the strategy used for filtering.'))
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
@@ -89,8 +94,15 @@ class ListAudit(command.Lister):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
params = {}
|
||||
if parsed_args.audit_template is not None:
|
||||
params['audit_template'] = parsed_args.audit_template
|
||||
|
||||
# Optional
|
||||
if parsed_args.goal:
|
||||
params['goal'] = parsed_args.goal
|
||||
|
||||
# Optional
|
||||
if parsed_args.strategy:
|
||||
params['strategy'] = parsed_args.strategy
|
||||
|
||||
if parsed_args.detail:
|
||||
fields = res_fields.AUDIT_FIELDS
|
||||
field_labels = res_fields.AUDIT_FIELD_LABELS
|
||||
@@ -115,36 +127,78 @@ class CreateAudit(command.ShowOne):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateAudit, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'-a', '--audit-template',
|
||||
required=True,
|
||||
dest='audit_template_uuid',
|
||||
metavar='<audit_template>',
|
||||
help=_('Audit template used for this audit (name or uuid).'))
|
||||
parser.add_argument(
|
||||
'-d', '--deadline',
|
||||
dest='deadline',
|
||||
metavar='<deadline>',
|
||||
help=_('Descrition of the audit.'))
|
||||
parser.add_argument(
|
||||
'-t', '--type',
|
||||
dest='type',
|
||||
metavar='<type>',
|
||||
'-t', '--audit_type',
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
help=_("Audit type."))
|
||||
|
||||
choices=['ONESHOT', 'CONTINUOUS'],
|
||||
help=_("Audit type. It must be ONESHOT or CONTINUOUS. "
|
||||
"Default is ONESHOT."))
|
||||
parser.add_argument(
|
||||
'-p', '--parameter',
|
||||
dest='parameters',
|
||||
metavar='<name=value>',
|
||||
action='append',
|
||||
help=_("Record strategy parameter/value metadata. "
|
||||
"Can be specified multiple times."))
|
||||
parser.add_argument(
|
||||
'-i', '--interval',
|
||||
dest='interval',
|
||||
metavar='<interval>',
|
||||
help=_("Audit interval."))
|
||||
parser.add_argument(
|
||||
'-g', '--goal',
|
||||
dest='goal',
|
||||
metavar='<goal>',
|
||||
help=_('Goal UUID or name associated to this audit.'))
|
||||
parser.add_argument(
|
||||
'-s', '--strategy',
|
||||
dest='strategy',
|
||||
metavar='<strategy>',
|
||||
help=_('Strategy UUID or name associated to this audit.'))
|
||||
parser.add_argument(
|
||||
'-r', '--host-aggregate',
|
||||
dest='host_aggregate',
|
||||
metavar='<host-aggregate>',
|
||||
help=_('Name or UUID of the host aggregate targeted '
|
||||
'by this audit.'))
|
||||
parser.add_argument(
|
||||
'-a', '--audit-template',
|
||||
dest='audit_template_uuid',
|
||||
metavar='<audit_template>',
|
||||
help=_('Audit template used for this audit (name or uuid).'))
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'type', 'deadline']
|
||||
field_list = ['audit_template_uuid', 'host_aggregate',
|
||||
'audit_type', 'deadline', 'parameters', 'interval',
|
||||
'goal', 'strategy']
|
||||
|
||||
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
|
||||
if k in field_list and v is not None)
|
||||
fields = common_utils.args_array_to_dict(fields, 'parameters')
|
||||
|
||||
if fields.get('goal'):
|
||||
if not uuidutils.is_uuid_like(fields['goal']):
|
||||
fields['goal'] = client.goal.get(fields['goal']).uuid
|
||||
|
||||
if fields.get('audit_template_uuid'):
|
||||
if not uuidutils.is_uuid_like(fields['audit_template_uuid']):
|
||||
fields['audit_template_uuid'] = client.audit_template.get(
|
||||
fields['audit_template_uuid']).uuid
|
||||
# optional
|
||||
if fields.get('strategy'):
|
||||
if not uuidutils.is_uuid_like(fields['strategy']):
|
||||
fields['strategy'] = client.strategy.get(
|
||||
fields['strategy']).uuid
|
||||
|
||||
audit = client.audit.create(**fields)
|
||||
|
||||
@@ -167,7 +221,7 @@ class UpdateAudit(command.ShowOne):
|
||||
'op',
|
||||
metavar='<op>',
|
||||
choices=['add', 'replace', 'remove'],
|
||||
help=_("Operation: 'add'), 'replace', or 'remove'."))
|
||||
help=_("Operation: 'add', 'replace', or 'remove'."))
|
||||
parser.add_argument(
|
||||
'attributes',
|
||||
metavar='<path=value>',
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
|
||||
@@ -37,6 +37,7 @@ class Client(object):
|
||||
self.action = v1.ActionManager(self.http_client)
|
||||
self.action_plan = v1.ActionPlanManager(self.http_client)
|
||||
self.goal = v1.GoalManager(self.http_client)
|
||||
self.scoring_engine = v1.ScoringEngineManager(self.http_client)
|
||||
self.strategy = v1.StrategyManager(self.http_client)
|
||||
# self.metric_collector = v1.MetricCollectorManager(self.http_client)
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
from osc_lib import utils
|
||||
import six
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@@ -36,6 +37,16 @@ class ShowGoal(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_indicator_spec_table(self, spec, parsed_args):
|
||||
out = six.StringIO()
|
||||
self.formatter.emit_one(
|
||||
column_names=list(field.capitalize() for field in spec.keys()),
|
||||
data=utils.get_dict_properties(spec, spec.keys()),
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -47,6 +58,15 @@ class ShowGoal(command.ShowOne):
|
||||
columns = res_fields.GOAL_FIELDS
|
||||
column_headers = res_fields.GOAL_FIELD_LABELS
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
indicator_specs = ''
|
||||
# Format complex data types:
|
||||
for indicator_spec in goal.efficacy_specification:
|
||||
indicator_specs += self._format_indicator_spec_table(
|
||||
indicator_spec, parsed_args)
|
||||
# Update the raw efficacy specs with the formatted one
|
||||
goal.efficacy_specification = indicator_specs
|
||||
|
||||
return column_headers, utils.get_item_properties(goal, columns)
|
||||
|
||||
|
||||
@@ -80,6 +100,20 @@ class ListGoal(command.Lister):
|
||||
|
||||
return parser
|
||||
|
||||
def _format_indicator_spec_table(self, goal, parsed_args):
|
||||
out = six.StringIO()
|
||||
efficacy_specification = goal.efficacy_specification
|
||||
fields = ['name', 'unit']
|
||||
self.formatter.emit_list(
|
||||
column_names=list(field.capitalize()
|
||||
for field in fields),
|
||||
data=[utils.get_dict_properties(spec, fields)
|
||||
for spec in efficacy_specification],
|
||||
stdout=out,
|
||||
parsed_args=parsed_args,
|
||||
)
|
||||
return out.getvalue() or ''
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -100,5 +134,11 @@ class ListGoal(command.Lister):
|
||||
except exceptions.HTTPNotFound as ex:
|
||||
raise exceptions.CommandError(str(ex))
|
||||
|
||||
if parsed_args.formatter == 'table':
|
||||
for goal in data:
|
||||
# Update the raw efficacy specs with the formatted one
|
||||
goal.efficacy_specification = (
|
||||
self._format_indicator_spec_table(goal, parsed_args))
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
|
||||
@@ -34,28 +34,35 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'deadline', 'state', 'type', 'audit_template_uuid',
|
||||
'audit_template_name']
|
||||
'deadline', 'state', 'audit_type',
|
||||
'parameters', 'interval',
|
||||
'host_aggregate', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Deadline', 'State', 'Type', 'Audit Template uuid',
|
||||
'Audit Template Name']
|
||||
'Deadline', 'State', 'Audit Type',
|
||||
'Parameters', 'Interval', 'Host Aggregate ID or Name',
|
||||
'Goal', 'Strategy']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'type', 'audit_template_name', 'state']
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'audit_type',
|
||||
'state', 'goal_name', 'strategy_name']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Type', 'Audit Template Name',
|
||||
'State']
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit Type', 'State', 'Goal',
|
||||
'Strategy']
|
||||
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'audit_uuid', 'state']
|
||||
'audit_uuid', 'strategy_name', 'state',
|
||||
'efficacy_indicators', 'global_efficacy']
|
||||
|
||||
ACTION_PLAN_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Audit', 'State']
|
||||
'Audit', 'Strategy', 'State',
|
||||
'Efficacy indicators', 'Global efficacy']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state', 'updated_at']
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state',
|
||||
'updated_at', 'global_efficacy']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit', 'State', 'Updated At']
|
||||
ACTION_PLAN_SHORT_LIST_FIELD_LABELS = ['UUID', 'Audit', 'State',
|
||||
'Updated At', 'Global efficacy']
|
||||
|
||||
# Action
|
||||
ACTION_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at', 'next_uuid',
|
||||
@@ -73,9 +80,9 @@ ACTION_SHORT_LIST_FIELD_LABELS = ['UUID', 'Next Action', 'State',
|
||||
'Action Plan', 'Action']
|
||||
# Goals
|
||||
|
||||
GOAL_FIELDS = ['uuid', 'name', 'display_name']
|
||||
GOAL_FIELDS = ['uuid', 'name', 'display_name', 'efficacy_specification']
|
||||
|
||||
GOAL_FIELD_LABELS = ['UUID', 'Name', 'Display name']
|
||||
GOAL_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Efficacy specification']
|
||||
|
||||
GOAL_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name']
|
||||
|
||||
@@ -83,14 +90,15 @@ GOAL_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name']
|
||||
|
||||
# Strategies
|
||||
|
||||
STRATEGY_FIELDS = ['uuid', 'name', 'display_name', 'goal_uuid']
|
||||
STRATEGY_FIELDS = ['uuid', 'name', 'display_name', 'goal_name',
|
||||
'parameters_spec']
|
||||
|
||||
STRATEGY_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal UUID']
|
||||
STRATEGY_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal',
|
||||
'Parameters spec']
|
||||
|
||||
STRATEGY_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name', 'goal_uuid']
|
||||
STRATEGY_SHORT_LIST_FIELDS = ['uuid', 'name', 'display_name', 'goal_name']
|
||||
|
||||
STRATEGY_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name',
|
||||
'Goal UUID']
|
||||
STRATEGY_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Display name', 'Goal']
|
||||
|
||||
# Metric Collector
|
||||
METRIC_COLLECTOR_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
@@ -104,3 +112,9 @@ METRIC_COLLECTOR_SHORT_LIST_FIELDS = ['uuid', 'endpoint', 'category']
|
||||
|
||||
METRIC_COLLECTOR_SHORT_LIST_FIELD_LABELS = ['UUID', 'Endpoint URL',
|
||||
'Metric Category']
|
||||
# Scoring Engines
|
||||
SCORING_ENGINE_FIELDS = ['uuid', 'name', 'description', 'metainfo']
|
||||
SCORING_ENGINE_FIELD_LABELS = ['UUID', 'Name', 'Description', 'Metainfo']
|
||||
|
||||
SCORING_ENGINE_SHORT_LIST_FIELDS = ['uuid', 'name', 'description']
|
||||
SCORING_ENGINE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Description']
|
||||
|
||||
78
watcherclient/v1/scoring_engine.py
Normal file
78
watcherclient/v1/scoring_engine.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2016 Intel
|
||||
#
|
||||
# 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 watcherclient.common import base
|
||||
from watcherclient.common import utils
|
||||
|
||||
|
||||
class ScoringEngine(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<ScoringEngine %s>" % self._info
|
||||
|
||||
|
||||
class ScoringEngineManager(base.Manager):
|
||||
resource_class = ScoringEngine
|
||||
|
||||
@staticmethod
|
||||
def _path(scoring_engine=None):
|
||||
return ('/v1/scoring_engines/%s' % scoring_engine
|
||||
if scoring_engine else '/v1/scoring_engines')
|
||||
|
||||
def list(self, limit=None, sort_key=None, sort_dir=None, detail=False):
|
||||
"""Retrieve a list of scoring engines.
|
||||
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of scoring engines to return.
|
||||
2) limit == 0, return the entire list of scoring engines.
|
||||
3) limit param is NOT specified (None), the number of items
|
||||
returned respect the maximum imposed by the Watcher API
|
||||
(see Watcher's api.max_limit option).
|
||||
|
||||
:param sort_key: Optional, field used for sorting.
|
||||
|
||||
:param sort_dir: Optional, direction of sorting, either 'asc' (the
|
||||
default) or 'desc'.
|
||||
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about scoring engines.
|
||||
|
||||
:returns: A list of scoring engines.
|
||||
|
||||
"""
|
||||
if limit is not None:
|
||||
limit = int(limit)
|
||||
|
||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
||||
|
||||
path = ''
|
||||
if detail:
|
||||
path += 'detail'
|
||||
if filters:
|
||||
path += '?' + '&'.join(filters)
|
||||
|
||||
if limit is None:
|
||||
return self._list(self._path(path), "scoring_engines")
|
||||
else:
|
||||
return self._list_pagination(self._path(path), "scoring_engines",
|
||||
limit=limit)
|
||||
|
||||
def get(self, scoring_engine_name):
|
||||
try:
|
||||
return self._list(self._path(scoring_engine_name))[0]
|
||||
except IndexError:
|
||||
return None
|
||||
105
watcherclient/v1/scoring_engine_shell.py
Normal file
105
watcherclient/v1/scoring_engine_shell.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2016 Intel
|
||||
#
|
||||
# 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 osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
from watcherclient.common import utils as common_utils
|
||||
from watcherclient import exceptions
|
||||
from watcherclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
class ShowScoringEngine(command.ShowOne):
|
||||
"""Show detailed information about a given scoring engine."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowScoringEngine, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'scoring_engine',
|
||||
metavar='<scoring_engine>',
|
||||
help=_('Name of the scoring engine'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
try:
|
||||
scoring_engine = client.scoring_engine.get(
|
||||
parsed_args.scoring_engine)
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
columns = res_fields.SCORING_ENGINE_FIELDS
|
||||
column_headers = res_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
|
||||
return column_headers, utils.get_item_properties(scoring_engine,
|
||||
columns)
|
||||
|
||||
|
||||
class ListScoringEngine(command.Lister):
|
||||
"""List information on retrieved scoring engines."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListScoringEngine, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Show detailed information about scoring engines."))
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
type=int,
|
||||
help=_('Maximum number of actions to return per request, '
|
||||
'0 for no limit. Default is the maximum number used '
|
||||
'by the Watcher API Service.'))
|
||||
parser.add_argument(
|
||||
'--sort-key',
|
||||
metavar='<field>',
|
||||
help=_('Action field that will be used for sorting.'))
|
||||
parser.add_argument(
|
||||
'--sort-dir',
|
||||
metavar='<direction>',
|
||||
choices=['asc', 'desc'],
|
||||
help=_('Sort direction: "asc" (the default) or "desc".'))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
params = {}
|
||||
if parsed_args.detail:
|
||||
fields = res_fields.SCORING_ENGINE_FIELDS
|
||||
field_labels = res_fields.SCORING_ENGINE_FIELD_LABELS
|
||||
else:
|
||||
fields = res_fields.SCORING_ENGINE_SHORT_LIST_FIELDS
|
||||
field_labels = res_fields.SCORING_ENGINE_SHORT_LIST_FIELD_LABELS
|
||||
|
||||
params.update(
|
||||
common_utils.common_params_for_list(
|
||||
parsed_args, fields, field_labels))
|
||||
|
||||
try:
|
||||
data = client.scoring_engine.list(**params)
|
||||
except exceptions.HTTPNotFound as ex:
|
||||
raise exceptions.CommandError(str(ex))
|
||||
|
||||
return (field_labels,
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
@@ -14,7 +14,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from openstackclient.common import utils
|
||||
import json
|
||||
from osc_lib import utils
|
||||
|
||||
from watcherclient._i18n import _
|
||||
from watcherclient.common import command
|
||||
@@ -35,6 +36,13 @@ class ShowStrategy(command.ShowOne):
|
||||
)
|
||||
return parser
|
||||
|
||||
def _format_spec(self, strategy):
|
||||
parameters_spec = strategy.parameters_spec.get('properties')
|
||||
if parameters_spec:
|
||||
return json.dumps(parameters_spec, indent=2)
|
||||
|
||||
return {}
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
@@ -43,6 +51,7 @@ class ShowStrategy(command.ShowOne):
|
||||
except exceptions.HTTPNotFound as exc:
|
||||
raise exceptions.CommandError(str(exc))
|
||||
|
||||
strategy.parameters_spec = self._format_spec(strategy)
|
||||
columns = res_fields.STRATEGY_FIELDS
|
||||
column_headers = res_fields.STRATEGY_FIELD_LABELS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user