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

Added support for track 2 SDKs (azure-mgmt-iothub >= 1.0.0) #329

Merged
merged 10 commits into from
Apr 22, 2021

Conversation

c-ryan-k
Copy link
Member


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Thank you for contributing to the IoT extension!

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • If introducing new functionality or modified behavior, are they backed by unit and integration tests?
  • In the same context as above are command names and their parameter definitions accurate? Do help docs have sufficient content?
  • Have all unit and integration tests passed locally? i.e. pytest <project root> -vv
  • Have static checks passed using the .pylintrc and .flake8 rules? Look at the CI scripts for example usage.
  • Have you made an entry in HISTORY.rst which concisely explains your feature or change?

@c-ryan-k
Copy link
Member Author

Will need to add an explicit dependency for packaging in setup.py, but waiting for #328 to get merged so I can clean up the conflicts

@c-ryan-k c-ryan-k marked this pull request as ready for review April 19, 2021 21:34
@c-ryan-k c-ryan-k requested a review from digimaun as a code owner April 19, 2021 21:34
setup.py Outdated
@@ -48,7 +48,7 @@
# though that is installed out of band (managed by the extension)
# for compatibility reasons.

DEPENDENCIES = ["paho-mqtt==1.5.0", "jsonschema==3.2.0", "setuptools"]
DEPENDENCIES = ["paho-mqtt==1.5.0", "jsonschema==3.2.0", "setuptools", "packaging"]
Copy link
Member

Choose a reason for hiding this comment

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

Do we need setuptools anymore?

@@ -182,6 +182,21 @@ def test_jobs(self):
checks=[self.check("jobId", self.job_ids[2])],
)

# Allow time for job to transfer to scheduled state (cannot cancel job in running state)
from time import sleep
sleep(5)
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this longer? Or is 5 second sleep consistently working.

Copy link
Member Author

Choose a reason for hiding this comment

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

Consistently working for me, but I also haven't seen this issue pop up in the build pipelines, only in local testing - one of my hubs got stuck with a job pending in a scheduled state, and couldn't add a new job.

The error was because our test tried to cancel a job before it transitioned from running to scheduled and this seemed to fix it for me (at least for now)

@@ -48,3 +48,6 @@

# Config Key's
CONFIG_KEY_UAMQP_EXT_VERSION = "uamqp_ext_version"

# Initial Track 2 SDK version
TRACK_2_SDK_MIN_VERSION = '1.0.0'
Copy link
Member

Choose a reason for hiding this comment

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

We should prefix this with IOTHUB_ or re-organize like creating dictionary that holds IoT Hub constants

@@ -438,10 +438,14 @@ def is_iso8601_time(self, to_validate: str) -> bool:
return False


def ensure_min_version(cur_ver, min_ver):
from pkg_resources._vendor.packaging import version
def ensure_min_version(min_ver):
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice either through docstrings and/or slightly altering the name that this is to ensure the min version of the iothub mgmt sdk.


if rg:
try:
return self.client.get(resource_group_name=rg, resource_name=hub_name)
except ErrorDetailsException:
except HttpResponseError:
Copy link
Member

@digimaun digimaun Apr 20, 2021

Choose a reason for hiding this comment

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

Will this exception work for both SDK types?

Copy link
Member

Choose a reason for hiding this comment

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

Btw python supports an exception tuple...for example except (ErrorDetailsException, HttpResponseError):. But one exception type would be preferred.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, this is an issue I was working on yesterday - the azure.core exception import will cause an issue with the older CLI (2.3.1) - I'll have an update on this in a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

So just to follow up, this issue is a bit complex.

  • We switched from ErrorDetailsException to the azure.core.HttpResponseError (base error class) as ErrorDetailsException no longer exists in our Track 2 SDKs.
  • In AZ CLI 2.3.1, however - we don't have the azure.core exceptions
  • The actual exception this will return is a ResourceNotFoundError which also comes from azure.core

Is it pertinent here to catch the specific error type if we're not utilizing the error/exception itself?
I'd like to avoid blanket except: statements (or more try/catch imports) but that might be the easiest fix here.

Copy link
Member

Choose a reason for hiding this comment

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

Good details...my initial thought was if there was a common base exception like Exception we could use but I think the most pragmatic solution is the one you suggest in this specific case having except: since we are not using the exception itself.

else:
self.client = self.cmd
self.sub_id = self.client.config.subscription_id
Copy link
Member

Choose a reason for hiding this comment

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

We may hit a regression here since before sub_id was extracted when the client was initialized and used to build the target dictionary. Might help determine problems if we change this https://github.com/c-ryan-k/azure-iot-cli-extension/blob/sdk_track_2_support/azext_iot/tests/iothub/test_iothub_discovery_int.py#L102 to assert sub_id is not the "unknown" placeholder value.

@digimaun digimaun merged commit 0c9f0f4 into Azure:dev Apr 22, 2021
@c-ryan-k c-ryan-k deleted the sdk_track_2_support branch August 27, 2021 22:28
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.

2 participants