~ubuntu-branches/ubuntu/natty/cloud-init/natty

« back to all changes in this revision

Viewing changes to debian/patches/catchup-rev-385.diff

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2011-03-04 21:17:21 UTC
  • Revision ID: package-import@ubuntu.com-20110304211721-yrbpgdo3wlsfn2xa
* catch up to trunk cloud-init (rev 385).
* attempt to install packages on failed apt-get update (LP: #728167)
* enabled timezone and mcollective cloud-config plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
------------------------------------------------------------
 
2
revno: 385
 
3
committer: Scott Moser <smoser@ubuntu.com>
 
4
branch nick: trunk
 
5
timestamp: Fri 2011-03-04 11:06:51 -0500
 
6
message:
 
7
  add mcollective to cloud.cfg
 
8
------------------------------------------------------------
 
9
revno: 384
 
10
committer: Scott Moser <smoser@ubuntu.com>
 
11
branch nick: trunk
 
12
timestamp: Thu 2011-03-03 20:37:30 -0500
 
13
message:
 
14
  add 'timezone' cloud-config module to cloud.cfg
 
15
------------------------------------------------------------
 
16
revno: 383
 
17
fixes bug(s): https://launchpad.net/bugs/728167
 
18
committer: Scott Moser <smoser@ubuntu.com>
 
19
branch nick: trunk
 
20
timestamp: Thu 2011-03-03 20:04:24 -0500
 
21
message:
 
22
  make update of sources not prevent installation attempt (LP: #728167)
 
23
------------------------------------------------------------
 
24
revno: 382
 
25
committer: Scott Moser <smoser@ubuntu.com>
 
26
branch nick: trunk
 
27
timestamp: Thu 2011-03-03 17:15:12 -0500
 
28
message:
 
29
  cc_resizefs.py: log output of failed resizefs or blkid commands
 
30
------------------------------------------------------------
 
31
revno: 381
 
32
committer: Scott Moser <smoser@ubuntu.com>
 
33
branch nick: trunk
 
34
timestamp: Thu 2011-03-03 17:12:27 -0500
 
35
message:
 
36
  in subp, put output and stderr into the raised error
 
37
------------------------------------------------------------
 
38
revno: 380
 
39
committer: Scott Moser <smoser@ubuntu.com>
 
40
branch nick: trunk
 
41
timestamp: Wed 2011-03-02 17:08:46 -0500
 
42
message:
 
43
  fix bug preventing early exit of cloud-init on 'no-net' path
 
44
------------------------------------------------------------
 
45
revno: 379 [merge]
 
46
committer: Scott Moser <smoser@ubuntu.com>
 
47
branch nick: trunk
 
48
timestamp: Tue 2011-02-22 12:18:23 -0500
 
49
message:
 
50
  merge mcollective fixes from Marc.  Changes to indentation and added comments
 
51
------------------------------------------------------------
 
52
revno: 378
 
53
tags: 0.6.1
 
54
committer: Scott Moser <smoser@ubuntu.com>
 
55
branch nick: trunk
 
56
timestamp: Sat 2011-02-19 00:42:32 -0500
 
57
message:
 
58
  add examples of kernel command line cloud-config
 
59
------------------------------------------------------------
 
60
Use --include-merges or -n0 to see merged revisions.
 
61
=== modified file 'cloud-init.py'
 
62
--- a/cloud-init.py
 
63
+++ b/cloud-init.py
 
64
@@ -93,7 +93,7 @@
 
65
         # most sense to exit early and silently
 
66
         for f in stop_files:
 
67
             try:
 
68
-                fp = open("/var/lib/cloud/instance/obj.pkl","r")
 
69
+                fp = open(f,"r")
 
70
                 fp.close()
 
71
             except:
 
72
                 continue
 
73
--- a/cloudinit/CloudConfig/cc_apt_update_upgrade.py
 
74
+++ b/cloudinit/CloudConfig/cc_apt_update_upgrade.py
 
75
@@ -55,15 +55,34 @@
 
76
             log.error("Failed to run debconf-set-selections")
 
77
             log.debug(traceback.format_exc())
 
78
 
 
79
+    errors = [ ]
 
80
     if update:
 
81
-        cc.update_package_sources()
 
82
+        try:
 
83
+            cc.update_package_sources()
 
84
+        except subprocess.CalledProcessError as e:
 
85
+            log.warn("apt-get update failed")
 
86
+            log.debug(traceback.format_exc())
 
87
+            errors.append(e)
 
88
 
 
89
     if upgrade:
 
90
-        cc.apt_get("upgrade")
 
91
+        try:
 
92
+            cc.apt_get("upgrade")
 
93
+        except subprocess.CalledProcessError as e:
 
94
+            log.warn("apt upgrade failed")
 
95
+            log.debug(traceback.format_exc())
 
96
+            errors.append(e)
 
97
 
 
98
     pkglist = util.get_cfg_option_list_or_str(cfg,'packages',[])
 
99
     if len(pkglist):
 
100
-        cc.install_packages(pkglist)
 
101
+        try:
 
102
+            cc.install_packages(pkglist)
 
103
+        except subprocess.CalledProcessError as e:
 
104
+            log.warn("Failed to install packages: %s " % pkglist)
 
105
+            log.debug(traceback.format_exc())
 
106
+            errors.append(e)
 
107
+
 
108
+    if len(errors):
 
109
+        raise errors[0]
 
110
 
 
111
     return(True)
 
112
 
 
113
--- a/cloudinit/CloudConfig/cc_mcollective.py
 
114
+++ b/cloudinit/CloudConfig/cc_mcollective.py
 
115
@@ -20,20 +20,21 @@
 
116
 import pwd
 
117
 import socket
 
118
 import subprocess
 
119
+import fileinput
 
120
 import StringIO
 
121
 import ConfigParser
 
122
 import cloudinit.CloudConfig as cc
 
123
 
 
124
 # Our fake header section
 
125
 class FakeSecHead(object):
 
126
-   def __init__(self, fp):
 
127
-     self.fp = fp
 
128
-     self.sechead = '[nullsection]\n'
 
129
-   def readline(self):
 
130
-     if self.sechead:
 
131
-       try: return self.sechead
 
132
-       finally: self.sechead = None
 
133
-     else: return self.fp.readline()
 
134
+    def __init__(self, fp):
 
135
+        self.fp = fp
 
136
+        self.sechead = '[nullsection]\n'
 
137
+    def readline(self):
 
138
+        if self.sechead:
 
139
+            try: return self.sechead
 
140
+            finally: self.sechead = None
 
141
+        else: return self.fp.readline()
 
142
 
 
143
 def handle(name,cfg,cloud,log,args):
 
144
     # If there isn't a mcollective key in the configuration don't do anything
 
145
@@ -53,11 +54,21 @@
 
146
             # to overwrite or create new items as needed
 
147
             for o, v in cfg.iteritems():
 
148
                 mcollective_config.set(cfg_name,o,v)
 
149
-            # We got all our config as wanted we'll rename
 
150
-            # the previous server.cfg and create our new one
 
151
-            os.rename('/etc/mcollective/server.cfg','/etc/mcollective/server.cfg.old')
 
152
-            with open('/etc/mcollective/server.cfg', 'wb') as configfile:
 
153
-                mcollective_config.write(configfile)
 
154
+        # We got all our config as wanted we'll rename
 
155
+        # the previous server.cfg and create our new one
 
156
+        os.rename('/etc/mcollective/server.cfg','/etc/mcollective/server.cfg.old')
 
157
+        outputfile = StringIO.StringIO()
 
158
+        mcollective_config.write(outputfile)
 
159
+        # Now we got the whole file, write to disk except first line
 
160
+        final_configfile = open('/etc/mcollective/server.cfg', 'wb')
 
161
+        # Note below, that we've just used ConfigParser because it generally
 
162
+        # works.  Below, we remove the initial 'nullsection' header
 
163
+        # and then change 'key = value' to 'key: value'.  The global
 
164
+        # search and replace of '=' with ':' could be problematic though.
 
165
+        # this most likely needs fixing.
 
166
+        final_configfile.write(outputfile.getvalue().replace('[nullsection]\n','').replace(' =',':'))
 
167
+        final_configfile.close()
 
168
+
 
169
     # Start mcollective
 
170
     subprocess.check_call(['service', 'mcollective', 'start'])
 
171
 
 
172
--- a/cloudinit/CloudConfig/cc_resizefs.py
 
173
+++ b/cloudinit/CloudConfig/cc_resizefs.py
 
174
@@ -34,8 +34,9 @@
 
175
     cmd = ['blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', '/dev/root']
 
176
     try:
 
177
         (fstype,err) = util.subp(cmd)
 
178
-    except Exception as e:
 
179
+    except subprocess.CalledProcessError as e:
 
180
         log.warn("Failed to get filesystem type via %s" % cmd)
 
181
+        log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1])
 
182
         raise
 
183
 
 
184
     if fstype.startswith("ext"):
 
185
@@ -48,7 +49,8 @@
 
186
 
 
187
     try:
 
188
         (out,err) = util.subp(resize_cmd)
 
189
-    except Exception as e:
 
190
+    except subprocess.CalledProcessError as e:
 
191
         log.warn("Failed to resize filesystem (%s)" % resize_cmd)
 
192
+        log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1])
 
193
         raise
 
194
         
 
195
--- a/cloudinit/util.py
 
196
+++ b/cloudinit/util.py
 
197
@@ -147,7 +147,7 @@
 
198
     sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=s_in)
 
199
     out,err = sp.communicate(input)
 
200
     if sp.returncode is not 0:
 
201
-        raise subprocess.CalledProcessError(sp.returncode,args)
 
202
+        raise subprocess.CalledProcessError(sp.returncode,args, (out,err))
 
203
     return(out,err)
 
204
 
 
205
 def render_to_file(template, outfile, searchList):
 
206
--- a/config/cloud.cfg
 
207
+++ b/config/cloud.cfg
 
208
@@ -19,7 +19,9 @@
 
209
  - set-passwords
 
210
  - grub-dpkg
 
211
  - apt-update-upgrade
 
212
+ - timezone
 
213
  - puppet
 
214
+ - mcollective
 
215
  - disable-ec2-metadata
 
216
  - runcmd
 
217
  - byobu
 
218
--- /dev/null
 
219
+++ b/doc/examples/cloud-config-mcollective.txt
 
220
@@ -0,0 +1,15 @@
 
221
+#cloud-config
 
222
+#
 
223
+# This is an example file to automatically setup and run mcollective
 
224
+# when the instance boots for the first time.
 
225
+# Make sure that this file is valid yaml before starting instances.
 
226
+# It should be passed as user-data when starting the instance.
 
227
+mcollective:
 
228
+ # Every key present in the conf object will be added to server.cfg:
 
229
+ # key: value
 
230
+ #
 
231
+ # For example the configuration below will have the following key
 
232
+ # added to server.cfg:
 
233
+ # plugin.stomp.host: dbhost
 
234
+ conf:
 
235
+   plugin.stomp.host: dbhost