diff --git a/TEST.md b/TEST.md index c43f9ac..23d9796 100644 --- a/TEST.md +++ b/TEST.md @@ -7,3 +7,21 @@ bundle exec kitchen verify ``` to test installation and setup procedures for the `instrumental_tools` command. You must have [Vagrant](https://www.vagrantup.com/) installed; currently the KitchenCI integration is setup to use [VMWare Fusion](http://www.vmware.com/products/fusion) and the [VMWare Fusion Vagrant provider](https://www.vagrantup.com/vmware); you can configure a separate provider for your specific setup by change the `provider` flag in the `.kitchen.yml` file for your particular setup. + +## Windows + +Ensure you have the `winrm` vagrant plugin installed. + +``` +vagrant plugin install vagrant-winrm +``` + + +To ensure you have a Windows Vagrant image, perform the following steps in a separate directory to build a Windows evaluation image: + +``` +git clone https://github.com/boxcutter/windows.git +cd windows +make virtualbox/eval-win2012r2-standard +vagrant box add windows-2012r2 ./box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.box +``` diff --git a/chef/.kitchen.yml b/chef/.kitchen.yml index 0fbfbfa..7664403 100644 --- a/chef/.kitchen.yml +++ b/chef/.kitchen.yml @@ -1,6 +1,8 @@ --- driver: name: vagrant + synced_folders: + - ["../", "/tools-root"] provisioner: name: chef_solo @@ -10,8 +12,12 @@ platforms: - name: ubuntu-12.04 - name: centos-6.6 - name: "d11wtq/gentoo" + - name: "windows-2012r2" suites: - name: default run_list: ["instrumental_tools"] attributes: + instrumental: + use_local: true + local_path: "/tools-root/" diff --git a/chef/instrumental_tools/attributes/default.rb b/chef/instrumental_tools/attributes/default.rb index 2509b83..aa457c8 100644 --- a/chef/instrumental_tools/attributes/default.rb +++ b/chef/instrumental_tools/attributes/default.rb @@ -6,3 +6,5 @@ default[:instrumental][:wget_path] = "/usr/bin/wget" default[:instrumental][:dist_init_file] = "/opt/instrumental-tools/lib/app/debian/instrument_server" default[:instrumental][:dest_init_file] = "/etc/init.d/instrument_server" +default[:instrumental][:use_local] = false +default[:instrumental][:local_path] = nil diff --git a/chef/instrumental_tools/recipes/default.rb b/chef/instrumental_tools/recipes/default.rb index 15b4476..87617ee 100644 --- a/chef/instrumental_tools/recipes/default.rb +++ b/chef/instrumental_tools/recipes/default.rb @@ -1,19 +1,51 @@ supported_platforms = %w{debian rhel fedora arch gentoo slackware suse} +version = node["instrumental"]["version"] +arch = case node["kernel"]["machine"] + when "i386" + "x86" + else + node["kernel"]["machine"] + end +pkg_arch = case node["kernel"]["machine"] + when "x86_64" + "amd64" + else + node["kernel"]["machine"] + end +file_name = case node["platform_family"] + when "osx" + "instrumental-tools_%s_osx.tar.gz" % version + when "debian" + "instrumental-tools_%s_%s.deb" % [version, pkg_arch] + when "rhel", "fedora" + "instrumental-tools_%s_%s.rpm" % [version, pkg_arch] + when "windows" + "instrumental-tools_%s_win32.exe" % version + else + "instrumental-tools_%s_linux-%s.tar.gz" % [version, arch] + end +local_path = ::File.join(node[:instrumental][:local_path], file_name) case node["platform_family"] when "debian", "rhel", "fedora" - packagecloud_repo "expectedbehavior/instrumental" do - case node["platform_family"] - when "debian" - type "deb" - when "rhel", "fedora" - type "rpm" + if node[:instrumental][:use_local] + package local_path_path do + action[:upgrade] + end + else + packagecloud_repo "expectedbehavior/instrumental" do + case node["platform_family"] + when "debian" + type "deb" + when "rhel", "fedora" + type "rpm" + end end - end - package "instrumental-tools" do - action :upgrade - version node["instrumental"]["version"] + package "instrumental-tools" do + action :upgrade + version node["instrumental"]["version"] + end end template "/etc/instrumental.yml" do @@ -25,18 +57,7 @@ ) end when "arch", "gentoo", "slackware", "suse", "osx" - version = node["instrumental"]["version"] - file_name = if node["platform_family"] == "osx" - "instrumental-tools_%s_osx.tar.gz" % version - else - arch = case node["kernel"]["machine"] - when "i386" - "x86" - else - node["kernel"]["machine"] - end - "instrumental-tools_%s_linux-%s.tar.gz" % [version, arch] - end + local_path = "/opt/instrumental-tools/%s" % file_name directory "/opt/instrumental-tools" do @@ -45,24 +66,32 @@ recursive true end - remote_name = "%s/%s/%s" % [node["instrumental"]["repo"], version, file_name] - if ::File.exists?(node["instrumental"]["curl_path"]) - execute "curl_download_instrumental_tools_package" do - command "%s -O %s" % [node["instrumental"]["curl_path"], remote_name] - cwd "/opt/instrumental-tools" - not_if { ::File.exists?(local_path) } - user "nobody" - end - elsif ::File.exists?(node["instrumental"]["wget_path"]) - execute "wget_download_instrumental_tools_package" do - command "%s %s" % [node["instrumental"]["wget_path"], remote_name] + if node[:instrumental][:use_local] + execute "copy_instrumental_tools_package" do + command "cp %s %s" % [local_path, ::File.basename(local_path)] cwd "/opt/instrumental-tools" - not_if { ::File.exists?(local_path) } user "nobody" end else - Chef::Log.fatal("Could not find curl or wget, unable to download package") - raise + remote_name = "%s/%s/%s" % [node["instrumental"]["repo"], version, file_name] + if ::File.exists?(node["instrumental"]["curl_path"]) + execute "curl_download_instrumental_tools_package" do + command "%s -O %s" % [node["instrumental"]["curl_path"], remote_name] + cwd "/opt/instrumental-tools" + not_if { ::File.exists?(local_path) } + user "nobody" + end + elsif ::File.exists?(node["instrumental"]["wget_path"]) + execute "wget_download_instrumental_tools_package" do + command "%s %s" % [node["instrumental"]["wget_path"], remote_name] + cwd "/opt/instrumental-tools" + not_if { ::File.exists?(local_path) } + user "nobody" + end + else + Chef::Log.fatal("Could not find curl or wget, unable to download package") + raise + end end execute "untar_instrumental_tools_package" do @@ -96,7 +125,15 @@ status_command "pgrep instrument_server" supports :restart => true, :reload => true, :status => false end - +when "windows" + if node[:instrumental][:use_local] + execute "install-tools" do + command "call %s /S" % local_path + end + end + service "instrument_server" do + action [:enable, :start] + end else Chef::Log.warn("The platform %s is not supported, instrumental_tools will not be installed" % node["platform_family"]) end diff --git a/test/integration/default/serverspec/instrumental_tools_spec.rb b/test/integration/default/serverspec/instrumental_tools_spec.rb index 2ec7140..5fc6382 100644 --- a/test/integration/default/serverspec/instrumental_tools_spec.rb +++ b/test/integration/default/serverspec/instrumental_tools_spec.rb @@ -1,11 +1,36 @@ require 'serverspec' -set :backend, :exec +details = {} + +if RUBY_PLATFORM =~ /(win|mswin|mingw)/i + set :backend, :cmd + set :os, :family => 'windows' + details = { + check_executable: false, + check_owner: false, + config: "c:\\Program Files (x86)\\Instrumental Tools\\etc\\instrumental.yml", + executable: "c:\\Program Files (x86)\\Instrumental Tools\\instrument_server.bat", + has_pid: false + } +else + set :backend, :exec + details = { + check_executable: true, + check_owner: true, + config: "/etc/instrumental.yml", + executable: "/opt/instrumental-tools/instrument_server", + has_pid: true, + pid_path: "/opt/instrumental-tools/instrument_server.pid", + owner: "nobody" + } +end -describe file('/opt/instrumental-tools/instrument_server') do +describe file(details[:executable]) do it { should be_file } - it { should be_executable } + if details[:check_executable] + it { should be_executable } + end end describe service('instrument_server') do @@ -13,18 +38,18 @@ it { should be_running } end -describe file('/opt/instrumental-tools/instrument_server.pid') do - it { should be_file } - it { should be_owned_by('nobody') } +if details[:has_pid] + describe file(details[:pid_path]) do + it { should be_file } + if details[:check_owner] + it { should be_owned_by(details[:owner]) } + end + end end -describe file('/etc/instrumental.yml') do +describe file(details[:config]) do it { should be_file } - it { should be_owned_by('nobody') } -end - -describe process('ruby') do - it { should be_running } - its(:user) { should eq 'nobody' } - its(:args) { should match /instrument_server/ } + if details[:check_owner] + it { should be_owned_by(details[:owner]) } + end end