def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_classes in _filter_resources( prefix, self.path(), self.statuses()): for resource_class in resource_classes: self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) self.attrs_schemata = attributes.schemata( self.resource_class.attributes_schema) self.update_policy_schemata = properties.schemata( self.resource_class.update_policy_schema) self._status_str(resource_class.support_status, section) cls_doc = pydoc.getdoc(resource_class) if cls_doc: # allow for rst in the class comments cls_nodes = core.publish_doctree(cls_doc).children section.extend(cls_nodes) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_update_policy(section) self.contribute_hot_syntax(section) return content
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_classes in _filter_resources(prefix, self.path(), self.statuses()): for resource_class in resource_classes: self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, "%s") self.props_schemata = properties.schemata(self.resource_class.properties_schema) self.attrs_schemata = attributes.schemata(self.resource_class.attributes_schema) # NOTE(prazumovsky): Adding base_attributes_schema dict to # Resource class should means adding new attributes from this # dict to documentation of each resource, else there is no # chance to learn about base attributes. self.attrs_schemata.update(self.resource_class.base_attributes_schema) self.update_policy_schemata = properties.schemata(self.resource_class.update_policy_schema) self._status_str(resource_class.support_status, section) cls_doc = pydoc.getdoc(resource_class) if cls_doc: # allow for rst in the class comments cls_nodes = core.publish_doctree(cls_doc).children section.extend(cls_nodes) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_update_policy(section) self.contribute_hot_syntax(section) return content
def _validate_against_facade(self, facade_cls): facade_schemata = properties.schemata(facade_cls.properties_schema) for n, fs in facade_schemata.items(): if fs.required and n not in self.properties_schema: msg = (_("Required property %(n)s for facade %(type)s " "missing in provider") % {'n': n, 'type': self.type()}) raise exception.StackValidationFailed(message=msg) ps = self.properties_schema.get(n) if (n in self.properties_schema and (fs.type != ps.type)): # Type mismatch msg = (_("Property %(n)s type mismatch between facade %(type)s" " (%(fs_type)s) and provider (%(ps_type)s)") % { 'n': n, 'type': self.type(), 'fs_type': fs.type, 'ps_type': ps.type}) raise exception.StackValidationFailed(message=msg) for n, ps in self.properties_schema.items(): if ps.required and n not in facade_schemata: # Required property for template not present in facade msg = (_("Provider requires property %(n)s " "unknown in facade %(type)s") % { 'n': n, 'type': self.type()}) raise exception.StackValidationFailed(message=msg) for attr in facade_cls.attributes_schema: if attr not in self.attributes_schema: msg = (_("Attribute %(attr)s for facade %(type)s " "missing in provider") % { 'attr': attr, 'type': self.type()}) raise exception.StackValidationFailed(message=msg)
def _validate_against_facade(self, facade_cls): facade_schemata = properties.schemata(facade_cls.properties_schema) for n, fs in facade_schemata.items(): if fs.required and n not in self.properties_schema: msg = ("Required property %s for facade %s " "missing in provider") % (n, self.type()) raise exception.StackValidationFailed(message=msg) ps = self.properties_schema.get(n) if (n in self.properties_schema and (fs.type != ps.type)): # Type mismatch msg = ("Property %s type mismatch between facade %s (%s) " "and provider (%s)") % (n, self.type(), fs.type, ps.type) raise exception.StackValidationFailed(message=msg) for n, ps in self.properties_schema.items(): if ps.required and n not in facade_schemata: # Required property for template not present in facade msg = ("Provider requires property %s " "unknown in facade %s") % (n, self.type()) raise exception.StackValidationFailed(message=msg) for attr in facade_cls.attributes_schema: if attr not in self.attributes_schema: msg = ("Attribute %s for facade %s " "missing in provider") % (attr, self.type()) raise exception.StackValidationFailed(message=msg)
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_class in _all_resources(prefix): self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) if resource_class.support_status.status == support.DEPRECATED: sstatus = resource_class.support_status.to_dict() msg = _('%(status)s') if sstatus['message'] is not None: msg = _('%(status)s - %(message)s') para = nodes.inline('', msg % sstatus) warning = nodes.note('', para) section.append(warning) cls_doc = pydoc.getdoc(resource_class) if cls_doc: para = nodes.paragraph('', cls_doc) section.append(para) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_hot_syntax(section) self.contribute_yaml_syntax(section) self.contribute_json_syntax(section) return content
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_class in _all_resources(prefix): self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) self.attrs_schemata = attributes.schemata( self.resource_class.attributes_schema) if resource_class.support_status.status == support.DEPRECATED: sstatus = resource_class.support_status.to_dict() msg = _('%(status)s') if sstatus['message'] is not None: msg = _('%(status)s - %(message)s') para = nodes.inline('', msg % sstatus) warning = nodes.note('', para) section.append(warning) cls_doc = pydoc.getdoc(resource_class) if cls_doc: para = nodes.paragraph('', cls_doc) section.append(para) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_hot_syntax(section) self.contribute_yaml_syntax(section) self.contribute_json_syntax(section) return content
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_classes in _filter_resources( prefix, self.path(), self.statuses()): for resource_class in resource_classes: self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) self.attrs_schemata = attributes.schemata( self.resource_class.attributes_schema) # NOTE(prazumovsky): Adding base_attributes_schema dict to # Resource class should means adding new attributes from this # dict to documentation of each resource, else there is no # chance to learn about base attributes. self.attrs_schemata.update( self.resource_class.base_attributes_schema) self.update_policy_schemata = properties.schemata( self.resource_class.update_policy_schema) self._status_str(resource_class.support_status, section) cls_doc = pydoc.getdoc(resource_class) if cls_doc: # allow for rst in the class comments cls_nodes = core.publish_doctree(cls_doc).children section.extend(cls_nodes) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_update_policy(section) self.contribute_hot_syntax(section) return content
def test_mem_alarm_high_update_no_replace(self): ''' Make sure that we can change the update-able properties without replacing the Alarm rsrc. ''' #short circuit the alarm's references t = template_format.parse(alarm_template) properties = t['Resources']['MEMAlarmHigh']['Properties'] properties['alarm_actions'] = ['signal_handler'] properties['matching_metadata'] = {'a': 'v'} self.stack = self.create_stack(template=json.dumps(t)) self.m.StubOutWithMock(self.fa.alarms, 'update') schema = schemata(alarm.CeilometerAlarm.properties_schema) al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items() if s.update_allowed) al2['alarm_id'] = mox.IgnoreArg() del al2['enabled'] del al2['repeat_actions'] self.fa.alarms.update(**al2).AndReturn(None) self.m.ReplayAll() self.stack.create() rsrc = self.stack['MEMAlarmHigh'] props = copy.copy(rsrc.properties.data) props.update({ 'comparison_operator': 'lt', 'description': 'fruity', 'evaluation_periods': '2', 'period': '90', 'enabled': True, 'repeat_actions': True, 'statistic': 'max', 'threshold': '39', 'insufficient_data_actions': [], 'alarm_actions': [], 'ok_actions': ['signal_handler'], }) snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, snippet)() self.m.VerifyAll()
def test_mem_alarm_high_update_no_replace(self): """ Make sure that we can change the update-able properties without replacing the Alarm rsrc. """ # short circuit the alarm's references t = template_format.parse(alarm_template) properties = t["Resources"]["MEMAlarmHigh"]["Properties"] properties["alarm_actions"] = ["signal_handler"] properties["matching_metadata"] = {"a": "v"} self.stack = self.create_stack(template=json.dumps(t)) self.m.StubOutWithMock(self.fa.alarms, "update") schema = schemata(alarm.CeilometerAlarm.properties_schema) al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items() if s.update_allowed) al2["alarm_id"] = mox.IgnoreArg() self.fa.alarms.update(**al2).AndReturn(None) self.m.ReplayAll() self.stack.create() rsrc = self.stack["MEMAlarmHigh"] props = copy.copy(rsrc.properties.data) props.update( { "comparison_operator": "lt", "description": "fruity", "evaluation_periods": "2", "period": "90", "enabled": "true", "repeat_actions": True, "statistic": "max", "threshold": "39", "insufficient_data_actions": [], "alarm_actions": [], "ok_actions": ["signal_handler"], } ) snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, snippet)() self.m.VerifyAll()
def validate(self): cri = self.stack.env.get_resource_info( self.type(), registry_type=environment.ClassResourceInfo) # If we're using an existing resource type as a facade for this # template, check for compatibility between the interfaces. if cri is not None and not isinstance(self, cri.get_class()): facade_cls = cri.get_class() facade_schemata = properties.schemata(facade_cls.properties_schema) for n, fs in facade_schemata.items(): if fs.required and n not in self.properties_schema: msg = ("Required property %s for facade %s " "missing in provider") % (n, self.type()) raise exception.StackValidationFailed(message=msg) ps = self.properties_schema.get(n) if (n in self.properties_schema and (fs.type != ps.type)): # Type mismatch msg = ("Property %s type mismatch between facade %s (%s) " "and provider (%s)") % (n, self.type(), fs.type, ps.type) raise exception.StackValidationFailed(message=msg) for n, ps in self.properties_schema.items(): if ps.required and n not in facade_schemata: # Required property for template not present in facade msg = ("Provider requires property %s " "unknown in facade %s") % (n, self.type()) raise exception.StackValidationFailed(message=msg) for attr in facade_cls.attributes_schema: if attr not in self.attributes_schema: msg = ("Attribute %s for facade %s " "missing in provider") % (attr, self.type()) raise exception.StackValidationFailed(message=msg) return super(TemplateResource, self).validate()
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_class in _all_resources(prefix): self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) self.attrs_schemata = attributes.schemata( self.resource_class.attributes_schema) if resource_class.support_status.status == support.DEPRECATED: para = nodes.paragraph('', self._status_str( resource_class.support_status)) note = nodes.note('', para) section.append(note) cls_doc = pydoc.getdoc(resource_class) if cls_doc: # allow for rst in the class comments cls_nodes = core.publish_doctree(cls_doc).children section.extend(cls_nodes) if (resource_class.support_status.status == support.SUPPORTED and resource_class.support_status.version is not None): tag = resource_class.support_status.version.title() message = (_('Available since %s.') % self._version_str(tag)) para = nodes.paragraph('', message) section.append(para) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_hot_syntax(section) self.contribute_yaml_syntax(section) self.contribute_json_syntax(section) return content
def run(self): prefix = self.arguments and self.arguments.pop() or None content = [] for resource_type, resource_class in _all_resources(prefix): self.resource_type = resource_type self.resource_class = resource_class section = self._section(content, resource_type, '%s') self.props_schemata = properties.schemata( self.resource_class.properties_schema) cls_doc = resource_class.__doc__ if cls_doc: para = nodes.paragraph('', cls_doc) section.append(para) self.contribute_properties(section) self.contribute_attributes(section) self.contribute_hot_syntax(section) self.contribute_yaml_syntax(section) self.contribute_json_syntax(section) return content
def test_mem_alarm_high_update_no_replace(self): """ Make sure that we can change the update-able properties without replacing the Alarm rsrc. """ # short circuit the alarm's references t = template_format.parse(alarm_template) properties = t["Resources"]["MEMAlarmHigh"]["Properties"] properties["alarm_actions"] = ["signal_handler"] properties["matching_metadata"] = {"a": "v"} properties["query"] = [dict(field="b", op="eq", value="w")] self.stack = self.create_stack(template=json.dumps(t)) self.m.StubOutWithMock(self.fa.alarms, "update") schema = props.schemata(alarm.CeilometerAlarm.properties_schema) exns = [ "period", "evaluation_periods", "threshold", "statistic", "comparison_operator", "meter_name", "matching_metadata", "query", ] al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items() if s.update_allowed and k not in exns) al2["alarm_id"] = mox.IgnoreArg() al2["type"] = "threshold" al2["threshold_rule"] = dict( meter_name=properties["meter_name"], period=90, evaluation_periods=2, threshold=39, statistic="max", comparison_operator="lt", query=[dict(field="c", op="ne", value="z"), dict(field="metadata.metering.x", op="eq", value="y")], ) self.fa.alarms.update(**al2).AndReturn(None) self.m.ReplayAll() self.stack.create() rsrc = self.stack["MEMAlarmHigh"] properties = copy.copy(rsrc.properties.data) properties.update( { "comparison_operator": "lt", "description": "fruity", "evaluation_periods": "2", "period": "90", "enabled": True, "repeat_actions": True, "statistic": "max", "threshold": "39", "insufficient_data_actions": [], "alarm_actions": [], "ok_actions": ["signal_handler"], "matching_metadata": {"x": "y"}, "query": [dict(field="c", op="ne", value="z")], } ) snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), properties) scheduler.TaskRunner(rsrc.update, snippet)() self.m.VerifyAll()
def test_mem_alarm_high_update_no_replace(self): ''' Make sure that we can change the update-able properties without replacing the Alarm rsrc. ''' # short circuit the alarm's references t = template_format.parse(alarm_template) properties = t['Resources']['MEMAlarmHigh']['Properties'] properties['alarm_actions'] = ['signal_handler'] properties['matching_metadata'] = {'a': 'v'} properties['query'] = [dict(field='b', op='eq', value='w')] self.stack = self.create_stack(template=json.dumps(t)) self.m.StubOutWithMock(self.fa.alarms, 'update') schema = props.schemata(alarm.CeilometerAlarm.properties_schema) exns = ['period', 'evaluation_periods', 'threshold', 'statistic', 'comparison_operator', 'meter_name', 'matching_metadata', 'query'] al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items() if s.update_allowed and k not in exns) al2['alarm_id'] = mox.IgnoreArg() al2['type'] = 'threshold' al2['threshold_rule'] = dict( meter_name=properties['meter_name'], period=90, evaluation_periods=2, threshold=39, statistic='max', comparison_operator='lt', query=[ dict(field='c', op='ne', value='z'), dict(field='metadata.metering.x', op='eq', value='y') ]) self.fa.alarms.update(**al2).AndReturn(None) self.m.ReplayAll() self.stack.create() rsrc = self.stack['MEMAlarmHigh'] properties = copy.copy(rsrc.properties.data) properties.update({ 'comparison_operator': 'lt', 'description': 'fruity', 'evaluation_periods': '2', 'period': '90', 'enabled': True, 'repeat_actions': True, 'statistic': 'max', 'threshold': '39', 'insufficient_data_actions': [], 'alarm_actions': [], 'ok_actions': ['signal_handler'], 'matching_metadata': {'x': 'y'}, 'query': [dict(field='c', op='ne', value='z')] }) snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), properties) scheduler.TaskRunner(rsrc.update, snippet)() self.m.VerifyAll()
def test_mem_alarm_high_update_no_replace(self): ''' Make sure that we can change the update-able properties without replacing the Alarm rsrc. ''' # short circuit the alarm's references t = template_format.parse(alarm_template) properties = t['Resources']['MEMAlarmHigh']['Properties'] properties['alarm_actions'] = ['signal_handler'] properties['matching_metadata'] = {'a': 'v'} properties['query'] = [dict(field='b', op='eq', value='w')] self.stack = self.create_stack(template=json.dumps(t)) self.m.StubOutWithMock(self.fa.alarms, 'update') schema = props.schemata(alarm.CeilometerAlarm.properties_schema) exns = ['period', 'evaluation_periods', 'threshold', 'statistic', 'comparison_operator', 'meter_name', 'matching_metadata', 'query'] al2 = dict((k, mox.IgnoreArg()) for k, s in schema.items() if s.update_allowed and k not in exns) al2['time_constraints'] = mox.IgnoreArg() al2['alarm_id'] = mox.IgnoreArg() al2['type'] = 'threshold' al2['threshold_rule'] = dict( meter_name=properties['meter_name'], period=90, evaluation_periods=2, threshold=39, statistic='max', comparison_operator='lt', query=[ dict(field='c', op='ne', value='z'), dict(field='metadata.metering.x', op='eq', value='y') ]) self.fa.alarms.update(**al2).AndReturn(None) self.m.ReplayAll() self.stack.create() rsrc = self.stack['MEMAlarmHigh'] properties = copy.copy(rsrc.properties.data) properties.update({ 'comparison_operator': 'lt', 'description': 'fruity', 'evaluation_periods': '2', 'period': '90', 'enabled': True, 'repeat_actions': True, 'statistic': 'max', 'threshold': '39', 'insufficient_data_actions': [], 'alarm_actions': [], 'ok_actions': ['signal_handler'], 'matching_metadata': {'x': 'y'}, 'query': [dict(field='c', op='ne', value='z')] }) snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), properties) scheduler.TaskRunner(rsrc.update, snippet)() self.m.VerifyAll()