summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
AgeCommit message (Collapse)Author
2017-07-17Support comments in content read by load_shell_content.Scott Moser
load_shell_content previously would not allow shell comment characters in the content being parsed. If comments=True is not passed then an exception would previously be raised as the line would not be guaranteed to have an '=' in it.
2017-06-29read_dmi_data: always return None when inside a container.Scott Moser
This fixes stacktrace and warning message that would be printed to the log if running inside a container and read_dmi_data tried to access a key that was not present. In a container, the /sys/class/dmi/id data is not relevant to the but to the host. Additionally an unpriviledged container might see strange behavior: # cd /sys/class/dmi/id/ # id -u 0 # ls -l chassis_serial -r-------- 1 nobody nogroup 4096 Jun 29 16:49 chassis_serial # cat chassis_serial cat: /sys/class/dmi/id/chassis_serial: Permission denied The solution here is to just always return None when running in a container. LP: #1701325
2017-06-15FreeBSD: Make freebsd a variant, fix unittests and tools/build-on-freebsd.Scott Moser
- Simplify the logic of 'variant' in util.system_info much of the data from https://github.com/hpcugent/easybuild/wiki/OS_flavor_name_version - fix get_resource_disk_on_freebsd when running on a system without an Azure resource disk. - fix tools/build-on-freebsd to replace oauth with oauthlib and add bash which is a dependency for tests. - update a fiew places that were checking for freebsd but not using the util.is_FreeBSD()
2017-05-23flake8: move the pinned version of flake8 up to 3.3.0Scott Moser
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
2017-05-16Improve detection of snappy to include os-release and kernel cmdline.Scott Moser
Recent core snap images (edge channel revision 1886) do not contain the previously known files used to detect that a system is ubuntu core. The changes here are to look in 2 additional locations to determine if a system is snappy. LP: #1689944
2017-05-10FreeBSD: improvements and fixes for use on AzureHongjiang Zhang
This patch targets to make FreeBSD 10.3 or 11 work on Azure. The modifications abide by the rule of: * making as less modification as possible * delegate to the distro or datasource where possible. The main modifications are: 1. network configuration improvements, and movement into distro path. 2. Fix setting of password. Password setting through "pw" can only work through pipe. 3. Add 'root:wheel' to syslog_fix_perms field. 4. Support resizing default file system (ufs) 5. copy cloud.cfg for freebsd to /etc/cloud/cloud.cfg rather than /usr/local/etc/cloud/cloud.cfg. 6. Azure specific changes: a. When reading the azure endpoint, search in a different path and read a different option name (option-245 vs. unknown-245). so, the lease file path should be generated according to platform. b. adjust the handling of ephemeral mounts for ufs filesystem and for finding the ephemeral device. c. fix mounting of cdrom LP: #1636345
2017-04-12util: teach write_file about copy_mode optionLars Kellogg-Stedman
On centos/fedora/rhel/derivatives, /etc/ssh/sshd_config has mode 0600, but cloud-init unilaterally sets file modes to 0644 when no explicit mode is passed to util.write_file. On ubuntu/debian, this file has mode 0644. With this patch, write_file learns about the copy_mode option, which will cause it to use the mode of the existing file by default, falling back to the explicit mode parameter if the file does not exist. LP: #1644064 Resolves: rhbz#1295984
2016-12-22LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm
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.
2016-12-02fix problems found in python2.6 test.Joshua Harlow
These are just simple syntax fixes to work correctly on python2.6. Found when testing in a centos 6 container.
2016-11-22Improve formatting for ProcessExecutionErrorWesley Wiedenmeier
This replaces long single lines in a log or console output with multiple lines that are much easier to read. It indents the stdout and stderr so logs are more easily read also.
2016-11-01dmidecode: Allow dmidecode to be used on aarch64Robert Schweikert
aarch64 systems have functional dmidecode, so allow that to be used. - aarch64 has support for dmidecode as well
2016-10-19Fix python2.6 things found running in centos 6.Scott Moser
This gets the tests running in centos 6. * ProcessExecutionError: remove setting of .message Nothing in cloud-init seems to use .message anywhere, so it does not seem necessary. The reason to change it is that on 2.6 it spits out: cloudinit/util.py:286: DeprecationWarning: BaseException.message * tox.ini: add a centos6 environment the tox versions listed here replicate a centos6 install with packages from EPEL. You will still need a python2.6 to run this env so we do not enable it by default.
2016-09-21Decode unicode types in decode_binaryRobert Schweikert
The test in decode_binary for six.text_type was incorrect as that includes unicode type in Python 2 which should actually be decoded. When the type is string_types we now properly check only for basestring and str in Python 2 and Python 3 respectively and return the given blob without making an attempt to decode.
2016-09-21subp: add 'update_env' argumentScott Moser
In order for a caller to use 'env' argument of subp, they will realistically do: env = os.environ.copy() env['FOO'] = 'BZR' subp(cmd, env=env) This shortens that to be: subp(cmd, update_env={'FOO': 'BZR'}) Add tests, and update growpart tests to use mock when playing with os.environ.
2016-08-18Apt: add new apt configuration formatChristian Ehrhardt
This adds an improved apt configuration format that is fully backwards compatible with previous behavior. This is mostly copied from curtin's implementation. It does: * clean up and centralizes many of the top level 'apt_*' values that previously existed into a single top level 'apt'key. * support a 'source' in apt/sources/entry that has only a key * documents new features and adds tests. See the added doc/examples/cloud-config-apt.txt for more information.
2016-08-12DigitalOcean: use the v1.json endpointBen Howard
Per [1], DigitalOcean provides the metadata in multiple formats. The JSON document is the preferred endpoint. Changes: - Switch to the v1.json meta-data endpoint - Identify droplet identity from SMBIOS - Only poll for metadata when the instance is confirmed to be a droplet - Removal of hard-coded mirrors Additionally, centralize the gates on running 'dmidecode' on arm arches, and update tests to address. [1] https://developers.digitalocean.com/documentation/metadata/
2016-03-14change return value for dmi data of all \xff to be ""Scott Moser
Previously we returned a string of "." the same length as the dmi field. That seems confusing to the user as "." would seem like a valid response when in fact this value should not be considered valid. So now, in this case, return empty string.
2016-03-14change return value for dmi data of all \xff to be ""Scott Moser
Previously we returned a string of "." the same length as the dmi field. That seems confusing to the user as "." would seem like a valid response when in fact this value should not be considered valid. So now, in this case, return empty string.
2016-03-10dmi data: fix failure of reading dmi data for unset dmi valuesScott Moser
it is not uncommon to find dmi data in /sys full of 'ff'. utf-8 decoding of those would fail, causing warning and stacktrace. Return '.' instead of \xff. This is what dmidecode would return. $ dmidecode --string system-product-name
2016-03-10dmi data: fix failure of reading dmi data for unset dmi valuesScott Moser
it is not uncommon to find dmi data in /sys full of 'ff'. utf-8 decoding of those would fail, causing warning and stacktrace. Return '.' instead of \xff. This maps to what dmidecode would return $ dmidecode --string system-product-name .................................
2015-05-14read_seeded: fix reed_seeded after regressionScott Moser
read_seeded was assuming a Response object back from load_tfile_or_url but load_tfile_or_url was returning string. since the only other user of this was a test, move load_tfile_or_url to a test, and just do the right thing in read_seeded. LP: #1455233
2015-03-04Add util.message_from_string to wrap email.message_from_string.Daniel Watkins
This is to work-around the fact that email.message_from_string uses cStringIO in Python 2.6, which can't handle Unicode.
2015-03-04Convert dmidecode values to sysfs names before looking for them.Daniel Watkins
dmidecode and /sys/class/dmi/id/* use different names for the same information. This modified the logic in util.read_dmi_data to map from dmidecode names to sysfs names before looking in sysfs.
2015-02-13tests/unittests/test_util.py: pep8Scott Moser
2015-02-11pep8Scott Moser
2015-02-11Add unittests for util.multi_log.Daniel Watkins
2015-02-11Fix import ordering in test_util.py.Daniel Watkins
2015-01-26Repair the Python 2.6 tests.Barry Warsaw
2015-01-26Trunk merged and ported.Barry Warsaw
2015-01-26Down to it.Barry Warsaw
2015-01-26More test repairs.Barry Warsaw
2015-01-22Conversion from mocker to mock completed.Barry Warsaw
2015-01-22More test ports from mocker to mock.Barry Warsaw
2015-01-22Port test__init__.py to unittest.mock.Barry Warsaw
2015-01-21Use either syspath or dmidecode based on the availability.Ben Howard
2015-01-21Fix file modes to be Python 2/3 compatible.Barry Warsaw
2015-01-14Drop reliance on dmidecode executable.Ben Howard
2014-08-26further remove evidence of pylint.Scott Moser
This just removes comments '# pylint:' things and other code remnents of pylint.
2014-07-24SeLinuxGuard: remove invalid check for sanity around restorecon, fix testScott Moser
previous commit occurred because the selinux test was failing in a schroot where there was no /etc/hosts. Now, fix that test more correctly, and fix some bad assumptions in the SeLinuxGuard.
2014-07-24test: make selinux test skipped if selinux not available.Scott Moser
Also, in debian packaging depend on it (so it wont skip there).
2014-07-23more import statementsDimitri John Ledkov
2013-10-02fix permission changesScott Moser
2013-10-01Reordered several imports in order for test suite to pass.Eric Nordlund
2013-07-24tests: fix pep8 issueScott Moser
Move long lines out of the test_util.py file and into tests/data. no pep8 or pylint errors now.
2013-03-19pylint fixesScott Moser
a.) appease pylint on raring, as it doesn't like subprocess pylint: 0.26.0-1ubuntu1 This is mentioned in comments at http://www.logilab.org/ticket/46273 b.) tests/unittests/test_util.py: the mountinfo lines are longer than 80 chars. Just disable long lines complaints for this file.
2013-03-10util.parse_mount_info(): add unit tests.Blair Zajac
2012-11-08Ensure that at needed stages the local variablesJoshua Harlow
of the init class are reset so that when they are regenerated that they will use the updated data instead of using previous data (since they weren't reset). LP: #1076811
2012-09-28add 'safeyaml' to cloudinitScott Moser
In 0.7.0 we started using yaml.safe_load to load data rather than yaml.load. Some producers (namely, ubuntu MAAS created) have produced cloud-config data in the past that included python unicode types. This creates a specialized safe_loader that is basically safe_load + support for python unicode.
2012-08-22fix pep8 complaints.Scott Moser
make pep8 now is silent on precise's pep8 ( 0.6.1-2ubuntu2).
2012-08-09test_util: add pylint ignore for FakeSelinuxScott Moser
The methods here have to match the real Selinux signiture, so even though we dont use these variables.