Add last_op property to ClusterPolicy
This property records the timestamp of last time that the policy takes effect on the cluster. Change-Id: Ia0db48943d52f6086b5f4a2ab0cf49589f90e232
This commit is contained in:
parent
8d1af2bd5a
commit
866f38a3db
@ -147,6 +147,7 @@ def upgrade(migrate_engine):
|
||||
sqlalchemy.Column('level', sqlalchemy.Integer),
|
||||
sqlalchemy.Column('enabled', sqlalchemy.Boolean),
|
||||
sqlalchemy.Column('data', types.Dict),
|
||||
sqlalchemy.Column('last_op', sqlalchemy.DateTime),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8'
|
||||
)
|
||||
|
@ -213,6 +213,7 @@ class ClusterPolicies(BASE, SenlinBase):
|
||||
level = sqlalchemy.Column(sqlalchemy.Integer)
|
||||
enabled = sqlalchemy.Column(sqlalchemy.Boolean)
|
||||
data = sqlalchemy.Column(types.Dict)
|
||||
last_op = sqlalchemy.Column(sqlalchemy.DateTime)
|
||||
|
||||
|
||||
class Profile(BASE, SenlinBase, SoftDelete):
|
||||
|
@ -36,6 +36,7 @@ class ClusterPolicy(object):
|
||||
self.level = kwargs.get('level', 50)
|
||||
self.enabled = kwargs.get('enabled', True)
|
||||
self.data = kwargs.get('data', {})
|
||||
self.last_op = kwargs.get('last_op', None)
|
||||
|
||||
# derived data from binding, put here for convenience
|
||||
self.cluster_name = kwargs.get('cluster_name', '')
|
||||
@ -50,6 +51,7 @@ class ClusterPolicy(object):
|
||||
'level': self.level,
|
||||
'enabled': self.enabled,
|
||||
'data': self.data,
|
||||
'last_op': self.last_op,
|
||||
}
|
||||
|
||||
if self.id:
|
||||
@ -75,6 +77,7 @@ class ClusterPolicy(object):
|
||||
'level': record.level,
|
||||
'enabled': record.enabled,
|
||||
'data': record.data,
|
||||
'last_op': record.last_op,
|
||||
|
||||
# derived data
|
||||
'cluster_name': record.cluster.name,
|
||||
@ -117,6 +120,7 @@ class ClusterPolicy(object):
|
||||
'level': self.level,
|
||||
'enabled': self.enabled,
|
||||
'data': self.data,
|
||||
'last_op': self.last_op,
|
||||
# below are derived data for user's convenience
|
||||
'cluster_name': self.cluster_name,
|
||||
'policy_name': self.policy_name,
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
from senlin.db.sqlalchemy import api as db_api
|
||||
from senlin.tests.common import base
|
||||
from senlin.tests.common import utils
|
||||
@ -120,6 +122,22 @@ class DBAPIClusterPolicyTest(base.SenlinTestCase):
|
||||
self.assertEqual(1, len(bindings))
|
||||
self.assertEqual({'foo': 'BAR'}, bindings[0].data)
|
||||
|
||||
def test_policy_update_last_op(self):
|
||||
policy = self.create_policy()
|
||||
|
||||
db_api.cluster_policy_attach(self.ctx, self.cluster.id, policy.id, {})
|
||||
bindings = db_api.cluster_policy_get_all(self.ctx, self.cluster.id)
|
||||
self.assertEqual(1, len(bindings))
|
||||
self.assertIsNone(bindings[0].last_op)
|
||||
|
||||
timestamp = datetime.datetime.utcnow()
|
||||
fields = {'last_op': timestamp}
|
||||
db_api.cluster_policy_update(self.ctx, self.cluster.id, policy.id,
|
||||
fields)
|
||||
bindings = db_api.cluster_policy_get_all(self.ctx, self.cluster.id)
|
||||
self.assertEqual(1, len(bindings))
|
||||
self.assertEqual(timestamp, bindings[0].last_op)
|
||||
|
||||
def test_policy_get_all_prioritized(self):
|
||||
policy = self.create_policy()
|
||||
|
||||
|
@ -33,7 +33,7 @@ class ProfileTypeTest(base.SenlinTestCase):
|
||||
def test_profile_type_list(self):
|
||||
types = self.eng.profile_type_list(self.ctx)
|
||||
self.assertIsInstance(types, list)
|
||||
self.assertIn({'name': 'os.heat.stack'}, types)
|
||||
self.assertIn({'name': 'TestProfile'}, types)
|
||||
self.assertNotIn({'name': 'some-weird-stuff'}, types)
|
||||
|
||||
def test_profile_type_schema(self):
|
||||
|
Loading…
Reference in New Issue
Block a user