Skip to content

Commit d10a80c

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add policy validation for senlin"
2 parents 9eabb71 + 4b22874 commit d10a80c

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

openstack/cluster/v1/_proxy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,18 @@ def update_policy(self, policy, **attrs):
641641
"""
642642
return self._update(_policy.Policy, policy, **attrs)
643643

644+
def validate_policy(self, **attrs):
645+
"""Validate a policy spec.
646+
647+
:param dict attrs: Keyword arguments that will be used to create a
648+
:class:`~openstack.cluster.v1.policy.PolicyValidate`, it is
649+
comprised of the properties on the Policy class.
650+
651+
:returns: The results of Policy validation.
652+
:rtype: :class:`~openstack.cluster.v1.policy.PolicyValidate`.
653+
"""
654+
return self._create(_policy.PolicyValidate, **attrs)
655+
644656
def cluster_policies(self, cluster, **query):
645657
"""Retrieve a generator of cluster-policy bindings.
646658

openstack/cluster/v1/policy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ class Policy(resource.Resource):
4545
spec = resource.Body('spec', type=dict)
4646
#: A dictionary containing runtime data of the policy.
4747
data = resource.Body('data', type=dict)
48+
49+
50+
class PolicyValidate(Policy):
51+
base_path = '/policies/validate'
52+
53+
# Capabilities
54+
allow_list = False
55+
allow_get = False
56+
allow_create = True
57+
allow_delete = False
58+
allow_update = False
59+
60+
patch_update = False

openstack/tests/unit/cluster/v1/test_policy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ def test_instantiate(self):
6363
self.assertEqual(FAKE['data'], sot.data)
6464
self.assertEqual(FAKE['created_at'], sot.created_at)
6565
self.assertEqual(FAKE['updated_at'], sot.updated_at)
66+
67+
68+
class TestPolicyValidate(testtools.TestCase):
69+
70+
def setUp(self):
71+
super(TestPolicyValidate, self).setUp()
72+
73+
def test_basic(self):
74+
sot = policy.PolicyValidate()
75+
self.assertEqual('policy', sot.resource_key)
76+
self.assertEqual('policies', sot.resources_key)
77+
self.assertEqual('/policies/validate', sot.base_path)
78+
self.assertEqual('clustering', sot.service.service_type)
79+
self.assertTrue(sot.allow_create)
80+
self.assertFalse(sot.allow_get)
81+
self.assertFalse(sot.allow_update)
82+
self.assertFalse(sot.allow_delete)
83+
self.assertFalse(sot.allow_list)

openstack/tests/unit/cluster/v1/test_proxy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ def test_node_recover(self, mock_get):
340340
def test_policy_create(self):
341341
self.verify_create(self.proxy.create_policy, policy.Policy)
342342

343+
def test_policy_validate(self):
344+
self.verify_create(self.proxy.validate_policy, policy.PolicyValidate)
345+
343346
def test_policy_delete(self):
344347
self.verify_delete(self.proxy.delete_policy, policy.Policy, False)
345348

0 commit comments

Comments
 (0)