Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6681724daa | ||
|
|
8d62995cf4 | ||
|
|
d82be4c8c4 | ||
|
|
152804168d | ||
|
|
4a4add3dcc | ||
|
|
db012f1f8f | ||
|
|
a4c020c19f | ||
|
|
8ef72f18c4 |
@@ -1,9 +1,9 @@
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- watcherclient-tempest-functional
|
||||
- watcherclient-tempest-functional:
|
||||
voting: false
|
||||
- openstack-tox-lower-constraints
|
||||
gate:
|
||||
jobs:
|
||||
- watcherclient-tempest-functional
|
||||
- openstack-tox-lower-constraints
|
||||
|
||||
@@ -71,8 +71,7 @@ Once you have an watcher `Client`_, you can perform various tasks::
|
||||
>>> watcher.audit.get(audit_uuid_or_name) # information about a particular audit
|
||||
|
||||
When the `Client`_ needs to propagate an exception, it will usually
|
||||
raise an instance subclassed from
|
||||
`watcherclient.exc.BaseException`_ or `watcherclient.exc.ClientException`_.
|
||||
raise an instance listed in `watcherclient.exceptions`_.
|
||||
|
||||
Refer to the modules themselves, for more details.
|
||||
|
||||
@@ -84,5 +83,4 @@ watcherclient Modules
|
||||
.. _watcherclient.v1.client.Client: api/watcherclient.v1.client.html#watcherclient.v1.client.Client
|
||||
.. _Client: api/watcherclient.v1.client.html#watcherclient.v1.client.Client
|
||||
.. _watcherclient.client.get_client(): api/watcherclient.client.html#watcherclient.client.get_client
|
||||
.. _watcherclient.exc.BaseException: api/watcherclient.exc.html#watcherclient.exc.BaseException
|
||||
.. _watcherclient.exc.ClientException: api/watcherclient.exc.html#watcherclient.exc.ClientException
|
||||
.. _watcherclient.exceptions: api/watcherclient.exceptions.html
|
||||
|
||||
@@ -54,7 +54,6 @@ openstack.infra_optim.v1 =
|
||||
|
||||
optimize_actionplan_show = watcherclient.v1.action_plan_shell:ShowActionPlan
|
||||
optimize_actionplan_list = watcherclient.v1.action_plan_shell:ListActionPlan
|
||||
optimize_actionplan_create = watcherclient.v1.action_plan_shell:CreateActionPlan
|
||||
optimize_actionplan_update = watcherclient.v1.action_plan_shell:UpdateActionPlan
|
||||
optimize_actionplan_start = watcherclient.v1.action_plan_shell:StartActionPlan
|
||||
optimize_actionplan_cancel = watcherclient.v1.action_plan_shell:CancelActionPlan
|
||||
@@ -91,7 +90,6 @@ watcherclient.v1 =
|
||||
|
||||
actionplan_show = watcherclient.v1.action_plan_shell:ShowActionPlan
|
||||
actionplan_list = watcherclient.v1.action_plan_shell:ListActionPlan
|
||||
actionplan_create = watcherclient.v1.action_plan_shell:CreateActionPlan
|
||||
actionplan_update = watcherclient.v1.action_plan_shell:UpdateActionPlan
|
||||
actionplan_start = watcherclient.v1.action_plan_shell:StartActionPlan
|
||||
actionplan_delete = watcherclient.v1.action_plan_shell:DeleteActionPlan
|
||||
|
||||
6
tox.ini
6
tox.ini
@@ -16,20 +16,25 @@ commands = rm -f .testrepository/times.dbm
|
||||
python setup.py testr --slowest --testr-args='{posargs}'
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python3
|
||||
commands = flake8
|
||||
|
||||
[testenv:venv]
|
||||
basepython = python3
|
||||
commands = {posargs}
|
||||
|
||||
[testenv:cover]
|
||||
basepython = python3
|
||||
commands =
|
||||
python setup.py testr --coverage --testr-args='{posargs}'
|
||||
coverage report
|
||||
|
||||
[testenv:docs]
|
||||
basepython = python3
|
||||
commands = python setup.py build_sphinx
|
||||
|
||||
[testenv:debug]
|
||||
basepython = python3
|
||||
commands = oslo_debug_helper -t watcherclient/tests/unit {posargs}
|
||||
|
||||
[testenv:functional]
|
||||
@@ -56,6 +61,7 @@ builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||
|
||||
[testenv:wheel]
|
||||
basepython = python3
|
||||
commands = python setup.py bdist_wheel
|
||||
|
||||
[hacking]
|
||||
|
||||
@@ -134,6 +134,11 @@ class Manager(object):
|
||||
def _delete(self, url):
|
||||
self.api.raw_request('DELETE', url)
|
||||
|
||||
def _start(self, url, body=None, method='POST'):
|
||||
resp, body = self.api.json_request(method, url, body={})
|
||||
if body:
|
||||
return self.resource_class(self, body)
|
||||
|
||||
|
||||
class Resource(base.Resource):
|
||||
"""Represents a particular instance of an object (tenant, user, etc).
|
||||
|
||||
@@ -28,7 +28,8 @@ class ActionPlanTests(base.TestCase):
|
||||
dummy_name = 'dummy'
|
||||
list_fields = ['UUID', 'Audit', 'State', 'Updated At', 'Global efficacy']
|
||||
detailed_list_fields = list_fields + ['Created At', 'Deleted At',
|
||||
'Strategy', 'Efficacy indicators']
|
||||
'Strategy', 'Efficacy indicators',
|
||||
'Hostname']
|
||||
audit_template_name = 'a' + uuidutils.generate_uuid()
|
||||
audit_uuid = None
|
||||
|
||||
@@ -94,52 +95,3 @@ class ActionPlanTests(base.TestCase):
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
))
|
||||
|
||||
|
||||
class ActionPlanActiveTests(base.TestCase):
|
||||
|
||||
audit_uuid = None
|
||||
audit_template_name = 'b' + uuidutils.generate_uuid()
|
||||
|
||||
list_fields = ['UUID', 'Audit', 'State', 'Updated At', 'Global efficacy']
|
||||
detailed_list_fields = list_fields + ['Created At', 'Deleted At',
|
||||
'Strategy', 'Efficacy indicators']
|
||||
|
||||
def _delete_action_plan(self):
|
||||
self.assertTrue(test_utils.call_until_true(
|
||||
func=functools.partial(
|
||||
self.has_audit_created, self.audit_uuid),
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
))
|
||||
output = self.parse_show(
|
||||
self.watcher('actionplan list --audit %s' % self.audit_uuid))
|
||||
action_plan_uuid = list(output[0])[0]
|
||||
raw_output = self.watcher('actionplan delete %s' % action_plan_uuid)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
def _delete_audit(self):
|
||||
raw_output = self.watcher('audit delete %s' % self.audit_uuid)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
def _delete_audit_template(self):
|
||||
raw_output = self.watcher(
|
||||
'audittemplate delete %s' % self.audit_template_name)
|
||||
self.assertOutput('', raw_output)
|
||||
|
||||
def _create_audit_template(self):
|
||||
template_raw_output = self.watcher(
|
||||
'audittemplate create %s dummy -s dummy'
|
||||
% self.audit_template_name)
|
||||
template_output = self.parse_show_as_object(template_raw_output)
|
||||
return template_output
|
||||
|
||||
def test_action_plan_create(self):
|
||||
template_output = self._create_audit_template()
|
||||
action_plan = self.watcher(
|
||||
'actionplan create -a %s' % template_output['Name'])
|
||||
self.audit_uuid = self.parse_show_as_object(action_plan)['UUID']
|
||||
self.assert_table_structure([action_plan], self.detailed_list_fields)
|
||||
self._delete_action_plan()
|
||||
self._delete_audit()
|
||||
self._delete_audit_template()
|
||||
|
||||
@@ -30,7 +30,7 @@ class AuditTests(base.TestCase):
|
||||
detailed_list_fields = list_fields + ['Created At', 'Updated At',
|
||||
'Deleted At', 'Parameters',
|
||||
'Interval', 'Audit Scope',
|
||||
'Next Run Time']
|
||||
'Next Run Time', 'Hostname']
|
||||
audit_template_name = 'a' + uuidutils.generate_uuid()
|
||||
audit_uuid = None
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ ACTION_PLAN2 = {
|
||||
UPDATED_ACTION_PLAN = copy.deepcopy(ACTION_PLAN1)
|
||||
NEW_STATE = 'PENDING'
|
||||
UPDATED_ACTION_PLAN['state'] = NEW_STATE
|
||||
START_ACTION_PLAN = copy.deepcopy(ACTION_PLAN1)
|
||||
START_ACTION_PLAN['state'] = NEW_STATE
|
||||
|
||||
fake_responses = {
|
||||
'/v1/action_plans':
|
||||
@@ -69,6 +71,13 @@ fake_responses = {
|
||||
UPDATED_ACTION_PLAN,
|
||||
),
|
||||
},
|
||||
'/v1/action_plans/%s/start' % ACTION_PLAN1['uuid']:
|
||||
{
|
||||
'POST': (
|
||||
{},
|
||||
START_ACTION_PLAN,
|
||||
),
|
||||
},
|
||||
'/v1/action_plans/detail?uuid=%s' % ACTION_PLAN1['uuid']:
|
||||
{
|
||||
'GET': (
|
||||
@@ -220,3 +229,10 @@ class ActionPlanManagerTest(testtools.TestCase):
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_STATE, action_plan.state)
|
||||
|
||||
def test_action_plan_start(self):
|
||||
action_plan = self.mgr.start(ACTION_PLAN1['uuid'])
|
||||
expect = [('POST', '/v1/action_plans/%s/start'
|
||||
% ACTION_PLAN1['uuid'], {}, {})]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_STATE, action_plan.state)
|
||||
|
||||
@@ -44,6 +44,7 @@ ACTION_PLAN_1 = {
|
||||
"description": "Dummy Global Efficacy2"}
|
||||
],
|
||||
'deleted_at': None,
|
||||
'hostname': ''
|
||||
}
|
||||
|
||||
ACTION_PLAN_2 = {
|
||||
@@ -63,6 +64,7 @@ ACTION_PLAN_2 = {
|
||||
"description": "Dummy Global Efficacy",
|
||||
}],
|
||||
'deleted_at': None,
|
||||
'hostname': ''
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ AUDIT_1 = {
|
||||
'auto_trigger': False,
|
||||
'next_run_time': None,
|
||||
'name': 'my_audit1',
|
||||
'hostname': '',
|
||||
}
|
||||
|
||||
AUDIT_2 = {
|
||||
@@ -88,6 +89,7 @@ AUDIT_2 = {
|
||||
'auto_trigger': False,
|
||||
'next_run_time': None,
|
||||
'name': 'my_audit2',
|
||||
'hostname': '',
|
||||
}
|
||||
|
||||
AUDIT_3 = {
|
||||
@@ -107,6 +109,7 @@ AUDIT_3 = {
|
||||
'auto_trigger': True,
|
||||
'next_run_time': None,
|
||||
'name': 'my_audit3',
|
||||
'hostname': '',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,13 @@ class ActionPlanManager(base.Manager):
|
||||
resource_class = ActionPlan
|
||||
|
||||
@staticmethod
|
||||
def _path(id=None):
|
||||
return '/v1/action_plans/%s' % id if id else '/v1/action_plans'
|
||||
def _path(id=None, q_param=None):
|
||||
if id and q_param:
|
||||
return '/v1/action_plans/%s/%s' % (id, q_param)
|
||||
elif id:
|
||||
return '/v1/action_plans/%s' % id
|
||||
else:
|
||||
return '/v1/action_plans'
|
||||
|
||||
def list(self, audit=None, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False, marker=None):
|
||||
@@ -90,8 +95,7 @@ class ActionPlanManager(base.Manager):
|
||||
return self._update(self._path(action_plan_id), patch)
|
||||
|
||||
def start(self, action_plan_id):
|
||||
patch = [{'op': 'replace', 'value': 'PENDING', 'path': '/state'}]
|
||||
return self._update(self._path(action_plan_id), patch)
|
||||
return self._start(self._path(action_plan_id, 'start'))
|
||||
|
||||
def cancel(self, action_plan_id):
|
||||
action_plan = self.get(action_plan_id)
|
||||
|
||||
@@ -200,47 +200,6 @@ class ListActionPlan(command.Lister):
|
||||
(utils.get_item_properties(item, fields) for item in data))
|
||||
|
||||
|
||||
class CreateActionPlan(command.ShowOne):
|
||||
"""Create new audit."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateActionPlan, 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(
|
||||
'-t', '--audit_type',
|
||||
dest='audit_type',
|
||||
metavar='<audit_type>',
|
||||
default='ONESHOT',
|
||||
choices=['ONESHOT', 'CONTINUOUS'],
|
||||
help=_("Audit type. It must be ONESHOT or CONTINUOUS. "
|
||||
"Default is ONESHOT."))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = getattr(self.app.client_manager, "infra-optim")
|
||||
|
||||
field_list = ['audit_template_uuid', 'audit_type']
|
||||
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'):
|
||||
if not uuidutils.is_uuid_like(fields['audit_template_uuid']):
|
||||
fields['audit_template_uuid'] = client.audit_template.get(
|
||||
fields['audit_template_uuid']).uuid
|
||||
|
||||
audit = client.audit.create(**fields)
|
||||
|
||||
columns = res_fields.ACTION_PLAN_FIELDS
|
||||
column_headers = res_fields.ACTION_PLAN_FIELD_LABELS
|
||||
|
||||
return column_headers, utils.get_item_properties(audit, columns)
|
||||
|
||||
|
||||
class UpdateActionPlan(command.ShowOne):
|
||||
"""Update action plan command."""
|
||||
|
||||
|
||||
@@ -32,12 +32,13 @@ AUDIT_TEMPLATE_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Goal', 'Strategy']
|
||||
# Audit
|
||||
AUDIT_FIELDS = ['uuid', 'name', 'created_at', 'updated_at', 'deleted_at',
|
||||
'state', 'audit_type', 'parameters', 'interval', 'goal_name',
|
||||
'strategy_name', 'scope', 'auto_trigger', 'next_run_time']
|
||||
'strategy_name', 'scope', 'auto_trigger', 'next_run_time',
|
||||
'hostname']
|
||||
|
||||
AUDIT_FIELD_LABELS = ['UUID', 'Name', 'Created At', 'Updated At', 'Deleted At',
|
||||
'State', 'Audit Type', 'Parameters', 'Interval', 'Goal',
|
||||
'Strategy', 'Audit Scope', 'Auto Trigger',
|
||||
'Next Run Time']
|
||||
'Next Run Time', 'Hostname']
|
||||
|
||||
AUDIT_SHORT_LIST_FIELDS = ['uuid', 'name', 'audit_type',
|
||||
'state', 'goal_name', 'strategy_name',
|
||||
@@ -49,11 +50,12 @@ AUDIT_SHORT_LIST_FIELD_LABELS = ['UUID', 'Name', 'Audit Type', 'State', 'Goal',
|
||||
# Action Plan
|
||||
ACTION_PLAN_FIELDS = ['uuid', 'created_at', 'updated_at', 'deleted_at',
|
||||
'audit_uuid', 'strategy_name', 'state',
|
||||
'efficacy_indicators', 'global_efficacy']
|
||||
'efficacy_indicators', 'global_efficacy', 'hostname']
|
||||
|
||||
ACTION_PLAN_FIELD_LABELS = ['UUID', 'Created At', 'Updated At', 'Deleted At',
|
||||
'Audit', 'Strategy', 'State',
|
||||
'Efficacy indicators', 'Global efficacy']
|
||||
'Efficacy indicators', 'Global efficacy',
|
||||
'Hostname']
|
||||
|
||||
ACTION_PLAN_SHORT_LIST_FIELDS = ['uuid', 'audit_uuid', 'state',
|
||||
'updated_at', 'global_efficacy']
|
||||
|
||||
Reference in New Issue
Block a user