summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--cloudinit/CloudConfig/cc_resizefs.py3
-rw-r--r--cloudinit/util.py23
3 files changed, 27 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 762abafa..14039690 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,7 @@
- fix cloud-init in ubuntu lxc containers (LP: #800824)
- sanitize hosts file for system's hostname to 127.0.1.1 (LP: #802637)
- add chef support (cloudinit/CloudConfig/cc_chef.py)
+ - do not give trace on failure to resize in lxc container (LP: #800856)
0.6.1:
- fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509)
- improve comment strings in rsyslog file tools/21-cloudinit.conf
diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py
index e396b283..883c269b 100644
--- a/cloudinit/CloudConfig/cc_resizefs.py
+++ b/cloudinit/CloudConfig/cc_resizefs.py
@@ -42,6 +42,9 @@ def handle(name,cfg,cloud,log,args):
dev=os.makedev(os.major(st_dev),os.minor(st_dev))
os.mknod(devpth, 0400 | stat.S_IFBLK, dev)
except:
+ if util.islxc():
+ log.debug("inside lxc, ignoring mknod failure in resizefs")
+ return
log.warn("Failed to make device node to resize /")
raise
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 8f6a6b0d..ec37f2f7 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -395,3 +395,26 @@ def dos2unix(input):
pos = input.find('\n')
if pos <= 0 or input[pos-1] != '\r': return(input)
return(input.replace('\r\n','\n'))
+
+def islxc():
+ # is this host running lxc?
+ try:
+ with open("/proc/1/cgroup") as f:
+ if f.read() == "/":
+ return True
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+ try:
+ # try to run a program named 'lxc-is-container'. if it returns true, then
+ # we're inside a container. otherwise, no
+ sp = subprocess.Popen(['lxc-is-container'], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ out,err = sp.communicate(None)
+ return(sp.returncode == 0)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+ return False