summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_altcloud.py
Commit message (Collapse)AuthorAgeFilesLines
* Reorganize unit test locations under tests/unittests (#1126)Brett Holman2021-12-031-450/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* cloudinit: move dmi functions out of util (#622)Scott Moser2020-11-021-10/+11
| | | | | | | | | This just separates the reading of dmi values into its own file. Some things of note: * left import of util in dmi.py only for 'is_container' It'd be good if is_container was not in util. * just the use of 'util.is_x86' to dmi.py * open() is used directly rather than load_file.
* Move subp into its own module. (#416)Scott Moser2020-06-081-3/+4
| | | | | | | | | | | | | | | | | 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.
* instance-data: Add standard keys platform and subplatform. Refactor ec2.Chad Smith2018-10-091-51/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the following instance-data.json standardized keys: * v1._beta_keys: List any v1 keys in beta development, e.g. ['subplatform']. * v1.public_ssh_keys: List of any cloud-provided ssh keys for the instance. * v1.platform: String representing the cloud platform api supporting the datasource. For example: 'ec2' for aws, aliyun and brightbox cloud names. * v1.subplatform: String with more details about the source of the metadata consumed. For example, metadata uri, config drive device path or seed directory. To support the new platform and subplatform standardized instance-data, DataSource and its subclasses grew platform and subplatform attributes. The platform attribute defaults to the lowercase string datasource name at self.dsname. This method is overridden in NoCloud, Ec2 and ConfigDrive datasources. The subplatform attribute calls a _get_subplatform method which will return a string containing a simple slug for subplatform type such as metadata, seed-dir or config-drive followed by a detailed uri, device or directory path where the datasource consumed its configuration. As part of this work, DatasourceEC2 methods _get_data and _crawl_metadata have been refactored for a few reasons: - crawl_metadata is now a read-only operation, persisting no attributes on the datasource instance and returns a dictionary of consumed metadata. - crawl_metadata now closely represents the raw stucture of the ec2 metadata consumed, so that end-users can leverage public ec2 metadata documentation where possible. - crawl_metadata adds a '_metadata_api_version' key to the crawled ds.metadata to advertise what version of EC2's api was consumed by cloud-init. - _get_data now does all the processing of crawl_metadata and saves datasource instance attributes userdata_raw, metadata etc. Additional drive-bys: * unit test rework for test_altcloud and test_azure to simplify mocks and make use of existing util and test_helpers functions.
* tests: Disallow use of util.subp except for where needed.Scott Moser2018-09-051-26/+18
| | | | | | | | | | | | | | | | | | 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.
* Datasources: Formalize DataSource get_data and related properties.Chad Smith2017-12-051-9/+13
| | | | | | | | | | | | | | | | | | | | | Each DataSource subclass must define its own get_data method. This branch formalizes our DataSource class to require that subclasses define an explicit dsname for sourcing cloud-config datasource configuration. Subclasses must also override the _get_data method or a NotImplementedError is raised. The branch also writes /run/cloud-init/instance-data.json. This file contains all meta-data, user-data and vendor-data and a standardized set of metadata keys in a json blob which other utilities with root-access could make use of. Because some meta-data or user-data is potentially sensitive the file is only readable by root. Generally most metadata content types should be json serializable. If specific keys or values are not serializable, those specific values will be base64encoded and the key path will be listed under the top-level key 'base64-encoded-keys' in instance-data.json. If json writing fails due to other TypeErrors or UnicodeDecodeErrors, a warning log will be emitted to /var/log/cloud-init.log and no instance-data.json will be created.
* AltCloud: Trust PATH for udevadm and modprobe.Scott Moser2017-09-251-2/+2
| | | | | | | | Previously we had hard coded paths in /sbin for the udevadm and modprobe programs invoked by AltCloud. Its more flexible to expect the PATH to be set correctly. Debian: #852564
* relocate tests/unittests/helpers.py to cloudinit/testsLars Kellogg-Stedman2017-09-051-1/+1
| | | | | This moves the base test case classes into into cloudinit/tests and updates all the corresponding imports.
* python2.6: fix unit tests usage of assertNone and format.Scott Moser2017-05-251-1/+2
| | | | | | | | | | | python2.6 unittest.TestCase does not have the assertIsNone or assertIsNotNone. We just have to explicitly use the unittest2 version, which we get from helpers. The desire to use assertIsNone comes from flake8 (through hacking, I believe). Also, fix "{}.format('foo')" which is not valid in python2.6.
* flake8: move the pinned version of flake8 up to 3.3.0Scott Moser2017-05-231-1/+1
| | | | | | | | | | | | | | | | This just moves flake8 and related tools up to newer versions and fixes the complaints associated with that. We added to the list of flake8 ignores: H102: do not put vim info in source files H304: no relative imports Also updates and pins the following in the flake8 environment: pep8: 1.7.0 => drop (although hacking still pulls it in). pyflakes 1.1.0 => 1.5.0 hacking 0.10.2 => 0.13.0 flake8 2.5.4 => 3.3.0 pycodestyle none => 2.3.1
* tests: fix AltCloud tests to not rely on blkidScott Moser2017-04-111-64/+59
| | | | | | | | | | | This just mocks out the AltCloud tests to not invoke blkid. Our tests should not rely on system command returning any specific value. Also, shorten long lines with change in the import name of DataSourceAltCloud. LP: #1636531
* LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm2016-12-221-18/+6
| | | | | | | | | | | | | | | | | | This has been a recurring ask and we had initially just made the change to the cloud-init 2.0 codebase. As the current thinking is we'll just continue to enhance the current codebase, its desirable to relicense to match what we'd intended as part of the 2.0 plan here. - put a brief description of license in LICENSE file - put full license versions in LICENSE-GPLv3 and LICENSE-Apache2.0 - simplify the per-file header to reference LICENSE - tox: ignore H102 (Apache License Header check) Add license header to files that ship. Reformat headers, make sure everything has vi: at end of file. Non-shipping files do not need the copyright header, but at the moment tests/ have it.
* run flake8 instead of pyflakes in tox. expect tests/ to pass flake8.Scott Moser2016-05-121-24/+24
|
* Update pep8 runner and fix pep8 issuesRyan Harper2016-03-031-13/+10
|
* Trunk merged and ported.Barry Warsaw2015-01-261-40/+26
|\
| * Drop reliance on dmidecode executable.Ben Howard2015-01-141-40/+26
| |
* | More octal literal fixes.Barry Warsaw2015-01-211-2/+2
| |
* | Fix file modes to be Python 2/3 compatible.Barry Warsaw2015-01-211-1/+1
|/
* test_altcloud: fix altcloud tests when running on armScott Moser2014-02-271-0/+24
|\ | | | | | | | | | | Similar test-hack as the SmartOS one. Here we just pretend that we're running on x86_64 so as to avoid re-writing the tests to expect otherwise on arm.
| * AltCloud: fix test failures related to new arm-specific behaviorOleg Strikov2014-02-271-0/+25
|/
* fix pep8 complaints.Scott Moser2012-08-221-45/+54
| | | | make pep8 now is silent on precise's pep8 ( 0.6.1-2ubuntu2).
* add test to excercise udevadm usage.Joe VLcek2012-08-131-0/+22
|
* Address review feedback for:Joe VLcek2012-08-101-124/+131
| | | | | https://code.launchpad.net/~joev-n/cloud-init/altcloud-changes/+merge/116542/comments/255564 https://code.launchpad.net/~joev-n/cloud-init/altcloud-changes/+merge/116542/comments/255565
* Address review feedback for:Joe VLcek2012-08-081-216/+83
| | | | https://code.launchpad.net/~joev-n/cloud-init/altcloud-changes/+merge/116542
* Add retry logic to DataSourceAltCloudJoe VLcek2012-07-201-22/+64
|
* Added RHEVm and vSphere support as source AltCloudJoe VLcek2012-07-171-0/+498