Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
83 stars 65 forks source link

'az iot central device command run' Throws Internal Error #361

Open scout208 opened 3 years ago

scout208 commented 3 years ago

Describe the bug

Trying to run the GetModuleLogs command on an IoT Central device throws an exception. See the trace below.

Command Name az iot central device command run Extension Name: azure-iot. Version: 0.10.11.

Errors:

[Errno 2] No such file or directory: '\\'
Traceback (most recent call last):
Temp\pip-unpacked-wheel-rpp6y7vh\knack\cli.py, ln 215, in invoke
cli\core\commands\__init__.py, ln 659, in execute
cli\core\commands\__init__.py, ln 722, in _run_jobs_serially
cli\core\commands\__init__.py, ln 715, in _run_job
Local\Temp\pip-unpacked-wheel-igh1xymj\six.py, ln 703, in reraise
cli\core\commands\__init__.py, ln 693, in _run_job
cli\core\commands\__init__.py, ln 330, in __call__
...
    content = read_file_content(content)
azure-iot\azext_iot\common\utility.py, ln 174, in read_file_content
    with codecs_open(file_path, encoding=encoding) as f:
codecs.py, ln 897, in open
FileNotFoundError: [Errno 2] No such file or directory: '\\'

To Reproduce:

Expected Behavior

This command should return the logs from the module.

Environment Summary

Windows-10-10.0.19041-SP0
Python 3.6.8
Installer: MSI

azure-cli 2.17.1 *

Extensions:
azure-iot 0.10.11

Additional Context

digimaun commented 3 years ago

@valluriraj @yang-hai-feng @prbans

yang-hai-feng commented 3 years ago

@scout208, the error looks like shows can't read input file, can you try to create a local json file(request.json) with

{
  "schemaVersion": "1.0",
   "items": [
     {
       "id": "$edgeAgent",
       "filter": {
         "tail": 10
       }
     }
   ],
   "encoding": "none",
   "contentType": "text"
}

Execute command az iot central device command run -n {appid} -d {deviceid} -i {interfaceid} --cn 'GetModuleLogs' -k "request.json"

BTW, would you please also provide the request id that CLI output?

scout208 commented 3 years ago

@yang-hai-feng I've tried it with a file instead and now I'm getting this response:

{'code': 'NotFound', 'message': 'The requested resource was not found. You can contact support at https://aka.ms/iotcentral-support. Please include the following information. Request ID: 1rdzkqj5, Time: Thu, 03 Jun 2021 23:02:01 GMT.', 'requestId': '1rdzkqj5', 'time': 'Thu, 03 Jun 2021 23:02:01 GMT'}

Unfortunately I closed my old Powershell session and I can't find the request ID of my original request. But, changing it to a file payload seems to have gotten a different result anyways.

yang-hai-feng commented 3 years ago

Checked the backend logs, looks like the resource was not found for "b0qynpqqpkv", is "b0qynpqqpkv" your device id or interface name?

scout208 commented 3 years ago

That's my interface id I got from the device template

yang-hai-feng commented 3 years ago

@scout208, would you please share with me your device template? try to figure out the root cause, but all my local created template is working.

scout208 commented 3 years ago

@yang-hai-feng Yes, is there a way to download it somehow? I only know how to access it through the web portal and I'd like to avoid having to screenshot every page if possible.

yang-hai-feng commented 3 years ago

image

Click on your device template name, and choose the top level of the model, click export, if it's not feasible to share here, you can send to my email: hayang@microsoft.com.

scout208 commented 3 years ago

Okay here is my device template:

[
  {
    "@id": "dtmi:d8bbddxvps:capabilitymodel:b0qynpqqpkv;4",
    "@type": "Interface",
    "contents": [
      {
        "@id": "dtmi:d8bbddxvps:capabilitymodel:b0qynpqqpkv:ZeroPositions;1",
        "@type": [
          "Relationship",
          "EdgeModule"
        ],
        "displayName": {
          "en": "ZeroPositions"
        },
        "maxMultiplicity": 1,
        "name": "ZeroPositions",
        "target": [
          "dtmi:d8bbddxvps:ZeroPositions;1"
        ]
      },
      {
        "@id": "dtmi:d8bbddxvps:capabilitymodel:b0qynpqqpkv:License;1",
        "@type": [
          "Relationship",
          "EdgeModule"
        ],
        "displayName": {
          "en": "License"
        },
        "maxMultiplicity": 1,
        "name": "License",
        "target": [
          "dtmi:d8bbddxvps:License;1"
        ]
      }
    ],
    "displayName": {
      "en": "Azure IoT Edge Capability Model b0qynpqqpkv"
    },
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ]
  },
  {
    "@id": "dtmi:d8bbddxvps:ZeroPositions;1",
    "@type": "Interface",
    "contents": [],
    "displayName": {
      "en": "Module ZeroPositions"
    },
    "extends": [
      "dtmi:d8bbddxvps:ZeroPositions:manage;1"
    ],
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ]
  },
  {
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ],
    "@id": "dtmi:d8bbddxvps:ZeroPositions:manage;1",
    "@type": [
      "Interface",
      "NamedInterface"
    ],
    "contents": [
      {
        "@id": "dtmi:d8bbddxvps:ZeroPositions:manage:YawZero;1",
        "@type": "Property",
        "displayName": {
          "en": "YawZero"
        },
        "name": "YawZero",
        "schema": "double",
        "writable": true
      },
      {
        "@id": "dtmi:d8bbddxvps:ZeroPositions:manage:PitchZero;1",
        "@type": "Property",
        "displayName": {
          "en": "PitchZero"
        },
        "name": "PitchZero",
        "schema": "double",
        "writable": true
      },
      {
        "@id": "dtmi:d8bbddxvps:ZeroPositions:manage:RotatorZero;1",
        "@type": "Property",
        "displayName": {
          "en": "RotatorZero"
        },
        "name": "RotatorZero",
        "schema": "double",
        "writable": true
      },
      {
        "@id": "dtmi:d8bbddxvps:ZeroPositions:manage:FeedZero;1",
        "@type": "Property",
        "displayName": {
          "en": "FeedZero"
        },
        "name": "FeedZero",
        "schema": "double",
        "writable": true
      }
    ],
    "displayName": {
      "en": "Manage"
    },
    "name": "management"
  },
  {
    "@id": "dtmi:d8bbddxvps:License;1",
    "@type": "Interface",
    "contents": [],
    "displayName": {
      "en": "Module License"
    },
    "extends": [
      "dtmi:d8bbddxvps:License:manage;1"
    ],
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ]
  },
  {
    "@context": [
      "dtmi:iotcentral:context;2",
      "dtmi:dtdl:context;2"
    ],
    "@id": "dtmi:d8bbddxvps:License:manage;1",
    "@type": [
      "Interface",
      "NamedInterface"
    ],
    "contents": [
      {
        "@id": "dtmi:d8bbddxvps:License:manage:Type;1",
        "@type": "Property",
        "displayName": {
          "en": "Type"
        },
        "name": "Type",
        "schema": "string",
        "writable": true
      },
      {
        "@id": "dtmi:d8bbddxvps:License:manage:ExpirationDate;1",
        "@type": "Property",
        "displayName": {
          "en": "ExpirationDate"
        },
        "name": "ExpirationDate",
        "schema": "string",
        "writable": true
      },
      {
        "@id": "dtmi:d8bbddxvps:License:manage:IsActive;1",
        "@type": "Property",
        "displayName": {
          "en": "IsActive"
        },
        "name": "IsActive",
        "schema": "boolean",
        "writable": true
      }
    ],
    "displayName": {
      "en": "Manage"
    },
    "name": "management"
  }
]
yang-hai-feng commented 3 years ago

@scout208 , Edge command is not supported in CLI today, we are still working on this feature support, will get you updated once the new version released.

yang-hai-feng commented 2 years ago

@scout208, we just released edge support a recent version of CLI extensions which had edge support on device, please check az iot central device edge -h on latest iot extensions.

Docs: https://docs.microsoft.com/en-us/cli/azure/iot/central/device/edge?view=azure-cli-latest