Fix _get_hash in splay executor

You can't pass a unicode value to bytearray()
This commit is contained in:
Erik Johnson 2018-09-05 16:07:57 -05:00
parent f73f2e5bb6
commit bbb8fe8540
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F
3 changed files with 28 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View 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()