22728491 cloudbase-init service stuck after install
authorPadma Dakoju <padma.dakoju@oracle.com>
Mon, 10 Oct 2016 10:57:41 -0700
changeset 7080 49b4c7a1ceca
parent 7079 315c9793dc1e
child 7081 616e1d8621e7
22728491 cloudbase-init service stuck after install
components/openstack/cloudbase-init/Makefile
components/openstack/cloudbase-init/cloudbase-init.p5m
components/openstack/cloudbase-init/files/cloudbase-init
components/openstack/cloudbase-init/files/cloudbase-init.xml
components/openstack/cloudbase-init/patches/url-timeout.patch
--- a/components/openstack/cloudbase-init/Makefile	Fri Oct 07 13:06:14 2016 -0700
+++ b/components/openstack/cloudbase-init/Makefile	Mon Oct 10 10:57:41 2016 -0700
@@ -63,4 +63,5 @@
 # Tests require testr which is not integrated
 test:		$(NO_TESTS)
 
+REQUIRED_PACKAGES += system/core-os
 REQUIRED_PACKAGES += system/network
--- a/components/openstack/cloudbase-init/cloudbase-init.p5m	Fri Oct 07 13:06:14 2016 -0700
+++ b/components/openstack/cloudbase-init/cloudbase-init.p5m	Mon Oct 10 10:57:41 2016 -0700
@@ -42,6 +42,7 @@
 file files/cloudbase-init.conf path=etc/cloudbase-init.conf
 file files/cloudbase-init.xml \
     path=lib/svc/manifest/application/cloudbase-init.xml
+file files/cloudbase-init path=lib/svc/method/cloudbase-init
 file path=usr/bin/cloudbase-init
 file path=usr/lib/python$(PYVER)/vendor-packages/cloudbase_init-$(COMPONENT_VERSION)-py$(PYVER).egg-info/PKG-INFO
 file path=usr/lib/python$(PYVER)/vendor-packages/cloudbase_init-$(COMPONENT_VERSION)-py$(PYVER).egg-info/SOURCES.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/openstack/cloudbase-init/files/cloudbase-init	Mon Oct 10 10:57:41 2016 -0700
@@ -0,0 +1,46 @@
+#!/usr/bin/python2.7
+
+# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import ConfigParser
+import os
+import sys
+import urllib2
+
+import smf_include
+
+
+def start():
+
+    # verify metadata service is reachable
+    try:
+        parser = ConfigParser.ConfigParser()
+        parser.read('/etc/cloudbase-init.conf')
+        if parser.has_option('DEFAULT', 'metadata_base_url'):
+            url = parser.get('DEFAULT', 'metadata_base_url')
+        else:
+            url = 'http://169.254.169.254'
+        open_url = urllib2.urlopen(url, timeout=20)
+    except Exception as err:
+        print >> sys.stderr, 'No response from %s: %s' % (url, err)
+        return smf_include.SMF_EXIT_ERR_FATAL
+
+    # Initiate cloudbase-init service
+    cmd_str = "/usr/bin/cloudbase-init --debug"
+    smf_include.smf_subprocess(cmd_str)
+
+if __name__ == "__main__":
+    os.putenv("LC_ALL", "C")
+    smf_include.smf_main()
--- a/components/openstack/cloudbase-init/files/cloudbase-init.xml	Fri Oct 07 13:06:14 2016 -0700
+++ b/components/openstack/cloudbase-init/files/cloudbase-init.xml	Mon Oct 10 10:57:41 2016 -0700
@@ -1,7 +1,7 @@
 <?xml version="1.0" ?>
 <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
 <!--
- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
 
  Licensed under the Apache License, Version 2.0 (the "License"); you may
  not use this file except in compliance with the License. You may obtain
@@ -33,7 +33,7 @@
     <logfile_attributes permissions='600'/>
 
     <exec_method timeout_seconds="0" type="method" name="start"
-      exec="/usr/bin/cloudbase-init --debug">
+      exec="/lib/svc/method/cloudbase-init %m">
     </exec_method>
     <exec_method timeout_seconds="30" type="method" name="stop"
       exec=":kill"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/openstack/cloudbase-init/patches/url-timeout.patch	Mon Oct 10 10:57:41 2016 -0700
@@ -0,0 +1,50 @@
+Add timeout to prevent cloudbase-init service being stuck in offline state
+for long time.
+This has not been committed upstream, but has been filed in launchpad:
+
+https://bugs.launchpad.net/cloudbase-init/+bug/1630006
+
+--- cloudbase-init-0.9.9/cloudbaseinit/metadata/services/httpservice.py.orig	2016-09-06 14:29:04.416253079 +0000
++++ cloudbase-init-0.9.9/cloudbaseinit/metadata/services/httpservice.py	2016-09-06 14:39:14.807656387 +0000
+@@ -58,7 +58,7 @@
+ 
+     def _get_response(self, req):
+         try:
+-            return request.urlopen(req)
++            return request.urlopen(req, timeout=1)
+         except error.HTTPError as ex:
+             if ex.code == 404:
+                 raise base.NotExistingMetadataException()
+--- cloudbase-init-0.9.9/cloudbaseinit/metadata/services/ec2service.py.orig	2016-09-06 14:29:11.956815039 +0000
++++ cloudbase-init-0.9.9/cloudbaseinit/metadata/services/ec2service.py	2016-09-06 14:40:09.253600964 +0000
+@@ -60,7 +60,7 @@
+ 
+     def _get_response(self, req):
+         try:
+-            return request.urlopen(req)
++            return request.urlopen(req, timeout=1)
+         except error.HTTPError as ex:
+             if ex.code == 404:
+                 raise base.NotExistingMetadataException()
+--- cloudbase-init-0.9.9/cloudbaseinit/metadata/services/maasservice.py.orig	2016-09-06 14:29:26.753303424 +0000
++++ cloudbase-init-0.9.9/cloudbaseinit/metadata/services/maasservice.py	2016-09-06 14:40:40.454202962 +0000
+@@ -79,7 +79,7 @@
+ 
+     def _get_response(self, req):
+         try:
+-            return request.urlopen(req)
++            return request.urlopen(req, timeout=1)
+         except error.HTTPError as ex:
+             if ex.code == 404:
+                 raise base.NotExistingMetadataException()
+--- cloudbase-init-0.9.9/cloudbaseinit/metadata/services/cloudstack.py.orig	2016-09-22 14:25:30.411026974 +0000
++++ cloudbase-init-0.9.9/cloudbaseinit/metadata/services/cloudstack.py	2016-09-22 14:26:29.615140081 +0000
+@@ -90,7 +90,7 @@
+         """Get content for received url."""
+         LOG.debug('Getting metadata from:  %s', url)
+         request = urllib.request.Request(url, **kwargs)
+-        response = urllib.request.urlopen(request)
++        response = urllib.request.urlopen(request, timeout=1)
+         return response.read()
+ 
+     def _get_data(self, path):