RandomString use the random string as the resource_id
This allows template authors to ref the resource to get the string as an alternative to getting the value attribute. Change-Id: If2b51923414655befd7af21e2de701e83b7994b6
This commit is contained in:
parent
8c4adee13f
commit
f082e8bbec
@ -63,7 +63,8 @@ class RandomString(resource.Resource):
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
'value': _('The random string generated by this resource'),
|
||||
'value': _('The random string generated by this resource. This value '
|
||||
'is also available by referencing the resource.'),
|
||||
}
|
||||
|
||||
_sequences = {
|
||||
@ -86,6 +87,7 @@ class RandomString(resource.Resource):
|
||||
sequence = self._sequences[self.properties.get(self.SEQUENCE)]
|
||||
random_string = self._generate_random_string(sequence, length)
|
||||
db_api.resource_data_set(self, 'value', random_string, redact=True)
|
||||
self.resource_id_set(random_string)
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
if name == 'value':
|
||||
|
@ -70,14 +70,17 @@ Resources:
|
||||
self.assertThat(random_string, MatchesRegex('[a-zA-Z0-9]{32}'))
|
||||
self.assertRaises(exception.InvalidTemplateAttribute,
|
||||
secret1.FnGetAtt, 'foo')
|
||||
self.assertEqual(random_string, secret1.FnGetRefId())
|
||||
|
||||
secret2 = stack['secret2']
|
||||
random_string = secret2.FnGetAtt('value')
|
||||
self.assertThat(random_string, MatchesRegex('[a-zA-Z0-9]{10}'))
|
||||
self.assertEqual(random_string, secret2.FnGetRefId())
|
||||
|
||||
secret3 = stack['secret3']
|
||||
random_string = secret3.FnGetAtt('value')
|
||||
self.assertThat(random_string, MatchesRegex('[0-7]{100}'))
|
||||
self.assertEqual(random_string, secret3.FnGetRefId())
|
||||
|
||||
|
||||
class TestGenerateRandomString(HeatTestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user