Commit Graph

62 Commits

Author SHA1 Message Date
Zuul 14dfe905bd Merge "Update the shebang to python3" 2024-03-08 15:01:24 +00:00
Takashi Kajinami cfa427c2c6 Drop direct execution of apply_config.py
Now we generate the console script using setuptools, and we don't
expect users may directly execute the *.py file.

Change-Id: I6ddeb659c641cf3af33518bb7bf4c24b101f87be
2024-01-29 23:52:20 +09:00
Takashi Kajinami 4df56c6586 Bump hacking
hacking 4.0.x is too old.

Change-Id: Ic4d2e9731ddcaae4a63283805fd9425573a80050
2024-01-17 01:37:23 +09:00
Joel Capitao f06ac135d3 Update the shebang to python3
It's needed downstream when packaging. In RDO and Fedora,
we are hitting the issue "ERROR: ambiguous python shebang" during
the build.

Change-Id: I19d99f96d9687c27e04e8cc2ecbf61b42a4dcdf3
2023-07-26 17:47:52 +02:00
Alex Schultz 474068e487 Drop six
python2 is no longer supported so let's drop six as well.

Change-Id: I2fef470423765a9c432d33e56edf93d08254b5c9
2021-09-24 10:15:42 -06:00
Alex Schultz 44cef7984d Clean up CI
Bump hacking to resolve dependency problems and drop the lower
constraints job. Includes pep8 fixes.

Change-Id: If5473a753e774767abf60b9fcf9f57a9aa31b580
2021-01-14 07:47:23 -07:00
Hervé Beraud 71a69b899e Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I919ea4dcf0e61d16a10c68cecb341e108d76c4aa
2020-06-02 20:35:10 +02:00
Sean McGinnis 852795d245
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Ia5a6219d6c4cc2cb10ddaeee22b957ca85064ab9
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-03 17:14:01 -05:00
Zane Bitter 75d527ab8f Don't render None as "null"
In a config file you never want the string "null" in place of a null
value. Just render an empty string instead.

Change-Id: Ibe145c4929d4944cd8d51c07a64aee6fd5f831f2
Closes-Bug: #1830967
Story: 2005797
2019-05-29 15:59:51 -04:00
Matthew Flusche f462d6fec8 fixes how os-apply-config handles invalid json
If invalid json is included as the last element in
os_config_files.json it can silently break the file
customizations managed by os-apply-config.

More details:
https://bugzilla.redhat.com/show_bug.cgi?id=1493303

Closes-Bug: #1722321

Change-Id: I0ad89fcde101ba6f3723ab2fa5a348c40452bae5
2017-10-09 20:18:09 +00:00
gecong1973 a68d6df930 Add __ne__ built-in function
In Python 3 __ne__ by default delegates to __eq__ and inverts the
result, but in Python 2 they urge you to define __ne__ when you
define __eq__ for it to work properly [1].There are no implied
relationships among the comparison operators. The truth of x==y
does not imply that x!=y is false. Accordingly, when defining __eq__(),
one should also define __ne__() so that the operators will behave as
expected.
[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: I3df4396495e3404e2c644c769693f89b7c01537a
2016-10-17 09:18:02 +08:00
Jenkins 752646a4ba Merge "Log warning when --boolean-key and --key are used" 2015-03-03 08:37:44 +00:00
Steve Baker 94f9819c67 Ignore top-level merge items which evaluate False
There has been recent tripleo regressions caused by heat
setting empty config as '' rather than {} which cause os-apply-config
to error on merge_configs.

This change ignores any top-level config which evaluates to False,
ignoring possible empty data including '', {}, None, []

An os-apply-config release with this fix would likely allow the current
heat pin to be removed Id134664a5df7232da0fb5d9ed62b82e12b3d54a8

Change-Id: Ia5bd99d1550f43760c064b769be3be46b3417331
Closes-Bug: #1426116
Related-Bug: #1425238
2015-02-27 09:45:39 +13:00
Jenkins 9d70d50ff3 Merge "Print JSON-compatible booleans" 2015-02-19 22:41:56 +00:00
Clint Byrum 59586b393f Log warning when --boolean-key and --key are used
These are not compatible, so log a warning when they're used together.

Change-Id: I8e72f90f9e789c413cba2e95543313c4a7bf95a3
2015-02-11 17:13:00 -08:00
Alexis Lee 1c17f543be Print JSON-compatible booleans
Given os-apply-config takes a JSON file as input and prints JSON-style
strings not Python ones, Booleans present an anomaly.

These are printed using `str(config)`, resulting in "True" and "False"
rather than the lowercase and JSON-compatible "true" and "false". This
patch corrects this.

There is some risk of breaking users but it should be trivial for them
to fix their scripts. As I write this, o-a-c is at 0.1.28, so we're
allowed breaking changes and I believe this is the last change required
to make all output JSON-compatible.

Change-Id: Ib41d3b01656fc7afc4911fd78ba7c1116aa9b1c9
2015-01-22 09:48:32 +00:00
Clint Byrum 92a9d5d011 Add --boolean-key for evaluating boolean keys
In the past if we wanted to have a boolean key we had to evaluate the
python string representation of the key which is not necessarily very
easy in shell. This allows us to replace this code:

    if [ "$(os-apply-config --key x.foo --type raw)" = "True" ] ; then
      ...
    fi

With a much more shell friendly version:

    if os-apply-config --boolean-key x.foo; then
      ...
    fi

Change-Id: Ie88663a0028596dbd2a9c25dfc4ce54a46a63e66
2015-01-14 12:53:56 -08:00
Dan Prince fcb3d0f96f Output useful JSON data
If you use os-apply-config to slice out a JSON blob on the command
line you'll get back a string formatted dump of a python
dictionary (or list). Ideally we would print out proper JSON text
so that other tooling (jq, etc) can post process things in a
useful manner.

This patch updates apply_config so that if an output key is
detected to be a dict or a list it is printed to stdout
in a JSON format.

Change-Id: Ibc8b21cd6922b8664ca71e9e6009c8573ea9d107
2014-12-16 16:54:03 +00:00
Jenkins 29db0f43e8 Merge "Treat null values in JSON as being absent rather than 'None'" 2014-10-30 17:33:35 +00:00
Jenkins 312d741eaf Merge "Set owner+group from control file" 2014-10-24 09:34:30 +00:00
Jenkins 9d11d4d0a5 Merge "Allow extraction of list items" 2014-10-24 09:01:43 +00:00
Alexis Lee b541159d27 Allow extraction of list items
OAC can be used to get a key from metadata by supplying EG '--key A'.
You can also extract an item from a dict, EG '--key A.B'.
However, if A is a list, there's no way to get an item out of the list.

Extend the expression language (if that's not too grand a term) to
support this. EG '--key A.0' gets the first item out of the list A.
'--key A.1.B' gets B out of the second item of list A (which must be a
dict).

Change-Id: I406cbd2d974544ed5948e137359629184d8ee156
2014-10-21 11:31:35 +01:00
Alexis Lee bfef75d33f Set owner+group from control file
Add keys 'uid' and 'gid' to control file. The values may be UID/GIDs or
names. In either case, the value is checked against the passwd/group
database to ensure it exists.

Change-Id: I1730a126cf024755635043b1a0f70006ab22c046
2014-10-21 09:59:19 +00:00
Alexis Lee ce14b9a4c3 Extract OacFile class to separate file
Change-Id: I97448fe2b503314398db5928ec6a3bbfffe6b2be
2014-10-21 09:59:12 +00:00
Jonathan Brownell e78b8d6964 Treat null values in JSON as being absent rather than 'None'
The current method of serialization for keys containing null
values in JSON input files is that they become a part of the
metadata tree, with a value expressed as the string 'None' in
output (when invoked with --key) or when inserted into templates.

The use of 'None' creates awkward ambiguity (no way for downstream
code logic to tell if the request JSON key originally contained
the string "None" or if it was actually null), and also throws
conversion errors when requested in any type other than 'raw'.

This patch proposes that keys with null values be handled as
though they were absent from the metadata completely. (If
such a key is requested in command-line invokations using "--key"
and "--key-default", the provided default will be printed.)

Change-Id: I9288dffb13d781e0c4dd9e5be0b483c090ec2d7c
2014-10-17 14:31:50 -07:00
Alexis Lee 638d62518e Add mode to metadata header
-- os-apply-config --
  mode: 0644
  -- end --

Mode must be an integer in [0, 0777]. Preferably this will be written as
three octal digits. The default is to use the mode of the target file if
it already exists, otherwise 0644.

Advances blueprint oac-header

Change-Id: I3abfee89d418474b3766a97cfc178c02252e2d02
2014-09-15 13:02:06 +01:00
Jenkins 0d39cd5e11 Merge "Support control files" 2014-09-15 06:45:39 +00:00
Alexis Lee 6158268631 Support control files
Allow templates to provide a control file (EG foo => foo.oac). The
control file must be a single YAML mapping. Directory control files are
not supported yet.

Provide a single valid key, allow_empty, by way of example. If
allow_empty is false, either the target file will not be created or if
there's already a file in place, it will be deleted.

Add requirement on 'six' library for Python 3.3 compatibility.

Advances blueprint oac-header
See spec I8fe7126d7261c1f106d7413bd31aa379e9ae5c3e

Change-Id: Ic6952688e4f8273885192bcd5eda8cb657f5a940
2014-09-10 15:25:55 +01:00
Clark Boylan 4ae6efd726 Support py34 tox target.
OpenStack is making a push to move projects that had been tested on py33
to py34 because py34 will have a much larger install base (and is
consequently easier to test).

The python 3.4 json lib returns new and different error strings when
json decoding fails. Remove assertions from test_load_list_from_json
hat check these error strings, instead simply rely on assertRaises to
assert that the appropriate error is thrown.

Change-Id: Ia6603783014b0114de0f29664834d21196744774
2014-09-09 11:03:59 -07:00
Steve Kowalik 117e7c0f77 Support for Python 3
Fix up various things to support Python 3. This also included removing
the pretty lines in README.rst, because tox with Python 3 just could
not cope.

Change-Id: I8e8a40ebc54ab781ccf0961a88fd1f8526aaeba0
2014-08-21 17:05:53 +10:00
Christian Berendt 3685add131 Bump hacking to 0.9.x series
Change-Id: Ic55dc90c2ce147ada45946ca2dd246c310d8e7f6
2014-07-21 09:43:19 +02:00
Coleman Corrigan e3aa1631c1 Fix for string key traversal bug #1321827
Gracefully handle the traversal of strings in a key search path.

Closes-Bug: #1321827

Change-Id: I1fab13905fc1f6ed2817081d58fcc5379f2a8515
2014-05-27 11:24:42 +01:00
Ben Nemec 31b7e64136 Use FHS-compliant default template location
/opt/stack is a very OpenStack-specific location to use as a
default for a project that is intended to be usable elsewhere.
This changes the default template directory to reside in
/usr/libexec and deprecates the /opt/stack location, but still
allows the use of /opt/stack so existing users won't be adversely
affected.

Change-Id: I3b7d356985a2c213303d52e36aec34e350f9b553
2014-04-24 17:11:07 +00:00
Shane Wang 33eb624ca1 Fix misspellings in os-apply-config
Fix misspellings detected by:
* pip install misspellings
* git ls-files | grep -v locale | misspellings -f -

Change-Id: I1c54a7bfc353e54e229263ae0e0bd9393917f2db
Closes-Bug: #1257295
2014-02-07 15:44:25 +08:00
Jenkins bd5ab107e6 Merge "Change default os_config_files location" 2014-01-23 22:04:20 +00:00
Clint Byrum 7f9444a48e Change default os_config_files location
Os-collect-config will change its' default in this change:

I78b3851b35addfc16913e3cd53c9d0e7eb3d191a

We will need to also follow suit. We print a deprecation warning on
fall back to the old path so that users do not depend on the old path
working forever.

Change-Id: I4fe6e66716b83b202f4ddd5b6870eda448b4c6c8
2014-01-22 09:32:25 -08:00
Derek Higgins 9752e5b261 Add new username type
Parsing usernames would be a fairly common thing todo from heat
metadata, this type allows what would be expected to cover most sane
usernames.

Change-Id: I3a5577d2c5bef1ce54629a0b99e2dc085d274f02
2014-01-20 22:23:05 +00:00
Clint Byrum 7575d45ed2 Fix netaddress test for bad values
This test was intended to make sure netaddress does not pass through a
SQL injection, but is only testing the default value type.

Change-Id: I817b5d02fa08b6b021a76de9ef43d2a69bbb7b3f
2013-12-28 14:22:30 -08:00
Clint Byrum 3e9c796f52 Add netdevice value type
While it is just a copy of the netaddress regexp, they may diverge later
and users should be able to continue using the appropriate one.

Change-Id: Ib6d96113f16fc5f4dc4b8918d2409d08e317a47d
Closes-Bug: #1262786
2013-12-21 08:05:28 -08:00
Jenkins 4d1a737943 Merge "Check file existence before loading it and check errors" 2013-12-09 07:23:45 +00:00
JUN JIE NAN a9207fb0da Check file existence before loading it and check errors
To avoid no such file or directory error or value error.

Closes-bug: #1258457

Change-Id: I8973a90b84a039cce4445cd5164f35368897e82e
2013-12-09 09:19:41 +08:00
Jenkins 6e87a75775 Merge "Add program main entry in apply_config.py" 2013-12-06 11:58:08 +00:00
Jenkins b23df8fc45 Merge "Add blank char in fallback-metadata usage" 2013-12-06 10:39:04 +00:00
JUN JIE NAN 09890b3b20 Add blank char in fallback-metadata usage
Or the usage will be displayed as `...OS_CONFIG_FILESis...'. It should
be `...OS_CONFIG_FILES is...'.

Change-Id: I2e5dc1cb565da327efcbba1e7b07ed442ff583fd
2013-12-06 17:40:15 +08:00
JUN JIE NAN fda190a37c Put _ ahead of unused variable subdirs
The variable is never used in loop, without `_' before the variable
name, pydev will mark a warning.

Change-Id: I3d63b0729c4ae9ec00ca97893c2ded65595235d1
2013-12-06 16:51:19 +08:00
JUN JIE NAN 7807b9aba8 Add program main entry in apply_config.py
So make it easier to debug or run apply_config.py directly(no need to
install it).

Change-Id: Id0dad9cb02b81fd22d9868e686867af074aed966
2013-12-06 15:15:52 +08:00
Clint Byrum f2fbb446a9 Log parsing errors from pystache as errors
Currently if an error is encountered in the template syntax one can only
see "could not render moustache template...". The error from pystache is
often quite helpful.

Change-Id: If79c3c07a5171d5ff58993066976f10cd9c2a1c7
2013-12-05 11:23:13 -08:00
Jenkins d3016bb579 Merge "Add new type for swiftdevices" 2013-11-18 23:02:51 +00:00
Derek Higgins 7b6d63ad6f Add new type for swiftdevices
Swift devices consist of a zone, region, host, port and device, if they
are passed into swift hosts via heat metadata we can now verify them as
native types.

Closes-Bug: #1252165

Change-Id: I8681e36a0b02f62e4856e42ef1900ce4888cb305
2013-11-18 16:50:05 +00:00
Tomas Sedovic 086b6b1551 Respect the preset permissions of config files
It's sometimes desirable to specify the permissions or ownership of the
generated config file instead of setting the default 644 root:root.

If the file is already present, os-apply-config will just update the
contents and leave everything else alone.

Closes-Bug: #1246266
Change-Id: Idd41ec276dd04f517760c1dbd97c75e376840b41
2013-11-18 16:43:49 +01:00