summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Pasquier <simon.pasquier@bull.net>2014-01-03 14:11:54 +0100
committerSimon Pasquier <simon.pasquier@bull.net>2014-02-18 18:14:12 +0100
commit4ece05a829845ccdbf1e78b030719614255bfc28 (patch)
tree7f4d3f0bbbf3037fa0cfd14f8f4d9878c4cde8ac
parenta61e2219504101ac487c0266d51422b03a766111 (diff)
downloadheat-cfntools-4ece05a829845ccdbf1e78b030719614255bfc28.tar.gz
cfn-signal provides a unique default id
Unless the parameter is provided, cfn-signal will use the instance UUID from the Nova metadata as the id sent back to the WaitCondition. In case the Nova metadata isn't available, it will use the hostname as a fallback. Change-Id: I1e5847c7babd7c6295d8c3e21f6cfa110a9b3026 Closes-bug: 1223429
-rwxr-xr-xbin/cfn-signal15
-rw-r--r--heat_cfntools/cfntools/cfn_helper.py8
-rw-r--r--heat_cfntools/tests/test_cfn_helper.py21
3 files changed, 42 insertions, 2 deletions
diff --git a/bin/cfn-signal b/bin/cfn-signal
index 9dfbde7..e3d1190 100755
--- a/bin/cfn-signal
+++ b/bin/cfn-signal
@@ -43,7 +43,7 @@ parser.add_argument('-d', '--data',
parser.add_argument('-i', '--id',
dest="unique_id",
help="the unique id to send back to the WaitCondition",
- default='00000',
+ default=None,
required=False)
parser.add_argument('-e', '--exit-code',
dest="exit_code",
@@ -80,10 +80,21 @@ else:
if args.success == 'true':
status = 'SUCCESS'
+unique_id = args.unique_id
+if unique_id is None:
+ LOG.debug('No id passed from the command line')
+ md = cfn_helper.Metadata('not-used', None)
+ unique_id = md.get_instance_id()
+ if unique_id is None:
+ LOG.error('Could not get the instance id from metadata!')
+ import socket
+ unique_id = socket.getfqdn()
+LOG.debug('id: %s' % (unique_id))
+
body = {
"Status": status,
"Reason": args.reason,
- "UniqueId": args.unique_id,
+ "UniqueId": unique_id,
"Data": args.data
}
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py
index 9579194..f2cb123 100644
--- a/heat_cfntools/cfntools/cfn_helper.py
+++ b/heat_cfntools/cfntools/cfn_helper.py
@@ -1078,6 +1078,14 @@ class Metadata(object):
pass
return None
+ def get_instance_id(self):
+ """Get the unique identifier for this server."""
+ instance_id = None
+ md = self.get_nova_meta()
+ if md is not None:
+ instance_id = md.get('uuid')
+ return instance_id
+
def get_tags(self):
"""Get the tags for this server."""
tags = {}
diff --git a/heat_cfntools/tests/test_cfn_helper.py b/heat_cfntools/tests/test_cfn_helper.py
index 9073d01..ca80190 100644
--- a/heat_cfntools/tests/test_cfn_helper.py
+++ b/heat_cfntools/tests/test_cfn_helper.py
@@ -959,6 +959,27 @@ class TestMetadataRetrieve(testtools.TestCase):
self.assertEqual(tags_expect, tags)
self.m.VerifyAll()
+ def test_get_instance_id(self):
+ self.m = mox.Mox()
+ self.addCleanup(self.m.UnsetStubs)
+
+ uuid = "f9431d18-d971-434d-9044-5b38f5b4646f"
+ md_data = {"uuid": uuid,
+ "availability_zone": "nova",
+ "hostname": "as-wikidatabase-4ykioj3lgi57.novalocal",
+ "launch_index": 0,
+ "public_keys": {"heat_key": "ssh-rsa etc...\n"},
+ "name": "as-WikiDatabase-4ykioj3lgi57"}
+
+ md = cfn_helper.Metadata('teststack', None)
+
+ self.m.StubOutWithMock(md, 'get_nova_meta')
+ md.get_nova_meta().AndReturn(md_data)
+ self.m.ReplayAll()
+
+ self.assertEqual(md.get_instance_id(), uuid)
+ self.m.VerifyAll()
+
class TestSourcesHandler(MockPopenTestCase):
def test_apply_sources_empty(self):