bug and requirements fixes
Change-Id: Ibf3c8f06ce09574bc1b0e99564882513f981be91
This commit is contained in:
99
README.rst
99
README.rst
@@ -11,3 +11,102 @@ Watcher takes advantage of CEP and ML algorithms/metaheuristics to improve physi
|
||||
* Source: http://git.openstack.org/cgit/stackforge/python-watcher
|
||||
* Bugs: http://bugs.launchpad.net/watcher
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Install the prerequisite packages
|
||||
---------------------------------
|
||||
|
||||
On Ubuntu (tested on 14.04-64)
|
||||
|
||||
.. code::
|
||||
|
||||
sudo apt-get install python-dev libssl-dev python-pip git-core libmysqlclient-dev libffi-dev
|
||||
|
||||
On Fedora-based distributions e.g., Fedora/RHEL/CentOS/Scientific Linux (tested on CentOS 6.5)
|
||||
|
||||
.. code::
|
||||
|
||||
sudo yum install python-virtualenv openssl-devel python-pip git gcc libffi-devel mysql-devel postgresql-devel
|
||||
|
||||
On openSUSE-based distributions (SLES 12, openSUSE 13.1, Factory or Tumbleweed)
|
||||
|
||||
.. code::
|
||||
|
||||
sudo zypper install gcc git libmysqlclient-devel libopenssl-devel postgresql-devel python-devel python-pip
|
||||
|
||||
Install the Watcher client
|
||||
--------------------------
|
||||
|
||||
You can install the Watcher CLI with the following command:
|
||||
|
||||
.. code::
|
||||
|
||||
pip install python-watcherclient
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
Create a **creds** file containing your Openstack credentials:
|
||||
|
||||
.. code::
|
||||
|
||||
export OS_IDENTITY_API_VERSION=3
|
||||
export OS_AUTH_URL=http://<your-keystone-server>:5000/v3
|
||||
export OS_PROJECT_DOMAIN_ID=default
|
||||
export OS_USER_DOMAIN_ID=default
|
||||
export OS_USERNAME=admin
|
||||
export OS_PASSWORD=<your-password>
|
||||
export OS_PROJECT_NAME=<your-project-name>
|
||||
|
||||
Source these credentials into your current shell session:
|
||||
|
||||
.. code::
|
||||
|
||||
# source creds
|
||||
|
||||
You should be able to launch the following command which gets the list of previously created Audit Templates:
|
||||
|
||||
.. code::
|
||||
|
||||
# watcher audit-template-list
|
||||
+------+------+
|
||||
| UUID | Name |
|
||||
+------+------+
|
||||
+------+------+
|
||||
|
||||
You can view the entire list of available Watcher commands and options using this command:
|
||||
|
||||
.. code::
|
||||
|
||||
# watcher help
|
||||
|
||||
|
||||
Troubleshootings
|
||||
================
|
||||
|
||||
If any watcher command fails, you can obtain more details with the **--debug** option :
|
||||
|
||||
.. code::
|
||||
|
||||
# watcher --debug audit-template-list
|
||||
|
||||
Install the openstack CLI :
|
||||
|
||||
.. code::
|
||||
|
||||
# pip install python-openstackclient
|
||||
|
||||
Make sure that your Openstack credentials are correct. If so, you should be able to verify that the watcher user has been declared in your Openstack keystone :
|
||||
|
||||
.. code::
|
||||
|
||||
# openstack user list
|
||||
|
||||
and that the watcher endpoints have been declared as well :
|
||||
|
||||
.. code::
|
||||
|
||||
# openstack endpoint list
|
||||
|
@@ -35,3 +35,6 @@ autodoc_index_modules = True
|
||||
source-dir = doc/source
|
||||
build-dir = doc/build
|
||||
all_files = 1
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
|
@@ -13,6 +13,10 @@ oslotest>=1.2.0 # Apache-2.0
|
||||
testrepository>=0.0.18
|
||||
testscenarios>=0.4
|
||||
testtools>=0.9.36,!=1.2.0
|
||||
mock>=1.0
|
||||
mock>=1.0,<1.1
|
||||
# httpretty>=0.8.4,!=0.8.7
|
||||
httpretty>=0.8.8
|
||||
|
||||
# Needed for pypi packaging
|
||||
wheel
|
||||
twine
|
||||
|
8
tox.ini
8
tox.ini
@@ -33,3 +33,11 @@ show-source = True
|
||||
ignore = E123,E125
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
|
||||
|
||||
[testenv:pypi]
|
||||
commands =
|
||||
python setup.py sdist bdist_wheel
|
||||
twine upload --config-file .pypirc {posargs} dist/*
|
||||
|
||||
[testenv:wheel]
|
||||
commands = python setup.py bdist_wheel
|
||||
|
@@ -30,8 +30,9 @@ class AuditShellTest(utils.BaseTestCase):
|
||||
with mock.patch.object(cliutils, 'print_dict', fake_print_dict):
|
||||
audit = object()
|
||||
a_shell._print_audit_show(audit)
|
||||
exp = ['created_at', 'audit_template_uuid', 'updated_at', 'uuid',
|
||||
'deleted_at', 'state', 'type', 'deadline']
|
||||
exp = ['created_at', 'audit_template_uuid', 'audit_template_name',
|
||||
'updated_at', 'uuid', 'deleted_at', 'state', 'type',
|
||||
'deadline']
|
||||
act = actual.keys()
|
||||
self.assertEqual(sorted(exp), sorted(act))
|
||||
|
||||
|
165
watcherclient/tests/v1/test_goal.py
Normal file
165
watcherclient/tests/v1/test_goal.py
Normal file
@@ -0,0 +1,165 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import testtools
|
||||
from testtools.matchers import HasLength
|
||||
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.goal
|
||||
|
||||
GOAL1 = {
|
||||
'name': "BASIC_CONSOLIDATION",
|
||||
'strategy': 'basic'
|
||||
}
|
||||
|
||||
GOAL2 = {
|
||||
'name': "COST_OPTIMIZATION",
|
||||
'strategy': 'basic'
|
||||
}
|
||||
|
||||
fake_responses = {
|
||||
'/v1/goals':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL1]},
|
||||
),
|
||||
},
|
||||
'/v1/goals/detail':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL1]},
|
||||
)
|
||||
},
|
||||
'/v1/goals/%s' % GOAL1['name']:
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
GOAL1,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_pagination = {
|
||||
'/v1/goals':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL1],
|
||||
"next": "http://127.0.0.1:6385/v1/goals/?limit=1"}
|
||||
),
|
||||
},
|
||||
'/v1/goals/?limit=1':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_sorting = {
|
||||
'/v1/goals/?sort_key=name':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL1, GOAL2]}
|
||||
),
|
||||
},
|
||||
'/v1/goals/?sort_dir=desc':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"goals": [GOAL2, GOAL1]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class GoalManagerTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(GoalManagerTest, self).setUp()
|
||||
self.api = utils.FakeAPI(fake_responses)
|
||||
self.mgr = watcherclient.v1.goal.GoalManager(self.api)
|
||||
|
||||
def test_goals_list(self):
|
||||
goals = self.mgr.list()
|
||||
expect = [
|
||||
('GET', '/v1/goals', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(goals))
|
||||
|
||||
def test_goals_list_detail(self):
|
||||
goals = self.mgr.list(detail=True)
|
||||
expect = [
|
||||
('GET', '/v1/goals/detail', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(goals))
|
||||
|
||||
def test_goals_list_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = watcherclient.v1.goal.GoalManager(self.api)
|
||||
goals = self.mgr.list(limit=1)
|
||||
expect = [
|
||||
('GET', '/v1/goals/?limit=1', {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(goals, HasLength(1))
|
||||
|
||||
def test_goals_list_pagination_no_limit(self):
|
||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||
self.mgr = watcherclient.v1.goal.GoalManager(self.api)
|
||||
goals = self.mgr.list(limit=0)
|
||||
expect = [
|
||||
('GET', '/v1/goals', {}, None),
|
||||
('GET', '/v1/goals/?limit=1', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertThat(goals, HasLength(2))
|
||||
|
||||
def test_goals_list_sort_key(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = watcherclient.v1.goal.GoalManager(self.api)
|
||||
goals = self.mgr.list(sort_key='name')
|
||||
expect = [
|
||||
('GET', '/v1/goals/?sort_key=name', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(goals))
|
||||
|
||||
def test_goals_list_sort_dir(self):
|
||||
self.api = utils.FakeAPI(fake_responses_sorting)
|
||||
self.mgr = watcherclient.v1.goal.GoalManager(self.api)
|
||||
goals = self.mgr.list(sort_dir='desc')
|
||||
expect = [
|
||||
('GET', '/v1/goals/?sort_dir=desc', {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(goals))
|
||||
|
||||
def test_goals_show(self):
|
||||
goal = self.mgr.get(GOAL1['name'])
|
||||
expect = [
|
||||
('GET', '/v1/goals/%s' % GOAL1['name'], {}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(GOAL1['name'], goal.name)
|
33
watcherclient/tests/v1/test_goal_shell.py
Normal file
33
watcherclient/tests/v1/test_goal_shell.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2013 IBM Corp
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from watcherclient.openstack.common import cliutils
|
||||
from watcherclient.tests import utils
|
||||
import watcherclient.v1.goal_shell as a_shell
|
||||
|
||||
|
||||
class GoalShellTest(utils.BaseTestCase):
|
||||
|
||||
def test_do_goal_show(self):
|
||||
actual = {}
|
||||
fake_print_dict = lambda data, *args, **kwargs: actual.update(data)
|
||||
with mock.patch.object(cliutils, 'print_dict', fake_print_dict):
|
||||
goal = object()
|
||||
a_shell._print_goal_show(goal)
|
||||
exp = ['name', 'strategy']
|
||||
act = actual.keys()
|
||||
self.assertEqual(sorted(exp), sorted(act))
|
@@ -20,6 +20,7 @@ from watcherclient.v1 import action
|
||||
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 metric_collector
|
||||
|
||||
|
||||
@@ -41,6 +42,7 @@ class Client(object):
|
||||
self.http_client)
|
||||
self.action = action.ActionManager(self.http_client)
|
||||
self.action_plan = action_plan.ActionPlanManager(self.http_client)
|
||||
self.goal = goal.GoalManager(self.http_client)
|
||||
self.metric_collector = metric_collector.MetricCollectorManager(
|
||||
self.http_client
|
||||
)
|
||||
|
77
watcherclient/v1/goal.py
Normal file
77
watcherclient/v1/goal.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2013 Red Hat, 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 watcherclient.common import base
|
||||
from watcherclient.common import utils
|
||||
|
||||
|
||||
class Goal(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Goal %s>" % self._info
|
||||
|
||||
|
||||
class GoalManager(base.Manager):
|
||||
resource_class = Goal
|
||||
|
||||
@staticmethod
|
||||
def _path(goal_name=None):
|
||||
return '/v1/goals/%s' % goal_name if goal_name else '/v1/goals'
|
||||
|
||||
def list(self, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
"""Retrieve a list of goal.
|
||||
|
||||
:param limit: The maximum number of results to return per
|
||||
request, if:
|
||||
|
||||
1) limit > 0, the maximum number of audits to return.
|
||||
2) limit == 0, return the entire list of audits.
|
||||
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 audits.
|
||||
|
||||
:returns: A list of audits.
|
||||
|
||||
"""
|
||||
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), "goals")
|
||||
else:
|
||||
return self._list_pagination(self._path(path), "goals",
|
||||
limit=limit)
|
||||
|
||||
def get(self, goal_name):
|
||||
try:
|
||||
return self._list(self._path(goal_name))[0]
|
||||
except IndexError:
|
||||
return None
|
79
watcherclient/v1/goal_shell.py
Normal file
79
watcherclient/v1/goal_shell.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from watcherclient.common import utils
|
||||
from watcherclient.openstack.common import cliutils
|
||||
from watcherclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
def _print_goal_show(goal):
|
||||
fields = res_fields.GOAL_FIELDS
|
||||
data = dict([(f, getattr(goal, f, '')) for f in fields])
|
||||
cliutils.print_dict(data, wrap=72)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
'goal',
|
||||
metavar='<goal>',
|
||||
help="Name of the goal")
|
||||
def do_goal_show(cc, args):
|
||||
"""Show detailed information about a _print_goal_show."""
|
||||
goal = cc.goal.get(args.goal)
|
||||
_print_goal_show(goal)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
'--detail',
|
||||
dest='detail',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="Show detailed information about metric collectors.")
|
||||
@cliutils.arg(
|
||||
'--limit',
|
||||
metavar='<limit>',
|
||||
type=int,
|
||||
help='Maximum number of goals to return per request, '
|
||||
'0 for no limit. Default is the maximum number used '
|
||||
'by the Watcher API Service.')
|
||||
@cliutils.arg(
|
||||
'--sort-key',
|
||||
metavar='<field>',
|
||||
help='Goal field that will be used for sorting.')
|
||||
@cliutils.arg(
|
||||
'--sort-dir',
|
||||
metavar='<direction>',
|
||||
choices=['asc', 'desc'],
|
||||
help='Sort direction: "asc" (the default) or "desc".')
|
||||
def do_goal_list(cc, args):
|
||||
"""List the goals."""
|
||||
params = {}
|
||||
|
||||
if args.detail:
|
||||
fields = res_fields.GOAL_FIELDS
|
||||
field_labels = res_fields.GOAL_FIELD_LABELS
|
||||
else:
|
||||
fields = res_fields.GOAL_SHORT_LIST_FIELDS
|
||||
field_labels = res_fields.GOAL_SHORT_LIST_FIELD_LABELS
|
||||
|
||||
params.update(utils.common_params_for_list(args,
|
||||
fields,
|
||||
field_labels))
|
||||
|
||||
goal = cc.goal.list(**params)
|
||||
cliutils.print_list(goal, fields,
|
||||
field_labels=field_labels,
|
||||
sortby_index=None)
|
@@ -33,14 +33,17 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name']
|
||||
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'deadline', 'state', 'type', 'audit_template_uuid']
|
||||
'deadline', 'state', 'type', 'audit_template_uuid',
|
||||
'audit_template_name']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Deadline', 'State', 'Type', 'Audit Template']
|
||||
'Deadline', 'State', 'Type', 'Audit Template uuid',
|
||||
'Audit Template Name']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'type', 'audit_template_uuid', 'state']
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'type', 'audit_template_name', 'state']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Type', 'Audit Template', 'State']
|
||||
AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Type', 'Audit Template Name',
|
||||
'State']
|
||||
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
@@ -69,6 +72,15 @@ ACTION_SHORT_LIST_FIELDS = ['uuid', 'next_uuid',
|
||||
|
||||
ACTION_SHORT_LIST_FIELD_LABELS = ['UUID', 'Next Action', 'State',
|
||||
'Action Plan', 'Action']
|
||||
# Goals
|
||||
|
||||
GOAL_FIELDS = ['name', 'strategy']
|
||||
|
||||
GOAL_FIELD_LABELS = ['Name', 'Strategy']
|
||||
|
||||
GOAL_SHORT_LIST_FIELDS = ['name', 'strategy']
|
||||
|
||||
GOAL_SHORT_LIST_FIELD_LABELS = ['Name', 'Strategy']
|
||||
|
||||
# Metric Collector
|
||||
METRIC_COLLECTOR_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
|
@@ -18,6 +18,7 @@ from watcherclient.v1 import action_plan_shell
|
||||
from watcherclient.v1 import action_shell
|
||||
from watcherclient.v1 import audit_shell
|
||||
from watcherclient.v1 import audit_template_shell
|
||||
from watcherclient.v1 import goal_shell
|
||||
# from watcherclient.v1 import metric_collector_shell
|
||||
|
||||
COMMAND_MODULES = [
|
||||
@@ -26,6 +27,7 @@ COMMAND_MODULES = [
|
||||
action_plan_shell,
|
||||
action_shell,
|
||||
# metric_collector_shell,
|
||||
goal_shell
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user