-
Notifications
You must be signed in to change notification settings - Fork 66
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
Changes from 5 commits
d5dce83
53c6718
d07576b
6bdb721
2a58430
5b2d66d
7433c2c
5efdd3d
a39d4ac
b45cd89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should prefix this with |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,13 @@ | |
|
||
from knack.util import CLIError | ||
from knack.log import get_logger | ||
from azext_iot.common.utility import trim_from_start | ||
from azure.cli.core.commands.client_factory import get_subscription_id | ||
from azext_iot.common.utility import trim_from_start, ensure_min_version | ||
from azext_iot.iothub.models.iothub_target import IotHubTarget | ||
from azext_iot._factory import iot_hub_service_factory | ||
from azext_iot.constants import TRACK_2_SDK_MIN_VERSION | ||
from typing import Dict, List | ||
from enum import Enum, EnumMeta | ||
|
||
PRIVILEDGED_ACCESS_RIGHTS_SET = set( | ||
["RegistryWrite", "ServiceConnect", "DeviceConnect"] | ||
|
@@ -30,9 +33,9 @@ def _initialize_client(self): | |
if not self.client: | ||
if getattr(self.cmd, "cli_ctx", None): | ||
self.client = iot_hub_service_factory(self.cmd.cli_ctx) | ||
self.sub_id = get_subscription_id(self.cmd.cli_ctx) | ||
else: | ||
self.client = self.cmd | ||
self.sub_id = self.client.config.subscription_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may hit a regression here since before |
||
|
||
def get_iothubs(self, rg: str = None) -> List: | ||
self._initialize_client() | ||
|
@@ -44,11 +47,15 @@ def get_iothubs(self, rg: str = None) -> List: | |
else: | ||
hubs_pager = self.client.list_by_resource_group(resource_group_name=rg) | ||
|
||
try: | ||
while True: | ||
hubs_list.extend(hubs_pager.advance_page()) | ||
except StopIteration: | ||
pass | ||
if ensure_min_version(TRACK_2_SDK_MIN_VERSION): | ||
for hubs in hubs_pager.by_page(): | ||
hubs_list.extend(hubs) | ||
else: | ||
try: | ||
while True: | ||
hubs_list.extend(hubs_pager.advance_page()) | ||
except StopIteration: | ||
pass | ||
|
||
return hubs_list | ||
|
||
|
@@ -60,23 +67,27 @@ def get_policies(self, hub_name: str, rg: str) -> List: | |
) | ||
policy_list = [] | ||
|
||
try: | ||
while True: | ||
policy_list.extend(policy_pager.advance_page()) | ||
except StopIteration: | ||
pass | ||
if ensure_min_version(TRACK_2_SDK_MIN_VERSION): | ||
for policy in policy_pager.by_page(): | ||
policy_list.extend(policy) | ||
else: | ||
try: | ||
while True: | ||
policy_list.extend(policy_pager.advance_page()) | ||
except StopIteration: | ||
pass | ||
|
||
return policy_list | ||
|
||
def find_iothub(self, hub_name: str, rg: str = None): | ||
self._initialize_client() | ||
|
||
from azure.mgmt.iothub.models import ErrorDetailsException | ||
from azure.core.exceptions import HttpResponseError | ||
|
||
if rg: | ||
try: | ||
return self.client.get(resource_group_name=rg, resource_name=hub_name) | ||
except ErrorDetailsException: | ||
except HttpResponseError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this exception work for both SDK types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw python supports an exception tuple...for example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, this is an issue I was working on yesterday - the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So just to follow up, this issue is a bit complex.
Is it pertinent here to catch the specific error type if we're not utilizing the error/exception itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
raise CLIError( | ||
"Unable to find IoT Hub: {} in resource group: {}".format( | ||
hub_name, rg | ||
|
@@ -186,7 +197,7 @@ def _build_target( | |
target["subscription"] = self.sub_id | ||
target["resourcegroup"] = iothub.additional_properties.get("resourcegroup") | ||
target["location"] = iothub.location | ||
target["sku_tier"] = iothub.sku.tier.value | ||
target["sku_tier"] = iothub.sku.tier.value if isinstance(iothub.sku.tier, (Enum, EnumMeta)) else iothub.sku.tier | ||
|
||
if include_events: | ||
events = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make this longer? Or is 5 second sleep consistently working. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 The error was because our test tried to cancel a job before it transitioned from |
||
|
||
self.cmd( | ||
"iot hub job show --job-id {} -n {} -g {}".format( | ||
self.job_ids[2], LIVE_HUB, LIVE_RG | ||
), | ||
checks=[ | ||
self.check("jobId", self.job_ids[2]), | ||
self.check("status", "scheduled"), | ||
], | ||
) | ||
|
||
# Cancel job | ||
self.cmd( | ||
"iot hub job cancel --job-id {} -n {} -g {}".format( | ||
self.job_ids[2], LIVE_HUB, LIVE_RG | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need setuptools anymore? |
||
|
||
|
||
CLASSIFIERS = [ | ||
|
There was a problem hiding this comment.
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.