jobs:
- job: 'integration_test_remote_windows'

  steps:
  - script: python -m pip install --upgrade pip setuptools
    displayName: 'Install python tools'
  - task: CopyFilesOverSSH@0
    inputs:
      sshEndpoint: $(end_point)
      targetFolder: /tmp/nnitest/$(Build.BuildId)/nni-remote
      overwrite: true
    displayName: 'Copy all files to remote machine'
  - script: |
      powershell.exe -file install.ps1
    displayName: 'Install nni toolkit via source code'
  - script: |
      python -m pip install scikit-learn==0.20.1 --user
    displayName: 'Install dependencies for integration tests'
  - task: SSH@0
    inputs:
      sshEndpoint: $(end_point)
      runOptions: inline
      inline: cd /tmp/nnitest/$(Build.BuildId)/nni-remote/deployment/pypi;make build
    continueOnError: true
    displayName: 'build nni bdsit_wheel'
  - task: SSH@0
    inputs:
      sshEndpoint: $(end_point)
      runOptions: commands
      commands: python3 /tmp/nnitest/$(Build.BuildId)/nni-remote/test/remote_docker.py --mode start --name $(Build.BuildId) --image nni/nni --os windows
    displayName: 'Start docker'
  - powershell: |
      Write-Host "Downloading Putty..."
      (New-Object Net.WebClient).DownloadFile("https://the.earth.li/~sgtatham/putty/latest/w64/pscp.exe", "$(Agent.TempDirectory)\pscp.exe")
      $(Agent.TempDirectory)\pscp.exe -hostkey $(hostkey) -pw $(pscp_pwd) $(remote_user)@$(remote_host):/tmp/nnitest/$(Build.BuildId)/port test\port
      Get-Content test\port
    displayName: 'Get docker port'
  - powershell: |
      cd test
      python generate_ts_config.py --ts remote --remote_user $(docker_user) --remote_host $(remote_host) --remote_port $(Get-Content port) --remote_pwd $(docker_pwd) --nni_manager_ip $(nni_manager_ip)
      Get-Content training_service.yml
      python config_test.py --ts remote --exclude cifar10,smac,bohb
    displayName: 'integration test'
  - task: SSH@0
    inputs:
      sshEndpoint: $(end_point)
      runOptions: commands
      commands: python3 /tmp/nnitest/$(Build.BuildId)/nni-remote/test/remote_docker.py --mode stop --name $(Build.BuildId) --os windows
    displayName: 'Stop docker'
