mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 09:27:31 -02:30
handle unicode host names in fact cache
This commit is contained in:
@@ -716,10 +716,10 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana
|
|||||||
return '{}'.format(self.inventory.id)
|
return '{}'.format(self.inventory.id)
|
||||||
|
|
||||||
def memcached_fact_host_key(self, host_name):
|
def memcached_fact_host_key(self, host_name):
|
||||||
return '{}-{}'.format(self.inventory.id, base64.b64encode(host_name))
|
return '{}-{}'.format(self.inventory.id, base64.b64encode(host_name.encode('utf-8')))
|
||||||
|
|
||||||
def memcached_fact_modified_key(self, host_name):
|
def memcached_fact_modified_key(self, host_name):
|
||||||
return '{}-{}-modified'.format(self.inventory.id, base64.b64encode(host_name))
|
return '{}-{}-modified'.format(self.inventory.id, base64.b64encode(host_name.encode('utf-8')))
|
||||||
|
|
||||||
def _get_inventory_hosts(self, only=['name', 'ansible_facts', 'modified',]):
|
def _get_inventory_hosts(self, only=['name', 'ansible_facts', 'modified',]):
|
||||||
return self.inventory.hosts.only(*only)
|
return self.inventory.hosts.only(*only)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
@@ -111,6 +113,18 @@ def test_start_job_fact_cache_existing_host(hosts, hosts2, job, job2, inventory,
|
|||||||
assert ansible_facts_cached == json.dumps(hosts[1].ansible_facts)
|
assert ansible_facts_cached == json.dumps(hosts[1].ansible_facts)
|
||||||
|
|
||||||
|
|
||||||
|
def test_memcached_fact_host_key_unicode(job):
|
||||||
|
host_name = u'Iñtërnâtiônàlizætiøn'
|
||||||
|
host_key = job.memcached_fact_host_key(host_name)
|
||||||
|
assert host_key == '5-ScOxdMOrcm7DonRpw7Ruw6BsaXrDpnRpw7hu'
|
||||||
|
|
||||||
|
|
||||||
|
def test_memcached_fact_modified_key_unicode(job):
|
||||||
|
host_name = u'Iñtërnâtiônàlizætiøn'
|
||||||
|
host_key = job.memcached_fact_modified_key(host_name)
|
||||||
|
assert host_key == '5-ScOxdMOrcm7DonRpw7Ruw6BsaXrDpnRpw7hu-modified'
|
||||||
|
|
||||||
|
|
||||||
def test_finish_job_fact_cache(job, hosts, inventory, mocker, new_time):
|
def test_finish_job_fact_cache(job, hosts, inventory, mocker, new_time):
|
||||||
|
|
||||||
job.start_job_fact_cache()
|
job.start_job_fact_cache()
|
||||||
|
|||||||
@@ -57,10 +57,10 @@ class CacheModule(BaseCacheModule):
|
|||||||
return '{}'.format(self._inventory_id)
|
return '{}'.format(self._inventory_id)
|
||||||
|
|
||||||
def translate_host_key(self, host_name):
|
def translate_host_key(self, host_name):
|
||||||
return '{}-{}'.format(self._inventory_id, base64.b64encode(host_name))
|
return '{}-{}'.format(self._inventory_id, base64.b64encode(host_name.encode('utf-8')))
|
||||||
|
|
||||||
def translate_modified_key(self, host_name):
|
def translate_modified_key(self, host_name):
|
||||||
return '{}-{}-modified'.format(self._inventory_id, base64.b64encode(host_name))
|
return '{}-{}-modified'.format(self._inventory_id, base64.b64encode(host_name.encode('utf-8')))
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
host_key = self.translate_host_key(key)
|
host_key = self.translate_host_key(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user