Merge "Set `public` as update allowed for cluster template"
This commit is contained in:
commit
8d455cb40a
|
@ -11,6 +11,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.engine import constraints
|
||||
|
@ -179,7 +181,10 @@ class ClusterTemplate(resource.Resource):
|
|||
),
|
||||
PUBLIC: properties.Schema(
|
||||
properties.Schema.BOOLEAN,
|
||||
_('Make the cluster template public.'),
|
||||
_('Make the cluster template public. To enable this option, you '
|
||||
'must own the right to publish in magnum. Which default set '
|
||||
'to admin only.'),
|
||||
update_allowed=True,
|
||||
default=False
|
||||
),
|
||||
REGISTRY_ENABLED: properties.Schema(
|
||||
|
@ -250,6 +255,35 @@ class ClusterTemplate(resource.Resource):
|
|||
ct = self.client().cluster_templates.create(**args)
|
||||
self.resource_id_set(ct.uuid)
|
||||
|
||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||
if prop_diff:
|
||||
patch = [{'op': 'replace', 'path': '/' + k, 'value': v}
|
||||
for k, v in six.iteritems(prop_diff)]
|
||||
self.client().cluster_templates.update(self.resource_id, patch)
|
||||
return self.resource_id
|
||||
|
||||
def check_update_complete(self, id):
|
||||
cluster_template = self.client().cluster_templates.get(id)
|
||||
if cluster_template.status == 'UPDATE_IN_PROGRESS':
|
||||
return False
|
||||
elif cluster_template.status == 'UPDATE_COMPLETE':
|
||||
return True
|
||||
elif cluster_template.status == 'UPDATE_FAILED':
|
||||
msg = (_("Failed to update Cluster Template "
|
||||
"'%(name)s' - %(reason)s")
|
||||
% {'name': self.name,
|
||||
'reason': cluster_template.status_reason})
|
||||
raise exception.ResourceInError(
|
||||
status_reason=msg, resource_status=cluster_template.status)
|
||||
|
||||
else:
|
||||
msg = (_("Unknown status updating Cluster Template "
|
||||
"'%(name)s' - %(reason)s")
|
||||
% {'name': self.name,
|
||||
'reason': cluster_template.status_reason})
|
||||
raise exception.ResourceUnknownStatus(
|
||||
status_reason=msg, resource_status=cluster_template.status)
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import mock
|
||||
import six
|
||||
|
||||
|
@ -19,6 +20,7 @@ from heat.common import template_format
|
|||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.magnum import cluster_template
|
||||
from heat.engine import scheduler
|
||||
from heat.engine import template
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
||||
|
@ -128,3 +130,34 @@ class TestMagnumClusterTemplate(common.HeatTestCase):
|
|||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
stack['test_cluster_template'].validate)
|
||||
self.assertEqual(msg, six.text_type(ex))
|
||||
|
||||
def _cluster_template_update(self, update_status='UPDATE_COMPLETE',
|
||||
exc_msg=None):
|
||||
ct = self._create_resource('ct', self.rsrc_defn, self.stack)
|
||||
status = mock.MagicMock(status=update_status)
|
||||
self.client.cluster_templates.get.return_value = status
|
||||
t = template_format.parse(self.magnum_template)
|
||||
new_t = copy.deepcopy(t)
|
||||
new_t['resources'][self.expected['name']]['properties'][
|
||||
cluster_template.ClusterTemplate.PUBLIC] = False
|
||||
rsrc_defns = template.Template(new_t).resource_definitions(self.stack)
|
||||
new_ct = rsrc_defns[self.expected['name']]
|
||||
if update_status == 'UPDATE_COMPLETE':
|
||||
scheduler.TaskRunner(ct.update, new_ct)()
|
||||
self.assertEqual((ct.UPDATE, ct.COMPLETE), ct.state)
|
||||
else:
|
||||
exc = self.assertRaises(
|
||||
exception.ResourceFailure,
|
||||
scheduler.TaskRunner(ct.update, new_ct))
|
||||
self.assertIn(exc_msg, six.text_type(exc))
|
||||
|
||||
def test_cluster_update(self):
|
||||
self._cluster_template_update()
|
||||
|
||||
def test_cluster_update_failed(self):
|
||||
self._cluster_template_update('UPDATE_FAILED',
|
||||
'Failed to update Cluster')
|
||||
|
||||
def test_cluster_update_unknown_status(self):
|
||||
self._cluster_template_update('UPDATE_BAR',
|
||||
'Unknown status updating Cluster')
|
||||
|
|
Loading…
Reference in New Issue