Skip to content

fix boto3_route53 module for Python3 #60951

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

Merged
merged 6 commits into from
Jan 25, 2022

Conversation

IndraGunawan
Copy link
Contributor

@IndraGunawan IndraGunawan commented Sep 24, 2021

What does this PR do?

What issues does this PR fix or reference?

Fixes: this PR fixed re.sub behaviour for Python 3

Previous Behavior

              An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/modules/boto3_route53.py", line 881, in aws_encode
                  ret = re.sub(r"\\x([a-f0-8]{2})", _hexReplace, x.encode("unicode_escape"))
                File "/usr/lib/python3.6/re.py", line 191, in sub
                  return _compile(pattern, flags).sub(repl, string, count)
              TypeError: cannot use a string pattern on a bytes-like object

              During handling of the above exception, another exception occurred:

              Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 2172, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 1241, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2274, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2289, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2322, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/boto3_route53.py", line 766, in rr_present
                  profile=profile,
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 1241, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2274, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/usr/lib/python3/dist-packages/contextvars/__init__.py", line 38, in run
                  return callable(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2289, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/modules/boto3_route53.py", line 1027, in get_resource_records
                  ) if next_rr_name else None
                File "/usr/lib/python3/dist-packages/salt/modules/boto3_route53.py", line 888, in aws_encode
                  raise CommandExecutionError(e)
              salt.exceptions.CommandExecutionError: cannot use a string pattern on a bytes-like object

New Behavior

Remove this section if not relevant

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@IndraGunawan IndraGunawan requested a review from a team as a code owner September 24, 2021 13:03
@IndraGunawan IndraGunawan requested review from krionbsd and removed request for a team September 24, 2021 13:03
@welcome
Copy link

welcome bot commented Sep 24, 2021

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@IndraGunawan
Copy link
Contributor Author

any chances that @krionbsd or @saltstack/team-boto review this PR?

@krionbsd
Copy link
Contributor

krionbsd commented Oct 6, 2021

any chances that @krionbsd or @saltstack/team-boto review this PR?

Any chance to add a test case for these changes in tests/unit/modules/test_boto_route53.py ?

@IndraGunawan
Copy link
Contributor Author

Any chance to add a test case for these changes in tests/unit/modules/test_boto_route53.py ?

test added

@anitakrueger
Copy link
Contributor

Looks like this fixes #59755.
What does it take to get this merged?
Our route53 record management has been broken since moving to 3002.

@IndraGunawan
Copy link
Contributor Author

@krionbsd any chance to review this PR?

@IndraGunawan
Copy link
Contributor Author

@krionbsd failed test is not related to this PR

@github-actions
Copy link

Hi! I'm your friendly PR bot!

You might be wondering what I'm doing commenting here on your PR.

Yes, as a matter of fact, I am...

I'm just here to help us improve the documentation. I can't respond to
questions or anything, but what I can do, I do well!

Okay... so what do you do?

I detect modules that are missing docstrings or "CLI Example" on existing docstrings!
When I was created we had a lot of these. The documentation for these
modules need some love and attention to make Salt better for our users.

So what does that have to do with my PR?

I noticed that in this PR there are some files changed that have some of these
issues. So I'm leaving this comment to let you know your options.

Okay, what are they?

Well, my favorite, is that since you were making changes here I'm hoping that
you would be the most familiar with this module and be able to add some other
examples or fix any of the reported issues.

If I can, then what?

Well, you can either add them to this PR or add them to another PR. Either way is fine!

Well... what if I can't, or don't want to?

That's also fine! We appreciate all contributions to the Salt Project. If you
can't add those other examples, either because you're too busy, or unfamiliar,
or you just aren't interested, we still appreciate the contributions that
you've made already.

Whatever approach you decide to take, just drop a comment here letting us know!

Detected Issues (click me)
Check Known Missing Docstrings...........................................Failed
- hook id: invoke
- duration: 1.55s
- exit code: 1

The function 'aws_encode' on 'salt/modules/boto3_route53.py' does not have a 'CLI Example:' in it's docstring
Found 1 errors


Thanks again!

Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

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

I don't know if it's worth blocking this PR on any of my comments. If you want to make those changes, then awesome! Otherwise I think just having the record of desired changes is good enough 👍

Comment on lines +29 to +43
def __virtual__():
"""
Returns True/False boolean depending on if Boto3 is installed and correct
version.
"""
if not HAS_BOTO3:
return False
if LooseVersion(boto3.__version__) < LooseVersion(REQUIRED_BOTO3_VERSION):
return (
False,
"The boto3 module must be greater or equal to version {}".format(
REQUIRED_BOTO3_VERSION
),
)
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion __virtual__ only applies to Salt modules/states, not tests.

}


@skipIf(HAS_BOTO3 is False, "The boto module must be installed.")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion can just use the module's HAS_BOTO3 - either skipIf(boto3_route53.HAS_BOTO3... or import HAS_BOTO3 from the module

random.choice(string.ascii_lowercase + string.digits) for _ in range(50)
)

self.conn = MagicMock()
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion(non-blocking) create_autospec is preferred (or patch(..., autospec=True)) to a bare MagicMock, since it will get you the correct signature. Sometimes it's not appropriate, though.

Comment on lines +145 to +152
[
{
"Name": "blog.saltstack.furniture.",
"ResourceRecords": [{"Value": "127.0.0.1"}],
"TTL": 60,
"Type": "A",
}
],
Copy link
Contributor

Choose a reason for hiding this comment

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

praise for tests we love to see hard coded expected values.

@garethgreenaway garethgreenaway merged commit bcca1e9 into saltstack:master Jan 25, 2022
@welcome
Copy link

welcome bot commented Jan 25, 2022

Congratulations on your first PR being merged! 🎉

@IndraGunawan IndraGunawan deleted the fix-binarysearch branch January 26, 2022 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants