vagrant-azure icon indicating copy to clipboard operation
vagrant-azure copied to clipboard

WinRM Endpoint sort call uses wrong sort method

Open lonniev opened this issue 9 years ago • 0 comments

Host: MacOS 10.11.6 Guest: Azure Windows Vagrant: 1.8.5 vagrant-azure: 1.3.0

Attempt: vagrant provision

Looking for WinRM
/Users/lonniev/.vagrant.d/gems/gems/vagrant-azure-1.3.0/lib/vagrant-azure/action/read_winrm_info.rb:41:in `>': comparison of String with 0 failed (ArgumentError)
    from /Users/lonniev/.vagrant.d/gems/gems/vagrant-azure-1.3.0/lib/vagrant-azure/action/read_winrm_info.rb:41:in `sort'
    from /Users/lonniev/.vagrant.d/gems/gems/vagrant-azure-1.3.0/lib/vagrant-azure/action/read_winrm_info.rb:41:in `read_winrm_info'

From vagrant-azure-1.3.0/lib/vagrant-azure/action/read_winrm_info.rb:

          types = %w(PowerShell WinRm-Http)

          endpoint = vm.tcp_endpoints.reject { |i| !types.include?(i[:name]) }.sort{ |i| i[:name] }.first
          if endpoint

The intent is to take the tcp_endpoints property as parsed from the string argument from the Vagrantfile, eliminate anything but those endpoints with names 'PowerShell' and 'WinRm-Http', and to then choose the first of whatever is left.

The wrong Array::sort method is being called. What was intended is Array::sort_by. The latter takes a block that specifies a sort key for each element of the collection while the former expects to see a block that implements the <=> operation. sort{ |x,y| x[:name] <=> y[:name]}.

See also http://brandon.dimcheff.com/2009/11/18/rubys-sort-vs-sort-by.html

lonniev avatar Aug 24 '16 20:08 lonniev