From cf3dd1ba86d4ddde149f451e026c697c07b4d732 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 28 Sep 2012 13:53:56 -0700 Subject: Rework the rest of the locations that used the previous 'user' and make those locations go through the new distros functions to select the default user or the user list (depending on usage). Adjust the tests to check the new 'default' field that signifies the default user + test the new method to extract just the default user from a normalized user dictionary. --- cloudinit/config/cc_byobu.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cloudinit/config/cc_byobu.py') diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py index 4e2e06bb..e1ec5af5 100644 --- a/cloudinit/config/cc_byobu.py +++ b/cloudinit/config/cc_byobu.py @@ -18,12 +18,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from cloudinit import distros as ds from cloudinit import util distros = ['ubuntu', 'debian'] -def handle(name, cfg, _cloud, log, args): +def handle(name, cfg, cloud, log, args): if len(args) != 0: value = args[0] else: @@ -56,7 +57,8 @@ def handle(name, cfg, _cloud, log, args): shcmd = "" if mod_user: - user = util.get_cfg_option_str(cfg, "user", "ubuntu") + (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) + (user, _user_config) = ds.extract_default(users, 'ubuntu') shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst) shcmd += " || X=$(($X+1)); " if mod_sys: -- cgit v1.2.3 From 7ab25c779433a614a6e4101ddfe852fc25f39c01 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 28 Sep 2012 14:06:22 -0700 Subject: Add a comment as to why distros can't be imported without being renamed due to previous usage of the attribute 'distros' --- cloudinit/config/cc_byobu.py | 4 ++++ cloudinit/config/cc_set_passwords.py | 4 ++++ cloudinit/config/cc_ssh.py | 4 ++++ cloudinit/config/cc_ssh_authkey_fingerprints.py | 8 ++++++-- cloudinit/config/cc_ssh_import_id.py | 4 ++++ cloudinit/config/cc_users_groups.py | 3 +++ 6 files changed, 25 insertions(+), 2 deletions(-) (limited to 'cloudinit/config/cc_byobu.py') diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py index e1ec5af5..e38fccdd 100644 --- a/cloudinit/config/cc_byobu.py +++ b/cloudinit/config/cc_byobu.py @@ -18,7 +18,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import util distros = ['ubuntu', 'debian'] diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py index bb95f948..26c558ad 100644 --- a/cloudinit/config/cc_set_passwords.py +++ b/cloudinit/config/cc_set_passwords.py @@ -20,7 +20,11 @@ import sys +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util diff --git a/cloudinit/config/cc_ssh.py b/cloudinit/config/cc_ssh.py index c2ee4635..32e48c30 100644 --- a/cloudinit/config/cc_ssh.py +++ b/cloudinit/config/cc_ssh.py @@ -21,7 +21,11 @@ import glob import os +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util diff --git a/cloudinit/config/cc_ssh_authkey_fingerprints.py b/cloudinit/config/cc_ssh_authkey_fingerprints.py index 32214fba..8c9a8806 100644 --- a/cloudinit/config/cc_ssh_authkey_fingerprints.py +++ b/cloudinit/config/cc_ssh_authkey_fingerprints.py @@ -21,7 +21,11 @@ import hashlib from prettytable import PrettyTable -from cloudinit import distros +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module +from cloudinit import distros as ds + from cloudinit import ssh_util from cloudinit import util @@ -94,7 +98,7 @@ def handle(name, cfg, cloud, log, _args): hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5") extract_func = ssh_util.extract_authorized_keys - (users, _groups) = distros.normalize_users_groups(cfg, cloud.distro) + (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) for (user_name, _cfg) in users.items(): (auth_key_fn, auth_key_entries) = extract_func(user_name, cloud.paths) _pprint_key_entries(user_name, auth_key_fn, diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py index a781cd7c..83af36e9 100644 --- a/cloudinit/config/cc_ssh_import_id.py +++ b/cloudinit/config/cc_ssh_import_id.py @@ -18,7 +18,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds + from cloudinit import util import pwd diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py index da587fb3..bf5b4581 100644 --- a/cloudinit/config/cc_users_groups.py +++ b/cloudinit/config/cc_users_groups.py @@ -16,6 +16,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Ensure this is aliased to a name not 'distros' +# since the module attribute 'distros' +# is a list of distros that are supported, not a sub-module from cloudinit import distros as ds from cloudinit.settings import PER_INSTANCE -- cgit v1.2.3 From 5233b6edb70702476463b47c06cb02b3c7f74c51 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 28 Sep 2012 14:17:42 -0700 Subject: Make byobu more tolerant of the user not being located and warn when it is not found + only run the shell command when actual contents exist to run. --- cloudinit/config/cc_byobu.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'cloudinit/config/cc_byobu.py') diff --git a/cloudinit/config/cc_byobu.py b/cloudinit/config/cc_byobu.py index e38fccdd..92d428b7 100644 --- a/cloudinit/config/cc_byobu.py +++ b/cloudinit/config/cc_byobu.py @@ -62,16 +62,19 @@ def handle(name, cfg, cloud, log, args): shcmd = "" if mod_user: (users, _groups) = ds.normalize_users_groups(cfg, cloud.distro) - (user, _user_config) = ds.extract_default(users, 'ubuntu') - shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst) - shcmd += " || X=$(($X+1)); " + (user, _user_config) = ds.extract_default(users) + if not user: + log.warn(("No default byobu user provided, " + "can not launch %s for the default user"), bl_inst) + else: + shcmd += " sudo -Hu \"%s\" byobu-launcher-%s" % (user, bl_inst) + shcmd += " || X=$(($X+1)); " if mod_sys: shcmd += "echo \"%s\" | debconf-set-selections" % dc_val shcmd += " && dpkg-reconfigure byobu --frontend=noninteractive" shcmd += " || X=$(($X+1)); " - cmd = ["/bin/sh", "-c", "%s %s %s" % ("X=0;", shcmd, "exit $X")] - - log.debug("Setting byobu to %s", value) - - util.subp(cmd, capture=False) + if len(shcmd): + cmd = ["/bin/sh", "-c", "%s %s %s" % ("X=0;", shcmd, "exit $X")] + log.debug("Setting byobu to %s", value) + util.subp(cmd, capture=False) -- cgit v1.2.3