Modify identify_stack to check for uuid.
If the passed name matches a uuid then lookup by uuid instead of name. Change-Id: I2058616ce0191aab4d364b652f1b20d072f6b258
This commit is contained in:
parent
75fc3c9bca
commit
89caca42d6
|
@ -26,6 +26,12 @@ class HeatIdentifier(collections.Mapping):
|
|||
)
|
||||
path_re = re.compile(r'stacks/([^/]+)/([^/]+)(.*)')
|
||||
|
||||
HEX_ELEM = '[0-9A-Fa-f]'
|
||||
UUID_PATTERN = '-'.join([HEX_ELEM + '{8}', HEX_ELEM + '{4}',
|
||||
HEX_ELEM + '{4}', HEX_ELEM + '{4}',
|
||||
HEX_ELEM + '{12}'])
|
||||
uuid_re = re.compile(r'^' + UUID_PATTERN + '$')
|
||||
|
||||
def __init__(self, tenant, stack_name, stack_id, path=''):
|
||||
'''
|
||||
Initialise a HeatIdentifier from a Tenant ID, Stack name, Stack ID
|
||||
|
@ -42,6 +48,10 @@ class HeatIdentifier(collections.Mapping):
|
|||
self.PATH: path,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def is_uuid(cls, uuid):
|
||||
return HeatIdentifier.uuid_re.match(uuid)
|
||||
|
||||
@classmethod
|
||||
def from_arn(cls, arn):
|
||||
'''
|
||||
|
|
|
@ -65,9 +65,12 @@ class EngineService(service.Service):
|
|||
The identify_stack method returns the full stack identifier for a
|
||||
single, live stack given the stack name.
|
||||
arg1 -> RPC context.
|
||||
arg2 -> Name of the stack to look up.
|
||||
arg2 -> Name or UUID of the stack to look up.
|
||||
"""
|
||||
s = db_api.stack_get_by_name(context, stack_name)
|
||||
if identifier.HeatIdentifier.is_uuid(stack_name):
|
||||
s = db_api.stack_get(context, stack_name)
|
||||
else:
|
||||
s = db_api.stack_get_by_name(context, stack_name)
|
||||
if s:
|
||||
stack = parser.Stack.load(context, stack=s)
|
||||
return dict(stack.identifier())
|
||||
|
|
|
@ -22,6 +22,7 @@ import mox
|
|||
import json
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
from heat.common import config
|
||||
from heat.common import context
|
||||
from heat.tests.v1_1 import fakes
|
||||
import heat.engine.api as engine_api
|
||||
|
@ -94,6 +95,7 @@ class DummyThreadGroup(object):
|
|||
class stackCreateTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.m = mox.Mox()
|
||||
config.register_engine_opts()
|
||||
|
||||
def tearDown(self):
|
||||
self.m.UnsetStubs()
|
||||
|
@ -341,6 +343,7 @@ class stackServiceTest(unittest.TestCase):
|
|||
cls.stack_name = 'service_test_stack'
|
||||
|
||||
stack = get_wordpress_stack(cls.stack_name, ctx)
|
||||
|
||||
setup_mocks(m, stack)
|
||||
m.ReplayAll()
|
||||
|
||||
|
@ -378,6 +381,10 @@ class stackServiceTest(unittest.TestCase):
|
|||
identity = self.man.identify_stack(self.ctx, self.stack_name)
|
||||
self.assertEqual(identity, self.stack_identity)
|
||||
|
||||
def test_stack_identify_uuid(self):
|
||||
identity = self.man.identify_stack(self.ctx, self.stack.id)
|
||||
self.assertEqual(identity, self.stack_identity)
|
||||
|
||||
def test_stack_identify_nonexist(self):
|
||||
self.assertRaises(AttributeError, self.man.identify_stack,
|
||||
self.ctx, 'wibble')
|
||||
|
|
|
@ -20,6 +20,7 @@ import mox
|
|||
import json
|
||||
|
||||
from heat.engine import identifier
|
||||
from heat.common import utils
|
||||
|
||||
|
||||
@attr(tag=['unit', 'identifier'])
|
||||
|
@ -221,6 +222,17 @@ class IdentifierTest(unittest.TestCase):
|
|||
'stack_name': 's',
|
||||
'stack_id': 'i'} == hi1)
|
||||
|
||||
def test_uuid_match(self):
|
||||
uuid = utils.generate_uuid()
|
||||
self.assertTrue(identifier.HeatIdentifier.is_uuid(uuid))
|
||||
self.assertFalse(identifier.HeatIdentifier.is_uuid('a' + uuid))
|
||||
self.assertFalse(identifier.HeatIdentifier.is_uuid(
|
||||
'zzzzzzzz-zzzz-zzzz-zzzzzzzzzzzz'))
|
||||
self.assertFalse(identifier.HeatIdentifier.is_uuid(uuid + 'a'))
|
||||
for i in xrange(100):
|
||||
self.assertTrue(identifier.HeatIdentifier.is_uuid(
|
||||
utils.generate_uuid()))
|
||||
|
||||
|
||||
# allows testing of the test directly, shown below
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue