256 Commits

Author SHA1 Message Date
Stephen Finucane
8b294f4895 trivial: Move setup code into setUp helper
All this stuff was being called at the beginning of each test. It
belongs in 'setUp', so place it there.

Change-Id: Icb50e64d47c364c3485371311abe1311502831a5
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2019-12-18 18:06:27 +00:00
Dougal Matthews
577da7f00b Verify the sanitize keys are lowered
This change is preventative to ensure any keys added in the future are
all lowercase.

Change-Id: Ib843fe59a80b081d9d0193717ff5a980e22c81b0
2019-11-22 08:57:53 +00:00
Radomir Dopieralski
a6acf8236c Fix invalid escapes in regular expression strings
The "r" for raw strings has to repeated when several strings are
concatenated, otherwise the backslash in the strings that miss
the "r" are interpreted directly, and result in invalid escapes.

Change-Id: I3736a40043c8aa6c36c21803bf68f842af5cd55e
2019-11-21 14:21:50 +01:00
Dougal Matthews
ed70bd3cd1 Make mask_dict_password case insensitive and add new patterns
In Icc19b7c8bdb6a3182939d5e9fdef21288b19f43d mask_password was made case
insensitive but mask_dict_password wasn't. This update makes the
behaviour of these functions the same.

Instead of lowering _SANITIZE_KEYS each time the source list is lowered.

New password patterns from realworld logs were added to the patterns.

Change-Id: Ic3ee301857630a15b9c26fd5d0fc907c43199517
Related-Bug: #1850843
2019-11-15 17:09:26 +01:00
Cédric Jeanneret
b41268417c Make mask_password case insensitive, and add new patterns
It appears that Mistral service logs everything, and doesn't use yet
the mask_password (nor mask_dict_password) method. In order to ensure
all is properly masked, we have to add some new patterns, and make it
case insensitive in order to simplify and avoid duplicated entries.

Change-Id: Icc19b7c8bdb6a3182939d5e9fdef21288b19f43d
Related-Bug: #1850843
Signed-off-by: Cédric Jeanneret <cjeanner@redhat.com>
2019-11-05 11:04:18 +00:00
Mark Mielke
5204dfcd6c Support "qemu-img info" virtual size in QEMU 4.1 and later
QEMU 4.0 and earlier have output like:

    virtual size: 1.5M (1572864 bytes)

QEMU 4.1 and later have output like:

    virtual size: 1.5 MiB (1572864 bytes)

Adjust the regular expression to allow for optional whitespace
between the magnitude and the unit.

Adjust the unit parsing to support the expanded "MiB" form.

Change-Id: I1f316d6982c0def3296af4835484ad2d81a87fd4
Closes-Bug: 1844050
2019-09-20 16:56:47 -04:00
Alfredo Moralejo
5ae7d21f98 Add digestmod when using hmac
Until Python 3.8 hmc.new() defaulted the digestmod argument to 'hmac-md5'.
This was deperecated, to be removed in Python 3.8 [1], so let's get
ready for new python.

Also switching to more secure sha1 algorithm, using md5 anywhere may
trigger alerts from automatic security tools.

[1] https://docs.python.org/3.8/library/hmac.html

Change-Id: I4b365cb05de98bdd498b3c2094e4a77ab3944b12
2019-08-21 18:28:09 +02:00
Zuul
9a2ae8affd Merge "eventletutils: Optimise EventletEvent.clear()" 2019-04-16 11:03:25 +00:00
Zuul
895062f3af Merge "Mask encryption_key_id" 2019-03-27 16:19:40 +00:00
ZhijunWei
1803b63823 Update hacking version
Use latest release 1.1.0 and compatible changes w.r.t pep8

Change-Id: Ide3a556918f341de6eafecb36ca431da40a0aed0
Closes-Bug: #1815715
2019-02-13 14:28:34 +08:00
yenai
08d76b5373 Mask encryption_key_id
Change-Id: I9e684cd8bab85728ff0117f95a30eb7dbb5bf51c
Closes-Bug: #1814365
2019-02-02 16:46:03 +08:00
Zane Bitter
c5b065c3e4 eventletutils: Optimise EventletEvent.clear()
When EventletEvent.clear() is called twice in succession without an
intervening set(), there's no need to replace the underlying
eventlet.event.Event object, since it has never been sent. Doing so
would have woken other greenthreads waiting on the event to no
particular end.

When clear() is called after the event has been set(), we already did
not do anything special with the existing eventlet.event.Event as we
cannot call send() on it twice. We simply replace it with a new one; the
code in wait() will handle the situation correctly, since it will wake
up (due to the initial event having been sent) and begin waiting on the
new eventlet.event.Event instead. This is consistent with the observed
behaviour of threading.Event. A new unit test verifies this.

Change-Id: Ibd5324926431fc760c3dd0be064324e3009cc2c2
2019-01-25 14:56:57 +13:00
Ben Nemec
4eb61941f8 Avoid double-setting event
In commit cc8b51e1e16f6bdc7d6c0e571e2002e70cde098d we added a send
on the old event when clearing an EventletEvent. However, this was
done unconditionally, which means if the event was already sent
then we attempt to send it again. This fails with:

AssertionError: Trying to re-send() an already-triggered event.

Similar to 14a53c4d8a9d5605b14a503803859df0d6d4b820, we should check
if self._set is True and if so then we know that the event was
already sent and we don't need to do it again.

Change-Id: I660601383072d11e4a077aada8c1b8c30b9d8d1d
Closes-Bug: 1812922
2019-01-23 15:28:50 +00:00
Zuul
eff0629790 Merge "Avoid calling eventlet.event.Event.reset()" 2019-01-18 03:31:53 +00:00
Zuul
380bf5a47e Merge "Support non-dict mappings in mask_dict_password" 2019-01-08 00:08:03 +00:00
Zane Bitter
14a53c4d8a Avoid calling eventlet.event.Event.reset()
The eventlet maintainers have made it clear that calling reset() on an
Event is not recommended:

715b2ced52

We don't really need to resend the event to wake up threads, because
Event.wait() will return immediately once the event has been sent. So
just rely on the internal _set flag to tell us whether we need to send
the event.

Change-Id: I466aa7cb64308e018598c3bb63a9d0cfbc833adc
2019-01-03 09:48:22 +13:00
Zane Bitter
cc8b51e1e1 Fix race condition in eventletutils Event
The threading-compatible eventlet Event class has a race condition on
the wait method. If greenthread A is blocked on the wait, but another
greenthread B calls clear() and then set(), B calls self._event.send(),
but A is waiting on a different eventlet Event which is no longer used
by the oslo.service Event...

To resolve this, when clearing an Event trigger the underlying eventlet
Event immediately, then have the wait() method resume waiting on the new
eventlet Event.

Change-Id: I81579e2977bb965a5398a2cb4e3e24f5671e856a
Co-Authored-By: Victor Stinner <vstinner@redhat.com>
Co-Authored-By: Hervé Beraud <hberaud@redhat.com>
Closes-Bug: #1805706
2018-12-05 20:06:39 +13:00
Zane Bitter
d7e70b11c6 Don't use monotonic on Python >=3.3
A change to the global-requirements[1] has limited use of the monotonic
library to Python versions earlier than 3.3 (later versions have
built-in support for a monotonic clock), so no requirements changes can
be merged until we similarly limit it in requirements.txt.

[1] https://review.openstack.org/615441

Change-Id: Ib53d89ea820d21114d10280c9f4ab1b0c2c4a4bc
2018-12-05 16:28:41 +13:00
Ben Nemec
ddc4369258 Support non-dict mappings in mask_dict_password
mask_dict_password doesn't actually have a dependency on the dict
type specifically. It can work on any subclass of collections.Mapping.
This changes the isinstance check to reflect that and adds a unit
test using a collections.Mapping subclass.

Change-Id: I28781acf027b9b34f8274196db5dd4d2a9adc9ba
Closes-Bug: 1804528
2018-12-03 16:44:28 +00:00
Ben Nemec
fde490f22d Expose eventlet Event wrapper class
We have a need to use the eventlet Event class directly in
oslo.service. Currently it is copy-pasted from this project, but
we now have a duplicate bug due to that so let's just expose it so
one copy can be used in both places.

This should be safe as the class implements a stdlib interface so
we can't really alter the API, and it's not really private since
instances of it are returned to users.

Change-Id: If8e7a41f9fe5573a780f9faabdbaf1326631d37a
Related-Change: https://review.openstack.org/558879
Related-Bug: 1800879
2018-11-01 20:53:53 +00:00
BubaVV
6e0b90be22 Fix exception raise at rpdb session
Some components raise unrelated exceptions during rpdb session due to
unaware attribute handling of file-like objects

Change-Id: I04dd5a7d0f6ec2920671dfa612439427dffefd52
Closes-bug: #1791104
2018-09-07 10:15:51 +03:00
Zuul
5b7c99bbc5 Merge "Fix docstring formatting nit in uuidsentinel" 2018-08-28 20:53:27 +00:00
Zuul
fa46125a87 Merge "UUID sentinel" 2018-08-28 17:13:22 +00:00
Ben Nemec
9fdcf64720 Fix docstring formatting nit in uuidsentinel
This doesn't actually appear in the docs because it's a private class,
but if we ever made it public we want it to format the code block
correctly.

Change-Id: Ia79b58d6d7847b65f946763c82a25ce8d8e581fb
2018-08-28 15:25:18 +00:00
Eric Fried
63d7649ed5 UUID sentinel
Add a private _UUIDSentinels() class to oslo_utils.fixture that behaves
like a mock.sentinel, but returns specifically UUIDs. Expose a
(singleton) instance of it called uuidsentinel. This is mostly copied
from [1], with the following differences:

- We don't do the enforced-singleton thing [2]. But importing the
  uuidsentinel global yields the same behavior.
- We don't do the local import thing [3][4], because we're already in
  the right lib, so no issues with circular imports.
- Locking is added to make this threadsafe. (See discussion at [5])

Note that there is some question as to whether it is more appropriate
for this to live here or in oslotest [6]. This has been discussed on the
dev ML [7] and it was concluded [8] that it should live here.

[1] 722d5b4772/nova/tests/uuidsentinel.py
[2] 722d5b4772/nova/tests/uuidsentinel.py (L30)
[3] 722d5b4772/nova/tests/uuidsentinel.py (L18-L19)
[4] 722d5b4772/nova/tests/uuidsentinel.py (L26)
[5] http://eavesdrop.openstack.org/irclogs/%23openstack-oslo/%23openstack-oslo.2018-08-20.log.html#t2018-08-20T20:10:33
[6] https://review.openstack.org/#/c/594068/
[7] http://lists.openstack.org/pipermail/openstack-dev/2018-August/133670.html
[8] http://lists.openstack.org/pipermail/openstack-dev/2018-August/133861.html

Change-Id: I214ff21b461fa1ca4b83476e1d0a763efe986217
2018-08-28 12:55:33 +00:00
Chuck Short
19352892cf Remove moxstubout usage
As of oslotest version 3.5.0 moxstub will be deprecated,
so remove it where it has been used.

Change-Id: I9f038428cbea07a307f08c2251eafed7ab8bbea1
Signed-off-by: Chuck Short <chucks@redhat.com>
2018-08-22 07:21:09 -04:00
Joshua Harlow
25ed5ceb58 Remove extra copy.deepcopy
This method is called recursively (ie deeply) by default
so there doesn't seem to be a good reason to deepcopy over
and over and over at every recusion level especially since
a new output dictionary is getting created anyway.

Change-Id: I644ef881e487c06dc4db77d60cfe765b0e59b547
2018-07-19 12:19:14 -07:00
Zuul
7f8397091f Merge "Handle non-string keys appropriately" 2018-07-18 03:43:01 +00:00
Joshua Harlow
4e2abfeec4 Handle non-string keys appropriately
In python dict keys can be anything that is hashable; which
includes non-strings such as ints. Currently the code is blowing
up with these types of keys with exceptions like:

TypeError: argument of type 'int' is not iterable

So to fix that handle the case where non-string keys are found.

Change-Id: I4f576a089df6f68e43572bf0eee15e99f2b557fe
2018-07-17 09:29:40 -07:00
changxun
e158c10ccb Fix exception with secretutils
1. There are some problems about the test method.
 problem 1:
  Unit tests may not cover our function, it depends on the python version
  that performed the test.
 problem 2:
  when using function 'constant_time_compare(first, second)', 'first' and
  'second' params are usually HMAC digest values, it is not appropriate to
  use utf-8 encoded values as mock data.

2. The previous commit `f1d332a` lead into a bug, but due to the problem 1
   and the problem 2, we did not find out the error.

Change-Id: I1c29bfe69f8eda60f3c5caaf3e5447dd5b69b108
Closes-Bug: #1772851
2018-05-24 18:55:24 +08:00
Matthew Booth
0fb1b0aabe Add private_key to the list of sanitized keys
Nova's create keypair operation will currently log the generated
keypair if debug logs are enabled.

Closes-Bug: #1770683
Change-Id: I7f889f0bf254fad43b1e26d32fa145f88c668b39
2018-05-11 17:19:57 +01:00
Tovin Seven
8d9d958c43 Trivial: Update pypi url to new url
Pypi url changed from [1] to [2]

[1] https://pypi.python.org/pypi/<package>
[2] https://pypi.org/project/<package>

Change-Id: I53bfd078ba2a47a5744c2ebf1354d06ad6438544
2018-04-20 17:13:42 +07:00
John Eckersberg
82678918aa eventletutils: Fix behavior discrepency when reusing Events
The threading.Event object allows calling set() multiple times, but
the eventlet.Event object only permits send() to be called once,
before a reset() is required to reuse the Event.

Calling eventletutils.Event.set() multiple times triggers an
AssertionError from eventlet.Event.  This change resets the underlying
eventlet.Event if the set() method had already been called previously,
and ensures the eventletutils.Event behaves the same as the
threading.Event.

Change-Id: If761b237266bbfe7e65c56e152074b5d1ccac74b
2018-04-11 13:02:29 -04:00
OpenStack Proposal Bot
00eeef6813 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: If10933e0bbc543f4a9ed686b96e13e43b3d8a296
2018-03-01 06:07:18 +00:00
Zuul
695abbe53a Merge "Clean imports in code" 2018-02-09 12:55:21 +00:00
OpenStack Proposal Bot
171b968e6e Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: Ic58353cda88124d10f320e62d19034a6c1278edd
2018-02-08 06:48:41 +00:00
Zuul
153e062a96 Merge "Document specs_matcher.py functions" 2018-02-07 07:47:58 +00:00
John L. Villalovos
010fe3b102 Fix breaking unit tests due to iso8601 changes
The move from iso8601===0.1.11 to iso8601===0.1.12 broke unit
tests in oslo.utils.

iso8601 used to do:
    from datetime import datetime

But now they call datetime.datetime():
    import datetime
    datetime.datetime()

Unfortunately the unit tests that mocked datetime.datetime() are now
mocking the one in iso8601. This causes a failure in the unit tests.

Fix this by using the 'wraps' argument to mock. So that the calls will
get passed through to datetime.datetime. Also changed to using the
decorator style of mock.

In addition Python 3 unit tests were broken due to changing how the
UTC time zone is represented from 'UTC' to 'UTC+00:00'.

Closes-Bug: #1747575
Closes-Bug: #1744160
Change-Id: Ia80ffb5e571cc5366bef2bc1a32c457a3c16843d
2018-02-06 09:47:15 -08:00
John L. Villalovos
dbb118f420 Document specs_matcher.py functions
Add some documentation to the specs_matcher.py functions.

Add some additional unit tests.

Change-Id: Ie399388e96d7a93fcb7e813b4b4da9ebd5d99688
2018-01-30 10:10:26 -08:00
Nguyen Hung Phuong
9180df19b8 Clean imports in code
In some part in the code we import objects. In the Openstack style
guidelines they recommend to import only modules.

https://docs.openstack.org/hacking/0.10.3/

Change-Id: Ie0151c2878c6a0ae09b7efcd5ccc7b31c622c0e7
2018-01-30 14:01:41 +07:00
sunyandi
84f950f6db Replace 'assertFalse(a in b)' with 'assertNotIn(a, b)'
Trivial fix.

Change-Id: Ie89f2bd03822cb76ee09d1d91284e7d356f5e5c5
2018-01-19 19:21:47 +08:00
Zuul
a449545a19 Merge "Add a mixed mode parser to string_to_bytes" 2018-01-13 01:33:32 +00:00
Zuul
d9ec025c39 Merge "Add missing information in docstring of validate_integer" 2018-01-07 05:01:17 +00:00
Zuul
f009808e34 Merge "Add method to escape ipv6 ip addresses" 2018-01-05 19:34:03 +00:00
Doug Hellmann
11feb68eb3 improve docstring for last_bytes()
Change-Id: Ic402a29c9e701a6cde3e882cc97721008cdd5460
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-01-02 08:50:18 -05:00
ChangBo Guo(gcb)
4d35db56f8 Add method last_bytes in fileutils
Method last_bytes is used in some projects[1]. It's good to bring
this method in fileutils according to discussion in dev ML[2].

[1] http://codesearch.openstack.org/?q=last_bytes&i=nope&files=&repos=
[2] http://lists.openstack.org/pipermail/openstack-dev/2017-July/120259.html

Change-Id: I1cd61de58b759916ecd0569afb2485de0b31c405
2017-12-27 10:52:27 +08:00
ChangBo Guo(gcb)
5d40f5bb1c Add missing information in docstring of validate_integer
Add versionadded and raises information in docstring

Change-Id: Ia5929dc81cfed927a7b5dd809c13d3ae7efdf699
2017-12-18 12:26:27 +08:00
Zuul
58fb709f58 Merge "Add method validate_integer" 2017-12-05 19:38:06 +00:00
Zuul
42a4d1c696 Merge "Fix some reST field lists in docstrings" 2017-11-30 07:59:09 +00:00
Rajath Agasthya
750ed32771 Add method to compute a file's checksum to fileutils
File checksums are used in projects like glance and
glance_store to verify image uploads and so on, so a
generic oslo utility method could be useful.

Change-Id: I1b76ee1876771e7965fd5704ab6281318f36e810
2017-10-25 09:44:53 -07:00