vagrant-service-manager 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/ansible/roles/centos/tasks/main.yml +3 -2
  3. data/.ci/jenkins-execute-script.py +6 -4
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +13 -0
  6. data/.rubocop_todo.yml +55 -0
  7. data/CHANGELOG.md +22 -1
  8. data/CONTRIBUTING.adoc +6 -6
  9. data/Gemfile +12 -4
  10. data/README.adoc +104 -70
  11. data/Rakefile +235 -66
  12. data/features/box-command.feature +26 -1
  13. data/features/env-command.feature +20 -3
  14. data/features/help-command.feature +4 -1
  15. data/features/install-cli.feature +58 -0
  16. data/features/openshift.feature +2 -1
  17. data/features/service-operation.feature +76 -3
  18. data/features/support/env.rb +26 -10
  19. data/lib/vagrant-service-manager.rb +7 -2
  20. data/lib/vagrant-service-manager/action/setup_network.rb +0 -2
  21. data/lib/vagrant-service-manager/archive_handlers/tar_handler.rb +26 -0
  22. data/lib/vagrant-service-manager/archive_handlers/zip_handler.rb +25 -0
  23. data/lib/vagrant-service-manager/binary_handlers/adb_binary_handler.rb +55 -0
  24. data/lib/vagrant-service-manager/binary_handlers/adb_docker_binary_handler.rb +38 -0
  25. data/lib/vagrant-service-manager/binary_handlers/adb_openshift_binary_handler.rb +49 -0
  26. data/lib/vagrant-service-manager/binary_handlers/binary_handler.rb +119 -0
  27. data/lib/vagrant-service-manager/binary_handlers/cdk_binary_handler.rb +33 -0
  28. data/lib/vagrant-service-manager/binary_handlers/cdk_docker_binary_handler.rb +9 -0
  29. data/lib/vagrant-service-manager/binary_handlers/cdk_openshift_binary_handler.rb +9 -0
  30. data/lib/vagrant-service-manager/command.rb +90 -15
  31. data/lib/vagrant-service-manager/config.rb +8 -8
  32. data/lib/vagrant-service-manager/installer.rb +49 -0
  33. data/lib/vagrant-service-manager/plugin.rb +2 -2
  34. data/lib/vagrant-service-manager/plugin_logger.rb +2 -2
  35. data/lib/vagrant-service-manager/plugin_util.rb +29 -6
  36. data/lib/vagrant-service-manager/service.rb +4 -3
  37. data/lib/vagrant-service-manager/service_base.rb +11 -0
  38. data/lib/vagrant-service-manager/services/docker.rb +29 -29
  39. data/lib/vagrant-service-manager/services/kubernetes.rb +7 -7
  40. data/lib/vagrant-service-manager/services/open_shift.rb +42 -41
  41. data/lib/vagrant-service-manager/version.rb +1 -1
  42. data/locales/en.yml +42 -4
  43. data/plugins/guests/redhat/cap/machine_ip.rb +2 -1
  44. data/plugins/guests/redhat/plugin.rb +1 -1
  45. data/plugins/hosts/darwin/cap/os_arch.rb +11 -0
  46. data/plugins/hosts/darwin/plugin.rb +13 -0
  47. data/plugins/hosts/linux/cap/os_arch.rb +11 -0
  48. data/plugins/hosts/linux/plugin.rb +13 -0
  49. data/plugins/hosts/windows/cap/os_arch.rb +18 -0
  50. data/plugins/hosts/windows/plugin.rb +13 -0
  51. data/test/test_data/docker-1.10.0.tar.gz +0 -0
  52. data/test/test_data/docker-1.11.0.tgz +0 -0
  53. data/test/test_data/docker-1.9.1.zip +0 -0
  54. data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-linux-64bit.tar.gz +0 -0
  55. data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-linux-64bit.zip +0 -0
  56. data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-mac.zip +0 -0
  57. data/test/test_helper.rb +121 -0
  58. data/test/vagrant-service-manager/archive_handler_test.rb +49 -0
  59. data/test/vagrant-service-manager/binary_handlers/adb_docker_binary_handler_test.rb +111 -0
  60. data/test/vagrant-service-manager/binary_handlers/adb_openshift_binary_handler_test.rb +107 -0
  61. data/test/vagrant-service-manager/installer_test.rb +96 -0
  62. data/vagrant-service-manager.gemspec +4 -3
  63. metadata +43 -16
  64. data/TODO +0 -24
  65. data/Vagrantfile +0 -29
  66. data/lib/vagrant-service-manager/os.rb +0 -22
  67. data/vagrant-service-manager.spec +0 -215
@@ -0,0 +1,58 @@
1
+ Feature: Command behavior of client side tools installation
2
+ service-manager should correctly verify behavior of install-cli command
3
+
4
+ @install_cli
5
+ Scenario Outline: Boot and install client side tools
6
+ Given box is <box>
7
+ And provider is <provider>
8
+ And a file named "Vagrantfile" with:
9
+ """
10
+ begin
11
+ require 'vagrant-libvirt'
12
+ rescue LoadError
13
+ # NOOP
14
+ end
15
+
16
+ Vagrant.configure('2') do |config|
17
+ config.vm.box = '<box>'
18
+ config.vm.box_url = 'file://../../.boxes/<box>-<provider>.box'
19
+ config.vm.network :private_network, ip: '<ip>'
20
+ config.vm.synced_folder '.', '/vagrant', disabled: true
21
+ config.servicemanager.services = 'docker'
22
+ end
23
+ """
24
+
25
+ When I successfully run `bundle exec vagrant up --provider <provider>`
26
+ And I successfully run `bundle exec vagrant service-manager install-cli --help`
27
+ Then the exit status should be 0
28
+ And stdout from "bundle exec vagrant service-manager install-cli --help" should contain:
29
+ """
30
+ Install the client binary for the specified service
31
+
32
+ Usage: vagrant service-manager install-cli [service] [options]
33
+
34
+ Service:
35
+ A supported service. For example: docker, kubernetes or openshift.
36
+
37
+ Options:
38
+ -h, --help print this help
39
+
40
+ Example:
41
+ vagrant service-manager install-cli docker
42
+ """
43
+
44
+ When I run `bundle exec vagrant service-manager install-cli`
45
+ Then the exit status should be 126
46
+ And stdout from "bundle exec vagrant service-manager install-cli" should match /Service name missing/
47
+
48
+ When I run `bundle exec vagrant service-manager install-cli docker --cli-version 111.222.333`
49
+ Then the exit status should be 126
50
+
51
+ When I run `bundle exec vagrant service-manager install-cli docker`
52
+ Then the exit status should be 0
53
+ And the binary "docker" should be installed
54
+
55
+ Examples:
56
+ | box | provider | ip |
57
+ | adb | virtualbox | 10.10.10.42 |
58
+ | adb | libvirt | 10.10.10.42 |
@@ -15,7 +15,7 @@ Feature: Command output from various OpenShift related commands
15
15
 
16
16
  Vagrant.configure('2') do |config|
17
17
  config.vm.box = '<box>'
18
- config.vm.box_url = 'file://../boxes/<box>-<provider>.box'
18
+ config.vm.box_url = 'file://../../.boxes/<box>-<provider>.box'
19
19
  config.vm.network :private_network, ip: '<ip>'
20
20
  config.vm.synced_folder '.', '/vagrant', disabled: true
21
21
  config.servicemanager.services = 'docker'
@@ -65,6 +65,7 @@ Feature: Command output from various OpenShift related commands
65
65
  export OPENSHIFT_URL=https://<ip>:8443
66
66
  export OPENSHIFT_WEB_CONSOLE=https://<ip>:8443/console
67
67
  export DOCKER_REGISTRY=hub.openshift.rhel-cdk.<ip>.xip.io
68
+
68
69
  # run following command to configure your shell:
69
70
  # eval "$(vagrant service-manager env)"
70
71
  """
@@ -15,7 +15,7 @@ Feature: Command output from service operations like stop/start/restart
15
15
 
16
16
  Vagrant.configure('2') do |config|
17
17
  config.vm.box = '<box>'
18
- config.vm.box_url = 'file://../boxes/<box>-<provider>.box'
18
+ config.vm.box_url = 'file://../../.boxes/<box>-<provider>.box'
19
19
  config.vm.network :private_network, ip: '<ip>'
20
20
  config.vm.synced_folder '.', '/vagrant', disabled: true
21
21
  config.servicemanager.services = 'docker'
@@ -23,7 +23,80 @@ Feature: Command output from service operations like stop/start/restart
23
23
  """
24
24
 
25
25
  When I successfully run `bundle exec vagrant up --provider <provider>`
26
- And I successfully run `bundle exec vagrant service-manager status`
26
+ And I successfully run `bundle exec vagrant service-manager status --help`
27
+ Then the exit status should be 0
28
+ And stdout from "bundle exec vagrant service-manager status --help" should contain:
29
+ """
30
+ Usage: vagrant service-manager status [service] [options]
31
+
32
+ Options:
33
+ -h, --help print this help
34
+
35
+ If a service is provided, only that service is reported.
36
+ If no service is provided only supported orchestrators are reported.
37
+
38
+ Example:
39
+ vagrant service-manager status openshift
40
+ """
41
+
42
+ And I successfully run `bundle exec vagrant service-manager stop --help`
43
+ Then the exit status should be 0
44
+ And stdout from "bundle exec vagrant service-manager stop --help" should contain:
45
+ """
46
+ stops the service
47
+
48
+ Usage: vagrant service-manager stop <service> [options]
49
+
50
+ Service:
51
+ A service provided by sccli. For example:
52
+ docker, kubernetes, openshift etc
53
+
54
+ Options:
55
+ -h, --help print this help
56
+
57
+ Examples:
58
+ vagrant service-manager stop docker
59
+ """
60
+
61
+ And I successfully run `bundle exec vagrant service-manager start --help`
62
+ Then the exit status should be 0
63
+ And stdout from "bundle exec vagrant service-manager start --help" should contain:
64
+ """
65
+ starts the service
66
+
67
+ Usage: vagrant service-manager start <service> [options]
68
+
69
+ Service:
70
+ A service provided by sccli. For example:
71
+ docker, kubernetes, openshift etc
72
+
73
+ Options:
74
+ -h, --help print this help
75
+
76
+ Examples:
77
+ vagrant service-manager start docker
78
+ """
79
+
80
+ And I successfully run `bundle exec vagrant service-manager restart --help`
81
+ Then the exit status should be 0
82
+ And stdout from "bundle exec vagrant service-manager restart --help" should contain:
83
+ """
84
+ restarts the service
85
+
86
+ Usage: vagrant service-manager restart <service> [options]
87
+
88
+ Service:
89
+ A service provided by sccli. For example:
90
+ docker, kubernetes, openshift etc
91
+
92
+ Options:
93
+ -h, --help print this help
94
+
95
+ Examples:
96
+ vagrant service-manager restart docker
97
+ """
98
+
99
+ When I successfully run `bundle exec vagrant service-manager status`
27
100
  Then stdout from "bundle exec vagrant service-manager status" should contain "docker - running"
28
101
  Then stdout from "bundle exec vagrant service-manager status" should contain "openshift - stopped"
29
102
  Then stdout from "bundle exec vagrant service-manager status" should contain "kubernetes - stopped"
@@ -35,7 +108,7 @@ Feature: Command output from service operations like stop/start/restart
35
108
  Then the exit status should be 126
36
109
  And stderr from "bundle exec vagrant service-manager status abcd" should contain:
37
110
  """
38
- Unkown service 'abcd'.
111
+ Unknown service 'abcd'.
39
112
  Supported services are docker, openshift, kubernetes etc.
40
113
  """
41
114
 
@@ -1,5 +1,6 @@
1
1
  require 'aruba/cucumber'
2
2
  require 'komenda'
3
+ require 'find'
3
4
 
4
5
  ###############################################################################
5
6
  # Aruba config and Cucumber hooks
@@ -19,12 +20,15 @@ end
19
20
  After do |_scenario|
20
21
  if File.exist?(File.join(aruba.config.working_directory, 'Vagrantfile'))
21
22
  Komenda.run('bundle exec vagrant destroy -f', cwd: aruba.config.working_directory, fail_on_fail: true)
22
- if ENV.has_key?('CUCUMBER_RUN_PROVIDER')
23
- # if we have more than one provider we need to wait between scenarios in order to allow for proper cleanup/shutdown
24
- # of virtualization framework
23
+ if ENV.key?('CUCUMBER_RUN_PROVIDER')
24
+ # if we have more than one provider we need to wait between scenarios in order to allow for
25
+ # proper cleanup/shutdown of virtualization framework
25
26
  sleep 10
26
27
  end
27
28
  end
29
+
30
+ # Remove the created Vagrant home dir
31
+ FileUtils.rmtree(ENV['VAGRANT_HOME']) if File.directory? ENV['VAGRANT_HOME']
28
32
  end
29
33
 
30
34
  ###############################################################################
@@ -59,19 +63,21 @@ end
59
63
  # Some shared step definitions
60
64
  ##############################################################################
61
65
  Given /provider is (.*)/ do |current_provider|
62
- requested_provider = ENV.has_key?('PROVIDER') ? ENV['PROVIDER']: 'virtualbox'
66
+ requested_provider = ENV.key?('PROVIDER') ? ENV['PROVIDER'] : 'virtualbox'
63
67
 
64
68
  unless requested_provider.include?(current_provider)
65
- #puts "Skipping scenario '#{@scenario_name}' for provider '#{current_provider}', since this provider is not explicitly enabled via environment variable 'PROVIDER'"
69
+ # puts "Skipping scenario '#{@scenario_name}' for provider '#{current_provider}', since this
70
+ # provider is not explicitly enabled via environment variable 'PROVIDER'"
66
71
  skip_this_scenario
67
72
  end
68
73
  end
69
74
 
70
75
  Given /box is (.*)/ do |current_box|
71
- requested_box = ENV.has_key?('BOX') ? ENV['BOX']: 'adb'
76
+ requested_box = ENV.key?('BOX') ? ENV['BOX'] : 'adb'
72
77
 
73
78
  unless requested_box.include?(current_box)
74
- #puts "Skipping scenario '#{@scenario_name}' for box '#{current_box}', since this box is not explicitly enabled via environment variable 'BOX'"
79
+ # puts "Skipping scenario '#{@scenario_name}' for box '#{current_box}', since this box is not explicitly
80
+ # enabled via environment variable 'BOX'"
75
81
  skip_this_scenario
76
82
  end
77
83
  end
@@ -84,7 +90,7 @@ Then(/^stdout from "([^"]*)" should be script readable$/) do |cmd|
84
90
  output_is_script_readable(aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd)).send(:stdout))
85
91
  end
86
92
 
87
- Then(/^stdout from "([^"]*)" should match \/(.*)\/$/) do |cmd, regexp|
93
+ Then(%r{^stdout from "([^"]*)" should match /(.*)/$}) do |cmd, regexp|
88
94
  aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd)).send(:stdout) =~ /#{regexp}/
89
95
  end
90
96
 
@@ -95,7 +101,7 @@ end
95
101
  Then(/^the service "([^"]*)" should be ([^"]*)$/) do |service, operation|
96
102
  run("vagrant ssh -c \"sudo systemctl status #{service}\"")
97
103
 
98
- if ['running', 'restarted'].include? operation
104
+ if %w(running restarted).include? operation
99
105
  exit_code = 0
100
106
  regexp = /Active: active \(running\)/
101
107
  elsif operation == 'stopped'
@@ -126,7 +132,7 @@ When(/^the "([^"]*)" service is \*not\* running$/) do |service|
126
132
  run("vagrant ssh -c \"sudo systemctl stop #{service}\"")
127
133
 
128
134
  expect(last_command_started).to have_exit_status(0)
129
- step "the \"docker\" service is not running"
135
+ step 'the "docker" service is not running'
130
136
  end
131
137
 
132
138
  # Note: Only for services supported through systemctl. Not for 'kubernetes'.
@@ -137,3 +143,13 @@ Then(/^have a new pid for "([^"]*)" service$/) do |service|
137
143
  stdout = aruba.command_monitor.find(Aruba.platform.detect_ruby(last_command_started)).send(:stdout)
138
144
  expect(@service_current_process_id).not_to eq(extract_process_id(stdout))
139
145
  end
146
+
147
+ Then(/^the binary "([^"]*)" should be installed$/) do |binary|
148
+ binaries = []
149
+ Find.find("#{ENV['VAGRANT_HOME']}/data/service-manager/bin") do |path|
150
+ binaries << path if path =~ %r{.*\/#{Regexp.quote(binary)}$} && File.file?(path)
151
+ end
152
+
153
+ expect(binaries.size).to eq(1)
154
+ expect(File.executable?(binaries[0])).to eq(true)
155
+ end
@@ -6,10 +6,11 @@ end
6
6
 
7
7
  require 'vagrant-service-manager/plugin'
8
8
  require 'vagrant-service-manager/command'
9
- require 'vagrant-service-manager/os'
10
9
 
11
10
  module VagrantPlugins
12
11
  module ServiceManager
12
+ SUPPORTED_HOSTS = %w(linux darwin windows).freeze
13
+
13
14
  # Returns the path to the source of this plugin
14
15
  def self.source_root
15
16
  @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
@@ -17,7 +18,11 @@ module VagrantPlugins
17
18
 
18
19
  # Temporally load the extra capabilities files for Red Hat
19
20
  load(File.join(source_root, 'plugins/guests/redhat/plugin.rb'))
21
+ # Load the host capabilities files
22
+ SUPPORTED_HOSTS.each do |host|
23
+ load(File.join(source_root, "plugins/hosts/#{host}/plugin.rb"))
24
+ end
20
25
  # Default I18n to load the en locale
21
- I18n.load_path << File.expand_path("locales/en.yml", source_root)
26
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
22
27
  end
23
28
  end
@@ -2,7 +2,6 @@ module VagrantPlugins
2
2
  module ServiceManager
3
3
  module Action
4
4
  class SetupNetwork
5
-
6
5
  def initialize(app, env)
7
6
  @app = app
8
7
  @machine = env[:machine]
@@ -31,7 +30,6 @@ Adding a private network using DHCP
31
30
  MSG
32
31
  @machine.config.vm.network :private_network, type: :dhcp
33
32
  end
34
-
35
33
  end
36
34
  end
37
35
  end
@@ -0,0 +1,26 @@
1
+ require 'rubygems/package'
2
+ require 'zlib'
3
+
4
+ module VagrantPlugins
5
+ module ServiceManager
6
+ class TarHandler
7
+ def initialize(source, dest_binary_path, file_regex)
8
+ @source = source
9
+ @dest_binary_path = dest_binary_path
10
+ @file_regex = file_regex
11
+ end
12
+
13
+ def unpack
14
+ Gem::Package::TarReader.new(Zlib::GzipReader.open(@source)) do |tar|
15
+ tar.each do |entry|
16
+ next unless entry.file? && entry.full_name =~ @file_regex
17
+
18
+ dest_directory = File.dirname(@dest_binary_path)
19
+ FileUtils.mkdir_p(dest_directory) unless File.directory?(dest_directory)
20
+ File.open(@dest_binary_path, 'wb') { |f| f.print(entry.read) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'zip'
2
+
3
+ module VagrantPlugins
4
+ module ServiceManager
5
+ class ZipHandler
6
+ def initialize(source, dest_binary_path, file_regex)
7
+ @source = source
8
+ @dest_binary_path = dest_binary_path
9
+ @file_regex = file_regex
10
+ end
11
+
12
+ def unpack
13
+ Zip::File.open(@source) do |zipfile|
14
+ zipfile.each do |entry|
15
+ next unless entry.ftype == :file && entry.name =~ @file_regex
16
+
17
+ dest_directory = File.dirname(@dest_binary_path)
18
+ FileUtils.mkdir_p(dest_directory) unless File.directory?(dest_directory)
19
+ zipfile.extract(entry, @dest_binary_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ module VagrantPlugins
2
+ module ServiceManager
3
+ class ADBBinaryHandler < BinaryHandler
4
+ def initialize(machine, env, options)
5
+ super(machine, env, options)
6
+ end
7
+
8
+ def build_archive_path
9
+ @archive_file_path = "#{@temp_bin_dir}/#{File.basename(@url)}"
10
+ end
11
+
12
+ def ensure_binary_and_temp_directories
13
+ FileUtils.mkdir_p(bin_dir) unless File.directory?(bin_dir)
14
+ FileUtils.mkdir_p(@temp_bin_dir) unless File.directory?(@temp_bin_dir)
15
+ end
16
+
17
+ def download_archive
18
+ return @skip_download = true if File.exist?(@archive_file_path)
19
+ Vagrant::Util::Downloader.new(@url, @archive_file_path).download!
20
+ rescue Vagrant::Errors::DownloaderError => e
21
+ @ui.error e.message
22
+ exit 126
23
+ end
24
+
25
+ def prepare_binary
26
+ tmp_binary_file_path = @archive_file_path
27
+
28
+ # If binary is in archive format, extract it
29
+ if binary_archived?
30
+ tmp_binary_file_path = "#{archive_dir_name}/#{binary_name}"
31
+ archive_handler_class.new(@archive_file_path, tmp_binary_file_path, file_regex).unpack
32
+ end
33
+
34
+ FileUtils.cp(tmp_binary_file_path, @path)
35
+ File.chmod(0o755, @path)
36
+ rescue StandardError => e
37
+ @ui.error e.message
38
+ exit 126
39
+ end
40
+
41
+ def print_message
42
+ binary_path = PluginUtil.format_path(@path)
43
+ @ui.info I18n.t(LABEL,
44
+ path: binary_path, dir: File.dirname(binary_path), service: @type,
45
+ binary: binary_name, when: (@binary_exists ? 'already' : 'now'))
46
+ end
47
+
48
+ private
49
+
50
+ def binary_archived?
51
+ BINARY_ARCHIVE_FORMATS.include? File.extname(@archive_file_path)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ module VagrantPlugins
2
+ module ServiceManager
3
+ class ADBDockerBinaryHandler < ADBBinaryHandler
4
+ # Refer https://docs.docker.com/v1.10/engine/installation/binaries
5
+ DOCKER_BINARY_BASE_URL = 'https://get.docker.com/builds'.freeze
6
+
7
+ def initialize(machine, env, options)
8
+ super(machine, env, options)
9
+ end
10
+
11
+ def build_download_url
12
+ arch = @machine.env.host.capability(:os_arch)
13
+ @url = "#{DOCKER_BINARY_BASE_URL}/#{os_type}/#{arch}/docker-#{@version}#{archive_ext}"
14
+ end
15
+
16
+ private
17
+
18
+ def os_type
19
+ if Vagrant::Util::Platform.windows?
20
+ 'Windows'
21
+ elsif Vagrant::Util::Platform.linux?
22
+ 'Linux'
23
+ elsif Vagrant::Util::Platform.darwin?
24
+ 'Darwin'
25
+ end
26
+ end
27
+
28
+ def archive_ext
29
+ # https://github.com/docker/docker/blob/v1.11.0-rc1/CHANGELOG.md#1110-2016-04-12
30
+ if @version == 'latest' || Gem::Version.new(@version) > Gem::Version.new('1.10.3')
31
+ Vagrant::Util::Platform.windows? ? '.zip' : '.tgz'
32
+ else
33
+ binary_ext
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end