Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue-32019: [Python 3] znode fails to create node (It uses string value instead of bytes value) #36999

Merged
merged 1 commit into from Mar 5, 2018

Conversation

velimir
Copy link
Contributor

@velimir velimir commented Mar 5, 2018

DESCRIPTION

The module znode doens't work for python 3 when trying to publish some value to zookeeper, It is because of KazooClient.create and KazooClient.set require a byte string in python 3 like b'value' instead of 'value'. This PR changes ansible/modules/clustering/znode.py to consume the proper message either for python2 or 3 by using from ansible.module_utils._text import to_bytes.

This PR is based on #32030, but also fixed set functional call, which was missing from the original PR.

ISSUE TYPE
  • Bug Report (Fixes 32019)
COMPONENT NAME

znode

ANSIBLE VERSION
ansible 2.5.0 [] last updated 2017/10/19 20:28:31 (GMT +100)
...
python version = 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
CONFIGURATION
OS / ENVIRONMENT

"N/A"

SUMMARY

In python 3, kazoo client requires bytes and not string, in order to solve the issue:

1.- include in znode.py:

from ansible.module_utils._text import to_bytes

2.- Replace znode.py line 235:

 - self.zk.set(path, value)
 + self.zk.set(path, to_bytes(value))

3.- Replace znode.py line 241:

 - self.zk.create(path, value, makepath=True)
 + self.zk.create(path, to_bytes(value), makepath=True)

This solve the issue and is backward compatible (I already tested and will create the proper PR if I have time, I'm actually working on other future PRs).

STEPS TO REPRODUCE
  • tested with: Python 2.7.13, Python 3.5.2
  • kazoo (2.4.0)
  • playbook:
- name: test my new module
  connection: local
  hosts: localhost
  - name: publish to zookeeper
    znode:
      hosts: "localhost:2181"
      name: "/mynode"
      value: "myvalue"
      state: present
EXPECTED RESULTS
TASK [testmod : publish to zookeeper] ************************************************************************************************************
ok: [localhost]
ACTUAL RESULTS
TASK [testmod : publish to zookeeper] ************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Invalid type for 'value' (must be a byte string)

kazoo client requires bytes and not string
@ansibot
Copy link
Contributor

ansibot commented Mar 5, 2018

@ansibot ansibot added bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Mar 5, 2018
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Mar 5, 2018
@bcoca bcoca requested a review from abadger March 5, 2018 14:39
@abadger abadger merged commit 2d98a2d into ansible:devel Mar 5, 2018
This was referenced Mar 5, 2018
@abadger
Copy link
Contributor

abadger commented Mar 5, 2018

Merged to devel for 2.6.x release. Opened a PR for backporting to 2.5: #37038

@abadger
Copy link
Contributor

abadger commented Mar 5, 2018

Merged to stable-2.5 for the 2.5.0 release and cherry-picked for the 2.4.4 release.

@velimir velimir deleted the fix-issue-32019 branch March 6, 2018 14:23
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

znode fails to create node (It uses string value instead of bytes value)
4 participants