Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Add automatic provider register hook#28

Merged
lmazuel merged 7 commits intomasterfrom
providerhook
Jun 19, 2017
Merged

Add automatic provider register hook#28
lmazuel merged 7 commits intomasterfrom
providerhook

Conversation

@lmazuel
Copy link
Copy Markdown
Member

@lmazuel lmazuel commented Jun 15, 2017

@yugangw-msft

  • This is not tested real on Azure, but HTTPretty is configured using your record.
  • Tests will break if new msrest is not released, but note that this is NOT a requirement. I print a warning if msrest mismatch.

@brettcannon
Copy link
Copy Markdown
Member

Should the tests be passing?

@lmazuel
Copy link
Copy Markdown
Member Author

lmazuel commented Jun 15, 2017

@brettcannon not until Azure/msrest-for-python#31 is merged.

If you can look into it as well, I'd like your review :)

@lmazuel
Copy link
Copy Markdown
Member Author

lmazuel commented Jun 15, 2017

@yugangw-msft This version works great (I tested on "Azure Search" account creation, which has a super fast register/unregister). If you can review the algorithm it would be nice :)
Since ScottGu wants this for OpenDev, I would like to release this tomorrow.

session = kwargs['msrest']['session']
url_prefix = _extract_subscription_url(r.request.url)
_register_rp(session, url_prefix, rp_name)
time.sleep(10)
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.

any reason we want to sleep for 10 more seconds?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no you're right, it was debugging, I'll remove it

"""Synchronously register the RP is paremeter."""
post_url = "{}providers/{}/register?api-version=2016-02-01".format(url_prefix, rp_name)
get_url = "{}providers/{}?api-version=2016-02-01".format(url_prefix, rp_name)
_LOGGER.warning("Resource provider '%s' used by the command is not "
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.

Maybe rename command to creating operation? I know CLI are commands, but guess not all of SDK's clients are commands

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point


def _register_rp(session, url_prefix, rp_name):
"""Synchronously register the RP is paremeter."""
post_url = "{}providers/{}/register?api-version=2016-02-01".format(url_prefix, rp_name)
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.

I assume you have double checked that this api-version is available in sovereign clouds and stacks. I think so, but just in case. Or you can feel free to import azure.mgmt.resource, 99% chance, the package will be there, then you just create a client and use the sdk method. Up to you, since you know SDK better than anyone

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If I use the SDK, I have no reason to believe that latest of the SDK is available in this connection, and I don't know how to call Azure to ask what are the available ApiVersion.
I might do a list of ApiVersion and loop on it until I find one that is working.
Anyway, I will recheck the code with this kind of situation in mind, I guess I should check the status code and if it's not 200, just fail.

if hasattr(self, 'hooks'):
self.hooks.append(register_rp_hook)
else:
_LOGGER.warning(("Your 'msrest' version is too old to activate all the ",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be a warn()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When I wrote warn, I got a Deprecation warning :)

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 16, 2017

Codecov Report

Merging #28 into master will increase coverage by 0.75%.
The diff coverage is 94.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
+ Coverage   84.28%   85.04%   +0.75%     
==========================================
  Files           6        7       +1     
  Lines         630      682      +52     
==========================================
+ Hits          531      580      +49     
- Misses         99      102       +3
Impacted Files Coverage Δ
msrestazure/azure_configuration.py 57.57% <85.71%> (+5.72%) ⬆️
msrestazure/tools.py 95.65% <95.65%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56481fc...66dd771. Read the comment docs.

"registered. We are registering for you.", rp_name)
post_response = session.post(post_url)
if post_response.status_code != 200:
_LOGGER.warning("Registration failed. Please register manually.")
Copy link
Copy Markdown
Contributor

@yugangw-msft yugangw-msft Jun 16, 2017

Choose a reason for hiding this comment

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

i suggest to include the rp_name in the warning
EDIT: ignore my comment please. We already mentioned it in the early warnings

@lmazuel
Copy link
Copy Markdown
Member Author

lmazuel commented Jun 16, 2017

@yugangw-msft @johanste
Yes, I try 2016-02-01. I added code so if the registration fails, I just do nothing and the user get the "provider not registered" exception. At least this is not doing weird stuff.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants