summaryrefslogtreecommitdiff
path: root/tests/unittests/sources/test_init.py
Commit message (Collapse)AuthorAgeFilesLines
* Make user/vendor data sensitive and remove log permissions (#2144)James Falcon2023-04-261-1/+26
| | | | | | | | | | | | | Because user data and vendor data may contain sensitive information, this commit ensures that any user data or vendor data written to instance-data.json gets redacted and is only available to root user. Also, modify the permissions of cloud-init.log to be 640, so that sensitive data leaked to the log isn't world readable. Additionally, remove the logging of user data and vendor data to cloud-init.log from the Vultr datasource. LP: #2013967 CVE: CVE-2023-1786
* chore: fix style tip (#2071)Alberto Contreras2023-03-141-3/+2
| | | | - remove too broad exceptions - ignore dynamic base types in templater
* cloud-id: better handling of change in datasource filesd1r3ct0r2023-02-021-3/+7
| | | | | | Stop deleting cloud-id-<cloudname> unless there is a change in discovered datasource cloud-id. LP: #1998998
* Refactor instance json files to use Paths (SC-1238) (#1709)James Falcon2022-09-021-16/+21
| | | | | | | We have multiple areas of the codebase where we fetch the rundir path and join it with the filename for instance-data.json or instance-data-sensitive.json. This commit refactors those calls to use a 'Paths' lookup instead.
* sources: obj.pkl cache should be written anyime get_data is run (#1669)Chad Smith2022-08-171-3/+44
| | | | | | | | | | | | | | | | When metadata update events trigger a new datasource.get_data run ensure we are syncing the cached obj.pkl to disk so subsequent boot stages can leverage the updated metadata. Add write_cache param to persist_instance_data to avoid persisting instance data when init.ds_restored from cache. This avoids a race on clouds where network config is updated per boot in init-local timeframe but init-network uses stale network metadata from cache because updated metadata was not persisted. Migate _pkl_load and _pkl_store out of stages module and into sources as it really is only applicable to datasource serialization.
* Rename function to avoid confusion (#1501)Brett Holman2022-06-091-1/+3
| | | | | Currently find_modules() and find_module() are imported from cloudinit.util and cloudinit.importer, respectively. Rename find_module() since its name doesn't match what it does.
* cc_set_hostname: do not write "localhost" when no hostname is given (#1453)Emanuele Giuseppe Esposito2022-05-311-9/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Systemd used to sometimes ignore localhost in /etc/hostnames, and many programs like cloud-init used this as a workaround to set a default hostname. From https://github.com/systemd/systemd/commit/d39079fcaa05e23540d2b1f0270fa31c22a7e9f1: We would sometimes ignore localhost-style names in /etc/hostname. That is brittle. If the user configured some hostname, it's most likely because they want to use that as the hostname. If they don't want to use such a hostname, they should just not create the config. Everything becomes simples if we just use the configured hostname as-is. This behaviour seems to have been a workaround for Anaconda installer and other tools writing out /etc/hostname with the default of "localhost.localdomain". Anaconda PR to stop doing that: rhinstaller/anaconda#3040. That might have been useful as a work-around for other programs misbehaving if /etc/hostname was not present, but nowadays it's not useful because systemd mostly controls the hostname and it is perfectly happy without that file. Apart from making things simpler, this allows users to set a hostname like "localhost" and have it honoured, if such a whim strikes them. As also suggested by the Anaconda PR, we need to stop writing default "localhost" in /etc/hostnames, and let the right service (networking, user) do that if they need to. Otherwise, "localhost" will permanently stay as hostname and will prevent other tools like NetworkManager from setting the right one. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> RHBZ: 1980403
* cloud-id: publish /run/cloud-init/cloud-id-<cloud-type> files (#1244)Chad Smith2022-02-101-2/+44
| | | | | | | | | | | | | | | | | | Once a valid datasource is detected, publish the following artifacts to expedite cloud-identification without having to invoke cloud-id from shell scripts or sheling out from python. These files can also be relied on in systemd ConditionPathExists directives to limit execution of services and units to specific clouds. /run/cloud-init/cloud-id: - A symlink with content that is the canonical cloud-id of the datasource detected. This content is the same lower-case value as the output of /usr/bin/cloud-id. /run/cloud-init/cloud-id-<canonical-cloud-id>: - A single file which will contain the canonical cloud-id encoded in the filename
* Adopt Black and isort (SC-700) (#1157)James Falcon2021-12-151-349/+530
| | | | | Applied Black and isort, fixed any linting issues, updated tox.ini and CI.
* Reorganize unit test locations under tests/unittests (#1126)Brett Holman2021-12-031-0/+771
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