summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler
AgeCommit message (Collapse)Author
2020-02-07cc_disk_setup: add swap filesystem force flag (#207)Ryan Harper
2020-01-31cloudinit: replace "from six import X" imports (except in util.py) (#183)Daniel Watkins
2020-01-29Replace mock library with unittest.mock (#186)Daniel Watkins
* cloudinit: replace "import mock" with "from unittest import mock" * test-requirements.txt: drop mock Co-authored-by: Chad Smith <chad.smith@canonical.com>
2020-01-23cloudinit: remove ImportError handling for mock imports (#182)Daniel Watkins
We only run on Python 3 now, so we can unambiguously expect unittest.mock to exist.
2020-01-23Do not use fallocate in swap file creation on xfs. (#70)Eduardo Otubo
When creating a swap file on an xfs filesystem, fallocate cannot be used. Doing so results in failure of swapon and a message like: swapon: swapfile has holes The solution here is to maintain a list (currently containing only XFS) of filesystems where fallocate cannot be used. The, on those fileystems use the slower but functional 'dd' method. Signed-off-by: Eduardo Otubo <otubo@redhat.com> Co-authored-by: Adam Dobrawy <naczelnik@jawnosc.tk> Co-authored-by: Scott Moser <smoser@brickies.net> Co-authored-by: Daniel Watkins <daniel@daniel-watkins.co.uk> LP: #1781781
2020-01-21Drop most of the remaining use of six (#179)Daniel Watkins
2020-01-16util: rename get_architecture to get_dpkg_architecture (#173)Daniel Watkins
This makes it clearer that we should only use this in code paths that will definitely have dpkg available to them. - Rename get_architecture -> get_dpkg_architecture - Add docstring to get_dpkg_architecture
2020-01-16Ensure util.get_architecture() runs only once (#172)Ryan Harper
* Ensure util.get_architecture() runs only once util.get_architecture() recently was wrapped using python3's lru_cache() which will cache the result so we only invoke 'dpkg --print-architecture' once. In practice, cloud-init.log will show multiple invocations of the command. The source of this was that the debian Distro object implements the get_primary_arch() with this command, but it was not calling it from util, but issuing a util.subp() directly. This branch also updates cc_apt_configure methods to fetch the arch value from the distro class, and then ensure that the methods apt_configure calls pass the arch value around. * utils: remove lsb_release and get_architecture wrappers The original lsb_release wrapper was used to prevent polluting the single value we cached, however lru_cache() already handles this case by using args, kwargs values to cache different calls to the method. * rename_apt_list: use all positional parameters
2020-01-14Only use gpart if it is the BSD gpart (#131)Conrad Hoffmann
Currently, cloud-init will happily try to run `gpart` on Linux even though on most distributions this a different tool [1]. Extend the availability check to make sure the `gpart` present is really the BSD variant, to avoid accidental execution. Also add a pointer to the docs, so that people do not try to install gpart on Linux in the expectation it will work with this module. [1] https://github.com/baruch/gpart
2019-12-19cc_snappy: remove deprecated module (#127)Daniel Watkins
* cc_snappy: remove deprecated module * cloud_tests: remove cc_snappy tests (and references) This module was deprecated in favor of cc_snap in cloud-init v.18.2
2019-10-31cc_puppet: Implement csr_attributes.yaml supportMatthias Baur
This change adds two new parameters: * csr_attributes * csr_attributes_path Those parameters allow to configure the content of the csr_attributes.yaml file. See https://puppet.com/docs/puppet/latest/config_file_csr_attributes.html
2019-10-17replace any deprecated log.warn with log.warningDominic Schlegel
Commit 6797e822959b84c98cf73e02b2a6e3d6ab3fd4fe replaced the LOG.warn calls that linters were warning about; this also replaces calls that linters would not have recognised (as `log` is generally a parameter in these scenarios). LP: #1508442
2019-08-19ubuntu-drivers: emit latelink=true debconf to accept nvidia eulaChad Smith
To accept NVIDIA EULA, cloud-init needs to emit latelink=true debconf setting to the linux-restricted-modules package to allow NVIDIA drivers to properly link to the running kernel. LP: #1840080
2019-07-16templates/ntp.conf.debian.tmpl: fix missing newline for poolsRyan Harper
The debian ntp.conf template did not contain a newline for the comment used to mark the rendered ntp pools configured. This resulted in an invalid line: '# poolspool 0.int.pool.ntp.org iburst' rather than: '# pools  pool 0.int.pool.ntp.org iburst' This patch fixes the template and updates the unittest to verify that the rendered templates puts servers and pools at the beginning of a line. LP: #1836598
2019-05-28freebsd: ability to grow root file systemGonéri Le Bouder
- UFS file system support - GPT partition table support - add support for newfs's -L parameter (label) - move freebsd specific test from Azure to freebsd
2019-05-08cc_mounts: check if mount -a on no-change fstab pathJason Zions (MSFT)
Under some circumstances, cc_disk_setup may reformat volumes which already appear in /etc/fstab (e.g. Azure ephemeral drive is reformatted from NTFS to ext4 after service-heal). Normally, cc_mounts only calls mount -a if it altered /etc/fstab. With this change cc_mounts will read /proc/mounts and verify if configured mounts are already mounted and if not raise flag to request a mount -a. This handles the case where no changes to fstab occur but a mount -a is required due to change in underlying device which prevented the .mount unit from running until after disk was reformatted. LP: #1825596
2019-03-19Add ubuntu_drivers config moduleDaniel Watkins
The ubuntu_drivers config module enables usage of the 'ubuntu-drivers' command. At this point it only serves as a way of installing NVIDIA drivers for general purpose graphics processing unit (GPGPU) functionality. Also, a small usability improvement to get_cfg_by_path to allow it to take a string for the key path "toplevel/second/mykey" in addition to the original: ("toplevel", "second", "mykey")
2019-02-25Enable encrypted_data_bag_secret support for ChefEric Williams
Encrypted data bags require a secrets file to be present to decrypt, and the location of the file must be configured the Chef client configuration file, client.rb. This update enables cloud-init's chef module to update that setting in client.rb. LP: #1817082
2019-01-25lxd: install zfs-linux instead of zfs meta packageJohnson Shi
When using the LXD module cloud-init will attempt to install ZFS if it does not exist on the target system. However instead of installing the `zfsutils-linux` package it attempts to install `zfs` resulting in an error. Ubuntu Xenial (16.04) has zfs meta package, but Bionic (18.04) does not. Use the specific base package instead of zfs meta. Co-authored-by: Michael Skalka <michael.skalka@canonical.com> LP: #1799779
2018-12-06write_files: add support for appending to files.James Baxter
Add 'append: true' to write_files entries to append 'content' to file specified by 'path' key. This modifies the file open mode to append.
2018-11-28tests: fix incorrect order of mocks in test_handle_zfs_root.Scott Moser
The order of parameters to test_handle_zfs_root did not match the order of the mocks applied. Thanks to Jason Zions for pointing this out.
2018-11-14resizefs: Prefix discovered devpath with '/dev/' when path does not existIgor Galić
In some environments, like FreeBSD, gpart can return the device basename instead of the full path. If this discovered devpath does not exist and is missing the '/dev/' prefix, add that prefix in an attempt to find the device.
2018-09-26lxd: adjust to snap installed lxd.Scott Moser
Relax expectation on path to lxc and lxd. The deb path still does install them in /usr/bin/ but that is overly pedantic. Add a 'lxd waitready' (present since lxd 0.5) to wait until lxd is ready before operating on it.
2018-09-17tests: Add mock for util.get_hostname.Robert Schweikert
At present the host network settings bleed into the test environment causing the test test_handler_apt_source_v3 to fail if the host has a domain setting other then localdomain. LP: #1792799
2018-09-11user-data: jinja template to render instance-data.json in cloud-configChad Smith
Allow users to provide '## template: jinja' as the first line or their #cloud-config or custom script user-data parts. When this header exists, the cloud-config or script will be rendered as a jinja template. All instance metadata keys and values present in /run/cloud-init/instance-data.json will be available as jinja variables for the template. This means any cloud-config module or script can reference any standardized instance data in templates and scripts. Additionally, any standardized instance-data.json keys scoped below a '<v#>' key will be promoted as a top-level key for ease of reference in templates. This means that '{{ local_hostname }}' is the same as using the latest '{{ v#.local_hostname }}'. Since instance-data is written to /run/cloud-init/instance-data.json, make sure it is persisted across reboots when the cached datasource opject is reloaded. LP: #1791781
2018-09-05tests: Disallow use of util.subp except for where needed.Scott Moser
In many cases, cloud-init uses 'util.subp' to run a subprocess. This is not really desirable in our unit tests as it makes the tests dependent upon existance of those utilities. The change here is to modify the base test case class (CiTestCase) to raise exception any time subp is called. Then, fix all callers. For cases where subp is necessary or actually desired, we can use it via   a.) context hander CiTestCase.allow_subp(value)   b.) class level self.allowed_subp = value Both cases the value is a list of acceptable executable names that will be called (essentially argv[0]). Some cleanups in AltCloud were done as the code was being updated.
2018-06-15lxd: Delete default network and detach device if lxd-init created them.Scott Moser
Newer versions (3.0.1+) of lxd create the 'lxdbr0' network when 'lxd init --auto' is invoked. When cloud-init is given a network configuration to pass on to lxc and that config had no name specified or 'lxdbr0', then cloud-init would fail to create the network as it already exists. Similarly, we need to remove the device from the default profile so that the attach code can work. Also, add a _lxc method and use it to make sure we're getting the --force-local flag everywhere. LP: #1776958
2018-05-23tests: Avoid using https in httpretty, improve HttPretty test case.Scott Moser
On OpenSuSE 42.3, we would get errors running tests/unittests/test_handler/test_handler_chef.py  - test_myhttps_nonet raises a UnmockedError    No mocking was registered, and real connections are not allowed  - test_myhttps_net raises SSLError    ("bad handshake: SysCallError(32, 'EPIPE')",) This fixes the errors by just using http instead of https. Also it modifies the HttprettyTestCase to do the httpretty activate and deactivate itself in setUp and tearDown. Then we don't have to decorate individual test_ methods. Also, we set    httpretty.HTTPretty.allow_net_connect = False Test cases here should not reach out to a network resource. LP: #1771659
2018-05-23yaml_load/schema: Add invalid line and column nums to error messageChad Smith
Yaml tracebacks are generally hard to read for average users. Add a bit of logic to util.yaml_load and schema validation to look for YAMLError.context_marker or problem_marker line and column counts. No longer log the full exceeption traceback from the yaml_load error, instead just LOG.warning for the specific error and point to the offending line and column where the problem exists.
2018-05-22cc_mounts: Do not add devices to fstab that are already present.Lars Kellogg-Stedman
Do not add new entries to /etc/fstab for devices that already have an existing fstab entry. Resolves: rhbz#1542578
2018-05-17read_file_or_url: move to url_helper, fix bug in its FileResponse.Scott Moser
The result of a read_file_or_url on a file and on a url would differ in behavior. str(UrlResponse) would return UrlResponse.contents.decode('utf-8') while str(FileResponse) would return str(FileResponse.contents) The difference being "b'foo'" versus "foo". As part of the general goal of cleaning util, move read_file_or_url into url_helper.
2018-05-04pycodestyle: Fix deprecated string literals, move away from flake8.Chad Smith
Fix remaining pycodesytle warnings related to invalid string literals introduced in more recent pycodeflakes versions https://bugs.python.org/issue27364 . Also stop using flake8 in tox as it is incompatible with newer versions of pyflakes. Instead we now add tox environments for pycodestyle and pyflakes individually. Set the versions in both pycodestyle and pyflakes to the currently available versions.
2018-05-01FreeBSD: Invoke growfs on ufs filesystems such that it does not prompt.Harm Weites
By default, FreeBSD's growfs runs interactively asking a question which can be mitigated using the '-y' command line option. The fix here is simply to pass -y to growfs to avoid the prompt. LP: #1404745
2018-04-20schema: in validation, raise ImportError if strict but no jsonschema.Scott Moser
validate_cloudconfig_schema with strict=True would not actually validate if there was no jsonschema available. That seems kind of strange. The change here is to make it raise an exception if strict was passed in. And then to fix the one test that needed a skipIfJsonSchema wrapper.
2018-04-19pylint: pay attention to unused variable warnings.Scott Moser
This enables warnings produced by pylint for unused variables (W0612), and fixes the existing errors.
2018-04-18Schema: do not warn on duplicate items in commands.Scott Moser
runcmd, bootcmd, snap/commands, ubuntu-advantage/commands would log warning (and fail if strict) on duplicate values in the commands. But those should be allowed. Example, it is perfectly valid to do: runcmd: ['sleep 1', 'sleep 1'] LP: #1764264
2018-04-12renderer: support unicode in render_from_file.Scott Moser
If a file passed to render_from_file had non-ascii text then jinja in python2 would decode as ascii, which would cause UnicodeDecodeError. This issue can be re-created in python2 with just: 'can\xe2\x80\x99t'.decode() The solution here is to explicitly pass in unicode supporting type (py3 str, py2 unicode). Those are six.text_type. Then jinja does not try to decode. The reason we hit this is that load_file calls decode_binary. decode_binary believes it has no work to do if it got a six.string_types. isinstance('can\xe2\x80\x99t', six.string_types) == True So it returns the original string which will blow up for jinja. Our fix here then is to load the file in binary mode and explicitly decode it to utf-8. Then in python2 we'll have a unicode type and in python3 we'll have a string type.
2018-04-12Implement ntp client spec with auto support for distro selectionRyan Harper
Add a base NTP client configuration dictionary and allow Distro specific changes to be merged. Add a select client function which implements logic to preferr installed clients over clients which need to be installed. Also allow distributions to override the cloud-init defaults. LP: #1749722
2018-03-27FreeBSD: resizefs module now able to handle zfs/zpool.Dominic Schlegel
Previously there was no support at all for zfs file system. With this change it is now possible to use the resizefs module to grow a zpool to its maximum partition size on FreeBSD. LP: #1721243
2018-03-22ubuntu-advantage: Add new config module to support ubuntu-advantage-toolsChad Smith
ubuntu-advantage-tools is a package for enabling and disabling extended support services such as Extended Security Maintenance (ESM), Canonical Livepatch and FIPS certified PPAs. Simplify Ubuntu Advantage setup on machines by allowing users to provide a list of ubuntu-advantage commands in cloud-config.
2018-03-16cc_snap: Add new module to install and configure snapd and snap packages.Chad Smith
Support installing and configuring snaps on ubuntu systems. Now, cloud-config files can provide a list or dictionary of snap:assertions which will be allow configuration of snapd on a system via 'snap ack' calls. The snap:commands configuration option supports arbitrary system commands intended to interact with snappy's cli. This allows users to run arbitrary snappy commands to create users, download, install and configure snap packages and snapd. This branch also deprecates old snappy and snap_config modules leaving warnings in documentation and runtime for consumers of these modules. Deprecated snap* modules will be dropped in cloud-init v.18.2 release.
2018-03-16tests: Make pylint happy and fix python2.6 uses of assertRaisesRegex.Scott Moser
Older unittest2.TestCase (as seen in CentOS 6) do not have an assertRaisesRegex method. They only have the now-deprecated assertRaisesRegexp. We need our unit tests to work there and on newer python (3.6). Simply making assertRaisesRegex = assertRaisesRegexp makes pylint complain as described in https://github.com/PyCQA/pylint/issues/1946 . What was here before this commit was actually broken. This commit makes assertRaisesRegex functional in CentOS 6 and works around the invalid Deprecated warning from pylint. To prove this, we use assertRaisesRegex in a unit test which will be exectued in py27, py3 and py26.
2018-03-14set_hostname: When present in metadata, set it before network bringup.Chad Smith
When instance meta-data provides hostname information, run cc_set_hostname in the init-local or init-net stage before network comes up. Prevent an initial DHCP request which leaks the stock cloud-image default hostname before the meta-data provided hostname was processed. A leaked cloud-image hostname adversely affects Dynamic DNS which would reallocate 'ubuntu' hostname in DNS to every instance brought up by cloud-init. These instances would only update DNS to the cloud-init configured hostname upon DHCP lease renewal. This branch extends the get_hostname methods in datasource, cloud and util to limit results to metadata_only to avoid extra cost of querying the distro for hostname information if metadata does not provide that information. LP: #1746455
2018-03-14tests: Centralize and re-use skipTest based on json schema presense.Scott Moser
This just centralizes a hunk of duplicated code and uses it from the new location.
2018-03-09shellify: raise TypeError on bad input.Scott Moser
This makes 2 changes to shellify's behavior: a.) raise a TypeError rather than a RuntimeError. b.) raise a TypeError if input is not a list or tuple.
2018-02-12tests: run nosetests in cloudinit/ directory, fix py26 fallout.Scott Moser
When we moved some tests to live under cloudinit/ we inadvertantly failed to change all things that would run nose to include that directory. This changes all the 'nose' invocations to consistently run with tests/unittests and cloudinit/. Also, it works around, more correctly this time, a python2.6-ism with the following code: with assertRaises(SystemExit) as cm: sys.exit(2)
2018-01-24btrfs: support resizing if root is mounted ro.Robert Schweikert
Resize of btrfs fails if the mount point for the file system we are trying to resize, i.e. the root of the filesystem is read only. With this change we use a known (currently snapper specific) rw location to work around a flaw that blocks resizing of the ro filesystem. LP: #1734787
2017-12-07pylint: Update pylint to 1.7.1, run on tests/ and tools and fix complaints.Ryan Harper
The motivation for this is that a.) 1.7.1 runs with python 3.6 (bionic) b.) we want to run pylint on tests/ and tools for the same reasons that we want to run it on cloudinit/ The changes are described below. - Update tox.ini to invoke pylint v1.7.1. - Modify .pylintrc generated-members ignore mocked object members (m_.*) - Replace "dangerous" params defaulting to {} - Fix up cloud_tests use of platforms - Cast some instance objects to with dict() - Handle python2.7 vs 3+ ConfigParser use of readfp (deprecated) - Update use of assertEqual(<boolean>, value) to assert<Boolean>(value) - replace depricated assertRegexp -> assertRegex - Remove useless test-class calls to super class - Assign class property accessors a result and use it - Fix missing class member in CepkoResultTests - Fix Cheetah test import
2017-11-16ntp: fix configuration template rendering for openSUSE and SLESChad Smith
Add opensuse distro support to cc_ntp module. LP: #1726572
2017-11-10hosts: Fix openSUSE and SLES setup for /etc/hosts and clarify docs.Robert Schweikert
The etc/hosts file is was not properly setup for openSUSE or SLES when manage_etc_hosts is set in the config file. Improve the doc to address the fact that the 'localhost' ip is distribution dependent (not always 127.0.0.1). LP: #1731022