]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make RDS (mysql) wait until setup is finished before proceeding
authorSteven Dake <sdake@redhat.com>
Mon, 27 Aug 2012 01:09:43 +0000 (18:09 -0700)
committerSteven Dake <sdake@redhat.com>
Mon, 27 Aug 2012 01:43:04 +0000 (18:43 -0700)
It is possible a service dependent on RDS may issue commands to
the RDS service before mysql has finished installing.  Added
a wait condition to force synchronization.

Change-Id: I6abf2d62e92d19945c587deeb61605df2c97ec85
Signed-off-by: Steven Dake <sdake@redhat.com>
heat/engine/dbinstance.py

index 5ed960aa62bb0c420b656b1d76a5756d397e75e5..54bcb6ccc8aa2e058fa914d198278ba96ff9b065 100644 (file)
@@ -77,6 +77,16 @@ mysql_template = r'''
 
 
   "Resources": {
+    "DatabaseInstanceCfnUser" : {
+      "Type" : "AWS::IAM::User"
+    },
+    "DatabaseInstanceKeys" : {
+      "Type" : "AWS::IAM::AccessKey",
+      "Properties" : {
+        "UserName" : {"Ref": "DatabaseInstanceCfnUser"}
+      }
+    },
+
     "DatabaseInstance": {
       "Type": "AWS::EC2::Instance",
       "Metadata": {
@@ -104,7 +114,21 @@ mysql_template = r'''
         "KeyName": { "Ref": "KeyName" },
         "UserData": { "Fn::Base64": { "Fn::Join": ["", [
           "#!/bin/bash -v\n",
-          "/opt/aws/bin/cfn-init\n",
+          "# Helper function\n",
+          "function error_exit\n",
+          "{\n",
+          "  /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '",
+          { "Ref" : "WaitHandle" }, "'\n",
+          "  exit 1\n",
+          "}\n",
+
+          "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
+          " -r DatabaseInstance",
+          " --access-key ", { "Ref" : "DatabaseInstanceKeys" },
+          " --secret-key ",
+          {"Fn::GetAtt": ["DatabaseInstanceKeys", "SecretAccessKey"]},
+          " --region ", { "Ref" : "AWS::Region" },
+          " || error_exit 'Failed to run cfn-init'\n",
           "# Setup MySQL root password and create a user\n",
           "mysqladmin -u root password '", {"Ref":"MasterUserPassword"},"'\n",
           "cat << EOF | mysql -u root --password='",
@@ -115,9 +139,26 @@ mysql_template = r'''
           "IDENTIFIED BY \"", { "Ref" : "MasterUserPassword" }, "\";\n",
           "FLUSH PRIVILEGES;\n",
           "EXIT\n",
-          "EOF\n"
+          "EOF\n",
+          "# Database setup completed, signal success\n",
+          "/opt/aws/bin/cfn-signal -e 0 -r \"MySQL server setup complete\" '",
+          { "Ref" : "WaitHandle" }, "'\n"
+
         ]]}}
       }
+    },
+
+    "WaitHandle" : {
+      "Type" : "AWS::CloudFormation::WaitConditionHandle"
+    },
+
+    "WaitCondition" : {
+      "Type" : "AWS::CloudFormation::WaitCondition",
+      "DependsOn" : "DatabaseInstance",
+      "Properties" : {
+        "Handle" : {"Ref" : "WaitHandle"},
+        "Timeout" : "600"
+      }
     }
   },