Browse Source

Merge "Stop using md5 for __repr__ of objects" into stable/ussuri

tags/15.0.1
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
341e8673d4
3 changed files with 3 additions and 14 deletions
  1. +1
    -6
      ironic/objects/fields.py
  2. +2
    -7
      ironic/tests/unit/objects/test_fields.py
  3. +0
    -1
      tools/bandit.yml

+ 1
- 6
ironic/objects/fields.py View File

@@ -14,8 +14,6 @@
# under the License.

import ast
import hashlib
import inspect

from oslo_versionedobjects import fields as object_fields

@@ -57,10 +55,7 @@ class StringFieldThatAcceptsCallable(object_fields.StringField):
default = self._default
if (self._default != object_fields.UnspecifiedDefault
and callable(self._default)):
default = "%s-%s" % (
self._default.__name__,
hashlib.md5(inspect.getsource(
self._default).encode()).hexdigest())
default = '<function %s>' % default.__name__
return '%s(default=%s,nullable=%s)' % (self._type.__class__.__name__,
default, self._nullable)



+ 2
- 7
ironic/tests/unit/objects/test_fields.py View File

@@ -13,9 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import hashlib
import inspect

from ironic.common import exception
from ironic.objects import fields
from ironic.tests import base as test_base
@@ -73,8 +70,6 @@ class TestStringFieldThatAcceptsCallable(test_base.TestCase):
def test_default_function():
return "default value"

self.test_default_function_hash = hashlib.md5(
inspect.getsource(test_default_function).encode()).hexdigest()
self.field = fields.StringFieldThatAcceptsCallable(
default=test_default_function)

@@ -102,8 +97,8 @@ class TestStringFieldThatAcceptsCallable(test_base.TestCase):
self.field.coerce('obj', 'attr', None))

def test__repr__includes_default_function_name_and_source_hash(self):
expected = ('StringAcceptsCallable(default=test_default_function-%s,'
'nullable=False)' % self.test_default_function_hash)
expected = ('StringAcceptsCallable(default=<function '
'test_default_function>,nullable=False)')
self.assertEqual(expected, repr(self.field))




+ 0
- 1
tools/bandit.yml View File

@@ -89,7 +89,6 @@ tests:
# (optional) list skipped test IDs here, eg '[B101, B406]':
skips:
- B104
- B303
- B604

### (optional) plugin settings - some test plugins require configuration data


Loading…
Cancel
Save