summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-04-27 12:50:12 -0400
committerScott Moser <smoser@brickies.net>2017-04-27 12:50:12 -0400
commit8310484a880690529a4936615df596d467e51708 (patch)
tree886aeb1a6e3ca809e466ddbcacbe9741b56dafa0 /cloudinit/util.py
parentaf63cf763946bca6163dc797195a3aeae975f8da (diff)
parent513e99e049eab4acea14e187f59d760adc755b40 (diff)
downloadvyos-cloud-init-8310484a880690529a4936615df596d467e51708.tar.gz
vyos-cloud-init-8310484a880690529a4936615df596d467e51708.zip
merge from 513e99e049ea at 0.7.9-113-g513e99e0
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 17abdf81..22af99dd 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -96,11 +96,11 @@ def _lsb_release(target=None):
data[fmap[fname]] = val.strip()
missing = [k for k in fmap.values() if k not in data]
if len(missing):
- LOG.warn("Missing fields in lsb_release --all output: %s",
- ','.join(missing))
+ LOG.warning("Missing fields in lsb_release --all output: %s",
+ ','.join(missing))
except ProcessExecutionError as err:
- LOG.warn("Unable to get lsb_release --all: %s", err)
+ LOG.warning("Unable to get lsb_release --all: %s", err)
data = dict((v, "UNAVAILABLE") for v in fmap.values())
return data
@@ -590,7 +590,7 @@ def system_info():
'release': platform.release(),
'python': platform.python_version(),
'uname': platform.uname(),
- 'dist': platform.linux_distribution(),
+ 'dist': platform.linux_distribution(), # pylint: disable=W1505
}
@@ -865,7 +865,7 @@ def read_file_or_url(url, timeout=5, retries=10,
url = "file://%s" % url
if url.lower().startswith("file://"):
if data:
- LOG.warn("Unable to post data to file resource %s", url)
+ LOG.warning("Unable to post data to file resource %s", url)
file_path = url[len("file://"):]
try:
contents = load_file(file_path, decode=False)
@@ -1279,7 +1279,7 @@ def get_cmdline():
# replace nulls with space and drop trailing null
cmdline = contents.replace("\x00", " ")[:-1]
except Exception as e:
- LOG.warn("failed reading /proc/1/cmdline: %s", e)
+ LOG.warning("failed reading /proc/1/cmdline: %s", e)
cmdline = ""
else:
try:
@@ -1400,7 +1400,7 @@ def logexc(log, msg, *args):
# or even desirable to have that much junk
# coming out to a non-debug stream
if msg:
- log.warn(msg, *args)
+ log.warning(msg, *args)
# Debug gets the full trace. However, nose has a bug whereby its
# logcapture plugin doesn't properly handle the case where there is no
# actual exception. To avoid tracebacks during the test suite then, we'll
@@ -1688,7 +1688,7 @@ def chmod(path, mode):
os.chmod(path, real_mode)
-def write_file(filename, content, mode=0o644, omode="wb"):
+def write_file(filename, content, mode=0o644, omode="wb", copy_mode=False):
"""
Writes a file with the given content and sets the file mode as specified.
Resotres the SELinux context if possible.
@@ -1698,6 +1698,14 @@ def write_file(filename, content, mode=0o644, omode="wb"):
@param mode: The filesystem mode to set on the file.
@param omode: The open mode used when opening the file (w, wb, a, etc.)
"""
+
+ if copy_mode:
+ try:
+ file_stat = os.stat(filename)
+ mode = stat.S_IMODE(file_stat.st_mode)
+ except OSError:
+ pass
+
ensure_dir(os.path.dirname(filename))
if 'b' in omode.lower():
content = encode_text(content)
@@ -2336,8 +2344,8 @@ def read_dmi_data(key):
if dmidecode_path:
return _call_dmidecode(key, dmidecode_path)
- LOG.warn("did not find either path %s or dmidecode command",
- DMI_SYS_PATH)
+ LOG.warning("did not find either path %s or dmidecode command",
+ DMI_SYS_PATH)
return None
@@ -2396,9 +2404,10 @@ def rootdev_from_cmdline(cmdline):
if found.startswith("LABEL="):
return "/dev/disk/by-label/" + found[len("LABEL="):]
if found.startswith("UUID="):
- return "/dev/disk/by-uuid/" + found[len("UUID="):]
+ return "/dev/disk/by-uuid/" + found[len("UUID="):].lower()
if found.startswith("PARTUUID="):
- disks_path = "/dev/disk/by-partuuid/" + found[len("PARTUUID="):]
+ disks_path = ("/dev/disk/by-partuuid/" +
+ found[len("PARTUUID="):].lower())
if os.path.exists(disks_path):
return disks_path
results = find_devs_with(found)