summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--cloudinit/config/cc_debug.py21
-rw-r--r--cloudinit/config/cc_ubuntu_init_switch.py30
-rw-r--r--cloudinit/distros/rhel.py12
-rw-r--r--cloudinit/sources/DataSourceDigitalOcean.py104
-rw-r--r--cloudinit/templater.py4
-rw-r--r--cloudinit/util.py2
-rw-r--r--cloudinit/version.py2
-rw-r--r--doc/rtd/conf.py2
-rw-r--r--doc/rtd/topics/modules.rst342
-rw-r--r--doc/sources/configdrive/README.rst2
-rw-r--r--doc/sources/digitalocean/README.rst21
-rw-r--r--packages/redhat/cloud-init.spec.in5
-rwxr-xr-xsetup.py55
-rw-r--r--tests/unittests/helpers.py5
-rw-r--r--tests/unittests/test_datasource/test_digitalocean.py126
-rw-r--r--tests/unittests/test_datasource/test_openstack.py3
-rw-r--r--tests/unittests/test_distros/test_netconfig.py7
-rw-r--r--tests/unittests/test_handler/test_handler_set_hostname.py9
19 files changed, 712 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index b655946b..d9e91410 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+0.7.7:
+ - open 0.7.7
+ - Digital Ocean: add datasource for Digital Ocean. [Neal Shrader]
+ - expose uses_systemd as a distro function (fix rhel7)
+ - fix broken 'output' config (LP: #1387340)
+ - begin adding cloud config module docs to config modules (LP: #1383510)
+ - retain trailing eol from template files (sources.list) when
+ rendered with jinja (LP: #1355343)
+ - Only use datafiles and initsys addon outside virtualenvs
+ - Fix the digital ocean test case on python 2.6
+ - Increase the usefulness, robustness, configurability of the chef module
+ so that it is more useful, more documented and better for users
0.7.6:
- open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986)
diff --git a/cloudinit/config/cc_debug.py b/cloudinit/config/cc_debug.py
index 7219b0f8..a3af4500 100644
--- a/cloudinit/config/cc_debug.py
+++ b/cloudinit/config/cc_debug.py
@@ -14,6 +14,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+**Summary:** helper to debug cloud-init *internal* datastructures.
+
+**Description:** This module will enable for outputting various internal
+information that cloud-init sources provide to either a file or to the output
+console/log location that this cloud-init has been configured with when
+running.
+
+It can be configured with the following option structure::
+
+ debug:
+ verbose: (defaulting to true)
+ output: (location to write output, defaulting to console + log)
+
+.. note::
+
+ Log configurations are not output.
+"""
+
from cloudinit import type_utils
from cloudinit import util
import copy
@@ -32,6 +51,8 @@ def _make_header(text):
def handle(name, cfg, cloud, log, args):
+ """Handler method activated by cloud-init."""
+
verbose = util.get_cfg_by_path(cfg, ('debug', 'verbose'), default=True)
if args:
# if args are provided (from cmdline) then explicitly set verbose
diff --git a/cloudinit/config/cc_ubuntu_init_switch.py b/cloudinit/config/cc_ubuntu_init_switch.py
index 6f994bff..7e88ed85 100644
--- a/cloudinit/config/cc_ubuntu_init_switch.py
+++ b/cloudinit/config/cc_ubuntu_init_switch.py
@@ -17,30 +17,27 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-ubuntu_init_switch: reboot system into another init
+**Summary:** reboot system into another init.
-This provides a way for the user to boot with systemd even if the
-image is set to boot with upstart. It should be run as one of the first
-cloud_init_modules, and will switch the init system and then issue a reboot.
-The next boot will come up in the target init system and no action will
+**Description:** This module provides a way for the user to boot with systemd
+even if the image is set to boot with upstart. It should be run as one of the
+first ``cloud_init_modules``, and will switch the init system and then issue a
+reboot. The next boot will come up in the target init system and no action will
be taken.
This should be inert on non-ubuntu systems, and also exit quickly.
-config is comes under the top level 'init_switch' dictionary.
+It can be configured with the following option structure::
-#cloud-config
-init_switch:
- target: systemd
- reboot: true
+ init_switch:
+ target: systemd (can be 'systemd' or 'upstart')
+ reboot: true (reboot if a change was made, or false to not reboot)
-'target' can be 'systemd' or 'upstart'. Best effort is made, but its possible
-this system will break, and probably won't interact well with any other
-mechanism you've used to switch the init system.
+.. note::
-'reboot': [default=true].
- true: reboot if a change was made.
- false: do not reboot.
+ Best effort is made, but it's possible
+ this system will break, and probably won't interact well with any other
+ mechanism you've used to switch the init system.
"""
from cloudinit.settings import PER_INSTANCE
@@ -91,6 +88,7 @@ fi
def handle(name, cfg, cloud, log, args):
+ """Handler method activated by cloud-init."""
if not isinstance(cloud.distro, ubuntu.Distro):
log.debug("%s: distro is '%s', not ubuntu. returning",
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index e8abf111..1a269e08 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -98,7 +98,7 @@ class Distro(distros.Distro):
rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
return dev_names
- def _dist_uses_systemd(self):
+ def uses_systemd(self):
# Fedora 18 and RHEL 7 were the first adopters in their series
(dist, vers) = util.system_info()['dist'][:2]
major = (int)(vers.split('.')[0])
@@ -106,7 +106,7 @@ class Distro(distros.Distro):
or (dist.startswith('Fedora') and major >= 18))
def apply_locale(self, locale, out_fn=None):
- if self._dist_uses_systemd():
+ if self.uses_systemd():
if not out_fn:
out_fn = self.systemd_locale_conf_fn
out_fn = self.systemd_locale_conf_fn
@@ -119,7 +119,7 @@ class Distro(distros.Distro):
rhel_util.update_sysconfig_file(out_fn, locale_cfg)
def _write_hostname(self, hostname, out_fn):
- if self._dist_uses_systemd():
+ if self.uses_systemd():
util.subp(['hostnamectl', 'set-hostname', str(hostname)])
else:
host_cfg = {
@@ -135,14 +135,14 @@ class Distro(distros.Distro):
return hostname
def _read_system_hostname(self):
- if self._dist_uses_systemd():
+ if self.uses_systemd():
host_fn = self.systemd_hostname_conf_fn
else:
host_fn = self.hostname_conf_fn
return (host_fn, self._read_hostname(host_fn))
def _read_hostname(self, filename, default=None):
- if self._dist_uses_systemd():
+ if self.uses_systemd():
(out, _err) = util.subp(['hostname'])
if len(out):
return out
@@ -163,7 +163,7 @@ class Distro(distros.Distro):
def set_timezone(self, tz):
tz_file = self._find_tz_file(tz)
- if self._dist_uses_systemd():
+ if self.uses_systemd():
# Currently, timedatectl complains if invoked during startup
# so for compatibility, create the link manually.
util.del_file(self.tz_local_fn)
diff --git a/cloudinit/sources/DataSourceDigitalOcean.py b/cloudinit/sources/DataSourceDigitalOcean.py
new file mode 100644
index 00000000..069bdb41
--- /dev/null
+++ b/cloudinit/sources/DataSourceDigitalOcean.py
@@ -0,0 +1,104 @@
+# vi: ts=4 expandtab
+#
+# Author: Neal Shrader <neal@digitalocean.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from cloudinit import log as logging
+from cloudinit import util
+from cloudinit import sources
+from cloudinit import ec2_utils
+from types import StringType
+import functools
+
+
+LOG = logging.getLogger(__name__)
+
+BUILTIN_DS_CONFIG = {
+ 'metadata_url': 'http://169.254.169.254/metadata/v1/',
+ 'mirrors_url': 'http://mirrors.digitalocean.com/'
+}
+MD_RETRIES = 0
+MD_TIMEOUT = 1
+
+class DataSourceDigitalOcean(sources.DataSource):
+ def __init__(self, sys_cfg, distro, paths):
+ sources.DataSource.__init__(self, sys_cfg, distro, paths)
+ self.metadata = dict()
+ self.ds_cfg = util.mergemanydict([
+ util.get_cfg_by_path(sys_cfg, ["datasource", "DigitalOcean"], {}),
+ BUILTIN_DS_CONFIG])
+ self.metadata_address = self.ds_cfg['metadata_url']
+
+ if self.ds_cfg.get('retries'):
+ self.retries = self.ds_cfg['retries']
+ else:
+ self.retries = MD_RETRIES
+
+ if self.ds_cfg.get('timeout'):
+ self.timeout = self.ds_cfg['timeout']
+ else:
+ self.timeout = MD_TIMEOUT
+
+ def get_data(self):
+ caller = functools.partial(util.read_file_or_url, timeout=self.timeout,
+ retries=self.retries)
+ md = ec2_utils.MetadataMaterializer(str(caller(self.metadata_address)),
+ base_url=self.metadata_address,
+ caller=caller)
+
+ self.metadata = md.materialize()
+
+ if self.metadata.get('id'):
+ return True
+ else:
+ return False
+
+ def get_userdata_raw(self):
+ return "\n".join(self.metadata['user-data'])
+
+ def get_vendordata_raw(self):
+ return "\n".join(self.metadata['vendor-data'])
+
+ def get_public_ssh_keys(self):
+ if type(self.metadata['public-keys']) is StringType:
+ return [self.metadata['public-keys']]
+ else:
+ return self.metadata['public-keys']
+
+ @property
+ def availability_zone(self):
+ return self.metadata['region']
+
+ def get_instance_id(self):
+ return self.metadata['id']
+
+ def get_hostname(self, fqdn=False):
+ return self.metadata['hostname']
+
+ def get_package_mirror_info(self):
+ return self.ds_cfg['mirrors_url']
+
+ @property
+ def launch_index(self):
+ return None
+
+# Used to match classes to dependencies
+datasources = [
+ (DataSourceDigitalOcean, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
+ ]
+
+
+# Return a list of data sources that match this set of dependencies
+def get_datasource_list(depends):
+ return sources.list_from_depends(depends, datasources)
diff --git a/cloudinit/templater.py b/cloudinit/templater.py
index 02f6261d..4cd3f13d 100644
--- a/cloudinit/templater.py
+++ b/cloudinit/templater.py
@@ -89,9 +89,11 @@ def detect_template(text):
return CTemplate(content, searchList=[params]).respond()
def jinja_render(content, params):
+ # keep_trailing_newline is in jinja2 2.7+, not 2.6
+ add = "\n" if content.endswith("\n") else ""
return JTemplate(content,
undefined=jinja2.StrictUndefined,
- trim_blocks=True).render(**params)
+ trim_blocks=True).render(**params) + add
if text.find("\n") != -1:
ident, rest = text.split("\n", 1)
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 71221e09..b71057fb 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1150,7 +1150,7 @@ def chownbyname(fname, user=None, group=None):
# this returns the specific 'mode' entry, cleanly formatted, with value
def get_output_cfg(cfg, mode):
ret = [None, None]
- if cfg or 'output' not in cfg:
+ if not cfg or 'output' not in cfg:
return ret
outcfg = cfg['output']
diff --git a/cloudinit/version.py b/cloudinit/version.py
index edb651a9..3d1d1d23 100644
--- a/cloudinit/version.py
+++ b/cloudinit/version.py
@@ -20,7 +20,7 @@ from distutils import version as vr
def version():
- return vr.StrictVersion("0.7.6")
+ return vr.StrictVersion("0.7.7")
def version_string():
diff --git a/doc/rtd/conf.py b/doc/rtd/conf.py
index 52a8f92b..9be02766 100644
--- a/doc/rtd/conf.py
+++ b/doc/rtd/conf.py
@@ -27,6 +27,8 @@ project = 'Cloud-Init'
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.intersphinx',
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.viewcode',
]
intersphinx_mapping = {
diff --git a/doc/rtd/topics/modules.rst b/doc/rtd/topics/modules.rst
index d4dd55df..b50acbfa 100644
--- a/doc/rtd/topics/modules.rst
+++ b/doc/rtd/topics/modules.rst
@@ -1,3 +1,341 @@
-=========
+=======
Modules
-=========
+=======
+
+Apt Configure
+-------------
+
+**Internal name:** ``cc_apt_configure``
+
+.. automodule:: cloudinit.config.cc_apt_configure
+
+Apt Pipelining
+--------------
+
+**Internal name:** ``cc_apt_pipelining``
+
+.. automodule:: cloudinit.config.cc_apt_pipelining
+
+Bootcmd
+-------
+
+**Internal name:** ``cc_bootcmd``
+
+.. automodule:: cloudinit.config.cc_bootcmd
+
+Byobu
+-----
+
+**Internal name:** ``cc_byobu``
+
+.. automodule:: cloudinit.config.cc_byobu
+
+Ca Certs
+--------
+
+**Internal name:** ``cc_ca_certs``
+
+.. automodule:: cloudinit.config.cc_ca_certs
+
+Chef
+----
+
+**Internal name:** ``cc_chef``
+
+.. automodule:: cloudinit.config.cc_chef
+
+Debug
+-----
+
+**Internal name:** ``cc_debug``
+
+.. automodule:: cloudinit.config.cc_debug
+ :members:
+
+Disable Ec2 Metadata
+--------------------
+
+**Internal name:** ``cc_disable_ec2_metadata``
+
+.. automodule:: cloudinit.config.cc_disable_ec2_metadata
+
+Disk Setup
+----------
+
+**Internal name:** ``cc_disk_setup``
+
+.. automodule:: cloudinit.config.cc_disk_setup
+
+Emit Upstart
+------------
+
+**Internal name:** ``cc_emit_upstart``
+
+.. automodule:: cloudinit.config.cc_emit_upstart
+
+Final Message
+-------------
+
+**Internal name:** ``cc_final_message``
+
+.. automodule:: cloudinit.config.cc_final_message
+
+Foo
+---
+
+**Internal name:** ``cc_foo``
+
+.. automodule:: cloudinit.config.cc_foo
+
+Growpart
+--------
+
+**Internal name:** ``cc_growpart``
+
+.. automodule:: cloudinit.config.cc_growpart
+
+Grub Dpkg
+---------
+
+**Internal name:** ``cc_grub_dpkg``
+
+.. automodule:: cloudinit.config.cc_grub_dpkg
+
+Keys To Console
+---------------
+
+**Internal name:** ``cc_keys_to_console``
+
+.. automodule:: cloudinit.config.cc_keys_to_console
+
+Landscape
+---------
+
+**Internal name:** ``cc_landscape``
+
+.. automodule:: cloudinit.config.cc_landscape
+
+Locale
+------
+
+**Internal name:** ``cc_locale``
+
+.. automodule:: cloudinit.config.cc_locale
+
+Mcollective
+-----------
+
+**Internal name:** ``cc_mcollective``
+
+.. automodule:: cloudinit.config.cc_mcollective
+
+Migrator
+--------
+
+**Internal name:** ``cc_migrator``
+
+.. automodule:: cloudinit.config.cc_migrator
+
+Mounts
+------
+
+**Internal name:** ``cc_mounts``
+
+.. automodule:: cloudinit.config.cc_mounts
+
+Package Update Upgrade Install
+------------------------------
+
+**Internal name:** ``cc_package_update_upgrade_install``
+
+.. automodule:: cloudinit.config.cc_package_update_upgrade_install
+
+Phone Home
+----------
+
+**Internal name:** ``cc_phone_home``
+
+.. automodule:: cloudinit.config.cc_phone_home
+
+Power State Change
+------------------
+
+**Internal name:** ``cc_power_state_change``
+
+.. automodule:: cloudinit.config.cc_power_state_change
+
+Puppet
+------
+
+**Internal name:** ``cc_puppet``
+
+.. automodule:: cloudinit.config.cc_puppet
+
+Resizefs
+--------
+
+**Internal name:** ``cc_resizefs``
+
+.. automodule:: cloudinit.config.cc_resizefs
+
+Resolv Conf
+-----------
+
+**Internal name:** ``cc_resolv_conf``
+
+.. automodule:: cloudinit.config.cc_resolv_conf
+
+Rightscale Userdata
+-------------------
+
+**Internal name:** ``cc_rightscale_userdata``
+
+.. automodule:: cloudinit.config.cc_rightscale_userdata
+
+Rsyslog
+-------
+
+**Internal name:** ``cc_rsyslog``
+
+.. automodule:: cloudinit.config.cc_rsyslog
+
+Runcmd
+------
+
+**Internal name:** ``cc_runcmd``
+
+.. automodule:: cloudinit.config.cc_runcmd
+
+Salt Minion
+-----------
+
+**Internal name:** ``cc_salt_minion``
+
+.. automodule:: cloudinit.config.cc_salt_minion
+
+Scripts Per Boot
+----------------
+
+**Internal name:** ``cc_scripts_per_boot``
+
+.. automodule:: cloudinit.config.cc_scripts_per_boot
+
+Scripts Per Instance
+--------------------
+
+**Internal name:** ``cc_scripts_per_instance``
+
+.. automodule:: cloudinit.config.cc_scripts_per_instance
+
+Scripts Per Once
+----------------
+
+**Internal name:** ``cc_scripts_per_once``
+
+.. automodule:: cloudinit.config.cc_scripts_per_once
+
+Scripts User
+------------
+
+**Internal name:** ``cc_scripts_user``
+
+.. automodule:: cloudinit.config.cc_scripts_user
+
+Scripts Vendor
+--------------
+
+**Internal name:** ``cc_scripts_vendor``
+
+.. automodule:: cloudinit.config.cc_scripts_vendor
+
+Seed Random
+-----------
+
+**Internal name:** ``cc_seed_random``
+
+.. automodule:: cloudinit.config.cc_seed_random
+
+Set Hostname
+------------
+
+**Internal name:** ``cc_set_hostname``
+
+.. automodule:: cloudinit.config.cc_set_hostname
+
+Set Passwords
+-------------
+
+**Internal name:** ``cc_set_passwords``
+
+.. automodule:: cloudinit.config.cc_set_passwords
+
+Ssh
+---
+
+**Internal name:** ``cc_ssh``
+
+.. automodule:: cloudinit.config.cc_ssh
+
+Ssh Authkey Fingerprints
+------------------------
+
+**Internal name:** ``cc_ssh_authkey_fingerprints``
+
+.. automodule:: cloudinit.config.cc_ssh_authkey_fingerprints
+
+Ssh Import Id
+-------------
+
+**Internal name:** ``cc_ssh_import_id``
+
+.. automodule:: cloudinit.config.cc_ssh_import_id
+
+Timezone
+--------
+
+**Internal name:** ``cc_timezone``
+
+.. automodule:: cloudinit.config.cc_timezone
+
+Ubuntu Init Switch
+------------------
+
+**Internal name:** ``cc_ubuntu_init_switch``
+
+.. automodule:: cloudinit.config.cc_ubuntu_init_switch
+ :members:
+
+Update Etc Hosts
+----------------
+
+**Internal name:** ``cc_update_etc_hosts``
+
+.. automodule:: cloudinit.config.cc_update_etc_hosts
+
+Update Hostname
+---------------
+
+**Internal name:** ``cc_update_hostname``
+
+.. automodule:: cloudinit.config.cc_update_hostname
+
+Users Groups
+------------
+
+**Internal name:** ``cc_users_groups``
+
+.. automodule:: cloudinit.config.cc_users_groups
+
+Write Files
+-----------
+
+**Internal name:** ``cc_write_files``
+
+.. automodule:: cloudinit.config.cc_write_files
+
+Yum Add Repo
+------------
+
+**Internal name:** ``cc_yum_add_repo``
+
+.. automodule:: cloudinit.config.cc_yum_add_repo
diff --git a/doc/sources/configdrive/README.rst b/doc/sources/configdrive/README.rst
index 797872ad..48ff579d 100644
--- a/doc/sources/configdrive/README.rst
+++ b/doc/sources/configdrive/README.rst
@@ -120,4 +120,4 @@ what all can be present here.
.. _python-novaclient: https://github.com/openstack/python-novaclient
.. _iso9660: https://en.wikipedia.org/wiki/ISO_9660
.. _vfat: https://en.wikipedia.org/wiki/File_Allocation_Table
-.. _the config drive extension: http://docs.openstack.org/developer/nova/api_ext/ext_config_drive.html
+.. _the config drive extension: http://docs.openstack.org/user-guide/content/config-drive.html
diff --git a/doc/sources/digitalocean/README.rst b/doc/sources/digitalocean/README.rst
new file mode 100644
index 00000000..1bb89fe1
--- /dev/null
+++ b/doc/sources/digitalocean/README.rst
@@ -0,0 +1,21 @@
+ The `DigitalOcean`_ datasource consumes the content served from DigitalOcean's `metadata service`_. This
+metadata service serves information about the running droplet via HTTP over the link local address
+169.254.169.254. The metadata API endpoints are fully described at
+`https://developers.digitalocean.com/metadata/ <https://developers.digitalocean.com/metadata/>`_.
+
+Configuration
+~~~~~~~~~~~~~
+
+DigitalOcean's datasource can be configured as follows:
+
+ datasource:
+ DigitalOcean:
+ retries: 3
+ timeout: 2
+
+- *retries*: Determines the number of times to attempt to connect to the metadata service
+- *timeout*: Determines the timeout in seconds to wait for a response from the metadata service
+
+.. _DigitalOcean: http://digitalocean.com/
+.. _metadata service: https://developers.digitalocean.com/metadata/
+.. _Full documentation: https://developers.digitalocean.com/metadata/
diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in
index 0e9862d8..75dd4d22 100644
--- a/packages/redhat/cloud-init.spec.in
+++ b/packages/redhat/cloud-init.spec.in
@@ -92,6 +92,11 @@ mkdir -p \$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
cp -p tools/21-cloudinit.conf \
\$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
+#if $systemd
+mkdir -p \$RPM_BUILD_ROOT/%{_unitdir}
+cp -p systemd/* \$RPM_BUILD_ROOT/%{_unitdir}
+#end if
+
%clean
rm -rf \$RPM_BUILD_ROOT
diff --git a/setup.py b/setup.py
index bd41bc91..3e188089 100755
--- a/setup.py
+++ b/setup.py
@@ -23,6 +23,7 @@
from glob import glob
import os
+import sys
import setuptools
from setuptools.command.install import install
@@ -86,6 +87,17 @@ if os.uname()[0] == 'FreeBSD':
ETC = "/usr/local/etc"
+# Avoid having datafiles installed in a virtualenv...
+def in_virtualenv():
+ try:
+ if sys.real_prefix == sys.prefix:
+ return False
+ else:
+ return True
+ except AttributeError:
+ return False
+
+
def get_version():
cmd = ['tools/read-version']
(ver, _e) = tiny_p(cmd)
@@ -135,6 +147,29 @@ class InitsysInstallData(install):
self.distribution.reinitialize_command('install_data', True)
+if in_virtualenv():
+ data_files = []
+ cmdclass = {}
+else:
+ data_files = [
+ (ETC + '/cloud', glob('config/*.cfg')),
+ (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
+ (ETC + '/cloud/templates', glob('templates/*')),
+ (USR + '/lib/cloud-init', ['tools/uncloud-init',
+ 'tools/write-ssh-key-fingerprints']),
+ (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples',
+ [f for f in glob('doc/examples/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples/seed',
+ [f for f in glob('doc/examples/seed/*') if is_f(f)]),
+ ]
+ # Use a subclass for install that handles
+ # adding on the right init system configuration files
+ cmdclass = {
+ 'install': InitsysInstallData,
+ }
+
+
setuptools.setup(name='cloud-init',
version=get_version(),
description='EC2 initialisation magic',
@@ -146,23 +181,7 @@ setuptools.setup(name='cloud-init',
'tools/cloud-init-per',
],
license='GPLv3',
- data_files=[(ETC + '/cloud', glob('config/*.cfg')),
- (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
- (ETC + '/cloud/templates', glob('templates/*')),
- (USR + '/lib/cloud-init',
- ['tools/uncloud-init',
- 'tools/write-ssh-key-fingerprints']),
- (USR + '/share/doc/cloud-init',
- [f for f in glob('doc/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples',
- [f for f in glob('doc/examples/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples/seed',
- [f for f in glob('doc/examples/seed/*') if is_f(f)]),
- ],
+ data_files=data_files,
install_requires=read_requires(),
- cmdclass={
- # Use a subclass for install that handles
- # adding on the right init system configuration files
- 'install': InitsysInstallData,
- },
+ cmdclass=cmdclass,
)
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 9700a4ca..52305397 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -35,6 +35,11 @@ else:
if PY26:
# For now add these on, taken from python 2.7 + slightly adjusted
class TestCase(unittest.TestCase):
+ def assertIs(self, expr1, expr2, msg=None):
+ if expr1 is not expr2:
+ standardMsg = '%r is not %r' % (expr1, expr2)
+ self.fail(self._formatMessage(msg, standardMsg))
+
def assertIn(self, member, container, msg=None):
if member not in container:
standardMsg = '%r not found in %r' % (member, container)
diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py
new file mode 100644
index 00000000..04bee340
--- /dev/null
+++ b/tests/unittests/test_datasource/test_digitalocean.py
@@ -0,0 +1,126 @@
+#
+# Copyright (C) 2014 Neal Shrader
+#
+# Author: Neal Shrader <neal@digitalocean.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import httpretty
+import re
+
+from types import ListType
+from urlparse import urlparse
+
+from cloudinit import settings
+from cloudinit import helpers
+from cloudinit.sources import DataSourceDigitalOcean
+
+from .. import helpers as test_helpers
+
+# Abbreviated for the test
+DO_INDEX = """id
+ hostname
+ user-data
+ vendor-data
+ public-keys
+ region"""
+
+DO_MULTIPLE_KEYS = """ssh-rsa AAAAB3NzaC1yc2EAAAA... neal@digitalocean.com
+ ssh-rsa AAAAB3NzaC1yc2EAAAA... neal2@digitalocean.com"""
+DO_SINGLE_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAA... neal@digitalocean.com"
+
+DO_META = {
+ '': DO_INDEX,
+ 'user-data': '#!/bin/bash\necho "user-data"',
+ 'vendor-data': '#!/bin/bash\necho "vendor-data"',
+ 'public-keys': DO_SINGLE_KEY,
+ 'region': 'nyc3',
+ 'id': '2000000',
+ 'hostname': 'cloudinit-test',
+}
+
+MD_URL_RE = re.compile(r'http://169.254.169.254/metadata/v1/.*')
+
+def _request_callback(method, uri, headers):
+ url_path = urlparse(uri).path
+ if url_path.startswith('/metadata/v1/'):
+ path = url_path.split('/metadata/v1/')[1:][0]
+ else:
+ path = None
+ if path in DO_META:
+ return (200, headers, DO_META.get(path))
+ else:
+ return (404, headers, '')
+
+
+class TestDataSourceDigitalOcean(test_helpers.HttprettyTestCase):
+
+ def setUp(self):
+ self.ds = DataSourceDigitalOcean.DataSourceDigitalOcean(
+ settings.CFG_BUILTIN, None,
+ helpers.Paths({}))
+ super(TestDataSourceDigitalOcean, self).setUp()
+
+ @httpretty.activate
+ def test_connection(self):
+ httpretty.register_uri(
+ httpretty.GET, MD_URL_RE,
+ body=_request_callback)
+
+ success = self.ds.get_data()
+ self.assertTrue(success)
+
+ @httpretty.activate
+ def test_metadata(self):
+ httpretty.register_uri(
+ httpretty.GET, MD_URL_RE,
+ body=_request_callback)
+ self.ds.get_data()
+
+ self.assertEqual(DO_META.get('user-data'),
+ self.ds.get_userdata_raw())
+
+ self.assertEqual(DO_META.get('vendor-data'),
+ self.ds.get_vendordata_raw())
+
+ self.assertEqual(DO_META.get('region'),
+ self.ds.availability_zone)
+
+ self.assertEqual(DO_META.get('id'),
+ self.ds.get_instance_id())
+
+ self.assertEqual(DO_META.get('hostname'),
+ self.ds.get_hostname())
+
+ self.assertEqual('http://mirrors.digitalocean.com/',
+ self.ds.get_package_mirror_info())
+
+ # Single key
+ self.assertEqual([DO_META.get('public-keys')],
+ self.ds.get_public_ssh_keys())
+
+ self.assertIs(type(self.ds.get_public_ssh_keys()), ListType)
+
+ @httpretty.activate
+ def test_multiple_ssh_keys(self):
+ DO_META['public_keys'] = DO_MULTIPLE_KEYS
+ httpretty.register_uri(
+ httpretty.GET, MD_URL_RE,
+ body=_request_callback)
+ self.ds.get_data()
+
+ # Multiple keys
+ self.assertEqual(DO_META.get('public-keys').splitlines(),
+ self.ds.get_public_ssh_keys())
+
+ self.assertIs(type(self.ds.get_public_ssh_keys()), ListType)
diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
index 7b4e651a..49894e51 100644
--- a/tests/unittests/test_datasource/test_openstack.py
+++ b/tests/unittests/test_datasource/test_openstack.py
@@ -19,7 +19,6 @@
import copy
import json
import re
-import unittest
from StringIO import StringIO
@@ -318,7 +317,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
self.assertIsNone(ds_os.version)
-class TestVendorDataLoading(unittest.TestCase):
+class TestVendorDataLoading(test_helpers.TestCase):
def cvj(self, data):
return openstack.convert_vendordata_json(data)
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index fbdb7b3f..35cc1f43 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -182,6 +182,12 @@ NETWORKING=yes
spec=False, passthrough=False)
load_mock = self.mocker.replace(util.load_file,
spec=False, passthrough=False)
+ subp_mock = self.mocker.replace(util.subp,
+ spec=False, passthrough=False)
+
+ subp_mock(['ifconfig', '-a'])
+ self.mocker.count(0, None)
+ self.mocker.result(('vtnet0', ''))
exists_mock(mocker.ARGS)
self.mocker.count(0, None)
@@ -190,6 +196,7 @@ NETWORKING=yes
write_bufs = {}
read_bufs = {
'/etc/rc.conf': '',
+ '/etc/resolv.conf': '',
}
def replace_write(filename, content, mode=0644, omode="wb"):
diff --git a/tests/unittests/test_handler/test_handler_set_hostname.py b/tests/unittests/test_handler/test_handler_set_hostname.py
index 03004ab9..e1530e30 100644
--- a/tests/unittests/test_handler/test_handler_set_hostname.py
+++ b/tests/unittests/test_handler/test_handler_set_hostname.py
@@ -37,10 +37,11 @@ class TestHostname(t_help.FilesystemMockingTestCase):
self.patchUtils(self.tmp)
cc_set_hostname.handle('cc_set_hostname',
cfg, cc, LOG, [])
- contents = util.load_file("/etc/sysconfig/network")
- n_cfg = ConfigObj(StringIO(contents))
- self.assertEquals({'HOSTNAME': 'blah.blah.blah.yahoo.com'},
- dict(n_cfg))
+ if not distro.uses_systemd():
+ contents = util.load_file("/etc/sysconfig/network")
+ n_cfg = ConfigObj(StringIO(contents))
+ self.assertEquals({'HOSTNAME': 'blah.blah.blah.yahoo.com'},
+ dict(n_cfg))
def test_write_hostname_debian(self):
cfg = {