test-kitchen / kitchen-google

Google Compute Engine driver for Test-Kitchen
Other
47 stars 39 forks source link

'Preparing modules for first use' Causing Tests to Fail #45

Closed kevinjpickard closed 7 years ago

kevinjpickard commented 7 years ago

I'm having trouble getting Powershell scripts to run in Windows VMs on GCE. I can run the exact same test suite locally, and everything works fine. I think the only significant differences between these failures and my local environment are the driver (kitchen-google) and the images, which are the default Windows Server images from google (2012 R2 and 2016 currently, but will expand to include other versions later, including Desktop variants).

I'm not using Chef or other configuration management tools, just serverspec and rspec. Here is the .kitchen.yml file I am using for these tests:

---
driver:
  name: gce
  project: jumpcloud-policies
  email: <%= ENV['KITCHEN_GCE_EMAIL'] %>
  machine_type: f1-micro
  service_account_name: <%= ENV['KITCHEN_GCE_EMAIL'] %>
  tags:
    - travis-ci
    - test-kitchen
  service_account_scopes:
    - https://www.googleapis.com/auth/compute # Full control access to Google Compute Engine methods.
  zone: us-central1-b

provisioner:
  data_path: "." # Syncs files in path to /tmp/kitchen/data
  name: chef_zero
  require_chef_omnibus: <%= ENV['CHEF_VERSION'] || '12.10.24' %>
  attributes:
    kitchen:
      data_path: <%= ENV['KITCHEN_DATA_PATH'] || '' %>
      win_data_path: <%= ENV['KITCHEN_DATA_WIN_PATH'] || '' %>

transport:
  name: sftp
  connection_timeout: 1200
  username: <%= ENV['KITCHEN_GCE_USERNAME'] %>
  ssh_key:
    - <%= ENV['KITCHEN_GCE_SSH_KEY_FILE'] %>

platforms:
  - name: windows-server-2012
    shell_type: powershell
    driver:
      image_name: windows-server-2012-r2-dc-v20160809
      machine_type: n1-standard-2
      disk_size: 50
    transport:
      name: winrm
      username: travis
      winrm_transport: ssl
      port: 5986

  - name: windows-server-2016
    shell_type: powershell
    driver:
      image_name: windows-server-2016-dc-v20170509
      machine_type: n1-standard-2
      disk_size: 50
    transport:
      name: winrm
      username: travis
      winrm_transport: ssl
      port: 5986

Note that there are also linux boxes defined, which is why the transport is overridden in the windows platforms.

The powershell scripts I am running are pretty simple, just setting a couple of registry keys each. Here is the general form:

$registryPath = <path>

$Name = <key>

$value = <value>

If(!(Test-Path $registryPath))
{
    New-Item -Path $registryPath -Force | Out-Null

    New-ItemProperty -Path $registryPath -Name $name -Value $value `
    -PropertyType DWORD -Force | Out-Null
}
Else
{
    Set-ItemProperty -Path $registryPath -Name $name -Value $value | Out-Null
}

This is obviously not the exact script, and there are a couple different ones that I'm seeing this error with, but they all follow this general format. Unless I am mistaken, I do not believe this is anything fancy, and I believe that these cmdlets are included with vanilla Powershell.

Again, I can also run these tests in local VMs using a second .kitchen.yml file, which is:

---
driver:
  name: vagrant
  synced_folders:
    - ['.', '/home/vagrant']
  ssh_key: ~/.vagrant.d/insecure_private_key
  ssh:
    insert_key: false

provisioner:
  name: chef_zero
  require_chef_omnibus: <%= ENV['CHEF_VERSION'] || '12.10.24' %>
  attributes:
    vagrant: true
    kitchen:
      data_path: <%= ENV['KITCHEN_DATA_PATH'] || '' %>
      win_data_path: C:\home\vagrant\windows

platforms:
  - name: windows-2012r2
    shell_type: powershell
    transport:
      name: winrm

verifier:
  shell:
    command: bundle exec rspec
    sudo: true

suites:
  - name: default
    run_list:
    attributes:

So when I run the tests locally, everything passes and I have no issues. When I push to github and travis kicks off the build (or I override the kitchen file to the one which points to GCE) I get the following message:

<path_to_ps_script>
       #< CLIXML
       <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
            # C:/Users/travis/AppData/Local/Temp/verifier/suites/serverspec/feature/remove_spec.rb:37:in `block (3 levels) in <top (required)>'

This then returns 1, which then is interpreted as a failure, and Test-Kitchen exits. I have tried different image versions as far back as a year ago, but no luck. Google shows me a few suggestions, but not many. Most of these involve $ProgressPreference = "SilentlyContinue" and -NoProfile, but those don't work for me.

In the ruby scripts which I use to drive the tests, this is how I'm running the command:

(@cmd = command("#{<path_to_ps_script>}")).exit_status

and when I check exit_status, 1 is returned:

expect(@cmd.exit_status).to eq(0)

In case its useful, here's my Gemfile.lock:

GIT
  remote: git@github.com:test-kitchen/kitchen-vagrant.git
  revision: 9b65a33165ac6ec2f76752b86e62850018023d4d
  specs:
    kitchen-vagrant (1.1.0)
      test-kitchen (~> 1.4)

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.5.1)
      public_suffix (~> 2.0, >= 2.0.2)
    artifactory (2.8.1)
    ast (2.3.0)
    builder (3.2.3)
    busser (0.7.1)
      thor (<= 0.19.0)
    diff-lcs (1.3)
    erubis (2.7.0)
    faraday (0.12.1)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.18)
    gcewinpass (1.0.0)
      google-api-client (~> 0.9.0)
    google-api-client (0.9.28)
      addressable (~> 2.3)
      googleauth (~> 0.5)
      httpclient (~> 2.7)
      hurley (~> 0.1)
      memoist (~> 0.11)
      mime-types (>= 1.6)
      representable (~> 2.3.0)
      retriable (~> 2.0)
    googleauth (0.5.0)
      faraday (~> 0.9)
      jwt (~> 1.4)
      logging (~> 2.0)
      memoist (~> 0.12)
      multi_json (~> 1.11)
      signet (~> 0.7)
    gssapi (1.2.0)
      ffi (>= 1.0.1)
    gyoku (1.3.1)
      builder (>= 2.1.2)
    httpclient (2.8.3)
    hurley (0.2)
    jwt (1.5.6)
    kitchen-google (1.1.0)
      gcewinpass (~> 1.0)
      google-api-client (~> 0.9.0)
      test-kitchen
    kitchen-sync (2.1.2)
      net-sftp
      test-kitchen (>= 1.0.0)
    little-plugger (1.1.4)
    logging (2.2.2)
      little-plugger (~> 1.1)
      multi_json (~> 1.10)
    memoist (0.15.0)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    mixlib-install (2.1.12)
      artifactory
      mixlib-shellout
      mixlib-versioning
      thor
    mixlib-shellout (2.2.7)
    mixlib-versioning (1.1.0)
    multi_json (1.12.1)
    multipart-post (2.0.0)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-sftp (2.1.2)
      net-ssh (>= 2.6.5)
    net-ssh (3.2.0)
    net-ssh-gateway (1.2.0)
      net-ssh (>= 2.6.5)
    net-telnet (0.1.1)
    nori (2.6.0)
    os (1.0.0)
    parser (2.4.0.0)
      ast (~> 2.2)
    powerpack (0.1.1)
    public_suffix (2.0.5)
    rainbow (2.2.2)
      rake
    rake (12.0.0)
    representable (2.3.0)
      uber (~> 0.0.7)
    retriable (2.1.0)
    rspec (3.6.0)
      rspec-core (~> 3.6.0)
      rspec-expectations (~> 3.6.0)
      rspec-mocks (~> 3.6.0)
    rspec-core (3.6.0)
      rspec-support (~> 3.6.0)
    rspec-expectations (3.6.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.6.0)
    rspec-its (1.2.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.6.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.6.0)
    rspec-support (3.6.0)
    rspec_junit_formatter (0.2.3)
      builder (< 4)
      rspec-core (>= 2, < 4, != 2.12.0)
    rubocop (0.48.1)
      parser (>= 2.3.3.1, < 3.0)
      powerpack (~> 0.1)
      rainbow (>= 1.99.1, < 3.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (~> 1.0, >= 1.0.1)
    ruby-progressbar (1.8.1)
    rubyntlm (0.6.2)
    rubyzip (1.2.1)
    safe_yaml (1.0.4)
    serverspec (2.39.1)
      multi_json
      rspec (~> 3.0)
      rspec-its
      specinfra (~> 2.68)
    sfl (2.3)
    signet (0.7.3)
      addressable (~> 2.3)
      faraday (~> 0.9)
      jwt (~> 1.5)
      multi_json (~> 1.10)
    specinfra (2.68.0)
      net-scp
      net-ssh (>= 2.7, < 5.0)
      net-telnet
      sfl
    test-kitchen (1.14.2)
      mixlib-install (>= 1.2, < 3.0)
      mixlib-shellout (>= 1.2, < 3.0)
      net-scp (~> 1.1)
      net-ssh (>= 2.9, < 4.0)
      net-ssh-gateway (~> 1.2.0)
      safe_yaml (~> 1.0)
      thor (~> 0.18)
    thor (0.19.0)
    uber (0.0.15)
    unicode-display_width (1.2.1)
    winrm (2.2.3)
      builder (>= 2.1.2)
      erubis (~> 2.7)
      gssapi (~> 1.2)
      gyoku (~> 1.0)
      httpclient (~> 2.2, >= 2.2.0.2)
      logging (>= 1.6.1, < 3.0)
      nori (~> 2.0)
      rubyntlm (~> 0.6.0, >= 0.6.1)
    winrm-fs (1.0.1)
      erubis (~> 2.7)
      logging (>= 1.6.1, < 3.0)
      rubyzip (~> 1.1)
      winrm (~> 2.0)

PLATFORMS
  ruby

DEPENDENCIES
  busser (~> 0.7.1)
  kitchen-google (~> 1.1.0)
  kitchen-sync (~> 2.1.2)
  kitchen-vagrant!
  os (>= 1.0.0)
  rake (>= 12.0.0)
  rspec_junit_formatter (>= 0.2.3)
  rubocop (~> 0.48.1)
  serverspec (>= 2.39.1)
  test-kitchen (~> 1.14.0)
  winrm (~> 2.2.2)
  winrm-fs (~> 1.0.1)

BUNDLED WITH
   1.15.0
silverbackbg commented 2 years ago

It might be an offtopic, but I receive the same message during Azure Automating runbook execution. Azure runs a script on a VM, and what the script does is to import the necessary modules. In Azure logs I see the "Preparing modules for first use" Still no resolution on that issue.