Skip to content

Fixed napalm_beacon compatability for python 3 - #53433

Closed
raddessi wants to merge 3 commits into
saltstack:developfrom
raddessi:develop.napalm-beacons-lists-p3
Closed

raddessi wants to merge 3 commits into
saltstack:developfrom
raddessi:develop.napalm-beacons-lists-p3

Conversation

@raddessi

@raddessi raddessi commented Jun 10, 2019 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes (for me) the napalm_beacon module's validate function when running on python 3.

What issues does this PR fix or reference?

I hit a bug trying to use the napalm_beacon on python 3, due to the dict_keys and dict_values objects not supporting indexing any more.

With just the pillar code copied out of the napalm_beacon example page

[CRITICAL] The beacon errored: 
Traceback (most recent call last):
  File "/opt/miniconda/envs/salt/lib/python3.6/site-packages/salt/minion.py", line 2592, in handle_beacons
    beacons = self.process_beacons(self.functions)
  File "/opt/miniconda/envs/salt/lib/python3.6/site-packages/salt/minion.py", line 449, in process_beacons
    return self.beacons.process(b_conf, self.opts['grains'])  # pylint: disable=no-member
  File "/opt/miniconda/envs/salt/lib/python3.6/site-packages/salt/beacons/__init__.py", line 104, in process
    valid, vcomment = self.beacons[validate_str](b_config[mod])
  File "/opt/miniconda/envs/salt/lib/python3.6/site-packages/salt/beacons/napalm_beacon.py", line 290, in validate
    fun_cfg = mod.values()[0]
TypeError: 'dict_values' object does not support indexing

Tests written?

[NOTICE] Bug fixes or features added to Salt require tests.
Please review the test documentation for details on how to implement tests into Salt's test suite.

No

Commits signed with GPG?

No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@raddessi

Copy link
Copy Markdown
Contributor Author

Ah crap, my black plugin auto formatted everything in the file. I can revert, it's only 4 lines of change, but do you all have an auto formatter for this project already? If so I'll add that in to my editor.

@raddessi raddessi changed the title Fixed napalm_beacon logic for python 3 Fixed napalm_beacon compatability for python 3 Jun 12, 2019
@Ch3LL
Ch3LL requested review from mirceaulinic and waynew June 14, 2019 18:24
@waynew

waynew commented Jun 15, 2019

Copy link
Copy Markdown
Contributor

@raddessi no, we don't have auto formatting yet, though there's been some discussion about possibly adopting black -S, since we do prefer ' wrapped strings.

@waynew waynew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor tweaks. Also, would it be possible to write a test for this? Or, if there's already some tests over this section, updating the test so it properly exercises this section on Python2 and 3.

Otherwise, 👍

for mod in config:
fun = mod.keys()[0]
fun_cfg = mod.values()[0]
fun = list(mod.keys())[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be list(mod)[0] - the default creating a list from mapping is to use the keys.

event = {}
fun = mod.keys()[0]
fun_cfg = mod.values()[0]
fun = list(mod.keys())[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here - list(mod)[0]

@mirceaulinic mirceaulinic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@raddessi

Copy link
Copy Markdown
Contributor Author

I'm closing this out myself (I didn't realize we had that capability) as it is superceded by #56243, thanks all

@raddessi raddessi closed this Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants