Convergence: Fix FnGetRefId to fetch value from cache_data

Fix FnGetRefId of WaitConditionHandle, ElasticIp and NeutronResource
to fetch value from cache_data, if present.

Change-Id: Icd92f6514c7590c90da2fcd2123d33862d613486
This commit is contained in:
Rakesh H S 2015-09-14 17:42:16 +05:30
parent cff9dda9c3
commit 9e31053c7c
7 changed files with 97 additions and 15 deletions

View File

@ -1459,6 +1459,12 @@ class Resource(object):
'''Returns state, tuple of action, status.'''
return (self.action, self.status)
def get_reference_id(self):
if self.resource_id is not None:
return six.text_type(self.resource_id)
else:
return six.text_type(self.name)
def FnGetRefId(self):
'''
For the intrinsic function Ref.
@ -1467,11 +1473,7 @@ class Resource(object):
'''
if self.stack.has_cache_data(self.name):
return self.stack.cache_data_reference_id(self.name)
if self.resource_id is not None:
return six.text_type(self.resource_id)
else:
return six.text_type(self.name)
return self.get_reference_id()
def physical_resource_name_or_FnGetRefId(self):
res_name = self.physical_resource_name()

View File

@ -35,10 +35,7 @@ class WaitConditionHandle(wc_base.BaseWaitConditionHandle):
'Data', 'Reason', 'Status', 'UniqueId'
)
def FnGetRefId(self):
'''
Override the default resource FnGetRefId so we return the signed URL
'''
def get_reference_id(self):
if self.resource_id:
wc = signal_responder.WAITCONDITION
return six.text_type(self._get_ec2_signed_url(signal_type=wc))

View File

@ -177,7 +177,7 @@ class ElasticIp(resource.Resource):
server = self.client().servers.get(instance_id_old)
server.remove_floating_ip(self._ipaddress())
def FnGetRefId(self):
def get_reference_id(self):
eip = self._ipaddress()
if eip:
return six.text_type(eip)

View File

@ -122,11 +122,7 @@ class NeutronResource(resource.Resource):
attributes = self._show_resource()
return attributes[name]
def FnGetRefId(self):
# convergence: try some luck with cached data first
if self.stack.has_cache_data(self.name):
return self.stack.cache_data_reference_id(self.name)
def get_reference_id(self):
return six.text_type(self.resource_id)
@staticmethod

View File

@ -13,6 +13,7 @@
import copy
import mock
import mox
from neutronclient.v2_0 import client as neutronclient
from novaclient import exceptions as nova_exceptions
@ -372,6 +373,37 @@ class EIPTest(common.HeatTestCase):
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
@mock.patch.object(eip.ElasticIp, '_ipaddress')
def test_FnGetRefId_resource_name(self, mock_ipaddr):
t = template_format.parse(ipassoc_template_validate)
stack = utils.parse_stack(t)
rsrc = stack['eip']
mock_ipaddr.return_value = None
self.assertEqual('eip', rsrc.FnGetRefId())
@mock.patch.object(eip.ElasticIp, '_ipaddress')
def test_FnGetRefId_resource_ip(self, mock_ipaddr):
t = template_format.parse(ipassoc_template_validate)
stack = utils.parse_stack(t)
rsrc = stack['eip']
mock_ipaddr.return_value = 'x.x.x.x'
self.assertEqual('x.x.x.x', rsrc.FnGetRefId())
def test_FnGetRefId_convergence_cache_data(self):
t = template_format.parse(ipassoc_template_validate)
template = tmpl.Template(t)
stack = parser.Stack(utils.dummy_context(), 'test', template,
cache_data={
'eip': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': '1.1.1.1'}})
rsrc = stack['eip']
self.assertEqual('1.1.1.1', rsrc.FnGetRefId())
class AllocTest(common.HeatTestCase):

View File

@ -16,6 +16,7 @@ import datetime
import json
import uuid
import mock
from oslo_utils import timeutils
import six
from six.moves.urllib import parse
@ -255,6 +256,35 @@ class WaitConditionTest(common.HeatTestCase):
self.assertEqual('status:SUCCESS reason:cat', ret)
self.m.VerifyAll()
def test_FnGetRefId_resource_name(self):
self.stack = self.create_stack()
rsrc = self.stack['WaitHandle']
self.assertEqual('WaitHandle', rsrc.FnGetRefId())
@mock.patch.object(aws_wch.WaitConditionHandle, '_get_ec2_signed_url')
def test_FnGetRefId_signed_url(self, mock_get_signed_url):
self.stack = self.create_stack()
rsrc = self.stack['WaitHandle']
rsrc.resource_id = '123'
mock_get_signed_url.return_value = 'http://signed_url'
self.assertEqual('http://signed_url', rsrc.FnGetRefId())
def test_FnGetRefId_convergence_cache_data(self):
t = template_format.parse(test_template_waitcondition)
template = tmpl.Template(t)
stack = parser.Stack(utils.dummy_context(), 'test', template,
cache_data={
'WaitHandle': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'http://convg_signed_url'
}})
rsrc = stack['WaitHandle']
self.assertEqual('http://convg_signed_url', rsrc.FnGetRefId())
def test_validate_handle_url_bad_stackid(self):
self.m.ReplayAll()

View File

@ -13,6 +13,7 @@
import copy
import mock
import mox
from neutronclient.common import exceptions as qe
from neutronclient.neutron import v2_0 as neutronV20
@ -23,6 +24,8 @@ from heat.common import template_format
from heat.engine.cfn import functions as cfn_funcs
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.engine import stack as parser
from heat.engine import template as tmpl
from heat.tests import common
from heat.tests import utils
@ -237,6 +240,28 @@ class NeutronFloatingIPTest(common.HeatTestCase):
self.m.VerifyAll()
def test_FnGetRefId(self):
t = template_format.parse(neutron_floating_template)
stack = utils.parse_stack(t)
rsrc = stack['floating_ip']
rsrc.resource_id = 'xyz'
self.assertEqual('xyz', rsrc.FnGetRefId())
def test_FnGetRefId_convergence_cache_data(self):
t = template_format.parse(neutron_floating_template)
template = tmpl.Template(t)
stack = parser.Stack(utils.dummy_context(), 'test', template,
cache_data={
'floating_ip': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'abc'}})
rsrc = stack['floating_ip']
self.assertEqual('abc', rsrc.FnGetRefId())
def test_port(self):
self.stub_NetworkConstraint_validate()
self.stub_SubnetConstraint_validate()