vagrant-kubevirt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +12 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +12 -0
  6. data/LICENSE +13 -0
  7. data/README.md +109 -0
  8. data/Rakefile +22 -0
  9. data/example_box/README.md +9 -0
  10. data/example_box/Vagrantfile +20 -0
  11. data/example_box/kubevirt.box +0 -0
  12. data/example_box/metadata.json +3 -0
  13. data/lib/vagrant-kubevirt.rb +18 -0
  14. data/lib/vagrant-kubevirt/action.rb +176 -0
  15. data/lib/vagrant-kubevirt/action/connect_kubevirt.rb +37 -0
  16. data/lib/vagrant-kubevirt/action/create_vm.rb +133 -0
  17. data/lib/vagrant-kubevirt/action/destroy_vm.rb +30 -0
  18. data/lib/vagrant-kubevirt/action/is_created.rb +18 -0
  19. data/lib/vagrant-kubevirt/action/is_stopped.rb +18 -0
  20. data/lib/vagrant-kubevirt/action/read_ssh_info.rb +54 -0
  21. data/lib/vagrant-kubevirt/action/read_state.rb +44 -0
  22. data/lib/vagrant-kubevirt/action/set_domain_name.rb +33 -0
  23. data/lib/vagrant-kubevirt/action/start_vm.rb +35 -0
  24. data/lib/vagrant-kubevirt/action/stop_vm.rb +37 -0
  25. data/lib/vagrant-kubevirt/action/wait_for_state.rb +64 -0
  26. data/lib/vagrant-kubevirt/config.rb +60 -0
  27. data/lib/vagrant-kubevirt/errors.rb +39 -0
  28. data/lib/vagrant-kubevirt/plugin.rb +73 -0
  29. data/lib/vagrant-kubevirt/provider.rb +50 -0
  30. data/lib/vagrant-kubevirt/version.rb +5 -0
  31. data/locales/en.yml +69 -0
  32. data/spec/spec_helper.rb +6 -0
  33. data/spec/support/environment_helper.rb +18 -0
  34. data/spec/support/kubevirt_context.rb +15 -0
  35. data/spec/support/sharedcontext.rb +33 -0
  36. data/spec/unit/action/create_vm_spec.rb +122 -0
  37. data/spec/unit/action/destroy_vm_spec.rb +33 -0
  38. data/spec/unit/action/read_ssh_info_spec.rb +45 -0
  39. data/spec/unit/action/read_state_spec.rb +44 -0
  40. data/spec/unit/action/start_vm_spec.rb +44 -0
  41. data/spec/unit/action/stop_vm_spec.rb +57 -0
  42. data/spec/unit/action/wait_for_state_spec.rb +57 -0
  43. data/spec/unit/config_spec.rb +41 -0
  44. data/vagrant-kubevirt.gemspec +26 -0
  45. metadata +161 -0
@@ -0,0 +1,33 @@
1
+ require 'support/sharedcontext'
2
+ require 'support/kubevirt_context'
3
+
4
+ require 'vagrant-kubevirt/action/destroy_vm'
5
+
6
+ describe VagrantPlugins::Kubevirt::Action::DestroyVM do
7
+ subject { described_class.new(app, env) }
8
+
9
+ include_context 'unit'
10
+ include_context 'kubevirt'
11
+
12
+ let(:services) { double('service') }
13
+ let(:vminstances) { double('vminstances') }
14
+ let(:vmi) { double('vmi') }
15
+
16
+ describe '#call' do
17
+ before do
18
+ allow(compute).to receive(:vminstances).and_return(vminstances)
19
+ allow(compute).to receive(:services).and_return(services)
20
+ allow(services).to receive(:delete)
21
+ allow(vminstances).to receive(:get).and_return(vmi)
22
+ allow(vmi).to receive(:name).and_return('test')
23
+
24
+ # always see this at the start of #call
25
+ expect(ui).to receive(:info).with('Removing the VM...')
26
+ end
27
+
28
+ it 'destroys a vmi' do
29
+ expect(vminstances).to receive(:destroy).with('test', 'default')
30
+ expect(subject.call(env)).to be_nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ require 'support/sharedcontext'
2
+ require 'support/kubevirt_context'
3
+
4
+ require 'vagrant-kubevirt/action/read_ssh_info'
5
+
6
+ describe VagrantPlugins::Kubevirt::Action::ReadSSHInfo do
7
+ subject { described_class.new(app, env) }
8
+
9
+ include_context 'unit'
10
+ include_context 'kubevirt'
11
+
12
+ let(:services) { double('services') }
13
+ let(:service) { double('service') }
14
+ let(:vminstances) { double('vminstances') }
15
+ let(:vmi) { double('vmi') }
16
+
17
+ describe '#call' do
18
+ before do
19
+ allow(compute).to receive(:vminstances).and_return(vminstances)
20
+ allow(compute).to receive(:services).and_return(services)
21
+ end
22
+
23
+ it 'checks when no id' do
24
+ allow(env[:machine]).to receive(:id).and_return(nil)
25
+
26
+ expect(subject.call(env)).to be_nil
27
+ end
28
+
29
+ it 'checks when no running vm' do
30
+ allow(vminstances).to receive(:get).and_return(nil)
31
+
32
+ expect(subject.call(env)).to be_nil
33
+ end
34
+
35
+ it 'checks when a running vm' do
36
+ allow(vminstances).to receive(:get).and_return(vmi)
37
+ allow(vmi).to receive(:node_name).and_return('127.0.0.1')
38
+ allow(services).to receive(:get).and_return(service)
39
+ allow(service).to receive(:node_port).and_return(30000)
40
+
41
+ expect(subject.call(env)).to be_nil
42
+ expect(env[:machine_ssh_info]).to eq({:host => '127.0.0.1', :port => 30000 })
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require 'support/sharedcontext'
2
+ require 'support/kubevirt_context'
3
+
4
+ require 'vagrant-kubevirt/action/read_state'
5
+
6
+ describe VagrantPlugins::Kubevirt::Action::ReadState do
7
+ subject { described_class.new(app, env) }
8
+
9
+ include_context 'unit'
10
+ include_context 'kubevirt'
11
+
12
+ let(:vms) { double('vms') }
13
+ let(:vm) { double('vm') }
14
+
15
+ describe '#call' do
16
+ before do
17
+ allow(compute).to receive(:vms).and_return(vms)
18
+ end
19
+
20
+ it 'checks when no vm' do
21
+ allow(env[:machine]).to receive(:id).and_return(nil)
22
+ expect(subject.call(env)).to be_nil
23
+
24
+ expect(env[:machine_state_id]).to eq(:not_created)
25
+ end
26
+
27
+ it 'checks when a vm in running state' do
28
+ allow(vms).to receive(:get).and_return(vm)
29
+ allow(vm).to receive(:status).and_return(:running)
30
+
31
+ expect(subject.call(env)).to be_nil
32
+
33
+ expect(env[:machine_state_id]).to eq(:running)
34
+ end
35
+
36
+ it 'checks when a vm not found' do
37
+ allow(vms).to receive(:get).and_raise(Fog::Kubevirt::Errors::ClientError, "404")
38
+
39
+ expect(subject.call(env)).to be_nil
40
+
41
+ expect(env[:machine_state_id]).to eq(:not_created)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ require 'support/sharedcontext'
2
+ require 'support/kubevirt_context'
3
+
4
+ require 'vagrant-kubevirt/errors'
5
+ require 'vagrant-kubevirt/action/start_vm'
6
+
7
+ describe VagrantPlugins::Kubevirt::Action::StartVM do
8
+ subject { described_class.new(app, env) }
9
+
10
+ include_context 'unit'
11
+ include_context 'kubevirt'
12
+
13
+ let(:vms) { double('vms') }
14
+ let(:vm) { double('vm') }
15
+
16
+ describe '#call' do
17
+ before do
18
+ allow(compute).to receive(:vms).and_return(vms)
19
+
20
+ # always see this at the start of #call
21
+ expect(ui).to receive(:info).with('Starting the VM...')
22
+ end
23
+
24
+ it 'starts a vm' do
25
+ allow(vms).to receive(:get).and_return(vm)
26
+ expect(vm).to receive(:start)
27
+
28
+ expect(subject.call(env)).to be_nil
29
+ end
30
+
31
+ it 'fails to find a vm' do
32
+ allow(vms).to receive(:get).and_return(nil)
33
+
34
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::Kubevirt::Errors::NoVMError)
35
+ end
36
+
37
+ it 'fails to start a vm' do
38
+ allow(vms).to receive(:get).and_return(vm)
39
+ expect(vm).to receive(:start).and_raise(::Fog::Errors::Error)
40
+
41
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::Kubevirt::Errors::StartVMError)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,57 @@
1
+ require 'fog/kubevirt'
2
+
3
+ require 'spec_helper'
4
+ require 'support/sharedcontext'
5
+ require 'support/kubevirt_context'
6
+
7
+ require 'vagrant-kubevirt/errors'
8
+ require 'vagrant-kubevirt/action/stop_vm'
9
+
10
+ describe VagrantPlugins::Kubevirt::Action::StopVM do
11
+ subject { described_class.new(app, env) }
12
+
13
+ include_context 'unit'
14
+ include_context 'kubevirt'
15
+
16
+ let(:vms) { double('vms') }
17
+ let(:vm) { double('vm') }
18
+
19
+ describe '#call' do
20
+ before do
21
+ allow(compute).to receive(:vms).and_return(vms)
22
+ end
23
+
24
+ it 'stops a vm' do
25
+ allow(vms).to receive(:get).and_return(vm)
26
+ allow(vm).to receive(:status).and_return(:running)
27
+ expect(vm).to receive(:stop)
28
+ expect(ui).to receive(:info).with('Stopping the VM...')
29
+
30
+ expect(subject.call(env)).to be_nil
31
+ end
32
+
33
+ it 'fails to find a vm' do
34
+ allow(vms).to receive(:get).and_return(nil)
35
+
36
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::Kubevirt::Errors::NoVMError)
37
+ end
38
+
39
+ it 'finds already stopped vm' do
40
+ allow(vms).to receive(:get).and_return(vm)
41
+ allow(vm).to receive(:status).and_return(:stopped)
42
+ expect(vm).not_to receive(:stop)
43
+ expect(ui).to receive(:info).with('The VM is already stopped.')
44
+
45
+ expect(subject.call(env)).to be_nil
46
+ end
47
+
48
+ it 'fails to start a vm' do
49
+ allow(vms).to receive(:get).and_return(vm)
50
+ allow(vm).to receive(:status).and_return(:running)
51
+ expect(vm).to receive(:stop).and_raise(::Fog::Errors::Error)
52
+ expect(ui).to receive(:info).with('Stopping the VM...')
53
+
54
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::Kubevirt::Errors::StopVMError)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ require "timeout"
2
+
3
+ require 'support/sharedcontext'
4
+ require 'support/kubevirt_context'
5
+
6
+ require 'vagrant-kubevirt/errors'
7
+ require 'vagrant-kubevirt/action/wait_for_state'
8
+
9
+ describe VagrantPlugins::Kubevirt::Action::WaitForState do
10
+ subject { described_class.new(app, env, :running, 0.2) }
11
+
12
+ include_context 'unit'
13
+ include_context 'kubevirt'
14
+
15
+ let(:vms) { double('vms') }
16
+ let(:vm) { double('vm') }
17
+ let(:watch) { double('watch') }
18
+ let(:notice) { double('notice') }
19
+
20
+ describe '#call' do
21
+ before do
22
+ allow(compute).to receive(:watch_vms).and_return(watch)
23
+ allow(compute).to receive(:vms).and_return(vms)
24
+ allow(vms).to receive(:get).and_return(vm)
25
+ end
26
+
27
+ it 'checks already running vm' do
28
+ allow(vm).to receive(:status).and_return(:running)
29
+ expect(ui).to receive(:info).with('The VM is already running.')
30
+ expect(watch).to receive(:finish)
31
+
32
+ expect(subject.call(env)).to be_nil
33
+ end
34
+
35
+ it 'timeouts when waiting on running state' do
36
+ allow(vm).to receive(:status).and_return(:stopped)
37
+ expect(ui).to receive(:info).with('Waiting for VM to reach state running')
38
+ expect(Timeout).to receive(:timeout).and_raise(Timeout::Error)
39
+
40
+ expect { subject.call(env) }.to raise_error(::VagrantPlugins::Kubevirt::Errors::VMReadyTimeout)
41
+ end
42
+
43
+ it 'waits on vm to start' do
44
+ allow(vm).to receive(:status).and_return(:stopped)
45
+ expect(ui).to receive(:info).with('Waiting for VM to reach state running')
46
+
47
+ allow(notice).to receive(:kind).and_return('VirtualMachine')
48
+ allow(notice).to receive(:name).and_return('test')
49
+ allow(notice).to receive(:status).and_return('running')
50
+
51
+ allow(watch).to receive(:each).and_return(notice)
52
+
53
+ expect(watch).to receive(:finish)
54
+ expect(subject.call(env)).to be_nil
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'support/sharedcontext'
3
+
4
+ require 'vagrant-kubevirt/config'
5
+
6
+ describe VagrantPlugins::Kubevirt::Config do
7
+ include_context 'unit'
8
+
9
+ def assert_invalid
10
+ errors = subject.validate(machine)
11
+ raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
12
+ end
13
+
14
+ def assert_valid
15
+ errors = subject.validate(machine)
16
+ raise "Errors: #{errors.inspect}" unless errors.values.all?(&:empty?)
17
+ end
18
+
19
+ describe '#validate' do
20
+ it 'is valid with defaults' do
21
+ assert_valid
22
+ end
23
+
24
+ context 'with missing params' do
25
+ let(:vm) { double('vm') }
26
+ let(:config) { double('config')}
27
+
28
+ before do
29
+ allow(subject).to receive(:template).and_return(nil)
30
+ allow(subject).to receive(:image).and_return(nil)
31
+ allow(subject).to receive(:pvc).and_return(nil)
32
+
33
+ expect(machine).to receive(:provider_config).and_return(subject).at_least(:once)
34
+ end
35
+
36
+ it 'is missing image info' do
37
+ assert_invalid
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-kubevirt/version"
3
+
4
+ Gem::Specification.new do |gem|
5
+ # Dynamically create the authors information {name => e-mail}
6
+ authors_hash = Hash[`git log --no-merges --reverse --format='%an,%ae'`.split("\n").uniq.collect {|i| i.split(",")}]
7
+
8
+ gem.authors = authors_hash.keys
9
+ gem.email = authors_hash.values
10
+ gem.description = %q{Vagrant provider for KubeVirt.}
11
+ gem.summary = %q{Vagrant provider for KubeVirt.}
12
+ gem.homepage = "https://github.com/pkliczewski/vagrant-kubevirt"
13
+ gem.license = "Apache-2.0"
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
17
+ gem.name = "vagrant-kubevirt"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = VagrantPlugins::Kubevirt::VERSION
20
+
21
+ gem.add_runtime_dependency "fog-kubevirt", "~> 1.3.0"
22
+ gem.add_runtime_dependency "iniparse", "~> 1.4", ">= 1.4.2"
23
+
24
+ gem.add_development_dependency "rspec", "~> 3.4"
25
+ gem.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-kubevirt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Kliczewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fog-kubevirt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: iniparse
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.4.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.4'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.4.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.4'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Vagrant provider for KubeVirt.
76
+ email:
77
+ - piotr.kliczewski@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - CHANGELOG.md
85
+ - Gemfile
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - example_box/README.md
90
+ - example_box/Vagrantfile
91
+ - example_box/kubevirt.box
92
+ - example_box/metadata.json
93
+ - lib/vagrant-kubevirt.rb
94
+ - lib/vagrant-kubevirt/action.rb
95
+ - lib/vagrant-kubevirt/action/connect_kubevirt.rb
96
+ - lib/vagrant-kubevirt/action/create_vm.rb
97
+ - lib/vagrant-kubevirt/action/destroy_vm.rb
98
+ - lib/vagrant-kubevirt/action/is_created.rb
99
+ - lib/vagrant-kubevirt/action/is_stopped.rb
100
+ - lib/vagrant-kubevirt/action/read_ssh_info.rb
101
+ - lib/vagrant-kubevirt/action/read_state.rb
102
+ - lib/vagrant-kubevirt/action/set_domain_name.rb
103
+ - lib/vagrant-kubevirt/action/start_vm.rb
104
+ - lib/vagrant-kubevirt/action/stop_vm.rb
105
+ - lib/vagrant-kubevirt/action/wait_for_state.rb
106
+ - lib/vagrant-kubevirt/config.rb
107
+ - lib/vagrant-kubevirt/errors.rb
108
+ - lib/vagrant-kubevirt/plugin.rb
109
+ - lib/vagrant-kubevirt/provider.rb
110
+ - lib/vagrant-kubevirt/version.rb
111
+ - locales/en.yml
112
+ - spec/spec_helper.rb
113
+ - spec/support/environment_helper.rb
114
+ - spec/support/kubevirt_context.rb
115
+ - spec/support/sharedcontext.rb
116
+ - spec/unit/action/create_vm_spec.rb
117
+ - spec/unit/action/destroy_vm_spec.rb
118
+ - spec/unit/action/read_ssh_info_spec.rb
119
+ - spec/unit/action/read_state_spec.rb
120
+ - spec/unit/action/start_vm_spec.rb
121
+ - spec/unit/action/stop_vm_spec.rb
122
+ - spec/unit/action/wait_for_state_spec.rb
123
+ - spec/unit/config_spec.rb
124
+ - vagrant-kubevirt.gemspec
125
+ homepage: https://github.com/pkliczewski/vagrant-kubevirt
126
+ licenses:
127
+ - Apache-2.0
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.7.6.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Vagrant provider for KubeVirt.
149
+ test_files:
150
+ - spec/spec_helper.rb
151
+ - spec/support/environment_helper.rb
152
+ - spec/support/kubevirt_context.rb
153
+ - spec/support/sharedcontext.rb
154
+ - spec/unit/action/create_vm_spec.rb
155
+ - spec/unit/action/destroy_vm_spec.rb
156
+ - spec/unit/action/read_ssh_info_spec.rb
157
+ - spec/unit/action/read_state_spec.rb
158
+ - spec/unit/action/start_vm_spec.rb
159
+ - spec/unit/action/stop_vm_spec.rb
160
+ - spec/unit/action/wait_for_state_spec.rb
161
+ - spec/unit/config_spec.rb