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
@@ -2,7 +2,7 @@ module VagrantPlugins
2
2
  module GuestRedHat
3
3
  module Cap
4
4
  class MachineIP
5
- def self.machine_ip(machine)
5
+ def self.machine_ip(machine, options = {})
6
6
  # Find the guest IP
7
7
  command = "ip -o -4 addr show up |egrep -v ': docker|: lo' |tail -1 | awk '{print $4}' |cut -f1 -d\/"
8
8
  ip = ''
@@ -10,6 +10,7 @@ module VagrantPlugins
10
10
  PluginLogger.debug
11
11
  machine.communicate.execute(command) do |type, data|
12
12
  ip << data.chomp if type == :stdout
13
+ return "IP=#{ip}" if options[:script_readable]
13
14
  end
14
15
 
15
16
  ip
@@ -2,7 +2,7 @@ require 'vagrant'
2
2
  require File.expand_path('../../../../', __FILE__) + '/lib/vagrant-service-manager/plugin_logger'
3
3
 
4
4
  module VagrantPlugins
5
- OS_RELEASE_FILE = '/etc/os-release'
5
+ OS_RELEASE_FILE = '/etc/os-release'.freeze
6
6
 
7
7
  module GuestRedHat
8
8
  class Plugin < Vagrant.plugin('2')
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module HostDarwin
3
+ module Cap
4
+ class OSArch
5
+ def self.os_arch(_env)
6
+ `uname -m`.chop
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module HostDarwin
5
+ class Plugin < Vagrant.plugin('2')
6
+ host_capability('darwin', 'os_arch') do
7
+ require_relative 'cap/os_arch'
8
+
9
+ Cap::OSArch
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module HostLinux
3
+ module Cap
4
+ class OSArch
5
+ def self.os_arch(_env)
6
+ `uname -m`.chop
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module HostLinux
5
+ class Plugin < Vagrant.plugin('2')
6
+ host_capability('linux', 'os_arch') do
7
+ require_relative 'cap/os_arch'
8
+
9
+ Cap::OSArch
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module HostWindows
3
+ module Cap
4
+ class OSArch
5
+ def self.os_arch(_env)
6
+ # Logic taken from http://stackoverflow.com/a/25845488
7
+ arch = 'x86_64'
8
+
9
+ if ENV['PROCESSOR_ARCHITECTURE'] == 'x86'
10
+ arch = 'i386' unless ENV['PROCESSOR_ARCHITEW6432']
11
+ end
12
+
13
+ arch
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module HostWindows
5
+ class Plugin < Vagrant.plugin('2')
6
+ host_capability('windows', 'os_arch') do
7
+ require_relative 'cap/os_arch'
8
+
9
+ Cap::OSArch
10
+ end
11
+ end
12
+ end
13
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,121 @@
1
+ $LOAD_PATH.push(File.expand_path('../../plugins', __FILE__))
2
+ $LOAD_PATH.push(File.expand_path('../../lib', __FILE__))
3
+ $LOAD_PATH.push(File.expand_path('../../locales', __FILE__))
4
+
5
+ require 'bundler/setup'
6
+ require 'minitest/spec'
7
+ require 'minitest/autorun'
8
+ require 'mocha/mini_test'
9
+
10
+ require 'vagrant-service-manager'
11
+ require 'guests/redhat/cap/box_version'
12
+ require 'guests/redhat/cap/os_variant'
13
+
14
+ def fake_environment(options = { enabled: true })
15
+ { machine: fake_machine(options), ui: FakeUI }
16
+ end
17
+
18
+ class FakeUI
19
+ attr_reader :received_info_messages
20
+
21
+ def initialize
22
+ @received_info_messages = []
23
+ end
24
+
25
+ def info(*args)
26
+ # puts "#{args}"
27
+ @received_info_messages << args[0]
28
+ end
29
+ end
30
+
31
+ class RecordingCommunicator
32
+ attr_reader :commands, :responses
33
+
34
+ def initialize
35
+ @commands = Hash.new([])
36
+ @responses = Hash.new('')
37
+ end
38
+
39
+ def stub_command(command, response)
40
+ responses[command] = response
41
+ end
42
+
43
+ def sudo(command)
44
+ commands[:sudo] << command
45
+ responses[command]
46
+ end
47
+
48
+ def execute(command)
49
+ commands[:execute] << command
50
+ responses[command].split("\n").each do |line|
51
+ yield(:stdout, "#{line}\n")
52
+ end
53
+ end
54
+
55
+ def test(command)
56
+ commands[:test] << command
57
+ true
58
+ end
59
+
60
+ def ready?
61
+ true
62
+ end
63
+ end
64
+
65
+ module ServiceManager
66
+ class FakeProvider
67
+ def initialize(*args)
68
+ end
69
+
70
+ def _initialize(*args)
71
+ end
72
+
73
+ def ssh_info
74
+ end
75
+
76
+ def state
77
+ @state ||= Vagrant::MachineState.new('fake-state', 'fake-state', 'fake-state')
78
+ end
79
+ end
80
+
81
+ class FakeConfig
82
+ def servicemanager
83
+ @servicemanager_config ||= VagrantPlugins::ServiceManager::Config.new
84
+ end
85
+
86
+ def vm
87
+ VagrantPlugins::Kernel_V2::VMConfig.new
88
+ end
89
+ end
90
+ end
91
+
92
+ def fake_machine(options = {})
93
+ env = options.fetch(:env, Vagrant::Environment.new)
94
+
95
+ machine = Vagrant::Machine.new(
96
+ 'fake_machine',
97
+ 'fake_provider',
98
+ ServiceManager::FakeProvider,
99
+ 'provider_config',
100
+ {}, # provider_options
101
+ env.vagrantfile.config, # config
102
+ Pathname('data_dir'),
103
+ 'box',
104
+ options.fetch(:env, Vagrant::Environment.new),
105
+ env.vagrantfile
106
+ )
107
+
108
+ machine.instance_variable_set('@communicator', RecordingCommunicator.new)
109
+ machine.config.vm.hostname = options.fetch(:hostname, 'somehost.vagrant.test')
110
+ machine
111
+ end
112
+
113
+ def test_data_dir_path
114
+ File.expand_path('test_data', File.dirname(__FILE__))
115
+ end
116
+
117
+ module MiniTest
118
+ class Spec
119
+ alias hush capture_io
120
+ end
121
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../test_helper'
2
+
3
+ module VagrantPlugins
4
+ module ServiceManager
5
+ describe 'Archive Handlers' do
6
+ before do
7
+ @machine = fake_machine
8
+
9
+ # set test path
10
+ @plugin_test_path = "#{@machine.env.data_dir}/service-manager/test"
11
+ end
12
+
13
+ after do
14
+ FileUtils.rmtree(@plugin_test_path) if File.directory? @plugin_test_path
15
+ end
16
+
17
+ describe TarHandler do
18
+ it "should unpack '.tgz' archive properly" do
19
+ test_archive_path = "#{test_data_dir_path}/docker-1.11.0.tgz"
20
+ dest_binary_path = @plugin_test_path + '/docker-1.11.0'
21
+ regex = %r{\/docker$}
22
+
23
+ TarHandler.new(test_archive_path, dest_binary_path, regex).unpack
24
+ assert_equal(File.exist?(dest_binary_path), true)
25
+ end
26
+
27
+ it "should unpack '.tar.gz' archive properly" do
28
+ test_archive_path = "#{test_data_dir_path}/docker-1.10.0.tar.gz"
29
+ dest_binary_path = @plugin_test_path + '/docker-1.10.0'
30
+ regex = %r{\/docker$}
31
+
32
+ TarHandler.new(test_archive_path, dest_binary_path, regex).unpack
33
+ assert_equal(File.exist?(dest_binary_path), true)
34
+ end
35
+ end
36
+
37
+ describe ZipHandler do
38
+ it "should unpack '.zip' archive properly" do
39
+ test_archive_path = "#{test_data_dir_path}/docker-1.9.1.zip"
40
+ dest_binary_path = @plugin_test_path + '/docker-1.9.1'
41
+ regex = %r{\/docker.exe$}
42
+
43
+ ZipHandler.new(test_archive_path, dest_binary_path, regex).unpack
44
+ assert_equal(File.exist?(dest_binary_path), true)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,111 @@
1
+ require_relative '../../test_helper'
2
+ require 'vagrant/util/downloader'
3
+
4
+ # Tests through ADBDockerBinaryHandler to BinaryHandler
5
+ module VagrantPlugins
6
+ module ServiceManager
7
+ describe ADBDockerBinaryHandler do
8
+ before do
9
+ @machine = fake_machine
10
+ @options = { type: :docker, '--cli-version' => '1.11.0' }
11
+
12
+ # set test path
13
+ @plugin_test_path = "#{@machine.env.data_dir}/service-manager/test"
14
+ ServiceManager.temp_dir = "#{@plugin_test_path}/temp"
15
+ ServiceManager.bin_dir = "#{@plugin_test_path}/bin"
16
+
17
+ @handler = ADBDockerBinaryHandler.new(@machine, @machine.env, @options)
18
+ end
19
+
20
+ after do
21
+ FileUtils.rmtree(@plugin_test_path) if File.directory? @plugin_test_path
22
+ end
23
+
24
+ it 'should set defaults values properly' do
25
+ @handler.instance_variable_get('@machine').must_equal @machine
26
+ @handler.url.must_equal ''
27
+ @handler.binary_exists.must_equal true
28
+ @handler.skip_download.must_equal false
29
+ @handler.archive_file_path.must_equal ''
30
+ @handler.type.must_equal @options[:type]
31
+ @handler.version.must_equal @options['--cli-version']
32
+ @handler.path.must_equal "#{ServiceManager.bin_dir}/docker/1.11.0/docker"
33
+ expected_temp_bin_dir = "#{ServiceManager.temp_dir}/docker"
34
+ @handler.instance_variable_get('@temp_bin_dir').must_equal expected_temp_bin_dir
35
+ end
36
+
37
+ it 'should build download url' do
38
+ expected_url = 'https://get.docker.com/builds/Linux/x86_64/docker-1.11.0.tgz'
39
+ expected_url.sub!(/Linux/, 'Darwin') if Vagrant::Util::Platform.darwin?
40
+
41
+ @handler.send(:build_download_url)
42
+ @handler.instance_variable_get('@url').must_equal expected_url
43
+ end
44
+
45
+ # Binary format changed after 1.11.0
46
+ # https://github.com/docker/docker/blob/v1.11.0-rc1/CHANGELOG.md#1110-2016-04-12
47
+ it 'should build download url for docker < 1.11.0' do
48
+ expected_url = 'https://get.docker.com/builds/Linux/x86_64/docker-1.10.3'
49
+ expected_url.sub!(/Linux/, 'Darwin') if Vagrant::Util::Platform.darwin?
50
+
51
+ @handler.version = '1.10.3'
52
+ @handler.build_download_url
53
+ @handler.url.must_equal expected_url
54
+ end
55
+
56
+ it 'should validate download url' do
57
+ @options['--cli-version'] = '111.222.333'
58
+ @handler = ADBDockerBinaryHandler.new(@machine, @machine.env, @options)
59
+ @handler.build_download_url
60
+ assert_raises(URLValidationError) { @handler.validate_url }
61
+ end
62
+
63
+ it 'should build archive path' do
64
+ expected_path = "#{ServiceManager.temp_dir}/docker/docker-1.11.0.tgz"
65
+ @handler.build_download_url
66
+ @handler.build_archive_path
67
+ @handler.instance_variable_get('@archive_file_path').must_equal expected_path
68
+ end
69
+
70
+ it 'should ensure availability of binary and temp directories' do
71
+ expected_bin_dir = "#{ServiceManager.bin_dir}/docker"
72
+ expected_temp_dir = "#{ServiceManager.temp_dir}/docker"
73
+
74
+ @handler.build_download_url
75
+ @handler.build_archive_path
76
+ @handler.ensure_binary_and_temp_directories
77
+
78
+ assert_equal(File.directory?(expected_bin_dir), true)
79
+ assert_equal(File.directory?(expected_temp_dir), true)
80
+ end
81
+
82
+ it 'should not download if archive file exists' do
83
+ archive_file_dir = "#{ServiceManager.temp_dir}/docker"
84
+ FileUtils.mkdir_p(archive_file_dir) unless File.directory?(archive_file_dir)
85
+ FileUtils.touch("#{archive_file_dir}/docker-1.11.0.tgz")
86
+
87
+ @handler.build_download_url
88
+ @handler.build_archive_path
89
+ @handler.download_archive
90
+
91
+ @handler.skip_download.must_equal true
92
+ end
93
+
94
+ it 'should prepare binary properly' do
95
+ test_archive_path = "#{test_data_dir_path}/docker-1.11.0.tgz"
96
+
97
+ @handler.build_download_url
98
+ @handler.build_archive_path
99
+ @handler.ensure_binary_and_temp_directories
100
+
101
+ FileUtils.cp(test_archive_path, @handler.archive_file_path)
102
+
103
+ @handler.prepare_binary
104
+ @handler.binary_name.must_equal 'docker'
105
+ @handler.file_regex.must_equal %r{\/docker$}
106
+ @handler.archive_handler_class.must_equal VagrantPlugins::ServiceManager::TarHandler
107
+ assert_equal(File.exist?(@handler.path), true)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,107 @@
1
+ require_relative '../../test_helper'
2
+ require 'vagrant/util/downloader'
3
+
4
+ # Tests through ADBOpenshiftBinaryHandler to BinaryHandler
5
+ module VagrantPlugins
6
+ module ServiceManager
7
+ describe ADBOpenshiftBinaryHandler do
8
+ before do
9
+ @machine = fake_machine
10
+ @options = { type: :openshift, '--cli-version' => '1.2.0' }
11
+ @archive_base_url = 'https://github.com/openshift/origin/releases/download/v1.2.0'
12
+ @archive_file = 'openshift-origin-client-tools-v1.2.0-2e62fab-linux-64bit.tar.gz'
13
+ @archive_file.sub!(/linux-64bit.tar.gz/, 'mac.zip') if Vagrant::Util::Platform.darwin?
14
+
15
+ # set test path
16
+ @plugin_test_path = "#{@machine.env.data_dir}/service-manager/test"
17
+ ServiceManager.temp_dir = "#{@plugin_test_path}/temp"
18
+ ServiceManager.bin_dir = "#{@plugin_test_path}/bin"
19
+
20
+ @handler = ADBOpenshiftBinaryHandler.new(@machine, @machine.env, @options)
21
+ end
22
+
23
+ after do
24
+ FileUtils.rmtree(@plugin_test_path) if File.directory? @plugin_test_path
25
+ end
26
+
27
+ it 'should set defaults values properly' do
28
+ @handler.instance_variable_get('@machine').must_equal @machine
29
+ @handler.url.must_equal ''
30
+ @handler.binary_exists.must_equal true
31
+ @handler.skip_download.must_equal false
32
+ @handler.archive_file_path.must_equal ''
33
+ @handler.type.must_equal @options[:type]
34
+ @handler.version.must_equal @options['--cli-version']
35
+ @handler.path.must_equal "#{ServiceManager.bin_dir}/openshift/1.2.0/oc"
36
+ expected_temp_bin_dir = "#{ServiceManager.temp_dir}/openshift"
37
+ @handler.instance_variable_get('@temp_bin_dir').must_equal expected_temp_bin_dir
38
+ end
39
+
40
+ it 'should build download url' do
41
+ expected_url = "#{@archive_base_url}/#{@archive_file}"
42
+
43
+ @handler.send(:build_download_url)
44
+ @handler.instance_variable_get('@url').must_equal expected_url
45
+ end
46
+
47
+ it 'should validate download url' do
48
+ @options['--cli-version'] = '111.222.333'
49
+ @handler = ADBDockerBinaryHandler.new(@machine, @machine.env, @options)
50
+ @handler.build_download_url
51
+ assert_raises(URLValidationError) { @handler.validate_url }
52
+ end
53
+
54
+ it 'should build archive path' do
55
+ expected_path = "#{ServiceManager.temp_dir}/openshift/#{@archive_file}"
56
+
57
+ @handler.build_download_url
58
+ @handler.build_archive_path
59
+ @handler.instance_variable_get('@archive_file_path').must_equal expected_path
60
+ end
61
+
62
+ it 'should ensure availability of binary and temp directories' do
63
+ expected_bin_dir = "#{ServiceManager.bin_dir}/openshift"
64
+ expected_temp_dir = "#{ServiceManager.temp_dir}/openshift"
65
+
66
+ @handler.build_download_url
67
+ @handler.build_archive_path
68
+ @handler.ensure_binary_and_temp_directories
69
+
70
+ assert_equal(File.directory?(expected_bin_dir), true)
71
+ assert_equal(File.directory?(expected_temp_dir), true)
72
+ end
73
+
74
+ it 'should not download if archive file exists' do
75
+ archive_file_dir = "#{ServiceManager.temp_dir}/openshift"
76
+ FileUtils.mkdir_p(archive_file_dir) unless File.directory?(archive_file_dir)
77
+ FileUtils.touch("#{archive_file_dir}/#{@archive_file}")
78
+
79
+ @handler.build_download_url
80
+ @handler.build_archive_path
81
+ @handler.download_archive
82
+
83
+ @handler.skip_download.must_equal true
84
+ end
85
+
86
+ it 'should prepare binary properly' do
87
+ test_archive_path = "#{test_data_dir_path}/#{@archive_file}"
88
+
89
+ @handler.build_download_url
90
+ @handler.build_archive_path
91
+ @handler.ensure_binary_and_temp_directories
92
+
93
+ FileUtils.cp(test_archive_path, @handler.archive_file_path)
94
+
95
+ @handler.prepare_binary
96
+ @handler.binary_name.must_equal 'oc'
97
+ @handler.file_regex.must_equal /oc$/
98
+ if Vagrant::Util::Platform.darwin?
99
+ @handler.archive_handler_class.must_equal VagrantPlugins::ServiceManager::ZipHandler
100
+ else
101
+ @handler.archive_handler_class.must_equal VagrantPlugins::ServiceManager::TarHandler
102
+ end
103
+ assert_equal(File.exist?(@handler.path), true)
104
+ end
105
+ end
106
+ end
107
+ end