Commit Graph

327 Commits

Author SHA1 Message Date
Adam Rozman 72c80f6993 add <range-in> spec DSL operator
Add a new spec DSL operator called `range-in` that allowes users of
the spec_matcher to match values against numeric ranges.
The surrounding brackets determines whether the limit should be
inclusive or not.

examples:
 <range-in> [ 10 20 ]  : 10 <= x <= 20
 <range-in> ( 10 20 ]  : 10 <  x <= 20
 <range-in> [ 10 20 )  : 10 <= x <  20
 <range-in> ( 10 20 )  : 10 <  x <  20

Closes-Bug: #2052619
Change-Id: I444c01219d02ea7572d4b82117b89b8d3eb75e56
Signed-off-by: Adam Rozman <adam.rozman@est.tech>
Co-authored-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
2024-02-19 13:23:13 +02:00
Takashi Kajinami e159cfd424 Bump hacking
hacking 3.0.x is too old.

Change-Id: I665eb5f8aa70863ac5750d2162ddc7a053444b56
2024-01-26 01:17:39 +09:00
Zuul 945f7eddf5 Merge "Remove reference to monotonic on PyPI" 2023-12-19 18:56:04 +00:00
Rodolfo Alonso Hernandez 59f3a0dba2 Python-3.12: do not use datetime.datetime.utcnow()
This is deprecated in the favor of:
  datetime.datetime.now(datetime.timezone.utc)

In order to return a ``datetime.datetime`` object without the TZ
zone defined, the ``tzinfo`` member is deleted. That allows the
addition/substraction from offset-naive ``datetime.datetime`` objects.

Change-Id: Id345167e71bf576ec383b9d700f222343b08b249
2023-12-18 14:47:13 +00:00
Zuul 4c4c4e3c1b Merge "Remove strict from is_same_callback()" 2023-11-16 17:48:42 +00:00
Zuul 505d80e557 Merge "versionutil: Remove trailing alpha/beta/rc suffix" 2023-11-07 20:28:13 +00:00
Takashi Kajinami 0588ba20d9 versionutil: Remove trailing alpha/beta/rc suffix
Sometimes we have to use the latest code instead of the latest release
to test upcoming changes (eg. sqlalchemy). In such case the version
string might contain its development status such as beta, and causes
failure while parsing the version string.

This makes the parse logic ignore the development status suffix to
avoid the failure.

Closes-Bug: #2042886
Change-Id: I27c14ede026c5600173047b1a0892a02a54dbb06
2023-11-08 02:19:55 +09:00
whoami-rajat cecf061e6e Mask chapsecret
Doesn't mask chapsecre
>>> strutils.mask_password("'chapsecre' : 'aaaaa'")
"'chapsecre' : 'aaaaa'"

Masks chapsecret
>>> strutils.mask_password("'chapsecret' : 'aaaaa'")
"'chapsecret' : '***'"

Closes-Bug: #2038466
Change-Id: Iae22a544ff69069b1b82b6ab3a885f3a19869287
2023-10-04 17:46:57 +00:00
Petr Vaněk 77c90bd6bd Replace deprecated assertAlmostEquals method
The assertAlmostEquals method has been deprecated since Python 3.2 and
was removed in Python 3.12 [1], assertAlmostEqual should be used as the
replacement.

[1] https://docs.python.org/3.13/whatsnew/3.12.html#removed

Change-Id: I1c1be8072e8be6aa5a0e876d08817b1255a31275
Signed-off-by: Petr Vaněk <arkamar@atlas.cz>
2023-06-22 12:03:58 +02:00
Zuul 7c2b949ce9 Merge "Add netutils.get_my_ipv6()" 2023-06-09 05:04:33 +00:00
Zuul 15da67c99e Merge "strutils: update string_to_bytes" 2023-06-01 20:52:08 +00:00
Zuul ed662b1654 Merge "Update units for current SI prefixes" 2023-06-01 14:13:37 +00:00
Brian Rosmaita c08e46d5ba strutils: update string_to_bytes
Update the string_to_bytes function to support current IEC/SI prefixes.

Change-Id: I9aa51df4825ffbe87598feb06821e8984cacd461
2023-05-31 13:28:24 -04:00
Brian Haley 650b31f8ea Add netutils.get_my_ipv6()
Analog to netutils.get_my_ipv4(), except will return an
IPv6 address on the local host.

Change-Id: I26812ca6eaaeff70796bafa9f735d15d80f1bc30
2023-05-24 13:58:29 +00:00
Takashi Kajinami 2c8668c4e5 Fix compatibility with Python 3.8
We removed compatibility with Python 3.8 once but it was added back to
tested runtimes for 2023.2. Thus we have to make sure the code works
with Python 3.8, which was broken by [1].

Note that ptyz is added back to requirmenets.txt and is now required
regardless of the python version. This is a short term solution until
we figure out the way to fix the requirement-check job (or we again
remove python 3.8 support).

[1] 7d9fda625f

Change-Id: Ica344021a4e922bcfd20d20cffcce585a5742c8f
2023-05-15 17:29:46 +09:00
Tobias Urdin c4746ef643 Remove reference to monotonic on PyPI
The monotonic module is no longer in use and
this comment is left here incorrectly.

Change-Id: Ie5f18dcd2d36cd637bfd799bde664ec13b51a711
2023-05-05 11:53:21 +00:00
Brian Rosmaita 4cc5693190 Update units for current SI prefixes
Following Resolution 3 of the 27th General Conference on Weights
and Measures (CGPM) in 2022 [0], update oslo units to include
'ronna' and 'quetta' for decimal prefixes.  Although ISO/IEC
80000-13 has not yet been updated for the binary equivalents,
it's safe to assume ISO will follow current practice [1], so
those are added as well.

[0] https://www.bipm.org/en/cgpm-2022/resolution-3
[1] https://iopscience.iop.org/article/10.1088/1681-7575/ac6afd

Change-Id: I6e6b3fe9fe24533553f655a687a3c4e6714fde6f
2023-04-07 11:34:06 -04:00
Hervé Beraud 7d9fda625f Implement zoneinfo support to drop dependency to pytz
Zoneinfo was introduced within python 3.9.

The support of pytz will be removed within RHEL 10 [1].

2023.2 (bobcat) will move our testing runtime to py3.9 and py3.10
so we want to see pytz removed within this series.

tzdata is required at runtime in our gates, because, by default,
zoneinfo uses the system’s time zone data if available; if no system
time zone data is available, the library will fall back to using the
first-party tzdata package available on PyPI. Apparently our gates have no
time zone data available nor tzdata installed by default because we get the
following error without tzdata installed [3]:
`ModuleNotFoundError: No module named 'tzdata'

So I prefer to add tzdata in our requirements to avoid runtime failure
related to time zone and ensure that time zone are always available.

[1] https://issues.redhat.com/browse/RHEL-219
[2] https://review.opendev.org/c/openstack/governance/+/872232
[3] https://zuul.opendev.org/t/openstack/build/0a1576775e894b09bc31269fea00ba03/log/job-output.txt#1445`

Depends-on: https://review.opendev.org/c/openstack/requirements/+/875854
Change-Id: I1f88bdadc68bfa726eac1da1c5824c1ed352ad98
2023-03-23 17:13:44 +01:00
Takashi Kajinami 2319e6d328 Remove strict from is_same_callback()
The strict argument has been deprecated since 4.6.0 because it has no
effect in Python >=3.8 [1].

Because now this library supports only Python >=3.8, the logic for old
python versions can be removed.

[1] https://review.opendev.org/c/openstack/oslo.utils/+/750216

Related-Bug: #1841072
Change-Id: I5873c0df347a4e9a8a1fbfcf9f1212af14f7aef2
2023-03-15 03:31:45 +00:00
Brian Rosmaita d49d594482 [imageutils] Fix __str__ for QemuImgInfo
Code is calling 'appened' on a list; correct this to 'append'.

Closes-bug: #1996426
Change-Id: I8729cf180f92f43519c942e22f3b285377a5612f
2022-11-11 16:18:15 -05:00
Zuul 7df64737c2 Merge "Remove deprecated helpers from oslo_utils.timeutils" 2022-06-13 17:10:27 +00:00
Zuul 3b7c49730a Merge "Remove oslo_utils.fnmatch" 2022-06-13 17:10:25 +00:00
Zuul 6890f1ef29 Merge "strutils: Defer import of pyparsing" 2022-05-31 14:54:43 +00:00
Stephen Finucane 76146aaca8 Remove deprecated helpers from oslo_utils.timeutils
Remove the 'isotime', 'strtime' and 'iso8601_from_timestamp' helpers
from 'oslo_utils.timeutils'. These are all available in the stdlib now.

Change-Id: If4afb9242b14c48cc70e409463865b7b644a919f
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-05-26 17:52:11 +01:00
Stephen Finucane 5832a7485e Remove oslo_utils.fnmatch
This has been deprecated for a long time. No need to keep it around any
longer.

Change-Id: I8273e164243e014a658b725a375e5632af211945
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-05-18 13:00:08 +01:00
Stephen Finucane 0eaa7de6a7 strutils: Defer import of pyparsing
This is a slow import and the single user of it, the 'split_by_commas'
helper, does not appear to have any users outside of python-glareclient
(which is a dead project). We might want to remove the user at some
point, but for now simply defer loading of the library.

Change-Id: I91d0c6eec5333a660f995a9d1436e4b068693900
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-05-18 12:51:01 +01:00
songwenping de2b367b48 Remove unnecessary unicode prefixes
Change-Id: Iaae10962581b84b4ae2af1a064dd27d78c05dd4d
2022-04-22 01:28:16 +00:00
Hervé Beraud de4429f2be fix strutils password regex
Those regexes will fix Object style representation output.
See the payload used in tests for details. This kind
of output can be obtained by using the command:

```
$ openstack --debug
```

Co-Authored-By: Daniel Bengtsson <dbengt@redhat.com>
Change-Id: I9024be93b109d1b64ca736546c0f69db7a5e06d0
2022-03-10 08:49:26 +01:00
Hervé Beraud 6e17ae1f79 Fix regex used to mask password
Some use cases are poorly handled by the regex used
to mask password. Indeed when the password contains
quotes or double quotes in the middle such as `pass"word`,
the mask_password method will return `***"word`.

For more details please see
https://bugs.launchpad.net/oslo.utils/+bug/1949623

Closes-Bug: #1949623
Change-Id: I941750b4d49d2d75f0831b24d6dd17f4040f70a2
2022-01-11 15:25:40 +01:00
Takashi Kajinami 3d585b7d4c Use LOG.warning instead of deprecated LOG.warn
The LOG.warn method is deprecated[1] and the LOG.warning method should
be used instead.

[1] https://docs.python.org/3/library/logging.html#logging.warning

Change-Id: If352bbb14a1a44fb2229e633d15e1bf1099fa425
2021-11-29 18:21:40 +09:00
Dmitriy Rabotyagov 3b5eebdc1c Add backing file format to the output
Since libvirt 6, it might be important to understand the
format of the backing image [1] and verify it before operations.

So we adding backing file format to the output of the QemuImgInfo

[1] https://libvirt.org/kbase/backing_chains.html

Change-Id: If83289882e79a973bc77f332408f8f7317351f6f
2021-11-11 10:57:50 +00:00
Takashi Kajinami 2922a3491a QemuImgInfo: Fix inconsistent value format of encrypted
The qemu-img info command shows the encrpyed field in different formats
according to the output format. When the default human format is used
the field can be 'yes' or None while when json format is used the same
field can be True or False.
This change ensures the corresponding attribute has the consistent
format regardless of the output format used.

Closes-Bug: #1942682
Change-Id: I949f07582a708114fdfba76f1a05aa3a3e5c4f40
2021-09-05 00:43:48 +09:00
Alexey Stupnikov 2c74bb92e5 Modify UUID sentinel to support keystone-like UUIDs
Keystone User IDs and Project IDs are used in unit tests, but
_UUIDSentinels() class doesn't generate UUIDs without hyphens.

This patch makes backward compatible modifications to
_UUIDSentinels() class and introduces keystoneidsentinel global
that could be used in the same way as existing uuidsentinel.

Original "UUID sentinel" change: I214ff21b461fa1ca4b83476e1d0a763efe986217

Related-Bug: #1746747
Change-Id: Idb3e893cc03d64ad0522b5e4cedfa30c4f4a2a2f
2021-08-03 13:13:58 +02:00
Takashi Kajinami 75c4abd909 QemuImgInfo: Skip deprecation warning when output is not passed
Change 73eb0673f6 deprecated usage of
the human format and introduced a deprecatipon warning message which
is shown unless format is explicitly set to 'json'.

To avoid the deprecation warning, all usage of QemuImgInfo requires
explicit definition of format='json'. This means that we should add
the format parameter to all existing usage of QemuImgInfo even if
output is blank as is described in the following example.
 QemuImgInfo()
 QemuImgInfo(output=None)

However later we should revert these implementations again when we
deprecated or remove the format parameter. These steps are very
redundant.

This change suppresses the warning message when output is blank so that
we can avoid deprecation warnings without redundant update and revert.

Change-Id: If1ec42dae757fa3d74c740a52c346701ea19f1c9
2021-07-06 22:11:55 +09:00
yatinkarel 4dc538d1c0 Drop warnings enable filter
[1] Enabled warnings without specifying category,
leading to all sort of warnings enabled, this patch
drops it and let it to consumers to enable warnings
types which they are interested in.

[1] https://review.opendev.org/c/openstack/oslo.utils/+/790429

Closes-Bug: #1934098
Change-Id: I822138c18e0932e8f7e3dc62267f167876c962ae
2021-07-01 10:21:19 +05:30
dengzhaosen 25e3d5889d Remove references to 'sys.version_info'
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: Ia183dc2f19bf08635fb830d603f2bed888765ef6
2021-06-01 11:43:51 +01:00
Zuul d4a00db7c1 Merge "Deprecate the fnmatch module." 2021-05-26 18:52:55 +00:00
Hervé Beraud 4c893c92f5 Deprecate the fnmatch module.
Oslo.utils's fnmatch module was added to fix the py2.7 fnmatch module
who was not thread safe [1]. Python 2.7 is no longer supported so now we
can use the stdlib's fnmatch module and deprecate the one of oslo.utils.

[1] https://bugs.python.org/issue23191$
[2] e46a46ba90

Change-Id: I538379f91d2ba415c566ada8d221b62b47ba80bb
2021-05-11 13:41:22 +02:00
Hervé Beraud 73eb0673f6 Deprecate the human format on QemuImgInfo
``human`` format parsing introduced many issue in the past.

Each time qemu will update it's human format output we could be
impacted by their changes and it could introduce new issues on
oslo.utils.

Human format is a human readable format which need to be parsed by
regexes, in other words it's not really a format that machine can
consume natively.

Qemu introduced json output since version 1.3 [1] and this format is
machine readable, for the sake of stability on oslo.utils we decided to
drop the support of the human format and to use json as the unique and
only supported format.

We will reach our goal by following this scenario:
step 1: deprecate the human format
step 2: remove the human format and deprecate the format parameters
step 3: remove the parameter (json all the time)

These changes deprecate the ``human`` format (step 1)

[1] https://wiki.qemu.org/ChangeLog/1.3

Change-Id: Ia8d6cd08a8989395f9b0f9097d2e57757b8cb915
2021-05-10 16:35:40 +02:00
Zuul 3d59521635 Merge "strutils: Stop masking encryption_key_id" 2021-04-16 12:20:22 +00:00
Zuul 3dd070ffac Merge "Address nits from six removal patch" 2021-04-16 12:20:17 +00:00
Zuul 73108fe295 Merge "Switch to collections.abc.*" 2021-04-16 11:49:39 +00:00
Hervé Beraud 3288539a0b Add a ``strict`` flag allowing users to restrict validation of IPv4 format
Add a ``strict`` flag allowing users to restrict validation to IP
addresses in presentation format (``a.b.c.d``) as opposed to address
format (``a.b.c.d``, ``a.b.c``, ``a.b``, ``a``).

https://github.com/netaddr/netaddr/issues/186
https://man7.org/linux/man-pages/man3/inet_pton.3.html
https://bugzilla.redhat.com/show_bug.cgi?id=1924436

Change-Id: I10fed16dad77ac17691a5d175c42b25916dc8bc4
Closes-Bug: #1914386
2021-02-05 14:07:20 +01:00
Stephen Finucane 6ccdbd3731 Address nits from six removal patch
Change-Id: Ia487c2961849a1d42eb72b2a69c360ea638f9d1b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-01 10:47:54 +00:00
Stephen Finucane 53e13b52a0 Switch to collections.abc.*
The abstract base classes previously defined in 'collections' were moved
to 'collections.abc' in 3.3. The aliases will be removed in 3.10.
Preempt this change now with a simple find-replace:

  $ ag -l 'collections.($TYPES)' | \
      xargs sed -i 's/\(collections\)\.\($TYPES\)/\1.abc.\2/g'

Where $TYPES is the list of moved ABCs from [1].

[1] https://docs.python.org/3/library/collections.abc.html

Change-Id: I85f2757852c0313967f5d82166124feb10aa4c6a
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-01 10:35:41 +00:00
Lee Yarwood dcfe3ad0fb strutils: Stop masking encryption_key_id
As the name suggests this is simply an id referring to a key and not the
actual key itself. As such we should stop masking this in an effort to
ease debugging and troubleshooting when it is logged.

This was previously incorrectly masked by
I9e684cd8bab85728ff0117f95a30eb7dbb5bf51c as part of bug #1814365.

Closes-Bug: #1905264
Change-Id: I856e3cf32c409debdfb15aa96415c3309fe2f516
2020-11-23 11:53:55 +00:00
haixin cfe9881e6b Remove all usage of six library
Replace six with Python 3 style code.

Change-Id: I52aa4a0f679b56ffa57cdd2199933e36cf076992
2020-10-09 19:20:51 +08:00
Zuul 87d2a1f9d4 Merge "Adding pre-commit" 2020-09-22 12:44:51 +00:00
Zuul a0ee8f5d19 Merge "Add function to encapsule md5 for FIPS systems" 2020-09-21 14:41:53 +00:00
Ade Lee 603fa500c1 Add function to encapsule md5 for FIPS systems
For systems in FIPS mode, invocations of MD5 will fail.  This occurs
even in cases where the MD5 is used in a non-cryptographical context
eg. for an etag in swift.

There is a proposal in Python to allow developers to mark these
non-crypto cases as valid through a new usedforsecurity keyword.
See https://bugs.python.org/issue9216.

Some downstream versions of python already implement this keyword.
To permit OpenStack to run in FIPS enabled systems with these versions
of python, we add a simple encapsulation of hashlib.md5() here.

Once the issue is resolved in upstream python, we can remove this
function.

Change-Id: I09433fea6ad6e6849677a93b269e24dec5c05b69
2020-09-16 16:47:07 -04:00