microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
382 stars 244 forks source link

Run-BCPTTestsInBcContainer fails when run in a current version sandbox container #3013

Closed amea20 closed 1 year ago

amea20 commented 1 year ago

Describe the issue When running the command Run-BCPTTestsInBcContainer in a BC22 sandbox container, I receive an error relating to an updated Microsoft.IdentityModel.Clients.ActiveDirectory.dll file which does not have the Microsoft.IdentityModel.Clients.ActiveDirectory.UserPasswordCredential

Scripts used to create container and cause the issue

$containerName = "bc"
$artifactUrl = Get-BCArtifactUrl -type Sandbox -select Current -country w1
$userName = "bcadmin"
$password = ConvertTo-SecureString -String "Passwordhere" -AsPlainText -Force
$credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $userName, $password
$licenseFileUri = 'C:\Licenses\BC22-License.bclicense'

New-BcContainer -accept_eula -accept_outdated `
        -containerName $containerName `
        -artifactUrl $artifactUrl `
        -auth NAVUserPassword `
        -Credential $credential `
        -memoryLimit 20G `
        -updateHosts `
        -doNotExportObjectsToText `
        -doNotCheckHealth `
        -shortcuts None `
        -includeAL `
        -licenseFile $licenseFileUri `
        -useBestContainerOS

$bcptSuite = Get-Content -Path "C:\Temp\bcptSuite.json" | ConvertFrom-Json
Run-BCPTTestsInBcContainer -containerName $containerName -credential $credential -BCPTSuite $bcptSuite -connectFromHost

Full output of scripts

Get-BCArtifactUrl -type sandbox -select Current -country w1 
Get-BcContainerId Telemetry Correlation Id: b5ca6376-8e95-4af2-bdfe-b9cabe2871f9
Create BC from https://bcartifacts.azureedge.net/sandbox/22.0.54157.55895/w1 using more recent image
BcContainerHelper is version 4.0.16
BcContainerHelper is running as administrator
HyperV is Disabled
UsePsSession is True
Host is Microsoft Windows Server 2022 Datacenter - 10.0.20348.1668
Docker Client Version is 20.10.9
Docker Server Version is 20.10.9
Removing Desktop shortcuts
Downloading application artifact /sandbox/22.0.54157.55895/w1
Downloading C:\Users\AzDevOps\AppData\Local\Temp\2599f6e9-6d0b-4d72-b91b-d6ec11c865e4.zip
Downloading using WebClient
Unpacking application artifact to tmp folder using Expand-Archive
Downloading platform artifact /sandbox/22.0.54157.55895/platform
https://bcartifacts.azureedge.net/sandbox/22.0.54157.55895/platform
Downloading C:\Users\AzDevOps\AppData\Local\Temp\c172c031-410e-455a-93cb-88fb727586ec.zip
Downloading using WebClient
Unpacking platform artifact to tmp folder using Expand-Archive
Downloading Prerequisite Components
Downloading c:\bcartifacts.cache\sandbox\22.0.54157.55895\platform\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw_x64.msi
Downloading using WebClient
Downloading c:\bcartifacts.cache\sandbox\22.0.54157.55895\platform\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-WindowsHosting.exe
Downloading using WebClient
Fetching all docker images
Fetching all docker volumes
ArtifactUrl and ImageName specified
Fetching all docker images
Building image bc_sandbox_w1:22.0.54157.55895 based on mcr.microsoft.com/businesscentral:10.0.20348.1668 with https://bcartifacts.azureedge.net/sandbox/22.0.54157.55895/w1
Pulling latest image mcr.microsoft.com/businesscentral:10.0.20348.1668
10.0.20348.1668: Pulling from businesscentral
Status: Downloaded newer image for mcr.microsoft.com/businesscentral:10.0.20348.1668
mcr.microsoft.com/businesscentral:10.0.20348.1668
Generic Tag: 1.0.2.14
Container OS Version: 10.0.20348.1668 (ltsc2022)
Host OS Version: 10.0.20348.1668 (ltsc2022)
Using process isolation
Using license file BC22-License.bclicense
Files in c:\bcartifacts.cache\egyilz22.fpv\my:
Copying Platform Artifacts
c:\bcartifacts.cache\sandbox\22.0.54157.55895\platform
Copying Database
Copying Licensefile
Copying Extensions
C:\bcartifacts.cache\sandbox\22.0.54157.55895\w1\Extensions
c:\bcartifacts.cache\egyilz22.fpv
Sending build context to Docker daemon   2.32GB
Step 1/6 : FROM mcr.microsoft.com/businesscentral:10.0.20348.1668
 ---> 8e310f667bf7
Step 2/6 : ENV DatabaseServer=localhost DatabaseInstance=SQLEXPRESS DatabaseName=CRONUS IsBcSandbox=Y artifactUrl=https://bcartifacts.azureedge.net/sandbox/22.0.54157.55895/w1 filesOnly=False
 ---> Running in 9e7de5059a38
Removing intermediate container 9e7de5059a38
 ---> 07e58f3a489e
Step 3/6 : COPY my /run/
 ---> bfb352d4a5a1
Step 4/6 : COPY NAVDVD /NAVDVD/
 ---> e15fe901fddd
Step 5/6 : RUN \Run\start.ps1 -installOnly -multitenant
 ---> Running in 19afdd564492
c:\run\my folder doesn't exist, creating it
Using installer from C:\Run\210-new
Installing Business Central
Installing from DVD
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
C:\NAVDVD\ServiceTier\Program Files
C:\NAVDVD\ServiceTier\System64Folder
Copying PowerShell Scripts
C:\NAVDVD\WindowsPowerShellScripts\Cloud\NAVAdministration
C:\NAVDVD\WindowsPowerShellScripts\WebSearch
Copying Web Client Files
C:\NAVDVD\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
C:\NAVDVD
C:\NAVDVD\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\NAVDVD\ConfigurationPackages
Copying Test Assemblies
C:\NAVDVD\Test Assemblies
Copying Extensions
C:\NAVDVD\Extensions
Copying Applications
C:\NAVDVD\Applications
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing CRONUS license file
Copying Database on localhost\SQLEXPRESS from tenant to default
Taking database tenant offline
Copying database files
Attaching files as new Database default
Putting database tenant back online
Mounting tenant database
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Stopping Business Central Service Tier
Installation took 204 seconds
Installation complete
Removing intermediate container 19afdd564492
 ---> d06d2378d644
Step 6/6 : LABEL legal="http://go.microsoft.com/fwlink/?LinkId=837447"       created="202304261909"       nav=""       cu=""       multitenant="Y"       country="W1"       version="22.0.54157.55895"       platform="22.0.55820.0"
 ---> Running in a158392abe3c
Removing intermediate container a158392abe3c
 ---> 431e98e6c01a
Successfully built 431e98e6c01a
Successfully tagged bc_sandbox_w1:22.0.54157.55895
Building image took 695 seconds
Using image bc_sandbox_w1:22.0.54157.55895
Disabling Health Check (always report healthy)
Creating Container BC
Style: sandbox
Multitenant: Yes
Version: 22.0.54157.55895
Platform: 22.0.55820.0
Generic Tag: 1.0.2.14
Container OS Version: 10.0.20348.1668 (ltsc2022)
Host OS Version: 10.0.20348.1668 (ltsc2022)
Using process isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file BC22-License.bclicense
Additional Parameters:
--volume "C:\a:C:\Agents"
Files in C:\ProgramData\BcContainerHelper\Extensions\BC\my:
- AdditionalOutput.ps1
- license.bclicense
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container BC from image bc_sandbox_w1:22.0.54157.55895
ecd0986d84c342580a03097329ea74608a03a1907a5a31e06fd3f082164a8610
Waiting for container BC to be ready
Initializing...
Setting host.containerhelper.internal to 172.19.48.1 in container hosts file
Starting Container
Hostname is BC
PublicDnsName is BC
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 28404991E39FF256B0A624AA838C9EE44FB79729
DNS identity BC
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: BC
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\BC
Create the application pool BC
Create website: NavWebApplicationContainer without SSL
Update configuration: navsettings.json
Done Configuring Web Client
Enabling Financials User Experience
Using license file 'c:\run\my\license.bclicense'
Import License
Dismounting Tenant
Mounting Tenant
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Creating http download site
Setting SA Password and enabling SA
Creating BCADMIN as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.19.50.161
Container Hostname  : BC
Container Dns Name  : BC
Web Client          : http://BC/BC/?tenant=default
Dev. Server         : http://BC
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting BC to 172.19.50.161 in host hosts file
Setting BC-default to 172.19.50.161 in host hosts file
Setting BC-default to 172.19.50.161 in container hosts file

Files:
http://BC:8080/ALLanguage.vsix

Container Total Physical Memory is 64.0Gb
Container Free Physical Memory is 57.4Gb

Initialization took 38 seconds
Ready for connections!
Reading CustomSettings.config from BC
Cleanup old dotnet core assemblies
Creating .net Assembly Reference Folder
Copying DLLs from C:\Program Files\Microsoft Dynamics NAV\220\Service to assemblyProbingPath
Copying DLLs from C:\Test Assemblies\Mock Assemblies to assemblyProbingPath
Removing dotnet Framework Assemblies
Container BC successfully created

Using CompanyName Baseline
Invoke GET on http://172.19.50.161:7048/BC/api/v1.0/companies?$filter=name%20eq%20'Baseline'&tenant=default
Using Company ID 89478aeb-67e4-ed11-a8ea-c05fd7e87e9f
Invoke POST on http://172.19.50.161:7048/BC/api/Microsoft/PerformancToolkit/v1.0/companies(89478aeb-67e4-ed11-a8ea-c05fd7e87e9f)/bcptSuites?tenant=default
Using testpage 149002
Using Suitecode PERFTEST
Service Url http://BC/BC/cs/?tenant=default&company=Baseline
Running Performance Tests for 5 minutes...
Running performance test failed
The passed path for -BCPTTestRunnerInternalFolderPath seem to be relative path, converting to absolute.
Absolute path is C:\ProgramData\BcContainerHelper\extensions\BC\my\TestRunner\Internal
Importing AL Test Runner from C:\ProgramData\BcContainerHelper\extensions\BC\my\TestRunner\Internal\BCPTTestRunnerInternal.psm1
WARNING: The names of some imported commands from the module 'ALTestRunnerInternal' include unapproved verbs that might
 make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the 
Verbose parameter. For a list of approved verbs, type Get-Verb.
Run-BCPTTestsInBcContainer Telemetry Correlation Id: c914eb98-33e2-4e7d-9a78-2e0080e61447
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to 
Stop: At C:\ProgramData\BcContainerHelper\extensions\BC\my\TestRunner\Internal\AadTokenProvider.ps1:59 char:35
+ ... edential = [Microsoft.IdentityModel.Clients.ActiveDirectory.UserPassw ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [Microsoft.IdentityModel.Clients.ActiveDirectory.UserPasswordCredential].
    + CategoryInfo          : ParserError: (:) [], ActionPreferenceStopException
    + FullyQualifiedErrorId : TypeNotFound
    + PSComputerName        : localhost

...

Screenshots none

Additional context

freddydk commented 1 year ago

This is a problem with BC 22 artifacts - will find a workaround that can be applied during New-BcContainer - it also doesn't work if you use the downloaded DVD image

amea20 commented 1 year ago

Much appreciated Freddy!

freddydk commented 1 year ago

Next prerelease will have a fix for 22.0 and 22.1 - assuming that the bug will be fixed before 22.2 BTW - the patch is during Download-Artifacts - you will need to flush the artifacts cache before re-running.

freddydk commented 1 year ago

Shipped in 5.0.0