summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--cloudinit/helpers.py18
-rw-r--r--cloudinit/stages.py12
-rw-r--r--cloudinit/util.py8
-rw-r--r--tests/unittests/test_handler/test_handler_seed_random.py2
-rwxr-xr-xtools/read-dependencies14
-rwxr-xr-xtools/read-version16
7 files changed, 38 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b2770a4..79dd07ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,8 @@
which also reads from uptime. uptime is useful as clock may change during
boot due to ntp.
- prefer growpart resizer to 'parted resizepart' (LP: #1212492)
+ - support random data seed from config drive or azure, and a module
+ 'seed_random' to read that and write it to /dev/urandom.
0.7.2:
- add a debian watch file
- add 'sudo' entry to ubuntu's default user (LP: #1080717)
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 1c46efde..e5eac6a7 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -292,11 +292,16 @@ class ContentHandlers(object):
def is_registered(self, content_type):
return content_type in self.registered
- def register(self, mod, initialized=False):
+ def register(self, mod, initialized=False, overwrite=True):
types = set()
for t in mod.list_types():
+ if overwrite:
+ types.add(t)
+ else:
+ if not self.is_registered(t):
+ types.add(t)
+ for t in types:
self.registered[t] = mod
- types.add(t)
if initialized and mod not in self.initialized:
self.initialized.append(mod)
return types
@@ -310,15 +315,6 @@ class ContentHandlers(object):
def iteritems(self):
return self.registered.iteritems()
- def register_defaults(self, defs):
- registered = set()
- for mod in defs:
- for t in mod.list_types():
- if not self.is_registered(t):
- self.registered[t] = mod
- registered.add(t)
- return registered
-
class Paths(object):
def __init__(self, path_cfgs, ds=None):
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 3e49e8c5..07c55802 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -375,7 +375,9 @@ class Init(object):
mod = importer.import_module(mod_locs[0])
mod = handlers.fixup_handler(mod)
types = c_handlers.register(mod)
- LOG.debug("Added handler for %s from %s", types, fname)
+ if types:
+ LOG.debug("Added custom handler for %s from %s",
+ types, fname)
except Exception:
util.logexc(LOG, "Failed to register handler from %s",
fname)
@@ -386,10 +388,10 @@ class Init(object):
# Register any other handlers that come from the default set. This
# is done after the cloud-dir handlers so that the cdir modules can
# take over the default user-data handler content-types.
- def_handlers = self._default_userdata_handlers()
- applied_def_handlers = c_handlers.register_defaults(def_handlers)
- if applied_def_handlers:
- LOG.debug("Registered default handlers: %s", applied_def_handlers)
+ for mod in self._default_userdata_handlers():
+ types = c_handlers.register(mod, overwrite=False)
+ if types:
+ LOG.debug("Added default handler for %s from %s", types, mod)
# Form our cloud interface
data = self.cloudify()
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 4a74ba57..5032cc47 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1791,15 +1791,19 @@ def log_time(logfunc, msg, func, args=None, kwargs=None, get_uptime=False):
ret = func(*args, **kwargs)
finally:
delta = time.time() - start
+ udelta = None
if ustart is not None:
try:
udelta = float(uptime()) - ustart
except ValueError:
- udelta = "N/A"
+ pass
tmsg = " took %0.3f seconds" % delta
if get_uptime:
- tmsg += "(%0.2f)" % udelta
+ if isinstance(udelta, (float)):
+ tmsg += " (%0.2f)" % udelta
+ else:
+ tmsg += " (N/A)"
try:
logfunc(msg + tmsg)
except:
diff --git a/tests/unittests/test_handler/test_handler_seed_random.py b/tests/unittests/test_handler/test_handler_seed_random.py
index 458b0028..1b0675bb 100644
--- a/tests/unittests/test_handler/test_handler_seed_random.py
+++ b/tests/unittests/test_handler/test_handler_seed_random.py
@@ -30,7 +30,7 @@ from cloudinit import helpers
from cloudinit import util
from cloudinit.sources import DataSourceNone
-
+
from tests.unittests import helpers as t_help
import logging
diff --git a/tools/read-dependencies b/tools/read-dependencies
index cadb09a8..87db5d83 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -12,20 +12,20 @@ find_root() {
[ $? -eq 0 -a -f "${topd}/setup.py" ] || return
ROOT_DIR="$topd"
}
+fail() { echo "$0:" "$@" 1>&2; exit 1; }
if ! find_root; then
- echo "Unable to locate 'setup.py' file that should" \
- "exist in the cloud-init root directory." 1>&2
- exit 1;
+ fail "Unable to locate 'setup.py' file that should " \
+ "exist in the cloud-init root directory."
fi
REQUIRES="$ROOT_DIR/Requires"
if [ ! -e "$REQUIRES" ]; then
- echo "Unable to find 'Requires' file located at $REQUIRES"
- exit 1
+ fail "Unable to find 'Requires' file located at '$REQUIRES'"
fi
-# Filter out comments and empty liens
-DEPS=$(grep -Pv "^\s*#" "$REQUIRES" | grep -Pv '^\s*$')
+# Filter out comments and empty lines
+DEPS=$(sed -n -e 's,#.*,,' -e '/./p' "$REQUIRES") ||
+ fail "failed to read deps from '${REQUIRES}'"
echo "$DEPS" | sort -d -f
diff --git a/tools/read-version b/tools/read-version
index c76b24a9..c37228f8 100755
--- a/tools/read-version
+++ b/tools/read-version
@@ -12,20 +12,20 @@ find_root() {
[ $? -eq 0 -a -f "${topd}/setup.py" ] || return
ROOT_DIR="$topd"
}
+fail() { echo "$0:" "$@" 1>&2; exit 1; }
if ! find_root; then
- echo "Unable to locate 'setup.py' file that should" \
- "exist in the cloud-init root directory." 1>&2
- exit 1;
+ fail "Unable to locate 'setup.py' file that should " \
+ "exist in the cloud-init root directory."
fi
CHNG_LOG="$ROOT_DIR/ChangeLog"
-if [ ! -e "$CHNG_LOG" ]
-then
- echo "Unable to find 'ChangeLog' file located at $CHNG_LOG"
- exit 1
+if [ ! -e "$CHNG_LOG" ]; then
+ fail "Unable to find 'ChangeLog' file located at '$CHNG_LOG'"
fi
-VERSION=$(grep -P "\d+.\d+.\d+:" "$CHNG_LOG" | cut -f1 -d ":" | head -n 1)
+VERSION=$(sed -n '/^[0-9]\+[.][0-9]\+[.][0-9]\+:/ {s/://; p; :a;n; ba}' \
+ "$CHNG_LOG") ||
+ fail "failed to get version from '$CHNG_LOG'"
echo "$VERSION"