mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 08:35:21 +00:00
Fix _get_hash in splay executor
You can't pass a unicode value to bytearray()
This commit is contained in:
parent
f73f2e5bb6
commit
bbb8fe8540
@ -7,6 +7,8 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import salt.utils.stringutils
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
_DEFAULT_SPLAYTIME = 300
|
_DEFAULT_SPLAYTIME = 300
|
||||||
@ -28,7 +30,7 @@ def _get_hash():
|
|||||||
bitmask = 0xffffffff
|
bitmask = 0xffffffff
|
||||||
h = 0
|
h = 0
|
||||||
|
|
||||||
for i in bytearray(__grains__['id']):
|
for i in bytearray(salt.utils.stringutils.to_bytes(__grains__['id'])):
|
||||||
h = (h + i) & bitmask
|
h = (h + i) & bitmask
|
||||||
h = (h + (h << 10)) & bitmask
|
h = (h + (h << 10)) & bitmask
|
||||||
h = (h ^ (h >> 6)) & bitmask
|
h = (h ^ (h >> 6)) & bitmask
|
||||||
|
1
tests/unit/executors/__init__.py
Normal file
1
tests/unit/executors/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
24
tests/unit/executors/test_splay.py
Normal file
24
tests/unit/executors/test_splay.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
|
# Import Salt libs
|
||||||
|
from tests.support.mixins import LoaderModuleMockMixin
|
||||||
|
from tests.support.unit import TestCase
|
||||||
|
|
||||||
|
import salt.executors.splay as splay_exec
|
||||||
|
|
||||||
|
|
||||||
|
class SplayTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
|
||||||
|
def setup_loader_modules(self):
|
||||||
|
return {
|
||||||
|
splay_exec: {
|
||||||
|
'__grains__': {'id': 'foo'},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def test__get_hash(self):
|
||||||
|
# We just want to make sure that this function does not result in an
|
||||||
|
# error due to passing a unicode value to bytearray()
|
||||||
|
assert splay_exec._get_hash()
|
Loading…
Reference in New Issue
Block a user