diff options
-rw-r--r-- | cloudinit/sources/DataSourceEc2.py | 20 | ||||
-rw-r--r-- | cloudinit/stages.py | 20 | ||||
-rw-r--r-- | cloudinit/util.py | 14 | ||||
-rw-r--r-- | config/cloud.cfg | 2 | ||||
-rwxr-xr-x | packages/bddeb | 23 | ||||
-rwxr-xr-x | packages/brpm | 17 | ||||
-rwxr-xr-x | tools/make-tarball | 29 | ||||
-rwxr-xr-x | tools/read-dependencies | 23 | ||||
-rwxr-xr-x | tools/read-version | 24 | ||||
-rwxr-xr-x | tools/run-pylint | 10 |
10 files changed, 98 insertions, 84 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index cb460de1..cde73de3 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -87,6 +87,7 @@ class DataSourceEc2(sources.DataSource): return self.get_mirror_from_availability_zone() def get_mirror_from_availability_zone(self, availability_zone=None): + # Return type None indicates there is no cloud specific mirror # Availability is like 'us-west-1b' or 'eu-west-1a' if availability_zone is None: availability_zone = self.get_availability_zone() @@ -94,26 +95,27 @@ class DataSourceEc2(sources.DataSource): if self.is_vpc(): return None - # Use the distro to get the mirror if not availability_zone: return None - mirror_tpl = self.distro.get_option('availability_zone_template') - if not mirror_tpl: + mirror_tpl = self.distro.get_option('package_mirror_ec2_template', + None) + + if mirror_tpl is None: return None + # in EC2, the 'region' is 'us-east-1' if 'zone' is 'us-east-1a' tpl_params = { 'zone': availability_zone.strip(), + 'region': availability_zone[:-1] } mirror_url = mirror_tpl % (tpl_params) - (max_wait, timeout) = self._get_url_settings() - worked = uhelp.wait_for_url([mirror_url], max_wait=max_wait, - timeout=timeout, status_cb=LOG.warn) - if not worked: - return None + found = util.search_for_mirror([mirror_url]) + if found is not None: + return mirror_url - return mirror_url + return None def _get_url_settings(self): mcfg = self.ds_cfg diff --git a/cloudinit/stages.py b/cloudinit/stages.py index 8fd6aa5d..3beeb36e 100644 --- a/cloudinit/stages.py +++ b/cloudinit/stages.py @@ -133,12 +133,24 @@ class Init(object): if log_file: util.ensure_file(log_file) if perms: - (u, g) = perms.split(':', 1) - if u == "-1" or u == "None": + perms_parted = perms.split(':', 1) + u = perms_parted[0] + if len(perms_parted) == 2: + g = perms_parted[1] + else: + g = '' + u = u.strip() + g = g.strip() + if u == "-1" or u.lower() == "none": u = None - if g == "-1" or g == "None": + if g == "-1" or g.lower() == "none": g = None - util.chownbyname(log_file, u, g) + try: + util.chownbyname(log_file, u, g) + except OSError: + util.logexc(LOG, ("Unable to change the ownership" + " of %s to user %s, group %s"), + log_file, u, g) def read_cfg(self, extra_fns=None): # None check so that we don't keep on re-loading if empty diff --git a/cloudinit/util.py b/cloudinit/util.py index d7dd20b5..e591e306 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -19,6 +19,8 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# pylint: disable=C0302 from StringIO import StringIO @@ -805,7 +807,10 @@ def is_resolvable_url(url): def search_for_mirror(candidates): - """ Search through a list of mirror urls for one that works """ + """ + Search through a list of mirror urls for one that works + This needs to return quickly. + """ for cand in candidates: try: if is_resolvable_url(cand): @@ -932,12 +937,9 @@ def chownbyname(fname, user=None, group=None): uid = pwd.getpwnam(user).pw_uid if group: gid = grp.getgrnam(group).gr_gid - except KeyError: - logexc(LOG, ("Failed changing the ownership of %s using username %s and" - " groupname %s (do they exist?)"), fname, user, group) - return False + except KeyError as e: + raise OSError("Unknown user or group: %s" % (e)) chownbyid(fname, uid, gid) - return True # Always returns well formated values diff --git a/config/cloud.cfg b/config/cloud.cfg index 5dae4047..cb51d061 100644 --- a/config/cloud.cfg +++ b/config/cloud.cfg @@ -70,5 +70,5 @@ system_info: templates_dir: /etc/cloud/templates/ upstart_dir: /etc/init/ package_mirror: http://archive.ubuntu.com/ubuntu - availability_zone_template: http://%(zone)s.ec2.archive.ubuntu.com/ubuntu/ + package_mirror_ec2_template: http://%(region)s.ec2.archive.ubuntu.com/ubuntu/ ssh_svcname: ssh diff --git a/packages/bddeb b/packages/bddeb index 871c5212..df2d6707 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -7,16 +7,14 @@ import glob def find_root(): - look_where = [ - os.path.join(os.getcwd(), 'setup.py'), - os.path.join(os.pardir, 'setup.py'), - ] - for fn in look_where: - if os.path.isfile(fn): - return os.path.dirname(os.path.abspath(fn)) - raise ImportError(("Unable to determine where your cloud-init 'setup.py'" - " file is located at!")) - + # expected path is in <top_dir>/packages/ + top_dir = os.environ.get("CLOUD_INIT_TOP_D", None) + if top_dir is None: + top_dir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) + if os.path.isfile(os.path.join(top_dir, 'setup.py')): + return os.path.abspath(top_dir) + raise OSError(("Unable to determine where your cloud-init topdir is." + " set CLOUD_INIT_TOP_D?")) # Use the util functions from cloudinit sys.path.insert(0, find_root()) @@ -53,8 +51,7 @@ def write_debian_folder(root, version, revno, init_sys): }) # Write out the control file template - cmd = [sys.executable, - util.abs_join(find_root(), 'tools', 'read-dependencies')] + cmd = [util.abs_join(find_root(), 'tools', 'read-dependencies')] (stdout, _stderr) = util.subp(cmd) # Map to known packages @@ -138,7 +135,7 @@ def main(): cmd = ['tar', '-xvzf', tmp_arch_fn, '-C', xdir] util.subp(cmd, capture=capture) - print("Creating a debian/ folder in %r" % (xdir))) + print("Creating a debian/ folder in %r" % (xdir)) write_debian_folder(xdir, version, revno, args.boot) # The naming here seems to follow some debian standard diff --git a/packages/brpm b/packages/brpm index 7d0dc78f..afd7016f 100755 --- a/packages/brpm +++ b/packages/brpm @@ -12,15 +12,14 @@ import re import argparse def find_root(): - look_where = [ - os.path.join(os.getcwd(), 'setup.py'), - os.path.join(os.pardir, 'setup.py'), - ] - for fn in look_where: - if os.path.isfile(fn): - return os.path.dirname(os.path.abspath(fn)) - raise ImportError(("Unable to determine where your cloud-init 'setup.py'" - " file is located at!")) + # expected path is in <top_dir>/packages/ + top_dir = os.environ.get("CLOUD_INIT_TOP_D", None) + if top_dir is None: + top_dir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) + if os.path.isfile(os.path.join(top_dir, 'setup.py')): + return os.path.abspath(top_dir) + raise OSError(("Unable to determine where your cloud-init topdir is." + " set CLOUD_INIT_TOP_D?")) # Use the util functions from cloudinit diff --git a/tools/make-tarball b/tools/make-tarball index 7fce5e28..7fdeb7df 100755 --- a/tools/make-tarball +++ b/tools/make-tarball @@ -1,22 +1,24 @@ #!/bin/sh - set -e -ROOT_DIR="" -if [ -e "setup.py" ] -then - ROOT_DIR="$PWD" -elif [ -e "../setup.py" ] -then - ROOT_DIR="$PWD/../" -else +find_root() { + local topd + if [ -z "${CLOUD_INIT_TOP_D}" ]; then + topd=$(cd "$(dirname "${0}")" && cd .. && pwd) + else + topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd) + fi + [ $? -eq 0 -a -f "${topd}/setup.py" ] || return + ROOT_DIR="$topd" +} + +if ! find_root; then echo "Unable to locate 'setup.py' file that should" \ - "exist in the cloud-init root directory." - exit 1 + "exist in the cloud-init root directory." 1>&2 + exit 1; fi -if [ ! -z "$1" ] -then +if [ ! -z "$1" ]; then ARCHIVE_FN="$1" else REVNO=$(bzr revno $ROOT_DIR) @@ -30,4 +32,3 @@ echo "$FILES" | tar czf $ARCHIVE_FN \ --no-recursion --files-from - echo "$ARCHIVE_FN" - diff --git a/tools/read-dependencies b/tools/read-dependencies index 3aa6e286..4c88aa87 100755 --- a/tools/read-dependencies +++ b/tools/read-dependencies @@ -2,16 +2,21 @@ set -e -if [ -e "setup.py" ] -then - ROOT_DIR="$PWD" -elif [ -e "../setup.py" ] -then - ROOT_DIR="$PWD/../" -else +find_root() { + local topd + if [ -z "${CLOUD_INIT_TOP_D}" ]; then + topd=$(cd "$(dirname "${0}")" && cd .. && pwd) + else + topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd) + fi + [ $? -eq 0 -a -f "${topd}/setup.py" ] || return + ROOT_DIR="$topd" +} + +if ! find_root; then echo "Unable to locate 'setup.py' file that should" \ - "exist in the cloud-init root directory." - exit 1 + "exist in the cloud-init root directory." 1>&2 + exit 1; fi REQUIRES="$ROOT_DIR/Requires" diff --git a/tools/read-version b/tools/read-version index 690666b5..323357fe 100755 --- a/tools/read-version +++ b/tools/read-version @@ -2,16 +2,21 @@ set -e -if [ -e "setup.py" ] -then - ROOT_DIR="$PWD" -elif [ -e "../setup.py" ] -then - ROOT_DIR="$PWD/../" -else +find_root() { + local topd + if [ -z "${CLOUD_INIT_TOP_D}" ]; then + topd=$(cd "$(dirname "${0}")" && cd .. && pwd) + else + topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd) + fi + [ $? -eq 0 -a -f "${topd}/setup.py" ] || return + ROOT_DIR="$topd" +} + +if ! find_root; then echo "Unable to locate 'setup.py' file that should" \ - "exist in the cloud-init root directory." - exit 1 + "exist in the cloud-init root directory." 1>&2 + exit 1; fi CHNG_LOG="$ROOT_DIR/ChangeLog" @@ -24,4 +29,3 @@ fi VERSION=$(grep -P "\d+.\d+.\d+:" $CHNG_LOG | cut -f1 -d ":" | head -n 1) echo $VERSION - diff --git a/tools/run-pylint b/tools/run-pylint index dd6369aa..7ef44ac5 100755 --- a/tools/run-pylint +++ b/tools/run-pylint @@ -1,15 +1,7 @@ #!/bin/bash -ci_files='cloud*.py cloudinit/*.py cloudinit/config/*.py' -test_files=$(find tests -name "*.py") -def_files="$ci_files $test_files" - if [ $# -eq 0 ]; then - files=( ) - for f in $def_files; do - [ -f "$f" ] || { echo "failed, $f not a file" 1>&2; exit 1; } - files[${#files[@]}]=${f} - done + files=( $(find * -name "*.py" -type f) ) else files=( "$@" ); fi |