Removed deadline, version, extra & host_aggregate
As we are about to version the Watcher objects, we need to make sure that upcoming model/object modifications are additive in order to avoid having to bump the major version of the API. Therefore, this changeset removes 4 unused DB fields that were exposed in their associated Watcher objects (i.e. AuditTemplate and Audit). Change-Id: Ifb0783f21cd66db16b31e3c8e376fc9d6c07dea3 Partially-Implements: blueprint watcher-versioned-objects
This commit is contained in:
parent
750e6bf213
commit
ed95d621f4
@ -4,7 +4,7 @@ actor Administrator
|
|||||||
|
|
||||||
== Create some Audit settings ==
|
== Create some Audit settings ==
|
||||||
|
|
||||||
Administrator -> Watcher : create new Audit Template (i.e. Audit settings : goal, scope, deadline,...)
|
Administrator -> Watcher : create new Audit Template (i.e. Audit settings : goal, scope, ...)
|
||||||
Watcher -> Watcher : save Audit Template in database
|
Watcher -> Watcher : save Audit Template in database
|
||||||
Administrator <-- Watcher : Audit Template UUID
|
Administrator <-- Watcher : Audit Template UUID
|
||||||
|
|
||||||
|
@ -41,9 +41,7 @@ table(audit_templates) {
|
|||||||
uuid : String[36]
|
uuid : String[36]
|
||||||
name : String[63], nullable
|
name : String[63], nullable
|
||||||
description : String[255], nullable
|
description : String[255], nullable
|
||||||
host_aggregate : Integer, nullable
|
scope : JSONEncodedList
|
||||||
extra : JSONEncodedDict
|
|
||||||
version : String[15], nullable
|
|
||||||
|
|
||||||
created_at : DateTime
|
created_at : DateTime
|
||||||
updated_at : DateTime
|
updated_at : DateTime
|
||||||
@ -59,10 +57,9 @@ table(audits) {
|
|||||||
uuid : String[36]
|
uuid : String[36]
|
||||||
audit_type : String[20]
|
audit_type : String[20]
|
||||||
state : String[20], nullable
|
state : String[20], nullable
|
||||||
deadline : DateTime, nullable
|
|
||||||
interval : Integer, nullable
|
interval : Integer, nullable
|
||||||
parameters : JSONEncodedDict, nullable
|
parameters : JSONEncodedDict, nullable
|
||||||
host_aggregate : Integer, nullable
|
scope : JSONEncodedList, nullable
|
||||||
|
|
||||||
created_at : DateTime
|
created_at : DateTime
|
||||||
updated_at : DateTime
|
updated_at : DateTime
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 45 KiB |
Binary file not shown.
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 72 KiB |
@ -54,16 +54,12 @@ class AuditPostType(wtypes.Base):
|
|||||||
|
|
||||||
audit_template_uuid = wtypes.wsattr(types.uuid, mandatory=False)
|
audit_template_uuid = wtypes.wsattr(types.uuid, mandatory=False)
|
||||||
|
|
||||||
scope = wtypes.wsattr(types.jsontype, readonly=True)
|
|
||||||
|
|
||||||
goal = wtypes.wsattr(wtypes.text, mandatory=False)
|
goal = wtypes.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
strategy = wtypes.wsattr(wtypes.text, mandatory=False)
|
strategy = wtypes.wsattr(wtypes.text, mandatory=False)
|
||||||
|
|
||||||
audit_type = wtypes.wsattr(wtypes.text, mandatory=True)
|
audit_type = wtypes.wsattr(wtypes.text, mandatory=True)
|
||||||
|
|
||||||
deadline = wtypes.wsattr(datetime.datetime, mandatory=False)
|
|
||||||
|
|
||||||
state = wsme.wsattr(wtypes.text, readonly=True,
|
state = wsme.wsattr(wtypes.text, readonly=True,
|
||||||
default=objects.audit.State.PENDING)
|
default=objects.audit.State.PENDING)
|
||||||
|
|
||||||
@ -71,6 +67,8 @@ class AuditPostType(wtypes.Base):
|
|||||||
default={})
|
default={})
|
||||||
interval = wsme.wsattr(int, mandatory=False)
|
interval = wsme.wsattr(int, mandatory=False)
|
||||||
|
|
||||||
|
scope = wtypes.wsattr(types.jsontype, readonly=True)
|
||||||
|
|
||||||
def as_audit(self, context):
|
def as_audit(self, context):
|
||||||
audit_type_values = [val.value for val in objects.audit.AuditType]
|
audit_type_values = [val.value for val in objects.audit.AuditType]
|
||||||
if self.audit_type not in audit_type_values:
|
if self.audit_type not in audit_type_values:
|
||||||
@ -81,7 +79,7 @@ class AuditPostType(wtypes.Base):
|
|||||||
raise exception.AuditIntervalNotAllowed(audit_type=self.audit_type)
|
raise exception.AuditIntervalNotAllowed(audit_type=self.audit_type)
|
||||||
|
|
||||||
if (self.audit_type == objects.audit.AuditType.CONTINUOUS.value and
|
if (self.audit_type == objects.audit.AuditType.CONTINUOUS.value and
|
||||||
self.interval in (wtypes.Unset, None)):
|
self.interval in (wtypes.Unset, None)):
|
||||||
raise exception.AuditIntervalNotSpecified(
|
raise exception.AuditIntervalNotSpecified(
|
||||||
audit_type=self.audit_type)
|
audit_type=self.audit_type)
|
||||||
|
|
||||||
@ -113,7 +111,6 @@ class AuditPostType(wtypes.Base):
|
|||||||
pass
|
pass
|
||||||
return Audit(
|
return Audit(
|
||||||
audit_type=self.audit_type,
|
audit_type=self.audit_type,
|
||||||
deadline=self.deadline,
|
|
||||||
parameters=self.parameters,
|
parameters=self.parameters,
|
||||||
goal_id=self.goal,
|
goal_id=self.goal,
|
||||||
strategy_id=self.strategy,
|
strategy_id=self.strategy,
|
||||||
@ -229,9 +226,6 @@ class Audit(base.APIBase):
|
|||||||
audit_type = wtypes.text
|
audit_type = wtypes.text
|
||||||
"""Type of this audit"""
|
"""Type of this audit"""
|
||||||
|
|
||||||
deadline = datetime.datetime
|
|
||||||
"""deadline of the audit"""
|
|
||||||
|
|
||||||
state = wtypes.text
|
state = wtypes.text
|
||||||
"""This audit state"""
|
"""This audit state"""
|
||||||
|
|
||||||
@ -291,8 +285,8 @@ class Audit(base.APIBase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _convert_with_links(audit, url, expand=True):
|
def _convert_with_links(audit, url, expand=True):
|
||||||
if not expand:
|
if not expand:
|
||||||
audit.unset_fields_except(['uuid', 'audit_type', 'deadline',
|
audit.unset_fields_except(['uuid', 'audit_type', 'state',
|
||||||
'state', 'goal_uuid', 'interval',
|
'goal_uuid', 'interval', 'scope',
|
||||||
'strategy_uuid', 'goal_name',
|
'strategy_uuid', 'goal_name',
|
||||||
'strategy_name'])
|
'strategy_name'])
|
||||||
|
|
||||||
@ -315,7 +309,6 @@ class Audit(base.APIBase):
|
|||||||
sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
|
sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
|
||||||
audit_type='ONESHOT',
|
audit_type='ONESHOT',
|
||||||
state='PENDING',
|
state='PENDING',
|
||||||
deadline=None,
|
|
||||||
created_at=datetime.datetime.utcnow(),
|
created_at=datetime.datetime.utcnow(),
|
||||||
deleted_at=None,
|
deleted_at=None,
|
||||||
updated_at=datetime.datetime.utcnow(),
|
updated_at=datetime.datetime.utcnow(),
|
||||||
@ -324,6 +317,7 @@ class Audit(base.APIBase):
|
|||||||
|
|
||||||
sample.goal_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ae'
|
sample.goal_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ae'
|
||||||
sample.strategy_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ff'
|
sample.strategy_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ff'
|
||||||
|
|
||||||
return cls._convert_with_links(sample, 'http://localhost:9322', expand)
|
return cls._convert_with_links(sample, 'http://localhost:9322', expand)
|
||||||
|
|
||||||
|
|
||||||
@ -423,16 +417,14 @@ class AuditsController(rest.RestController):
|
|||||||
|
|
||||||
@wsme_pecan.wsexpose(AuditCollection, types.uuid, int, wtypes.text,
|
@wsme_pecan.wsexpose(AuditCollection, types.uuid, int, wtypes.text,
|
||||||
wtypes.text, wtypes.text, wtypes.text, int)
|
wtypes.text, wtypes.text, wtypes.text, int)
|
||||||
def get_all(self, marker=None, limit=None,
|
def get_all(self, marker=None, limit=None, sort_key='id', sort_dir='asc',
|
||||||
sort_key='id', sort_dir='asc', goal=None,
|
goal=None, strategy=None):
|
||||||
strategy=None):
|
|
||||||
"""Retrieve a list of audits.
|
"""Retrieve a list of audits.
|
||||||
|
|
||||||
:param marker: pagination marker for large data sets.
|
:param marker: pagination marker for large data sets.
|
||||||
:param limit: maximum number of resources to return in a single result.
|
:param limit: maximum number of resources to return in a single result.
|
||||||
:param sort_key: column to sort results by. Default: id.
|
:param sort_key: column to sort results by. Default: id.
|
||||||
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
|
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
|
||||||
id.
|
|
||||||
:param goal: goal UUID or name to filter by
|
:param goal: goal UUID or name to filter by
|
||||||
:param strategy: strategy UUID or name to filter by
|
:param strategy: strategy UUID or name to filter by
|
||||||
"""
|
"""
|
||||||
|
@ -41,11 +41,6 @@ settings related to the level of automation for the
|
|||||||
A flag will indicate whether the :ref:`Action Plan <action_plan_definition>`
|
A flag will indicate whether the :ref:`Action Plan <action_plan_definition>`
|
||||||
will be launched automatically or will need a manual confirmation from the
|
will be launched automatically or will need a manual confirmation from the
|
||||||
:ref:`Administrator <administrator_definition>`.
|
:ref:`Administrator <administrator_definition>`.
|
||||||
|
|
||||||
Last but not least, an :ref:`Audit Template <audit_template_definition>` may
|
|
||||||
contain a list of extra parameters related to the
|
|
||||||
:ref:`Strategy <strategy_definition>` configuration. These parameters can be
|
|
||||||
provided as a list of key-value pairs.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -79,21 +74,12 @@ class AuditTemplatePostType(wtypes.Base):
|
|||||||
description = wtypes.wsattr(wtypes.text, mandatory=False)
|
description = wtypes.wsattr(wtypes.text, mandatory=False)
|
||||||
"""Short description of this audit template"""
|
"""Short description of this audit template"""
|
||||||
|
|
||||||
deadline = wsme.wsattr(datetime.datetime, mandatory=False)
|
|
||||||
"""deadline of the audit template"""
|
|
||||||
|
|
||||||
extra = wtypes.wsattr({wtypes.text: types.jsontype}, mandatory=False)
|
|
||||||
"""The metadata of the audit template"""
|
|
||||||
|
|
||||||
goal = wtypes.wsattr(wtypes.text, mandatory=True)
|
goal = wtypes.wsattr(wtypes.text, mandatory=True)
|
||||||
"""Goal UUID or name of the audit template"""
|
"""Goal UUID or name of the audit template"""
|
||||||
|
|
||||||
strategy = wtypes.wsattr(wtypes.text, mandatory=False)
|
strategy = wtypes.wsattr(wtypes.text, mandatory=False)
|
||||||
"""Strategy UUID or name of the audit template"""
|
"""Strategy UUID or name of the audit template"""
|
||||||
|
|
||||||
version = wtypes.text
|
|
||||||
"""Internal version of the audit template"""
|
|
||||||
|
|
||||||
scope = wtypes.wsattr(types.jsontype, mandatory=False, default=[])
|
scope = wtypes.wsattr(types.jsontype, mandatory=False, default=[])
|
||||||
"""Audit Scope"""
|
"""Audit Scope"""
|
||||||
|
|
||||||
@ -101,13 +87,10 @@ class AuditTemplatePostType(wtypes.Base):
|
|||||||
return AuditTemplate(
|
return AuditTemplate(
|
||||||
name=self.name,
|
name=self.name,
|
||||||
description=self.description,
|
description=self.description,
|
||||||
deadline=self.deadline,
|
|
||||||
extra=self.extra,
|
|
||||||
goal_id=self.goal, # Dirty trick ...
|
goal_id=self.goal, # Dirty trick ...
|
||||||
goal=self.goal,
|
goal=self.goal,
|
||||||
strategy_id=self.strategy, # Dirty trick ...
|
strategy_id=self.strategy, # Dirty trick ...
|
||||||
strategy_uuid=self.strategy,
|
strategy_uuid=self.strategy,
|
||||||
version=self.version,
|
|
||||||
scope=self.scope,
|
scope=self.scope,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -308,15 +291,9 @@ class AuditTemplate(base.APIBase):
|
|||||||
name = wtypes.text
|
name = wtypes.text
|
||||||
"""Name of this audit template"""
|
"""Name of this audit template"""
|
||||||
|
|
||||||
description = wtypes.text
|
description = wtypes.wsattr(wtypes.text, mandatory=False)
|
||||||
"""Short description of this audit template"""
|
"""Short description of this audit template"""
|
||||||
|
|
||||||
deadline = datetime.datetime
|
|
||||||
"""deadline of the audit template"""
|
|
||||||
|
|
||||||
extra = {wtypes.text: types.jsontype}
|
|
||||||
"""The metadata of the audit template"""
|
|
||||||
|
|
||||||
goal_uuid = wsme.wsproperty(
|
goal_uuid = wsme.wsproperty(
|
||||||
wtypes.text, _get_goal_uuid, _set_goal_uuid, mandatory=True)
|
wtypes.text, _get_goal_uuid, _set_goal_uuid, mandatory=True)
|
||||||
"""Goal UUID the audit template refers to"""
|
"""Goal UUID the audit template refers to"""
|
||||||
@ -333,9 +310,6 @@ class AuditTemplate(base.APIBase):
|
|||||||
wtypes.text, _get_strategy_name, _set_strategy_name, mandatory=False)
|
wtypes.text, _get_strategy_name, _set_strategy_name, mandatory=False)
|
||||||
"""The name of the strategy this audit template refers to"""
|
"""The name of the strategy this audit template refers to"""
|
||||||
|
|
||||||
version = wtypes.text
|
|
||||||
"""Internal version of the audit template"""
|
|
||||||
|
|
||||||
audits = wsme.wsattr([link.Link], readonly=True)
|
audits = wsme.wsattr([link.Link], readonly=True)
|
||||||
"""Links to the collection of audits contained in this audit template"""
|
"""Links to the collection of audits contained in this audit template"""
|
||||||
|
|
||||||
@ -378,7 +352,7 @@ class AuditTemplate(base.APIBase):
|
|||||||
if not expand:
|
if not expand:
|
||||||
audit_template.unset_fields_except(
|
audit_template.unset_fields_except(
|
||||||
['uuid', 'name', 'goal_uuid', 'goal_name',
|
['uuid', 'name', 'goal_uuid', 'goal_name',
|
||||||
'strategy_uuid', 'strategy_name'])
|
'scope', 'strategy_uuid', 'strategy_name'])
|
||||||
|
|
||||||
# The numeric ID should not be exposed to
|
# The numeric ID should not be exposed to
|
||||||
# the user, it's internal only.
|
# the user, it's internal only.
|
||||||
@ -407,7 +381,6 @@ class AuditTemplate(base.APIBase):
|
|||||||
description='Description of my audit template',
|
description='Description of my audit template',
|
||||||
goal_uuid='83e44733-b640-40e2-8d8a-7dd3be7134e6',
|
goal_uuid='83e44733-b640-40e2-8d8a-7dd3be7134e6',
|
||||||
strategy_uuid='367d826e-b6a4-4b70-bc44-c3f6fe1c9986',
|
strategy_uuid='367d826e-b6a4-4b70-bc44-c3f6fe1c9986',
|
||||||
extra={'automatic': True},
|
|
||||||
created_at=datetime.datetime.utcnow(),
|
created_at=datetime.datetime.utcnow(),
|
||||||
deleted_at=None,
|
deleted_at=None,
|
||||||
updated_at=datetime.datetime.utcnow(),
|
updated_at=datetime.datetime.utcnow(),
|
||||||
|
@ -275,7 +275,6 @@ class BaseConnection(object):
|
|||||||
'name': 'example',
|
'name': 'example',
|
||||||
'description': 'free text description'
|
'description': 'free text description'
|
||||||
'goal': 'DUMMY'
|
'goal': 'DUMMY'
|
||||||
'extra': {'automatic': True}
|
|
||||||
}
|
}
|
||||||
:returns: An audit template.
|
:returns: An audit template.
|
||||||
:raises: :py:class:`~.AuditTemplateAlreadyExists`
|
:raises: :py:class:`~.AuditTemplateAlreadyExists`
|
||||||
@ -375,7 +374,6 @@ class BaseConnection(object):
|
|||||||
{
|
{
|
||||||
'uuid': utils.generate_uuid(),
|
'uuid': utils.generate_uuid(),
|
||||||
'type': 'ONESHOT',
|
'type': 'ONESHOT',
|
||||||
'deadline': None
|
|
||||||
}
|
}
|
||||||
:returns: An audit.
|
:returns: An audit.
|
||||||
:raises: :py:class:`~.AuditAlreadyExists`
|
:raises: :py:class:`~.AuditAlreadyExists`
|
||||||
|
@ -165,8 +165,6 @@ class AuditTemplate(Base):
|
|||||||
description = Column(String(255), nullable=True)
|
description = Column(String(255), nullable=True)
|
||||||
goal_id = Column(Integer, ForeignKey('goals.id'), nullable=False)
|
goal_id = Column(Integer, ForeignKey('goals.id'), nullable=False)
|
||||||
strategy_id = Column(Integer, ForeignKey('strategies.id'), nullable=True)
|
strategy_id = Column(Integer, ForeignKey('strategies.id'), nullable=True)
|
||||||
extra = Column(JSONEncodedDict)
|
|
||||||
version = Column(String(15), nullable=True)
|
|
||||||
scope = Column(JSONEncodedList)
|
scope = Column(JSONEncodedList)
|
||||||
|
|
||||||
goal = orm.relationship(Goal, foreign_keys=goal_id, lazy=None)
|
goal = orm.relationship(Goal, foreign_keys=goal_id, lazy=None)
|
||||||
@ -185,7 +183,6 @@ class Audit(Base):
|
|||||||
uuid = Column(String(36))
|
uuid = Column(String(36))
|
||||||
audit_type = Column(String(20))
|
audit_type = Column(String(20))
|
||||||
state = Column(String(20), nullable=True)
|
state = Column(String(20), nullable=True)
|
||||||
deadline = Column(DateTime, nullable=True)
|
|
||||||
parameters = Column(JSONEncodedDict, nullable=True)
|
parameters = Column(JSONEncodedDict, nullable=True)
|
||||||
interval = Column(Integer, nullable=True)
|
interval = Column(Integer, nullable=True)
|
||||||
goal_id = Column(Integer, ForeignKey('goals.id'), nullable=False)
|
goal_id = Column(Integer, ForeignKey('goals.id'), nullable=False)
|
||||||
|
@ -83,7 +83,6 @@ class Audit(base.WatcherObject):
|
|||||||
'uuid': obj_utils.str_or_none,
|
'uuid': obj_utils.str_or_none,
|
||||||
'audit_type': obj_utils.str_or_none,
|
'audit_type': obj_utils.str_or_none,
|
||||||
'state': obj_utils.str_or_none,
|
'state': obj_utils.str_or_none,
|
||||||
'deadline': obj_utils.datetime_or_str_or_none,
|
|
||||||
'parameters': obj_utils.dict_or_none,
|
'parameters': obj_utils.dict_or_none,
|
||||||
'interval': obj_utils.int_or_none,
|
'interval': obj_utils.int_or_none,
|
||||||
'goal_id': obj_utils.int_or_none,
|
'goal_id': obj_utils.int_or_none,
|
||||||
|
@ -67,8 +67,6 @@ class AuditTemplate(base.WatcherObject):
|
|||||||
'description': obj_utils.str_or_none,
|
'description': obj_utils.str_or_none,
|
||||||
'goal_id': obj_utils.int_or_none,
|
'goal_id': obj_utils.int_or_none,
|
||||||
'strategy_id': obj_utils.int_or_none,
|
'strategy_id': obj_utils.int_or_none,
|
||||||
'extra': obj_utils.dict_or_none,
|
|
||||||
'version': obj_utils.str_or_none,
|
|
||||||
'scope': obj_utils.list_or_none,
|
'scope': obj_utils.list_or_none,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class TestListAudit(api_base.FunctionalTest):
|
|||||||
self.assertEqual([], response['audits'])
|
self.assertEqual([], response['audits'])
|
||||||
|
|
||||||
def _assert_audit_fields(self, audit):
|
def _assert_audit_fields(self, audit):
|
||||||
audit_fields = ['audit_type', 'deadline', 'state', 'goal_uuid',
|
audit_fields = ['audit_type', 'scope', 'state', 'goal_uuid',
|
||||||
'strategy_uuid']
|
'strategy_uuid']
|
||||||
for field in audit_fields:
|
for field in audit_fields:
|
||||||
self.assertIn(field, audit)
|
self.assertIn(field, audit)
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
"""Tests for custom SQLAlchemy types via Magnum DB."""
|
|
||||||
|
|
||||||
from oslo_db import exception as db_exc
|
|
||||||
|
|
||||||
from watcher.common import utils as w_utils
|
|
||||||
from watcher.db import api as dbapi
|
|
||||||
import watcher.db.sqlalchemy.api as sa_api
|
|
||||||
from watcher.db.sqlalchemy import models
|
|
||||||
from watcher.tests.db import base
|
|
||||||
|
|
||||||
|
|
||||||
class SqlAlchemyCustomTypesTestCase(base.DbTestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(SqlAlchemyCustomTypesTestCase, self).setUp()
|
|
||||||
self.dbapi = dbapi.get_instance()
|
|
||||||
|
|
||||||
def test_JSONEncodedDict_default_value(self):
|
|
||||||
# Create audit_template w/o extra
|
|
||||||
audit_template1_id = w_utils.generate_uuid()
|
|
||||||
self.dbapi.create_audit_template({'uuid': audit_template1_id,
|
|
||||||
'goal_id': "DUMMY"})
|
|
||||||
audit_template1 = sa_api.model_query(models.AuditTemplate) \
|
|
||||||
.filter_by(uuid=audit_template1_id).one()
|
|
||||||
self.assertEqual({}, audit_template1.extra)
|
|
||||||
|
|
||||||
def test_JSONEncodedDict_extra_value(self):
|
|
||||||
# Create audit_template with extra
|
|
||||||
audit_template2_id = w_utils.generate_uuid()
|
|
||||||
self.dbapi.create_audit_template({'uuid': audit_template2_id,
|
|
||||||
'goal_id': "DUMMY",
|
|
||||||
'extra': {'bar': 'foo'}})
|
|
||||||
audit_template2 = sa_api.model_query(models.AuditTemplate) \
|
|
||||||
.filter_by(uuid=audit_template2_id).one()
|
|
||||||
self.assertEqual('foo', audit_template2.extra['bar'])
|
|
||||||
|
|
||||||
def test_JSONEncodedDict_type_check(self):
|
|
||||||
self.assertRaises(db_exc.DBError,
|
|
||||||
self.dbapi.create_audit_template,
|
|
||||||
{'extra': ['this is not a dict']})
|
|
@ -278,7 +278,6 @@ class DbActionPlanTestCase(base.DbTestCase):
|
|||||||
id=2,
|
id=2,
|
||||||
audit_type='ONESHOT',
|
audit_type='ONESHOT',
|
||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
deadline=None,
|
|
||||||
state=ap_objects.State.ONGOING)
|
state=ap_objects.State.ONGOING)
|
||||||
action_plan1 = self._create_test_action_plan(
|
action_plan1 = self._create_test_action_plan(
|
||||||
id=1,
|
id=1,
|
||||||
|
@ -291,13 +291,11 @@ class DbAuditTestCase(base.DbTestCase):
|
|||||||
id=1,
|
id=1,
|
||||||
audit_type=objects.audit.AuditType.ONESHOT.value,
|
audit_type=objects.audit.AuditType.ONESHOT.value,
|
||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
deadline=None,
|
|
||||||
state=objects.audit.State.ONGOING)
|
state=objects.audit.State.ONGOING)
|
||||||
audit2 = self._create_test_audit(
|
audit2 = self._create_test_audit(
|
||||||
id=2,
|
id=2,
|
||||||
audit_type='CONTINUOUS',
|
audit_type='CONTINUOUS',
|
||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
deadline=None,
|
|
||||||
state=objects.audit.State.PENDING)
|
state=objects.audit.State.PENDING)
|
||||||
|
|
||||||
res = self.dbapi.get_audit_list(
|
res = self.dbapi.get_audit_list(
|
||||||
|
@ -273,15 +273,21 @@ class DbAuditTemplateTestCase(base.DbTestCase):
|
|||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
name='My Audit Template 1',
|
name='My Audit Template 1',
|
||||||
description='Description of my audit template 1',
|
description='Description of my audit template 1',
|
||||||
goal='DUMMY',
|
goal='DUMMY')
|
||||||
extra={'automatic': True})
|
|
||||||
audit_template2 = self._create_test_audit_template(
|
audit_template2 = self._create_test_audit_template(
|
||||||
id=2,
|
id=2,
|
||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
name='My Audit Template 2',
|
name='My Audit Template 2',
|
||||||
description='Description of my audit template 2',
|
description='Description of my audit template 2',
|
||||||
goal='DUMMY',
|
goal='DUMMY')
|
||||||
extra={'automatic': True})
|
|
||||||
|
res = self.dbapi.get_audit_template_list(
|
||||||
|
self.context, filters={'name': 'My Audit Template 1'})
|
||||||
|
self.assertEqual([audit_template1['id']], [r.id for r in res])
|
||||||
|
|
||||||
|
res = self.dbapi.get_audit_template_list(
|
||||||
|
self.context, filters={'name': 'Does not exist'})
|
||||||
|
self.assertEqual([], [r.id for r in res])
|
||||||
|
|
||||||
res = self.dbapi.get_audit_template_list(
|
res = self.dbapi.get_audit_template_list(
|
||||||
self.context,
|
self.context,
|
||||||
|
@ -28,12 +28,10 @@ def get_test_audit_template(**kwargs):
|
|||||||
'strategy_id': kwargs.get('strategy_id', None),
|
'strategy_id': kwargs.get('strategy_id', None),
|
||||||
'name': kwargs.get('name', 'My Audit Template'),
|
'name': kwargs.get('name', 'My Audit Template'),
|
||||||
'description': kwargs.get('description', 'Desc. Of My Audit Template'),
|
'description': kwargs.get('description', 'Desc. Of My Audit Template'),
|
||||||
'extra': kwargs.get('extra', {'automatic': False}),
|
'scope': kwargs.get('scope', []),
|
||||||
'version': kwargs.get('version', 'v1'),
|
|
||||||
'created_at': kwargs.get('created_at'),
|
'created_at': kwargs.get('created_at'),
|
||||||
'updated_at': kwargs.get('updated_at'),
|
'updated_at': kwargs.get('updated_at'),
|
||||||
'deleted_at': kwargs.get('deleted_at'),
|
'deleted_at': kwargs.get('deleted_at'),
|
||||||
'scope': kwargs.get('scope', []),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +57,6 @@ def get_test_audit(**kwargs):
|
|||||||
'uuid': kwargs.get('uuid', '10a47dd1-4874-4298-91cf-eff046dbdb8d'),
|
'uuid': kwargs.get('uuid', '10a47dd1-4874-4298-91cf-eff046dbdb8d'),
|
||||||
'audit_type': kwargs.get('audit_type', 'ONESHOT'),
|
'audit_type': kwargs.get('audit_type', 'ONESHOT'),
|
||||||
'state': kwargs.get('state'),
|
'state': kwargs.get('state'),
|
||||||
'deadline': kwargs.get('deadline'),
|
|
||||||
'created_at': kwargs.get('created_at'),
|
'created_at': kwargs.get('created_at'),
|
||||||
'updated_at': kwargs.get('updated_at'),
|
'updated_at': kwargs.get('updated_at'),
|
||||||
'deleted_at': kwargs.get('deleted_at'),
|
'deleted_at': kwargs.get('deleted_at'),
|
||||||
|
@ -62,7 +62,7 @@ class InfraOptimClientJSON(base.BaseInfraOptimClient):
|
|||||||
:param description: The description of the audit template.
|
:param description: The description of the audit template.
|
||||||
:param goal_uuid: The related Goal UUID associated.
|
:param goal_uuid: The related Goal UUID associated.
|
||||||
:param strategy_uuid: The related Strategy UUID associated.
|
:param strategy_uuid: The related Strategy UUID associated.
|
||||||
:param extra: Metadata associated to this audit template.
|
:param audit_scope: Scope the audit should apply to.
|
||||||
:return: A tuple with the server response and the created audit
|
:return: A tuple with the server response and the created audit
|
||||||
template.
|
template.
|
||||||
"""
|
"""
|
||||||
@ -76,7 +76,7 @@ class InfraOptimClientJSON(base.BaseInfraOptimClient):
|
|||||||
'description': parameters.get('description'),
|
'description': parameters.get('description'),
|
||||||
'goal': parameters.get('goal'),
|
'goal': parameters.get('goal'),
|
||||||
'strategy': parameters.get('strategy'),
|
'strategy': parameters.get('strategy'),
|
||||||
'extra': parameters.get('extra', {}),
|
'scope': parameters.get('scope', []),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self._create_request('audit_templates', audit_template)
|
return self._create_request('audit_templates', audit_template)
|
||||||
|
@ -115,21 +115,21 @@ class BaseInfraOptimTest(test.BaseTestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_audit_template(cls, goal, name=None, description=None,
|
def create_audit_template(cls, goal, name=None, description=None,
|
||||||
strategy=None, extra=None):
|
strategy=None, scope=None):
|
||||||
"""Wrapper utility for creating a test audit template
|
"""Wrapper utility for creating a test audit template
|
||||||
|
|
||||||
:param goal: Goal UUID or name related to the audit template.
|
:param goal: Goal UUID or name related to the audit template.
|
||||||
:param name: The name of the audit template. Default: My Audit Template
|
:param name: The name of the audit template. Default: My Audit Template
|
||||||
:param description: The description of the audit template.
|
:param description: The description of the audit template.
|
||||||
:param strategy: Strategy UUID or name related to the audit template.
|
:param strategy: Strategy UUID or name related to the audit template.
|
||||||
:param extra: Metadata associated to this audit template.
|
:param scope: Scope that will be applied on all derived audits.
|
||||||
:return: A tuple with The HTTP response and its body
|
:return: A tuple with The HTTP response and its body
|
||||||
"""
|
"""
|
||||||
description = description or data_utils.rand_name(
|
description = description or data_utils.rand_name(
|
||||||
'test-audit_template')
|
'test-audit_template')
|
||||||
resp, body = cls.client.create_audit_template(
|
resp, body = cls.client.create_audit_template(
|
||||||
name=name, description=description, goal=goal,
|
name=name, description=description,
|
||||||
strategy=strategy, extra=extra)
|
goal=goal, strategy=strategy, scope=scope)
|
||||||
|
|
||||||
cls.created_audit_templates.add(body['uuid'])
|
cls.created_audit_templates.add(body['uuid'])
|
||||||
|
|
||||||
@ -153,19 +153,18 @@ class BaseInfraOptimTest(test.BaseTestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_audit(cls, audit_template_uuid, audit_type='ONESHOT',
|
def create_audit(cls, audit_template_uuid, audit_type='ONESHOT',
|
||||||
state=None, deadline=None, interval=None):
|
state=None, interval=None):
|
||||||
"""Wrapper utility for creating a test audit
|
"""Wrapper utility for creating a test audit
|
||||||
|
|
||||||
:param audit_template_uuid: Audit Template UUID this audit will use
|
:param audit_template_uuid: Audit Template UUID this audit will use
|
||||||
:param type: Audit type (either ONESHOT or CONTINUOUS)
|
:param type: Audit type (either ONESHOT or CONTINUOUS)
|
||||||
:param state: Audit state (str)
|
:param state: Audit state (str)
|
||||||
:param deadline: Audit deadline (datetime)
|
|
||||||
:param interval: Audit interval in seconds (int)
|
:param interval: Audit interval in seconds (int)
|
||||||
:return: A tuple with The HTTP response and its body
|
:return: A tuple with The HTTP response and its body
|
||||||
"""
|
"""
|
||||||
resp, body = cls.client.create_audit(
|
resp, body = cls.client.create_audit(
|
||||||
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
||||||
state=state, deadline=deadline, interval=interval)
|
state=state, interval=interval)
|
||||||
|
|
||||||
cls.created_audits.add(body['uuid'])
|
cls.created_audits.add(body['uuid'])
|
||||||
cls.created_action_plans_audit_uuids.add(body['uuid'])
|
cls.created_action_plans_audit_uuids.add(body['uuid'])
|
||||||
|
@ -35,18 +35,14 @@ class TestCreateDeleteAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
params = {
|
params = {
|
||||||
'name': 'my at name %s' % uuid.uuid4(),
|
'name': 'my at name %s' % uuid.uuid4(),
|
||||||
'description': 'my at description',
|
'description': 'my at description',
|
||||||
'goal': goal['uuid'],
|
'goal': goal['uuid']}
|
||||||
'extra': {'str': 'value', 'int': 123, 'float': 0.123,
|
|
||||||
'bool': True, 'list': [1, 2, 3],
|
|
||||||
'dict': {'foo': 'bar'}}}
|
|
||||||
expected_data = {
|
expected_data = {
|
||||||
'name': params['name'],
|
'name': params['name'],
|
||||||
'description': params['description'],
|
'description': params['description'],
|
||||||
'goal_uuid': params['goal'],
|
'goal_uuid': params['goal'],
|
||||||
'goal_name': goal_name,
|
'goal_name': goal_name,
|
||||||
'strategy_uuid': None,
|
'strategy_uuid': None,
|
||||||
'strategy_name': None,
|
'strategy_name': None}
|
||||||
'extra': params['extra']}
|
|
||||||
|
|
||||||
_, body = self.create_audit_template(**params)
|
_, body = self.create_audit_template(**params)
|
||||||
self.assert_expected(expected_data, body)
|
self.assert_expected(expected_data, body)
|
||||||
@ -62,8 +58,7 @@ class TestCreateDeleteAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
params = {
|
params = {
|
||||||
'name': 'my at name %s' % uuid.uuid4(),
|
'name': 'my at name %s' % uuid.uuid4(),
|
||||||
'description': 'my àt déscrïptïôn',
|
'description': 'my àt déscrïptïôn',
|
||||||
'goal': goal['uuid'],
|
'goal': goal['uuid']}
|
||||||
'extra': {'foo': 'bar'}}
|
|
||||||
|
|
||||||
expected_data = {
|
expected_data = {
|
||||||
'name': params['name'],
|
'name': params['name'],
|
||||||
@ -71,8 +66,7 @@ class TestCreateDeleteAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
'goal_uuid': params['goal'],
|
'goal_uuid': params['goal'],
|
||||||
'goal_name': goal_name,
|
'goal_name': goal_name,
|
||||||
'strategy_uuid': None,
|
'strategy_uuid': None,
|
||||||
'strategy_name': None,
|
'strategy_name': None}
|
||||||
'extra': params['extra']}
|
|
||||||
|
|
||||||
_, body = self.create_audit_template(**params)
|
_, body = self.create_audit_template(**params)
|
||||||
self.assert_expected(expected_data, body)
|
self.assert_expected(expected_data, body)
|
||||||
@ -166,14 +160,12 @@ class TestAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
|
|
||||||
params = {'name': 'my at name %s' % uuid.uuid4(),
|
params = {'name': 'my at name %s' % uuid.uuid4(),
|
||||||
'description': 'my at description',
|
'description': 'my at description',
|
||||||
'goal': self.goal['uuid'],
|
'goal': self.goal['uuid']}
|
||||||
'extra': {'key1': 'value1', 'key2': 'value2'}}
|
|
||||||
|
|
||||||
_, body = self.create_audit_template(**params)
|
_, body = self.create_audit_template(**params)
|
||||||
|
|
||||||
new_name = 'my at new name %s' % uuid.uuid4()
|
new_name = 'my at new name %s' % uuid.uuid4()
|
||||||
new_description = 'my new at description'
|
new_description = 'my new at description'
|
||||||
new_extra = {'key1': 'new-value1', 'key2': 'new-value2'}
|
|
||||||
|
|
||||||
patch = [{'path': '/name',
|
patch = [{'path': '/name',
|
||||||
'op': 'replace',
|
'op': 'replace',
|
||||||
@ -186,13 +178,7 @@ class TestAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
'value': new_goal['uuid']},
|
'value': new_goal['uuid']},
|
||||||
{'path': '/strategy',
|
{'path': '/strategy',
|
||||||
'op': 'replace',
|
'op': 'replace',
|
||||||
'value': new_strategy['uuid']},
|
'value': new_strategy['uuid']}]
|
||||||
{'path': '/extra/key1',
|
|
||||||
'op': 'replace',
|
|
||||||
'value': new_extra['key1']},
|
|
||||||
{'path': '/extra/key2',
|
|
||||||
'op': 'replace',
|
|
||||||
'value': new_extra['key2']}]
|
|
||||||
|
|
||||||
self.client.update_audit_template(body['uuid'], patch)
|
self.client.update_audit_template(body['uuid'], patch)
|
||||||
|
|
||||||
@ -201,59 +187,40 @@ class TestAuditTemplate(base.BaseInfraOptimTest):
|
|||||||
self.assertEqual(new_description, body['description'])
|
self.assertEqual(new_description, body['description'])
|
||||||
self.assertEqual(new_goal['uuid'], body['goal_uuid'])
|
self.assertEqual(new_goal['uuid'], body['goal_uuid'])
|
||||||
self.assertEqual(new_strategy['uuid'], body['strategy_uuid'])
|
self.assertEqual(new_strategy['uuid'], body['strategy_uuid'])
|
||||||
self.assertEqual(new_extra, body['extra'])
|
|
||||||
|
|
||||||
@test.attr(type='smoke')
|
@test.attr(type='smoke')
|
||||||
def test_update_audit_template_remove(self):
|
def test_update_audit_template_remove(self):
|
||||||
extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
|
||||||
description = 'my at description'
|
description = 'my at description'
|
||||||
name = 'my at name %s' % uuid.uuid4()
|
name = 'my at name %s' % uuid.uuid4()
|
||||||
params = {'name': name,
|
params = {'name': name,
|
||||||
'description': description,
|
'description': description,
|
||||||
'goal': self.goal['uuid'],
|
'goal': self.goal['uuid']}
|
||||||
'extra': extra}
|
|
||||||
|
|
||||||
_, audit_template = self.create_audit_template(**params)
|
_, audit_template = self.create_audit_template(**params)
|
||||||
|
|
||||||
# Removing one item from the collection
|
# Removing the description
|
||||||
self.client.update_audit_template(
|
self.client.update_audit_template(
|
||||||
audit_template['uuid'],
|
audit_template['uuid'],
|
||||||
[{'path': '/extra/key2', 'op': 'remove'}])
|
[{'path': '/description', 'op': 'remove'}])
|
||||||
|
|
||||||
extra.pop('key2')
|
|
||||||
_, body = self.client.show_audit_template(audit_template['uuid'])
|
_, body = self.client.show_audit_template(audit_template['uuid'])
|
||||||
self.assertEqual(extra, body['extra'])
|
self.assertIsNone(body.get('description'))
|
||||||
|
|
||||||
# Removing the collection
|
|
||||||
self.client.update_audit_template(
|
|
||||||
audit_template['uuid'],
|
|
||||||
[{'path': '/extra', 'op': 'remove'}])
|
|
||||||
_, body = self.client.show_audit_template(audit_template['uuid'])
|
|
||||||
self.assertEqual({}, body['extra'])
|
|
||||||
|
|
||||||
# Assert nothing else was changed
|
# Assert nothing else was changed
|
||||||
self.assertEqual(name, body['name'])
|
self.assertEqual(name, body['name'])
|
||||||
self.assertEqual(description, body['description'])
|
self.assertIsNone(body['description'])
|
||||||
self.assertEqual(self.goal['uuid'], body['goal_uuid'])
|
self.assertEqual(self.goal['uuid'], body['goal_uuid'])
|
||||||
|
|
||||||
@test.attr(type='smoke')
|
@test.attr(type='smoke')
|
||||||
def test_update_audit_template_add(self):
|
def test_update_audit_template_add(self):
|
||||||
params = {'name': 'my at name %s' % uuid.uuid4(),
|
params = {'name': 'my at name %s' % uuid.uuid4(),
|
||||||
'description': 'my at description',
|
|
||||||
'goal': self.goal['uuid']}
|
'goal': self.goal['uuid']}
|
||||||
|
|
||||||
_, body = self.create_audit_template(**params)
|
_, body = self.create_audit_template(**params)
|
||||||
|
|
||||||
extra = {'key1': 'value1', 'key2': 'value2'}
|
patch = [{'path': '/description', 'op': 'add', 'value': 'description'}]
|
||||||
|
|
||||||
patch = [{'path': '/extra/key1',
|
|
||||||
'op': 'add',
|
|
||||||
'value': extra['key1']},
|
|
||||||
{'path': '/extra/key2',
|
|
||||||
'op': 'add',
|
|
||||||
'value': extra['key2']}]
|
|
||||||
|
|
||||||
self.client.update_audit_template(body['uuid'], patch)
|
self.client.update_audit_template(body['uuid'], patch)
|
||||||
|
|
||||||
_, body = self.client.show_audit_template(body['uuid'])
|
_, body = self.client.show_audit_template(body['uuid'])
|
||||||
self.assertEqual(extra, body['extra'])
|
self.assertEqual('description', body['description'])
|
||||||
|
@ -74,21 +74,19 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
|||||||
# ### AUDIT TEMPLATES ### #
|
# ### AUDIT TEMPLATES ### #
|
||||||
|
|
||||||
def create_audit_template(self, goal, name=None, description=None,
|
def create_audit_template(self, goal, name=None, description=None,
|
||||||
strategy=None, extra=None):
|
strategy=None):
|
||||||
"""Wrapper utility for creating a test audit template
|
"""Wrapper utility for creating a test audit template
|
||||||
|
|
||||||
:param goal: Goal UUID or name related to the audit template.
|
:param goal: Goal UUID or name related to the audit template.
|
||||||
:param name: The name of the audit template. Default: My Audit Template
|
:param name: The name of the audit template. Default: My Audit Template
|
||||||
:param description: The description of the audit template.
|
:param description: The description of the audit template.
|
||||||
:param strategy: Strategy UUID or name related to the audit template.
|
:param strategy: Strategy UUID or name related to the audit template.
|
||||||
:param extra: Metadata associated to this audit template.
|
|
||||||
:return: A tuple with The HTTP response and its body
|
:return: A tuple with The HTTP response and its body
|
||||||
"""
|
"""
|
||||||
description = description or data_utils.rand_name(
|
description = description or data_utils.rand_name(
|
||||||
'test-audit_template')
|
'test-audit_template')
|
||||||
resp, body = self.client.create_audit_template(
|
resp, body = self.client.create_audit_template(
|
||||||
name=name, description=description, goal=goal,
|
name=name, description=description, goal=goal, strategy=strategy)
|
||||||
strategy=strategy, extra=extra)
|
|
||||||
|
|
||||||
self.addCleanup(
|
self.addCleanup(
|
||||||
self.delete_audit_template,
|
self.delete_audit_template,
|
||||||
@ -109,7 +107,7 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
|||||||
# ### AUDITS ### #
|
# ### AUDITS ### #
|
||||||
|
|
||||||
def create_audit(self, audit_template_uuid, audit_type='ONESHOT',
|
def create_audit(self, audit_template_uuid, audit_type='ONESHOT',
|
||||||
state=None, deadline=None):
|
state=None):
|
||||||
"""Wrapper utility for creating a test audit
|
"""Wrapper utility for creating a test audit
|
||||||
|
|
||||||
:param audit_template_uuid: Audit Template UUID this audit will use
|
:param audit_template_uuid: Audit Template UUID this audit will use
|
||||||
@ -118,7 +116,7 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
|||||||
"""
|
"""
|
||||||
resp, body = self.client.create_audit(
|
resp, body = self.client.create_audit(
|
||||||
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
audit_template_uuid=audit_template_uuid, audit_type=audit_type,
|
||||||
state=state, deadline=deadline)
|
state=state)
|
||||||
|
|
||||||
self.addCleanup(self.delete_audit, audit_uuid=body["uuid"])
|
self.addCleanup(self.delete_audit, audit_uuid=body["uuid"])
|
||||||
return resp, body
|
return resp, body
|
||||||
|
Loading…
Reference in New Issue
Block a user