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

feat: deviceregistry check and support bundle updates for 0.7.0 #343

Merged
merged 10 commits into from
Sep 12, 2024
3 changes: 1 addition & 2 deletions azext_edge/edge/providers/check/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class DataSourceStageType(ListableEnum):

ASSET_PROPERTIES = [
("description", "Description", True),
("assetType", "Asset Type", False),
("attributes", "Attributes", True),
("defaultDataPointsConfiguration", "Default Data Points Configuration", False),
("defaultDatasetsConfiguration", "Default Dataset Configuration", False),
("defaultEventsConfiguration", "Default Events Configuration", False),
("displayName", "Display Name", False),
("documentationUri", "Documentation Uri", False),
Expand Down
20 changes: 12 additions & 8 deletions azext_edge/edge/providers/check/deviceregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def evaluate_assets(
) -> Dict[str, Any]:
check_manager = CheckManager(check_name="evalAssets", check_desc="Evaluate Device Registry instances")

asset_namespace_conditions = ["spec.assetEndpointProfileUri"]
asset_namespace_conditions = ["spec.assetEndpointProfileRef"]

target_assets = generate_target_resource_name(api_info=DEVICEREGISTRY_API_V1, resource_kind=DeviceRegistryResourceKinds.ASSET.value)

Expand Down Expand Up @@ -119,15 +119,15 @@ def evaluate_assets(
)

asset_spec = asset["spec"]
endpoint_profile_uri = asset_spec.get("assetEndpointProfileUri", "")
endpoint_profile_uri = asset_spec.get("assetEndpointProfileRef", "")
endpoint_profile = get_resources_by_name(
api_info=DEVICEREGISTRY_API_V1,
kind=DeviceRegistryResourceKinds.ASSETENDPOINTPROFILE,
resource_name=endpoint_profile_uri
)
spec_padding = padding + PADDING_SIZE

endpoint_profile_uri_value = {"spec.assetEndpointProfileUri": endpoint_profile_uri}
endpoint_profile_uri_value = {"spec.assetEndpointProfileRef": endpoint_profile_uri}
endpoint_profile_uri_status = CheckTaskStatus.success.value
if endpoint_profile:
endpoint_profile_uri_text = (
Expand All @@ -151,22 +151,26 @@ def evaluate_assets(
)

# data points
data_points = asset_spec.get("dataPoints", [])
# all should be under one dataset
dataset = asset_spec.get("datasets", [])
data_points = []
if dataset:
data_points = dataset[0].get("dataPoints", [])

if data_points:
if not added_datapoint_conditions:
check_manager.add_target_conditions(
target_name=target_assets,
namespace=namespace,
conditions=[
"len(spec.dataPoints)",
"spec.dataPoints.dataSource"
"len(spec.datasets[0].dataPoints)",
"spec.datasets[0].dataPoints.dataSource"
]
)
added_datapoint_conditions = True

data_points_count = len(data_points)
data_points_value = {"len(spec.dataPoints)": data_points_count}
data_points_value = {"len(spec.datasets[0].dataPoints)": data_points_count}
data_points_status = CheckTaskStatus.success.value

if data_points_count > MAX_ASSET_DATAPOINTS:
Expand All @@ -192,7 +196,7 @@ def evaluate_assets(
for index, data_point in enumerate(data_points):
data_point_data_source = data_point.get("dataSource", "")
datapoint_padding = spec_padding + PADDING_SIZE
data_point_data_source_value = {f"spec.dataPoints.[{index}].dataSource": data_point_data_source}
data_point_data_source_value = {f"spec.datasets[0].dataPoints.[{index}].dataSource": data_point_data_source}
data_point_data_source_status = CheckTaskStatus.success.value
if data_point_data_source:
data_point_data_source_text = (
Expand Down
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/edge_api/deviceregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class DeviceRegistryResourceKinds(ListableEnum):


DEVICEREGISTRY_API_V1 = EdgeResourceApi(
group="deviceregistry.microsoft.com", version="v1beta1", moniker="deviceregistry"
group="deviceregistry.microsoft.com", version="v1beta2", moniker="deviceregistry"
)
48 changes: 25 additions & 23 deletions azext_edge/tests/edge/checks/test_deviceregistry_checks_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
"name": "asset-1",
},
"spec": {
"assetEndpointProfileUri": "endpoint",
"assetEndpointProfileRef": "endpoint",
}
},
],
Expand All @@ -77,16 +77,16 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
},
],
# namespace conditions str
["spec.assetEndpointProfileUri"],
["spec.assetEndpointProfileRef"],
# namespace evaluations str
[
[
("status", "success"),
("value/spec.assetEndpointProfileUri", "endpoint"),
("value/spec.assetEndpointProfileRef", "endpoint"),
],
]
),
# assetEndpointProfileUri not present
# assetEndpointProfileRef not present
(
# assets
[
Expand All @@ -101,12 +101,12 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
# asset_endpoint_profiles
[],
# namespace conditions str
["spec.assetEndpointProfileUri"],
["spec.assetEndpointProfileRef"],
# namespace evaluations str
[
[
("status", "error"),
("value/spec.assetEndpointProfileUri", ''),
("value/spec.assetEndpointProfileRef", ''),
],
]
),
Expand All @@ -119,13 +119,15 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
"name": "asset-1",
},
"spec": {
"assetEndpointProfileUri": "endpoint",
"dataPoints": [
{
"name": "datapoint-1",
"type": "double",
},
],
"assetEndpointProfileRef": "endpoint",
"datasets": [{
"dataPoints": [
{
"name": "datapoint-1",
"type": "double",
},
],
}]
}
},
],
Expand All @@ -141,20 +143,20 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
},
],
# namespace conditions str
["spec.assetEndpointProfileUri", 'len(spec.dataPoints)'],
["spec.assetEndpointProfileRef", 'len(spec.datasets[0].dataPoints)'],
# namespace evaluations str
[
[
("status", "success"),
("value/spec.assetEndpointProfileUri", 'endpoint'),
("value/spec.assetEndpointProfileRef", 'endpoint'),
],
[
("status", "success"),
("value/len(spec.dataPoints)", 1),
("value/len(spec.datasets[0].dataPoints)", 1),
],
[
("status", "error"),
("value/spec.dataPoints.[0].dataSource", ""),
("value/spec.datasets[0].dataPoints.[0].dataSource", ""),
],
]
),
Expand Down Expand Up @@ -183,7 +185,7 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
"name": "asset-1",
},
"spec": {
"assetEndpointProfileUri": "endpoint",
"assetEndpointProfileRef": "endpoint",
"status": {
"errors": [
{
Expand All @@ -207,12 +209,12 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
},
],
# namespace conditions str
["spec.assetEndpointProfileUri", "spec.status"],
["spec.assetEndpointProfileRef", "spec.status"],
# namespace evaluations str
[
[
("status", "success"),
("value/spec.assetEndpointProfileUri", 'endpoint'),
("value/spec.assetEndpointProfileRef", 'endpoint'),
],
[
("status", "error"),
Expand All @@ -229,7 +231,7 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
"name": "asset-1",
},
"spec": {
"assetEndpointProfileUri": "endpoint",
"assetEndpointProfileRef": "endpoint",
"events": [
{
"name": "event-1",
Expand All @@ -250,12 +252,12 @@ def test_check_deviceregistry_by_resource_types(ops_service, mocker, mock_resour
},
],
# namespace conditions str
["spec.assetEndpointProfileUri", "len(spec.events)"],
["spec.assetEndpointProfileRef", "len(spec.events)"],
# namespace evaluations str
[
[
("status", "success"),
("value/spec.assetEndpointProfileUri", 'endpoint'),
("value/spec.assetEndpointProfileRef", 'endpoint'),
],
[
("status", "success"),
Expand Down