def __eq__(self, other):
'''Allow == comparison of two resources'''
# For the purposes of comparison, we declare two resource objects
- # equal if their parsed_templates are the same
+ # equal if their names and parsed_templates are the same
if isinstance(other, Resource):
- return self.parsed_template() == other.parsed_template()
+ return (self.name == other.name) and (
+ self.parsed_template() == self.parsed_template(
+ template=other.t))
return NotImplemented
def __ne__(self, other):
return identifier.ResourceIdentifier(resource_name=self.name,
**self.stack.identifier())
- def parsed_template(self, section=None, default={}):
+ def parsed_template(self, section=None, default={}, template=None):
'''
Return the parsed template data for the resource. May be limited to
only one section of the data, in which case a default value may also
be supplied.
'''
if section is None:
- template = self.t
+ template = template or self.t
else:
template = self.t.get(section, default)
return self.stack.resolve_runtime_data(template)
res = resource.GenericResource('test_resource', tmpl, self.stack)
self.assertEqual(res.metadata, {})
+ def test_equals_different_stacks(self):
+ tmpl1 = {'Type': 'Foo'}
+ tmpl2 = {'Type': 'Foo'}
+ tmpl3 = {'Type': 'Bar'}
+ stack2 = parser.Stack(None, 'test_stack', parser.Template({}),
+ stack_id=-1)
+ res1 = resource.GenericResource('test_resource', tmpl1, self.stack)
+ res2 = resource.GenericResource('test_resource', tmpl2, stack2)
+ res3 = resource.GenericResource('test_resource2', tmpl3, stack2)
+
+ self.assertEqual(res1, res2)
+ self.assertNotEqual(res1, res3)
+
+ def test_equals_names(self):
+ tmpl1 = {'Type': 'Foo'}
+ tmpl2 = {'Type': 'Foo'}
+ res1 = resource.GenericResource('test_resource1', tmpl1, self.stack)
+ res2 = resource.GenericResource('test_resource2', tmpl2, self.stack)
+
+ self.assertNotEqual(res1, res2)
+
@attr(tag=['unit', 'resource'])
@attr(speed='fast')