summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler
AgeCommit message (Collapse)Author
2021-12-03Reorganize unit test locations under tests/unittests (#1126)Brett Holman
This attempts to standardize unit test file location under test/unittests/ such that any source file located at cloudinit/path/to/file.py may have a corresponding unit test file at test/unittests/path/to/test_file.py. Noteworthy Comments: ==================== Four different duplicate test files existed: test_{gpg,util,cc_mounts,cc_resolv_conf}.py Each of these duplicate file pairs has been merged together. This is a break in git history for these files. The test suite appears to have a dependency on test order. Changing test order causes some tests to fail. This should be rectified, but for now some tests have been modified in tests/unittests/config/test_set_passwords.py. A helper class name starts with "Test" which causes pytest to try executing it as a test case, which then throws warnings "due to Class having __init__()". Silence by changing the name of the class. # helpers.py is imported in many test files, import paths change cloudinit/tests/helpers.py -> tests/unittests/helpers.py # Move directories: cloudinit/distros/tests -> tests/unittests/distros cloudinit/cmd/devel/tests -> tests/unittests/cmd/devel cloudinit/cmd/tests -> tests/unittests/cmd/ cloudinit/sources/helpers/tests -> tests/unittests/sources/helpers cloudinit/sources/tests -> tests/unittests/sources cloudinit/net/tests -> tests/unittests/net cloudinit/config/tests -> tests/unittests/config cloudinit/analyze/tests/ -> tests/unittests/analyze/ # Standardize tests already in tests/unittests/ test_datasource -> sources test_distros -> distros test_vmware -> sources/vmware test_handler -> config # this contains cloudconfig module tests test_runs -> runs
2021-11-22testing: monkeypatch system_info call in unit tests (SC-533) (#1117)James Falcon
testing: monkeypatch system_info call in unit tests system_info can make calls that read or write from the filesystem, which should require special mocking. It is also decorated with 'lru_cache', which means test authors often don't realize they need to be mocking. Also, we don't actually want the results from the user's local machine, so monkeypatching it across all tests should be reasonable. Additionally, moved some of 'system_info` into a helper function to reduce the surface area of the monkeypatch, added tests for the new function (and fixed a bug as a result), and removed related mocks that should be no longer needed.
2021-11-17testing: add growpart integration test (#1104)Brett Holman
Add growpart integration test and associated unit tests Additionally, a small runcmd check for a commented line.
2021-11-09Wait for apt lock (#1034)James Falcon
Currently any attempt to run an apt command while another process holds an apt lock will fail. We should instead wait to acquire the apt lock. LP: #1944611
2021-10-29Allow libexec for hotplug (#1088)James Falcon
When we added the install hotplug module, we forgot to update the redhet/cloud-init.spec.in file and allow for execution on /usr/libexec. This PR adds that functionality.
2021-10-29Remove (deprecated) apt-key (#1068)Brett Holman
Also, add the "signed by" option to source definitions. This enables users to limit the scope of trust for individual keys. LP: #1836336
2021-10-27Add "install hotplug" module (SC-476) (#1069)James Falcon
This commit removes automatically installing udev rules for hotplug and adds a module to install them instead. Automatically including the udev rules and checking if hotplug was enabled consumed too many resources in certain circumstances. Moving the rules to a module ensures we don't spend extra extra cycles on hotplug if hotplug functionality isn't desired. LP: #1946003
2021-10-25Add module 'write-files-deferred' executed in stage 'final' (#916)Lucendio
The main idea is to introduce a second module that takes care of writing files, but in the 'final' stage. While the introduction of a second module would allow for choosing the appropriate place withing the order of modules (and stages), there is no addition top-level directive being added to the cloud configuration schema. Instead, 'write-files' schema is being extended to include a 'defer' attribute used only by the 'write-deffered-files' modules. The new module 'write-deferred-files' reuses as much as possible of the 'write-files' functionality.
2021-10-22Remove pin in dependencies for jsonschema (#1078)James Falcon
In jsonschema 4, hostname validation was changed to have an optional dependency on the fqdn package. Since we don't have this dependency in cloud-init, attempting this validation will no longer fail for a string that isn't a valid hostname.
2021-10-20Leave the details of service management to the distro (#1074)Andy Fiddaman
Various modules restart services and they all have logic to try and detect if they are running on a system that needs 'systemctl' or 'service', and then have code to decide which order the arguments need to be etc. On top of that, not all modules do this in the same way. The duplication and different approaches are not ideal but this also makes it hard to add support for a new distribution that does not use either 'systemctl' or 'service'. This change adds a new manage_service() method to the distro class and updates several modules to use it.
2021-10-15testing: add get_cloud function (SC-461) (#1038)James Falcon
Also added supporting distro/datasource classes and updated tests that have a `get_cloud` call.
2021-10-07Allow comments in runcmd and report failed commands correctly (#1049)Brett Holman
Allow comments in runcmd and report failed commands correctly A `runcmd` script may fail to parse properly, but does not mark `runcmd` as failed when that occurs. Additionally `shellify()` fails to correctly parse scripts that contain a comment line. Rectify both issues and add unit tests to verify correct behavior. LP: #1853146
2021-09-29testing: remove cloud_tests (#1020)James Falcon
Cloud tests have been replaced with integration tests
2021-09-21tox: bump the pinned flake8 and pylint version (#1029)Paride Legovini
tox: bump the pinned flake8 and pylint version * pylint: fix W1406 (redundant-u-string-prefix) The u prefix for strings is no longer necessary in Python >=3.0. * pylint: disable W1514 (unspecified-encoding) From https://www.python.org/dev/peps/pep-0597/ (Python 3.10): The new warning stems form https://www.python.org/dev/peps/pep-0597, which says: Developers using macOS or Linux may forget that the default encoding is not always UTF-8. [...] Even Python experts may assume that the default encoding is UTF-8. This creates bugs that only happen on Windows. The warning could be fixed by always specifying encoding='utf-8', however we should be careful to not break environments which are not utf-8 (or explicitly state that only utf-8 is supported). Let's silence the warning for now. * _quick_read_instance_id: cover the case where load_yaml() returns None Spotted by pylint: - E1135 (unsupported-membership-test) - E1136 (unsubscriptable-object) LP: #1944414
2021-09-01puppet config: add the start_agent option (#1002)Andrew Bogott
The current code starts the puppet agent and also sets autostart in all cases. This conflicts with a common pattern where puppet itself manages the agent and autostart state. For example, in my deploy puppet disables the puppet agent and replaces it with a cron. This causes various races both within this cloud-init unit and within puppet itself while cloud-init and puppet fight over whether or not to enable the service.
2021-08-12cc_resolv_conf: fix typos (#969)Shreenidhi Shedi
Add tests for cc_resolv_conf handler
2021-08-12Replace broken httpretty tests with mock (SC-324) (#973)James Falcon
* Replace broken httpretty tests with mock Certain versions of python/httpretty don't work correctly using https URIs. #960 recently added httpretty tests using https. This commit replaces the httpretty tests that were failing on https with mocks of readurl instead.
2021-08-10cc_puppet: support AIO installations and more (#960)Gabriel Nagy
- update the puppet module to support AIO installations by setting `install_type` to `aio` - make the install collection configurable through the `collection` parameter; by default the rolling `puppet` collection will be used, which installs the latest version) - when `install_type` is `aio`, puppetlabs repos will be purged after installation; set `cleanup` to `False` to prevent this - AIO installations are performed by downloading and executing a shell script; the URL for this script can be overridden using the `aio_install_url` parameter - make it possible to run puppet agent after installation/configuration via the `exec` key - by default, puppet agent will run with the `--test` argument; this can be overridden via the `exec_args` key
2021-08-09photon: refactor hostname handling and add networkd activator (#958)sshedi
2021-08-03Implementing device_aliases as described in docs (#945)Mal Graty
Implement missing device_aliases feature The device_aliases key has been documented as part of disk_setup for years, however the feature was never implemented. This implements the feature as documented allowing usercfg (rather than dsconfig) to create a mapping of device names. This is not to be confused with disk_aliases, a very similar map but existing solely for use by datasources. LP: #1867532
2021-06-18Add support for VMware PhotonOS (#909)sshedi
Also added a new (currently experimental) systemd-networkd renderer, and includes a small refactor to cc_resolv_conf.py to support the resolved.conf used by systemd-resolved.
2021-05-18Added support for importing keys via primary/security mirror clauses (#882)Paul Goins
Presently, mirror keys cannot be associated with primary/security mirrors. Unfortunately, this prevents use of Landscape-managed package mirrors as the mirror key for the Landscape-hosted repository cannot be provided. This patch allows the same key-related fields usable on "sources" entries to be used on the "primary" and "security" entries as well. LP: #1925395
2021-05-03Revert "Add support to resize rootfs if using LVM (#721)" (#887)Daniel Watkins
This reverts commit 74fa008bfcd3263eb691cc0b3f7a055b17569f8b. During pre-release testing, we discovered two issues with this commit. Firstly, there's a typo in the udevadm command that causes a TypeError for _all_ growpart executions. Secondly, the LVM resizing does not appear to successfully resize everything up to the LV, though some things do get resized. We certainly want this change, so we'll be happy to review and land it alongside an integration test which confirms that it is working as expected. LP: #1922742
2021-04-15add prefer_fqdn_over_hostname config option (#859)hamalq
the above option allows the user to control the behavior of a distro hostname selection if both short hostname and FQDN are supplied. If `prefer_fqdn_over_hostname` is true the FQDN will be selected as hostname; if false the hostname will be selected LP: #1921004
2021-03-30Add support to resize rootfs if using LVM (#721)Eduardo Otubo
This patch adds support to resize a single partition of a VM if it's using an LVM underneath. The patch detects if it's LVM if the given block device is a device mapper by its name (e.g. `/dev/dm-1`) and if it has slave devices under it on sysfs. After that syspath is updated to the real block device and growpart will be called to resize it (and automatically its Physical Volume). The Volume Group will be updated automatically and a final call to extend the rootfs to the remaining space available will be made. Using the same growpart configuration, the user can specify only one device to be resized when using LVM and growpart, otherwise cloud-init won't know which one should be resized and will fail. rhbz: #1810878 LP: #1799953 Signed-off-by: Eduardo Otubo <otubo@redhat.com> Signed-off-by: Scott Moser <smoser@brickies.net>
2021-03-15archlinux: Fix broken locale logic (#841)Kristian Klausen
The locale wasn't persisted correct nor set. LP: #1402406
2020-12-17cc_ca_certs: add RHEL support (#633)cawamata
This refactors cc_ca_certs to support non-ca-certificates distros, and adds RHEL support.
2020-12-09sandbox CA Cert tests to not require ca-certificates (#715)Eduardo Otubo
CA Cert tests will fail on systems that don't have ca-certificates installed and configured. Signed-off-by: Daniel Watkins <oddbloke@ubuntu.com> Signed-off-by: Eduardo Otubo <otubo@redhat.com>
2020-11-19cc_resizefs on FreeBSD: Fix _can_skip_ufs_resize (#655)Mina Galić
On FreeBSD, if a UFS has trim: (-t) or MAC multilabel: (-l) flag, resize FS fail, because the _can_skip_ufs_resize check gets tripped up by the missing options. This was reported at FreeBSD Bugzilla: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=250496 and as LP: #1901958 Rather than fixing the parser as in the patches proposed there (and attempted in #636) this pull-request rips out all of it, and simplifies the code. We now use `growfs -N` and check if that returns an error. If it returns the correct kind of error, we can skip the resize, because we either are at the correct size, or the filesystem in question is broken or not UFS. If it returns the wrong kind of error, we just re-raise it. LP: #1901958
2020-11-18cli: add --system param to allow validating system user-data on a machine (#575)Chad Smith
Allow root user to validate the userdata provided to the launched machine using `cloud-init devel schema --system`
2020-10-28Add config modules for controlling IBM PowerVM RMC. (#584)Aman306
Reliable Scalable Cluster Technology (RSCT) is a set of software components that together provide a comprehensive clustering environment(RAS features) for IBM PowerVM based virtual machines. RSCT includes the Resource Monitoring and Control (RMC) subsystem. RMC is a generalized framework used for managing, monitoring, and manipulating resources. RMC runs as a daemon process on individual machines and needs creation of unique node id and restarts during VM boot. LP: #1895979 Co-authored-by: Scott Moser <smoser@brickies.net>
2020-09-15create a shutdown_command method in distro classes (#567)Emmanuel Thomé
Under FreeBSD, we want to use "shutdown -p" for poweroff. Alpine Linux also has some specificities. We choose to define a method that returns the shutdown command line to use, rather than a method that actually does the shutdown. This makes it easier to have the tests in test_handler_power_state do their verifications. Two tests are added for the special behaviours that are known so far.
2020-08-27LXD: detach network from profile before deleting it (#542)Paride Legovini
* LXD: detach network from profile before deleting it When cleaning up the bridge network created by default by LXD as part of the `lxd init` process detach the network its profile before deleting it. LXD will otherwise refuse to delete it with error: Error: The network is currently in use. Discussion with LXD upstream: https://github.com/lxc/lxd/issues/7804. LP: #1776958 * LXD bridge deletion: fail if bridge exists but can't be deleted * LXD bridge deletion: remove useless failure logging
2020-08-19Add Alpine Linux support. (#535)dermotbradley
Add new module cc_apk_configure for creating Alpine /etc/apk/repositories file. Modify cc_ca_certs, cc_ntp, cc_power_state_change, and cc_resolv_conf for Alpine. Add Alpine template files for Chrony and Busybox NTP support. Add Alpine template file for /etc/hosts.
2020-08-18Detect kernel version before swap file creation (#428)Eduardo Otubo
According to man page `man 8 swapon', "Preallocated swap files are supported on XFS since Linux 4.18". This patch checks for kernel version before attepting to create swapfile, using dd for XFS only on kernel versions <= 4.18 or btrfs. Add new func util.kernel_version which returns a tuple of ints (major, minor) Signed-off-by: Eduardo Otubo otubo@redhat.com
2020-07-15cc_ca_certs.py: fix blank line problem when removing CAs and adding new one ↵dermotbradley
(#483) Problem: When cc_ca_certs configuration has both "remove-defaults: true" and also specifies one, or more, new trusted CAs to add then the resultant /etc/ca-certificates.conf file's 1st line is blank. As noted in comments in the existing cc_ca_certs.py code blank lines in this file cause problems. Fix: Before adding the cloud-init CA filename to this file first check the size of the file - if is is empty (as all existing CAs have been deleted) then write only the cloud-init CA filename to the file rather than appending it to the file.
2020-07-10cc_mounts: handle missing fstab (#484)Ryan Harper
Do not fail if /etc/fstab is not present. Some images, like container rootfs may not include this file by default. LP: #1886531
2020-06-30Disable ec2 mirror for non aws instances (#390)lucasmoura
For versions before 20.2, we allowed the use of ec2 mirrors if the datasource availability_zone matches one of the ec2 regions. We are now updating that behavior to allow allow the use of ec2 mirrors on ec2 instances or if the user directly passes an an ec2 mirror url through #cloud-config apt directives. LP: #1456277
2020-06-29Add schema for cc_chef module (#375)lucasmoura
Create a schema object for the chef module and validate this schema in the handle function of the module. Some of the config keys description, so I tried looking at the code and chef documentation to provide an information to the user. However, I don't know if I have the best description for all fields. For example, for the key show_time I could not find an accurate description of what it did, so I used what was in our code base to infer what it should do. LP: #1858888
2020-06-10test: fix all flake8 E126 errors (#425)Joshua Powers
2020-06-08Move subp into its own module. (#416)Scott Moser
This was painful, but it finishes a TODO from cloudinit/subp.py. It moves the following from util to subp: ProcessExecutionError subp which target_path I moved subp_blob_in_tempfile into cc_chef, which is its only caller. That saved us from having to deal with it using write_file and temp_utils from subp (which does not import any cloudinit things now). It is arguable that 'target_path' could be moved to a 'path_utils' or something, but in order to use it from subp and also from utils, we had to get it out of utils.
2020-06-02test: fix all flake8 E121 and E123 errors (#404)Joshua Powers
This fixes issues with closing brackets not matching the opening bracket's line and continuation line under-idented for hanging indent.
2020-06-01test: fix all flake8 E741 errors (#401)Joshua Powers
This removes the use of variables named ‘l’, ‘O’, or ‘I’. Generally these are used in list comprehension to read the line of lines.
2020-05-27Enable chef_license support for chef infra client (#389)Bipin Bachhao
Co-authored-by: Daniel Watkins <oddbloke@ubuntu.com>
2020-05-13Add schema to apt configure config (#357)lucasmoura
Create a schema object for the `apt_configure` module and validate this schema in the `handle` function of the module. There are some considerations regarding this PR: * The `primary` and `security` keys have the exact same properties. I tried to eliminate this redundancy by moving their properties to a common place and then just referencing it for both security and primary. Similar to what is documented here: https://json-schema.org/understanding-json-schema/structuring.html under the `Reuse` paragraph. However, this approach does not work, because the `#` pointer goes to the beginning of the file, which is a python module instead of a json file, not allowing the pointer to find the correct definition. What I did was to create a separate dict for the mirror config and reuse it for primary and security, but maybe there are better approaches to do that. * There was no documentation for the config `debconf_selections`. I tried to infer what it supposed to do by looking at the code and the `debconf-set-selections` manpage, but my description may not be accurate or complete. * Add a _parse_description function to schema.py to render multi-line preformatted content instead of squashing all whitespace LP: #1858884
2020-05-08Add test to ensure docs examples are valid cloud-init configs (#355)James Falcon
Also update all examples to include the cloud-config header if they don't have it LP: #1876414
2020-05-07make suse and sles support 127.0.1.1 (#336)chengcheng-chcheng
Move from 127.0.0.1 to 127.0.1.1 for localhost IP addr for opensuse and sles
2020-05-06Create tests to validate schema examples (#348)lucasmoura
Add a unit test to validate if the examples provided in the config modules are conforming to the concatenated schema of all config modules. The rationale behind that is not only to verify if the examples are correctly written but to assert that no config schema is interfering with each other. Failures in validate_cloudconfig_schema raise the SchemaValidationError by using strict=True, so I have only called the function passing the right schema examples to validate. This branch also fixes an invalid schema example in cc_snap. LP: #1876412
2020-04-30cc_locale: introduce schema (#335)Daniel Watkins
2020-04-24schema: add json schema for write_files module (#152)Chad Smith
Add schema definition to cc_write_files.py Cloud-config containing write_files config directives will now emit warnings for invalid config keys or values for the write_files module. Add an extension to JSON schema's draft4validator to permit either binary or text values for 'string' objects. This allows for JSON schema validating the YAML declaration of binary valiues in cloud-config using YAML's '!!binary' syntax. Add the ability to pass a specific module name to `cloud-init devel schema --docs <module_name>|all` to optionally limit doc output during development to a single schema doc.