Commit Graph

515 Commits

Author SHA1 Message Date
Takashi Kajinami f5c4096092 Bump hacking (again)
The previous attempt did not update the version in pre commit config
so the old version is still used by pep8 target.

Change-Id: I62048df659f4bc35f714de824aadfe9306e81c71
2024-01-26 01:18:49 +09:00
Philippe SERAPHIN 83bbc0df43 Add choices parameter for IntOpt class
Change-Id: Ic9e9a2fd7d1229616387a6a9d61f8a5b8f32829f
2023-12-20 10:17:52 +01:00
Takashi Kajinami 2930db4892 Remove compatibility with Python < 3.8
... because this library now supports only Python 3.8 or newer
versions.

Change-Id: Ibb48af4c501946b62a244994ecea5bfcd998810c
2023-10-07 12:01:26 +09:00
Hervé Beraud 3dff974eea Bump bandit and make oslo.config compatible with latest rules
Apply a timeout to requests calls to avoid uncontrolled
resource consumption (CWE400) [1].

[1] https://cwe.mitre.org/data/definitions/400.html

Change-Id: I9e3c1e5f98e2ecfb5564d8dbd608d19d4a66cfce
2023-05-17 11:19:22 +02:00
Hervé Beraud 84478d83f8 Make tests backward compat with cliff' older versions
Change the assertion kind to support all versions of cliff.
The previous related fix 78098e6b18
was only compatible with cliff>3.4.0.

Change-Id: I7ac27919b0d58929b4c975ebb308f33124a6060f
2022-09-29 09:59:31 +02:00
Hervé Beraud 7b838f5c31 Disable a config test if ran under the root user
The `test_conf_file_permission_denied` is designed to test
if a config file can't be read due to missing file permissions.

However if we run unit tests with the root user we will beneficiat
from the root privileges and so this test will fails. This can
be reproduced by running `tox` with `sudo`.

These changes propose to skip this test if root privileges are
detected.

Closes-bug: #1983358

Change-Id: Idd124082265032c30f83242b612d002d7093aa61
2022-08-03 16:47:25 +02:00
Hervé Beraud 78098e6b18 fix CLI mismatch in unit tests
Since cliff > 3.4.0 we can see mismatch errors with unit tests, this
patch fix this error.

Also this patch fix some issues with deprecation messages.

All these issues needs to be fixed together to unlock our gates.

Closes-bug: #1908934
Change-Id: I8396b4f3ba74a9ea023bff2e3027710f16a74af4
2022-08-03 16:47:25 +02:00
Cyril Roelandt 88c831cfad Fix tests for Python3.
Change-Id: Ifbf6f52a312929ac07154db8eeee976b0ab0d46a
2021-08-19 00:42:44 +00:00
Zuul 1a7bd66a71 Merge "config-generator yaml format doesn't work with i18n fields" 2021-06-02 17:36:45 +00:00
Zuul 2e7b39e443 Merge "Ussuri+ is python3 only" 2021-06-01 12:24:52 +00:00
David Vallee Delisle e5fc313ecf config-generator yaml format doesn't work with i18n fields
This is because there's no yaml representer for i18n Messages object.
This patch aims to add this representer and allow the generation of
configurations using oslo.i18n strings.

One example of this is cinder.

Closes-bug: #1928582
Change-Id: I70ab87c9bed093cad883b6301b8a09753fc470d9
2021-05-16 11:49:38 +00:00
Zuul d8cf65ddc9 Merge "Add the version parameter." 2021-05-05 12:06:22 +00:00
dengzhaosen b9468aaf4f Ussuri+ is python3 only
update python to python3

Change-Id: I83c8c9897678f8a0628987a071adda68062ac515
2021-05-05 10:11:01 +08:00
Zuul c879c836d9 Merge "Remove references to 'sys.version_info'" 2021-05-04 15:08:56 +00:00
Daniel Bengtsson 1f16007ce8 Add the version parameter.
Call the parent with the version parameter.

Change-Id: I20016e299077a7b678ecabceacb21cc0c7d306c8
2021-05-04 15:00:11 +02:00
Zuul 6e91dbb2d5 Merge "Adding the missing HostDomain config option" 2021-04-26 15:51:48 +00:00
dengzhaosen 934fba53e4 Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: I668c1bddba29a5e823734b1cad5116ba2fdb5f75
2021-04-25 16:06:39 +08:00
Hervé Beraud bb5e4cbeb9 Adding the missing HostDomain config option
The ``HostDomain`` config type have been added few months ago [1]
however the config option have been forgotten and this new type
isn't importable.

When we try to import this type without defining a new related cfg
option we get the following issue:

```
AttributeError: module 'oslo_config.cfg' has no attribute 'HostDomain'
```

These changes allow us to import this new type and allow us to use
it in our configs:

```
>>> from oslo_config import cfg
>>> foo = cfg.HostDomain('foo')
>>> foo.type.__call__("1")
...
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/oslo.config/oslo_config/types.py", line 893, in __call__
     raise ValueError(
ValueError: 1 is not a valid host address
>>> foo.type.__call__("host_name")
'host_name'
```

Also properly initialize HostDomain because The HostDomain class wasn't
calling super in it's __init__() method, which resulted in the type_name not
being set properly for instances of that class.

[1] 6480356928

Change-Id: Ie947803f61ba0ef080018e0447de894a400d7975
Closes-Bug: 1924283
2021-04-22 12:31:48 +02:00
Zuul 758775c07b Merge "tests: Add test for config file priority order" 2021-04-21 17:52:59 +00:00
xuanyandong 604bde417b remove unicode from code
Change-Id: I062829a44a62014e88f285a82b6800e37f00ff28
2021-04-16 11:17:19 +08:00
Stephen Finucane 068c13547e tests: Add test for config file priority order
This was documented in the docstring but we had nothing to assert it in
tests. Correct that gap.

Change-Id: I4002e7fe18c43eb5f9ba2eae16022d7da87f790d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-04-14 13:16:39 +01:00
Moisés Guimarães de Medeiros 05b6a33336 inherit from object is not required for py3
Change-Id: I3f3b1dca78e2e9b2515231ccc6600b64f31039fb
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2021-01-12 17:09:25 +00:00
David Vallee Delisle f2ca66fdc9 Adding --check-defaults to validator
When troubleshooting, it's often interesting to see the deltas between
the default or sample configs and the running configuration. The
oslo_config.validator is a great tool to integrate this feature across
all projects. It can also be easily captured by data collection tools
like sosreports with the current deployment packages.

Change-Id: I172d82f19a81282093b0d5f7ae4c1817801cd887
Signed-off-by: David Vallee Delisle <dvd@redhat.com>
2020-11-24 13:55:33 -05:00
Zuul 8f667f8e3d Merge "Add a new type HostDomain." 2020-10-22 18:16:44 +00:00
Hervé Beraud 6480356928 Add a new type HostDomain.
HostDomain is like HostAddress with the support of
_ character - RFC1033

openstack services are failing to start when a hostname with underscore
_ is provided.

Example:

```
overcloud-novacompute_edge1-0.internalapi.localdomain
overcloud-novacompute_edge1-0.internalapi
```

Nova use `HostAddressOpt` to define `live_migration_inbound_addr`,
and if a hostname with underscore is present in the config file
then the service fail to start.

Example:

```
/etc/nova/nova.conf
live_migration_inbound_addr =
overcloud-novacompute_edge1-0.internalapi.localdomain
```

FQDN is a domain name that specifies its exact
location in the tree hierarchy of the Domain Name System (DNS).

Underscore are allowed by RFC1033 [1][2][3]. Indeed, while a hostname may not
contain other characters, such as the underscore character (_), other
DNS names may contain the underscore.[1][2].
Systems such as DomainKeys and service records use the underscore.

These changes allow us to use underscore with the `HostDomain`.

[1] https://www.ietf.org/rfc/rfc1912.txt
[2] https://www.ietf.org/rfc/rfc1033.txt
[3] http://domainkeys.sourceforge.net/underscore.html

Co-authored-by: Daniel Bengtsson <dbengt@redhat.com>
Change-Id: I0a0670207f96a987996d329e5efa9a5eb2ce000c
Closes-Bug: #1892044
2020-10-22 12:30:39 +02:00
Zuul 445f1c42d9 Merge "Convert rst to plaintext for oslo.config output" 2020-10-12 17:38:22 +00:00
Zuul dce2afd789 Merge "sphinxext: Add 'merge_domaindata'" 2020-09-22 14:51:47 +00:00
Hervé Beraud 5e1011a630 Adding pre-commit
Introduced changes:
- pre-commit config and rules
- Add pre-commit to pep8 gate, Flake8 is covered in the pre-commit hooks.
- Applying fixes for pre-commit compliance in all code.

Also commit hash will be used instead of version tags in pre-commit to
prevend arbitrary code from running in developer's machines.

pre-commit will be used to:
- trailing whitespace;
- Replaces or checks mixed line ending (mixed-line-ending);
- Forbid files which have a UTF-8 byte-order marker (check-byte-order-marker);
- Checks that non-binary executables have a proper
  shebang (check-executables-have-shebangs);
- Check for files that contain merge conflict strings (check-merge-conflict);
- Check for debugger imports and py37+ breakpoint()
  calls in python source (debug-statements);
- Attempts to load all yaml files to verify syntax (check-yaml);
- Run flake8 checks (flake8) (local)

For further details about tests please refer to:
https://github.com/pre-commit/pre-commit-hooks

Change-Id: I65a40bbff17d92b959764846801d5e0ddd3b97ce
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-09-22 12:25:01 +02:00
Stephen Finucane 01f63b875e sphinxext: Add 'merge_domaindata'
This is necessary to enable parallel builds. As noted in the Sphinx docs
[1], this method has the following function:

  Merge in data regarding docnames from a different domaindata inventory
  (coming from a subprocess in parallel builds).

Given how simple the datatypes we're storing are, this is pretty easy to
implement.

[1] https://www.sphinx-doc.org/en/master/extdev/domainapi.html#sphinx.domains.Domain.merge_domaindata

Change-Id: I46c7903b159f99c68896a4c3c4d20daef848f9c2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-Bug: #1895162
2020-09-10 16:36:46 +01:00
Stephen Finucane 78698b5c99 Convert rst to plaintext for oslo.config output
This lets us use powerful rST roles and directives in our help text
without these being emitted to the configuration file, where they don't
read quite as well. It also fixes our formatting somewhat, which is
nice.

Note that we're doing something funky where we disable line wrapping. We
can't totally disable this due to how rst2txt works, so instead we set
the line length to an arbitrarily long line length, which is taken from
RFC5322 (Internet Message Format) for want of something better. I
personally question whether anyone is configuring this, but that's a
fight for another day.

Also note that this might caught issues for people who are using invalid
rST in their docstrings or use roles/directives in their config options
that aren't part of the standard Sphinx set or oslo.config set. They
will already be seeing the former issues if they are using the
'sphinxext' extension though, and the latter sounds like it would be
fairly rare.

Change-Id: I6c7208f0facfb4f334d7440cb6a9562901543dd3
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-07-23 11:47:05 +02:00
yatinkarel a2652b3584 Fix unit tests to work with stevedore > 2.0.1
stevedore has switched to importlib_metadata[1] and
this breaked unit test as the test relied on internal
implementation of it.

Instead we should switch to mock NamedExtensionManager
that's what called by oslo_config.

[1] https://review.opendev.org/#/c/739306/

Closes-Bug: #1888208
Change-Id: Ic4b990a387d875a351c9f8e7eaaef726734ff305
2020-07-23 11:06:29 +05:30
Doug Hellmann 392922aa33 drop use of pkg_resources
Importing pkg_resources scans all of the installed modules for data
that won't be used. Switch to using importlib.metdata, which more
efficiently loads the metadata for a package.

Change-Id: Idd2a0d0026fef9296172c9995b428ea43a746483
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2020-07-05 19:37:01 -04:00
Zuul fcc0e08132 Merge "generator: Handle 'cfg.Opt'-type options" 2020-06-08 17:20:36 +00:00
Stephen Finucane 8737919f3d generator: Handle 'cfg.Opt'-type options
These are used when declaring an option with a custom type. There's no
reason they shouldn't be handled and indeed they are albeit with an ugly
warning. Resolve this by making this handling explicit.

Change-Id: Ib7a6f26496cf19777b020c12998e953e9aae4601
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-bug: #1880852
2020-05-27 11:00:14 +01:00
Zuul ad1eb1be0a Merge "Raise hacking minimum to 3.0.1" 2020-05-25 13:20:17 +00:00
Sean McGinnis 8242416801
Raise hacking minimum to 3.0.1
This raises hacking to a newer version, fixes a few issues the newer
version uncovered, and removes the cap for flake8 to allow that version
to be controlled by the hacking constraints.

Change-Id: Ie550119322bca3c217e4a74eca789f156cfa7e2c
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-05-19 15:15:53 -05:00
Stephen Finucane 2c11e9dd82 Resolve UnboundLocalError
As discussed in bug 1841038, configuring a StrOpt with a regex parameter
and providing an invalid environment variable will result in an ugly
stacktrace due to an undefined 'alt_loc' variable. Resolve this by
creating said variable.

Change-Id: Id0fb6efdc435a2bd88d5dfea2b4720df453fbfec
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-Bug: #1841038
2020-05-01 16:45:04 +01:00
Zuul e5142bbf03 Merge "Use unittest.mock instead of third party mock" 2020-04-17 19:02:45 +00:00
Sean McGinnis 76075a6d99 Mark sphinx extensions thread safe
This adds the return of some metadata to our sphinx extension setup to
indicate they are thread safe. This is needed to allow consuming
projects to do multithreaded docs builds. In some cases, this can save a
noticeable amount of time in job execution.

Change-Id: I53a580b336a49372e27b69d009da555c03f03e35
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-14 11:04:14 +00:00
Sean McGinnis 1b248b4f98
Remove redundant class docstring info
This now fails with the newest Sphinx due to multiple entries between
the added reference to the class's docstrings, and the docstrings
themselves. This fixes the warnings by just removing the duplication.

Change-Id: I284a49a5df9506f936ebf1846688339c94d9a6b8
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-13 10:21:20 -05:00
Sean McGinnis 66b3da9689
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: I2f8067eeb2aec62f098bfbb3770a67f1876ce7a2
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-03-31 14:40:09 -05:00
Stephen Finucane 81589565ba Switch to hacking 2.x
This bumps the version of flake8 and pycodestyle to something much
newer, which resolves a long-standing warning about nested sets and
allows us to use new fangled features like f-strings if we so choose.

Note that this requires some minor modifications to keep the 'pep8' task
passing.

Change-Id: I3af8eb490345a6152372730ca3e0a6702bf482ea
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-02-12 09:56:58 +00:00
Stephen Finucane 20a7cee3e3 Remove six
We don't need this in a Python 3-only world. We can't remove mock yet
since there's an issue with the stdlib variant in python3.6, but that is
called out.

Change-Id: I9657b1fd4409be90d645175a6e177d7e1d2ebac2
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-02-12 09:56:55 +00:00
Zuul edcb46deae Merge "Support hyphens in positional argument names" 2019-12-20 11:36:48 +00:00
Zuul 543daf4f7a Merge "Assume positional arguments are required" 2019-12-20 10:32:44 +00:00
Zuul 062b98a610 Merge "Refactor unit tests for CLI usage" 2019-12-20 10:29:50 +00:00
Zuul 6011b9c8a3 Merge "Remove ConfigFilter" 2019-12-20 10:23:03 +00:00
Ben Nemec c7ac122554 Remove ConfigFilter
Per the deprecation in change I04baae695a7ba0bb93c91ea642c4e33c04bf87bd
this can be removed.

Change-Id: I31156e2f47b0d68ea32726cde7f0c2b133022c9f
2019-12-17 17:00:56 +00:00
Stephen Finucane e3e2ba55ee Ensure option groups don't change during logging
oslo.config allows us to configure groups and options dynamically. This
can cause a race with our logging as we attempt to iterate through
option groups that are changing under our feet. This wouldn't be a huge
issue, since these are just logs are we can always log again, if needed,
but we store groups in a dictionary and Python doesn't like us changing
the size of a dict it's iterating through:

  RuntimeError: dictionary changed size during iteration

Given that we're only reading through this option group and don't need
to worry about a group _disappearing_, the solution is pretty simple:
create a copy of our option group names ahead of time so we don't need
to worry about new ones coming and messing things up.

No tests are included since this is a race and the only way I see to
reproduce this would involve lots of ugly threading.

Change-Id: Id3b28465d645a24f0fcebff2dd68a9bd30e21594
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Closes-Bug: #1856312
2019-12-13 16:18:33 +00:00
huang.xiangdong 561db7ac32 fix: fix float opt min and max value format errror
"%d" will truncate float and generates wrong format message,
use "format" to handle floats correctly.

Closes-Bug: 1850879
Change-Id: If0dd3933695ac84f0e9cacefd28a9d7a60dd88d7
2019-11-04 09:50:42 +08:00