Skip to content

Commit

Permalink
Fix installed criteria error in example proxy updates (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nox-MSFT authored and jw-msft committed Apr 14, 2022
1 parent 8a13a99 commit ebf7b8c
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 1,483 deletions.
@@ -1,69 +1,16 @@
# Device Update for Azure IoT Hub tutorial using the Device Update agent to do Proxy Updates

## How To Import Example Updates
## Generate Example Updates

> Requirement: perform these steps on machine that supports PowerShell
### Import Example Updates using PowerShell scripts

#### Install and Import ADU PowerShell Modules

- Install PowerShellGet [see details here](https://docs.microsoft.com/en-us/powershell/scripting/gallery/installing-psget?view=powershell-7.1)

```powershell
Install-PackageProvider -Name NuGet -Force
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Install-Module -Name PowerShellGet -Force -AllowClobber
Update-Module -Name PowerShellGet
```

- Install Azure Az PowerShell Modules

```powershell
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
```

- Create storage account
- Get container for updates storage

For example:

```powershell
Import-Module .\AduAzStorageBlobHelper.psm1
Import-Module .\AduImportUpdate.psm1
$AzureSubscriptionId = '<YOUR SUBSCRIPTION ID>'
$AzureResourceGroupName = '<YOUR RESOURCE GROUP NAME>'
$AzureStorageAccountName = '<YOUR STORAGE ACCOUNT>'
$AzureBlobContainerName = '<YOUR BLOB CONTAINER NAME>'
$container = Get-AduAzBlobContainer -SubscriptionId $AzureSubscriptionId -ResourceGroupName $AzureResourceGroupName -StorageAccountName $AzureStorageAccountName -ContainerName $AzureBlobContainerName
```

- Get REST API token
Open PowerShell terminal, go [[project-root]/tools/AduCmdlets](../../../../../../tools/AduCmdlets/) directory, then import AduUpdate.psm1 module:

```powershell
Install-Module MSAL.PS
$AzureAdClientId = '<AZURE AD CLIENT ID>'
$AzureAdTenantId = '<AZURE AD TENANT ID>'
$token = Get-MsalToken -ClientId $AzureAdClientId -TenantId $AzureAdTenantId -Scopes 'https://api.adu.microsoft.com/user_impersonation' -Authority https://login.microsoftonline.com/$AzureAdTenantId/v2.0
Import-Module ./AduUpdate.psm1
```

#### Generate Example Updates
Next, go to [sample-updates](./sample-updates/) directory, then run following commands to generate **all** example updates:

Go to `sample-updates` directory, then run following commands to generate **all** example updates.
Note that you can choose to generate only updates you want to try.
> NOTE | You can choose to generate only updates you want to try.
```powershell
./CreateSampleMSOEUpdate-1.x.ps1
Expand All @@ -77,28 +24,6 @@ Note that you can choose to generate only updates you want to try.
./CreateSampleMSOEUpdate-10.x.ps1
```

#### Import Example Updates

Import generated example update using the IoT Hub Device Update portal.

Or, try one of the provided PowerShell scripts below:

```powershell
./ImportSampleMSOEUpdate-1.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
./ImportSampleMSOEUpdate-2.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
./ImportSampleMSOEUpdate-3.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
./ImportSampleMSOEUpdate-4.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
./ImportSampleMSOEUpdate-5.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
./ImportSampleMSOEUpdate-10.x.ps1 -AccountEndpoint <your account endpoint url> -InstanceId <your instant id> -BlobContainer $container -AuthorizationToken $token.AccessToken -Verbose
```

## Setup Test Device

### Prerequisites
Expand Down Expand Up @@ -131,6 +56,9 @@ e.g.
Note: this will automatically install the delivery-optimization-agent package from packages.microsoft.com

- Specify a connection string in /etc/adu/du-config.json

>NOTE | The current example only compatible with device with "contoso" manufacturer, and "virtual-vacuum-v1" model. These values must be correctly set inside `agents` entry in du-config.json
- Ensure that /etc/adu/du-diagnostics-config.json contain correct settings.
e.g.

Expand Down Expand Up @@ -168,7 +96,7 @@ For testing and demonstration purposes, we'll be creating following mock compone
**IMPORTANT**
This components configuration depends on the implementation of an example Component Enumerator extension called libcontoso-component-enumerator.so, which required a mock component inventory data file `/usr/local/contoso-devices/components-inventory.json`

> Tip: you can copy [`demo`](../demo) folder to your home directory on the test VM and run `~/demo/tools/reset-demo-components.sh` to copy required files to the right locations.
> Tip: you can copy [demo](../demo) folder to your home directory on the test VM and run `~/demo/tools/reset-demo-components.sh` to copy required files to the right locations.
#### Add /usr/local/contoso-devices/components-inventory.json

Expand Down
Expand Up @@ -91,7 +91,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='missing-contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-0"; `
'installedCriteria'="$RefUpdateVersion"; `
'arguments'="--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -102,7 +102,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile, $cameraFirmwareFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-1"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--firmware-file camera-firmware-1.1.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -113,7 +113,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-2"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand Down Expand Up @@ -236,7 +236,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-0"; `
'installedCriteria'="$RefUpdateVersion"; `
'arguments'="--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -248,7 +248,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile, $cameraFirmwareFile `
-HandlerProperties @{ `
'scriptFileName'='missing-contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-1"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--firmware-file camera-firmware-1.1.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -259,7 +259,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-2"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand Down Expand Up @@ -382,7 +382,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-0"; `
'installedCriteria'="$RefUpdateVersion"; `
'arguments'="--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -393,7 +393,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile, $cameraFirmwareFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-1"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--firmware-file camera-firmware-1.1.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -405,7 +405,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='missing-contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-2"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand Down Expand Up @@ -529,7 +529,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-0"; `
'installedCriteria'="$RefUpdateVersion"; `
'arguments'="--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -540,7 +540,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile, $cameraFirmwareFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-1"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--firmware-file camera-firmware-1.1.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -551,7 +551,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $cameraScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-camera-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-2"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand Down
Expand Up @@ -93,7 +93,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $steamerScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-steamer-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-0"; `
'installedCriteria'="$RefUpdateVersion"; `
'arguments'="--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -104,7 +104,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $steamerScriptFile, $steamerFirmwareFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-steamer-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-1"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--firmware-file steamer-firmware-$steamersFirmwareVersion.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand All @@ -115,7 +115,7 @@ Write-Host "Preparing update $parentUpdateIdStr ..."
-Files $steamerScriptFile `
-HandlerProperties @{ `
'scriptFileName'='contoso-steamer-installscript.sh'; `
'installedCriteria'="$RefUpdateManufacturer-$RefUpdateName-$RefUpdateVersion-step-2"; `
'installedCriteria'="$RefUpdateVersion"; `
"arguments"="--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path" `
} `
`
Expand Down

0 comments on commit ebf7b8c

Please sign in to comment.