summaryrefslogtreecommitdiff
path: root/azurelinuxagent/daemon
diff options
context:
space:
mode:
authorƁukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com>2017-03-15 10:19:34 +0100
committerusd-importer <ubuntu-server@lists.ubuntu.com>2017-03-17 13:08:24 +0000
commit83be006e288c58a46f5b76c29b6886c1f417d88c (patch)
tree91ba57e843714c232b5af5ab8dc6f3322ff7841e /azurelinuxagent/daemon
parentd064ab0bffd429382ea4fafeb144784d403848bd (diff)
downloadvyos-walinuxagent-83be006e288c58a46f5b76c29b6886c1f417d88c.tar.gz
vyos-walinuxagent-83be006e288c58a46f5b76c29b6886c1f417d88c.zip
Import patches-unapplied version 2.2.6-0ubuntu1 to ubuntu/zesty-proposed
Imported using git-ubuntu import. Changelog parent: d064ab0bffd429382ea4fafeb144784d403848bd New changelog entries: * New upstream release (LP: #1661750). * debian/control: - Change the maintainer to Ubuntu Developers (LP: #1657528). - Add the dependency of isc-dhcp-client as our maintainer scripts assume it's installed. - Add trailing commas to dependencies, add whitespaces. * Rename ephemeral-disk-warning.sh to ephemeral-disk-warning (lintian error). * debian/docs: - Remove LICENSE.txt as it's redundant. * debian/postinst: - Stop checking for update-initramfs existence using the absolute path, use the 'command' command instead to make lintian happy. * Remove debian/patches/disable-auto-update.patch: - We now ship with auto-updates enabled (LP: #1650522). * debian/maintscript: - Add a maintscript to rename the old logrotate file on upgrade from an ancient version of walinuxagent (LP: #1673152).
Diffstat (limited to 'azurelinuxagent/daemon')
-rw-r--r--azurelinuxagent/daemon/main.py31
-rw-r--r--azurelinuxagent/daemon/resourcedisk/default.py51
-rw-r--r--azurelinuxagent/daemon/resourcedisk/freebsd.py3
3 files changed, 57 insertions, 28 deletions
diff --git a/azurelinuxagent/daemon/main.py b/azurelinuxagent/daemon/main.py
index d3185a1..b0da02a 100644
--- a/azurelinuxagent/daemon/main.py
+++ b/azurelinuxagent/daemon/main.py
@@ -23,34 +23,32 @@ import time
import traceback
import azurelinuxagent.common.conf as conf
-import azurelinuxagent.common.event as event
-import azurelinuxagent.common.utils.fileutil as fileutil
import azurelinuxagent.common.logger as logger
-
-from azurelinuxagent.common.future import ustr
+import azurelinuxagent.common.utils.fileutil as fileutil
from azurelinuxagent.common.event import add_event, WALAEventOperation
-from azurelinuxagent.common.exception import ProtocolError
+from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.protocol import get_protocol_util
-from azurelinuxagent.common.rdma import RDMADeviceHandler, setup_rdma_device
-from azurelinuxagent.common.utils.textutil import parse_doc, find, getattrib
+from azurelinuxagent.common.rdma import setup_rdma_device
from azurelinuxagent.common.version import AGENT_LONG_NAME, AGENT_VERSION, \
- DISTRO_NAME, DISTRO_VERSION, \
- DISTRO_FULL_NAME, PY_VERSION_MAJOR, \
- PY_VERSION_MINOR, PY_VERSION_MICRO
+ DISTRO_NAME, DISTRO_VERSION, PY_VERSION_MAJOR, PY_VERSION_MINOR, \
+ PY_VERSION_MICRO
from azurelinuxagent.daemon.resourcedisk import get_resourcedisk_handler
from azurelinuxagent.daemon.scvmm import get_scvmm_handler
+from azurelinuxagent.ga.update import get_update_handler
from azurelinuxagent.pa.provision import get_provision_handler
from azurelinuxagent.pa.rdma import get_rdma_handler
-from azurelinuxagent.ga.update import get_update_handler
+
def get_daemon_handler():
return DaemonHandler()
+
class DaemonHandler(object):
"""
Main thread of daemon. It will invoke other threads to do actual work
"""
+
def __init__(self):
self.running = True
self.osutil = get_osutil()
@@ -59,7 +57,7 @@ class DaemonHandler(object):
logger.info("{0} Version:{1}", AGENT_LONG_NAME, AGENT_VERSION)
logger.info("OS: {0} {1}", DISTRO_NAME, DISTRO_VERSION)
logger.info("Python: {0}.{1}.{2}", PY_VERSION_MAJOR, PY_VERSION_MINOR,
- PY_VERSION_MICRO)
+ PY_VERSION_MICRO)
self.check_pid()
@@ -68,12 +66,11 @@ class DaemonHandler(object):
self.daemon()
except Exception as e:
err_msg = traceback.format_exc()
- add_event("WALA", is_success=False, message=ustr(err_msg),
+ add_event("WALA", is_success=False, message=ustr(err_msg),
op=WALAEventOperation.UnhandledError)
logger.info("Sleep 15 seconds and restart daemon")
time.sleep(15)
-
def check_pid(self):
"""Check whether daemon is already running"""
pid = None
@@ -84,11 +81,11 @@ class DaemonHandler(object):
if self.osutil.check_pid_alive(pid):
logger.info("Daemon is already running: {0}", pid)
sys.exit(0)
-
+
fileutil.write_file(pid_file, ustr(os.getpid()))
def daemon(self):
- logger.info("Run daemon")
+ logger.info("Run daemon")
self.protocol_util = get_protocol_util()
self.scvmm_handler = get_scvmm_handler()
@@ -125,6 +122,6 @@ class DaemonHandler(object):
logger.error("Error setting up rdma device: %s" % e)
else:
logger.info("RDMA capabilities are not enabled, skipping")
-
+
while self.running:
self.update_handler.run_latest()
diff --git a/azurelinuxagent/daemon/resourcedisk/default.py b/azurelinuxagent/daemon/resourcedisk/default.py
index 18ce884..21de38f 100644
--- a/azurelinuxagent/daemon/resourcedisk/default.py
+++ b/azurelinuxagent/daemon/resourcedisk/default.py
@@ -19,6 +19,8 @@ import os
import re
import sys
import threading
+from time import sleep
+
import azurelinuxagent.common.logger as logger
from azurelinuxagent.common.future import ustr
import azurelinuxagent.common.conf as conf
@@ -99,7 +101,14 @@ class ResourceDiskHandler(object):
existing)
return existing
- fileutil.mkdir(mount_point, mode=0o755)
+ try:
+ fileutil.mkdir(mount_point, mode=0o755)
+ except OSError as ose:
+ msg = "Failed to create mount point " \
+ "directory [{0}]: {1}".format(mount_point, ose)
+ logger.error(msg)
+ raise ResourceDiskError(msg=msg, inner=ose)
+
logger.info("Examining partition table")
ret = shellutil.run_get_output("parted {0} print".format(device))
if ret[0]:
@@ -144,9 +153,23 @@ class ResourceDiskHandler(object):
mount_string = self.get_mount_string(mount_options,
partition,
mount_point)
+ attempts = 5
+ while not os.path.exists(partition) and attempts > 0:
+ logger.info("Waiting for partition [{0}], {1} attempts remaining",
+ partition,
+ attempts)
+ sleep(5)
+ attempts -= 1
+
+ if not os.path.exists(partition):
+ raise ResourceDiskError("Partition was not created [{0}]".format(partition))
+
logger.info("Mount resource disk [{0}]", mount_string)
- ret = shellutil.run(mount_string, chk_err=False)
- if ret:
+ ret, output = shellutil.run_get_output(mount_string, chk_err=False)
+ # if the exit code is 32, then the resource disk is already mounted
+ if ret == 32:
+ logger.warn("Could not mount resource disk: {0}", output)
+ elif ret != 0:
# Some kernels seem to issue an async partition re-read after a
# 'parted' command invocation. This causes mount to fail if the
# partition re-read is not complete by the time mount is
@@ -154,19 +177,25 @@ class ResourceDiskHandler(object):
# the partition and try mounting.
logger.warn("Failed to mount resource disk. "
"Retry mounting after re-reading partition info.")
+
if shellutil.run("sfdisk -R {0}".format(device), chk_err=False):
shellutil.run("blockdev --rereadpt {0}".format(device),
chk_err=False)
- ret = shellutil.run(mount_string, chk_err=False)
+
+ ret, output = shellutil.run_get_output(mount_string)
if ret:
logger.warn("Failed to mount resource disk. "
- "Attempting to format and retry mount.")
+ "Attempting to format and retry mount. [{0}]",
+ output)
+
shellutil.run(mkfs_string)
- ret = shellutil.run(mount_string)
+ ret, output = shellutil.run_get_output(mount_string)
if ret:
raise ResourceDiskError("Could not mount {0} "
"after syncing partition table: "
- "{1}".format(partition, ret))
+ "[{1}] {2}".format(partition,
+ ret,
+ output))
logger.info("Resource disk {0} is mounted at {1} with {2}",
device,
@@ -217,7 +246,9 @@ class ResourceDiskHandler(object):
swapfile = os.path.join(mount_point, 'swapfile')
swaplist = shellutil.run_get_output("swapon -s")[1]
- if swapfile in swaplist and os.path.getsize(swapfile) == size:
+ if swapfile in swaplist \
+ and os.path.isfile(swapfile) \
+ and os.path.getsize(swapfile) == size:
logger.info("Swap already enabled")
return
@@ -253,8 +284,8 @@ class ResourceDiskHandler(object):
if not isinstance(nbytes, int):
nbytes = int(nbytes)
- if nbytes < 0:
- raise ValueError(nbytes)
+ if nbytes <= 0:
+ raise ResourceDiskError("Invalid swap size [{0}]".format(nbytes))
if os.path.isfile(filename):
os.remove(filename)
diff --git a/azurelinuxagent/daemon/resourcedisk/freebsd.py b/azurelinuxagent/daemon/resourcedisk/freebsd.py
index 4ca0058..e43d9c4 100644
--- a/azurelinuxagent/daemon/resourcedisk/freebsd.py
+++ b/azurelinuxagent/daemon/resourcedisk/freebsd.py
@@ -47,7 +47,8 @@ class FreeBSDResourceDiskHandler(ResourceDiskHandler):
dic[geom_name] = line[8:]
return dic
- def mount_resource_disk(self, mount_point, fs):
+ def mount_resource_disk(self, mount_point):
+ fs = self.fs
if fs != 'ufs':
raise ResourceDiskError("Unsupported filesystem type:{0}, only ufs is supported.".format(fs))