foreman_virt_who_configure 0.0.2 → 0.1.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_virt_who_configure/config_copy_and_paste.js +8 -0
  3. data/app/assets/javascripts/foreman_virt_who_configure/config_edit.js +23 -8
  4. data/app/controllers/foreman_virt_who_configure/api/v2/configs_controller.rb +120 -0
  5. data/app/controllers/foreman_virt_who_configure/configs_controller.rb +17 -2
  6. data/app/helpers/foreman_virt_who_configure/compatibility_helper.rb +9 -0
  7. data/app/helpers/foreman_virt_who_configure/configs_helper.rb +4 -10
  8. data/app/models/foreman_virt_who_configure/auth_source_hidden_with_authentication.rb +10 -1
  9. data/app/models/foreman_virt_who_configure/config.rb +24 -29
  10. data/app/models/foreman_virt_who_configure/output_generator.rb +99 -17
  11. data/app/services/sso/basic_with_hidden.rb +1 -1
  12. data/app/views/dashboard/_foreman_virt_who_configs_status_widget.html.erb +7 -8
  13. data/app/views/foreman_virt_who_configure/api/v2/configs/base.json.rabl +3 -0
  14. data/app/views/foreman_virt_who_configure/api/v2/configs/create.json.rabl +3 -0
  15. data/app/views/foreman_virt_who_configure/api/v2/configs/deploy_script.json.rabl +3 -0
  16. data/app/views/foreman_virt_who_configure/api/v2/configs/index.json.rabl +3 -0
  17. data/app/views/foreman_virt_who_configure/api/v2/configs/main.json.rabl +8 -0
  18. data/app/views/foreman_virt_who_configure/api/v2/configs/show.json.rabl +3 -0
  19. data/app/views/foreman_virt_who_configure/api/v2/configs/update.json.rabl +3 -0
  20. data/app/views/foreman_virt_who_configure/configs/show.html.erb +10 -4
  21. data/app/views/foreman_virt_who_configure/configs/steps/_connection_form.erb +13 -13
  22. data/app/views/foreman_virt_who_configure/configs/steps/_general_information_form.erb +4 -4
  23. data/app/views/foreman_virt_who_configure/configs/steps/_schedule_form.erb +1 -2
  24. data/config/routes.rb +19 -0
  25. data/lib/foreman_virt_who_configure/engine.rb +18 -4
  26. data/lib/foreman_virt_who_configure/version.rb +1 -1
  27. data/locale/action_names.rb +1 -0
  28. data/locale/en/LC_MESSAGES/foreman_virt_who_configure.mo +0 -0
  29. data/locale/en/foreman_virt_who_configure.edit.po +733 -0
  30. data/locale/en/foreman_virt_who_configure.po +262 -2
  31. data/locale/en/foreman_virt_who_configure.po.time_stamp +0 -0
  32. data/locale/foreman_virt_who_configure.pot +441 -8
  33. data/test/functional/api/v2/configs_controller_test.rb +178 -0
  34. data/test/unit/output_generator_test.rb +29 -0
  35. metadata +19 -4
@@ -0,0 +1,178 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController::TestCase
4
+ setup do
5
+ @new_config = FactoryGirl.create(:virt_who_config,
6
+ :name => 'my vmware',
7
+ :interval => 120,
8
+ :listing_mode => ForemanVirtWhoConfigure::Config::WHITELIST,
9
+ :whitelist => 'a,b',
10
+ :hypervisor_id => 'hostname',
11
+ :hypervisor_type => 'esx',
12
+ :hypervisor_server => "vmware.example.com",
13
+ :hypervisor_username => "root",
14
+ :debug => false,
15
+ :satellite_url => "foreman.example.com",
16
+ :proxy => 'proxy.example.com',
17
+ :no_proxy => nil
18
+ )
19
+
20
+ @out_of_date_config = FactoryGirl.create(:virt_who_config, :out_of_date)
21
+ @ok_config = FactoryGirl.create(:virt_who_config, :ok)
22
+ end
23
+
24
+ test "should get index" do
25
+ get :index, {}, set_session_user
26
+ response = ActiveSupport::JSON.decode(@response.body)
27
+ assert_not response['results'].empty?
28
+ assert_response :success
29
+
30
+ result_config = response['results'].find { |r| r['id'] == @new_config.id }
31
+ refute_nil result_config
32
+ assert_equal 'my vmware', result_config['name']
33
+ assert_equal 120, result_config['interval']
34
+ assert_equal ForemanVirtWhoConfigure::Config::WHITELIST, result_config['listing_mode']
35
+ assert_equal 'a,b', result_config['whitelist']
36
+ assert_equal 'hostname', result_config['hypervisor_id']
37
+ assert_equal 'esx', result_config['hypervisor_type']
38
+ assert_equal 'vmware.example.com', result_config['hypervisor_server']
39
+ assert_equal 'root', result_config['hypervisor_username']
40
+ refute result_config.has_key?('hypervisor_password')
41
+ refute result_config['debug']
42
+ assert_not_nil result_config['debug']
43
+ assert_equal 'foreman.example.com', result_config['satellite_url']
44
+ assert_equal 'proxy.example.com', result_config['proxy']
45
+ assert_nil result_config['no_proxy']
46
+ assert_equal 'unknown', result_config['status']
47
+ assert_nil result_config['last_report_at']
48
+ assert_nil result_config['out_of_date_at']
49
+
50
+ result_config = response['results'].find { |r| r['id'] == @ok_config.id }
51
+ assert_equal 'ok', result_config['status']
52
+ assert_equal @ok_config.last_report_at.to_s, Time.zone.parse(result_config['last_report_at']).to_s
53
+ assert_equal @ok_config.out_of_date_at.to_s, Time.zone.parse(result_config['out_of_date_at']).to_s
54
+
55
+ result_config = response['results'].find { |r| r['id'] == @out_of_date_config.id }
56
+ assert_equal 'error', result_config['status']
57
+ assert_equal @out_of_date_config.last_report_at.to_s, Time.zone.parse(result_config['last_report_at']).to_s
58
+ assert_equal @out_of_date_config.out_of_date_at.to_s, Time.zone.parse(result_config['out_of_date_at']).to_s
59
+ end
60
+
61
+ test "should get show for new config" do
62
+ get :show, { :id => @new_config.to_param }, set_session_user
63
+ response = ActiveSupport::JSON.decode(@response.body)
64
+
65
+ assert_equal 'my vmware', response['name']
66
+ assert_equal 120, response['interval']
67
+ assert_equal ForemanVirtWhoConfigure::Config::WHITELIST, response['listing_mode']
68
+ assert_equal 'a,b', response['whitelist']
69
+ assert_equal 'hostname', response['hypervisor_id']
70
+ assert_equal 'esx', response['hypervisor_type']
71
+ assert_equal 'vmware.example.com', response['hypervisor_server']
72
+ assert_equal 'root', response['hypervisor_username']
73
+ refute response.has_key?('hypervisor_password')
74
+ refute response['debug']
75
+ assert_not_nil response['debug']
76
+ assert_equal 'foreman.example.com', response['satellite_url']
77
+ assert_equal 'proxy.example.com', response['proxy']
78
+ assert_nil response['no_proxy']
79
+ assert_equal 'unknown', response['status']
80
+ assert_nil response['last_report_at']
81
+ assert_nil response['out_of_date_at']
82
+
83
+ assert_response :success
84
+ end
85
+
86
+ test "should get show for ok config" do
87
+ get :show, { :id => @ok_config.to_param }, set_session_user
88
+ response = ActiveSupport::JSON.decode(@response.body)
89
+
90
+ assert_equal 'ok', response['status']
91
+ assert_equal @ok_config.last_report_at.to_s, Time.zone.parse(response['last_report_at']).to_s
92
+ assert_equal @ok_config.out_of_date_at.to_s, Time.zone.parse(response['out_of_date_at']).to_s
93
+ assert_response :success
94
+ end
95
+
96
+ test "should get show for out of date config" do
97
+ get :show, { :id => @out_of_date_config.to_param }, set_session_user
98
+ response = ActiveSupport::JSON.decode(@response.body)
99
+
100
+ assert_equal 'error', response['status']
101
+ assert_equal @out_of_date_config.last_report_at.to_s, Time.zone.parse(response['last_report_at']).to_s
102
+ assert_equal @out_of_date_config.out_of_date_at.to_s, Time.zone.parse(response['out_of_date_at']).to_s
103
+ assert_response :success
104
+ end
105
+
106
+ test "should get deploy script for config" do
107
+ get :deploy_script, { :id => @out_of_date_config.to_param }, set_session_user
108
+ response = ActiveSupport::JSON.decode(@response.body)
109
+
110
+ assert_response :success
111
+ assert_equal @out_of_date_config.virt_who_config_script, response['virt_who_config_script']
112
+ end
113
+
114
+ test "should get deploy script for plain/text format" do
115
+ get :deploy_script, { :id => @out_of_date_config.to_param, :format => 'txt' }, set_session_user
116
+ response = @response.body
117
+
118
+ assert_response :success
119
+ assert_equal @out_of_date_config.virt_who_config_script, response
120
+ end
121
+
122
+ test "should get deploy script for shell script format" do
123
+ get :deploy_script, { :id => @out_of_date_config.to_param, :format => 'sh' }, set_session_user
124
+ response = @response.body
125
+
126
+ assert_response :success
127
+ assert_equal @out_of_date_config.virt_who_config_script, response
128
+ end
129
+
130
+ test "should create the config" do
131
+ org = FactoryGirl.create(:organization)
132
+ post :create, { :foreman_virt_who_configure_config => { :name => 'my new config',
133
+ :interval => 240,
134
+ :listing_mode => ForemanVirtWhoConfigure::Config::BLACKLIST,
135
+ :blacklist => ' a,b ',
136
+ :hypervisor_id => 'uuid',
137
+ :hypervisor_type => 'esx',
138
+ :hypervisor_server => "vmware.example.com",
139
+ :hypervisor_username => "root",
140
+ :hypervisor_password => "password",
141
+ :debug => true,
142
+ :satellite_url => "foreman.example.com",
143
+ :organization_id => org.id }
144
+ }, set_session_user
145
+
146
+ assert_response :success
147
+
148
+ response = ActiveSupport::JSON.decode(@response.body)
149
+ new_config = ForemanVirtWhoConfigure::Config.find(response['id'])
150
+
151
+ assert_equal 'my new config', new_config.name
152
+ assert_equal 240, new_config.interval
153
+ assert_equal ForemanVirtWhoConfigure::Config::BLACKLIST, new_config.listing_mode
154
+ assert_equal 'a,b', new_config.blacklist
155
+ assert_equal 'uuid', new_config.hypervisor_id
156
+ assert_equal 'vmware.example.com', new_config.hypervisor_server
157
+ assert_equal 'root', new_config.hypervisor_username
158
+ assert_equal 'password', new_config.hypervisor_password
159
+ assert_equal true, new_config.debug
160
+ assert_equal 'foreman.example.com', new_config.satellite_url
161
+ end
162
+
163
+ test "should update the config" do
164
+ put :update, { :id => @ok_config.to_param, :foreman_virt_who_configure_config => { :name => 'updated', :interval => 240, :hypervisor_password => 'new_pass' } }, set_session_user
165
+ assert_response :success
166
+ @ok_config.reload
167
+ assert_equal 'updated', @ok_config.name
168
+ assert_equal 240, @ok_config.interval
169
+ assert_equal 'new_pass', @ok_config.hypervisor_password
170
+ end
171
+
172
+ test "should destroy the config" do
173
+ delete :destroy, { :id => @ok_config.to_param }, set_session_user
174
+ assert_response :success
175
+
176
+ assert_empty ForemanVirtWhoConfigure::Config.where(:id => @ok_config.id).all
177
+ end
178
+ end
@@ -4,6 +4,7 @@ module ForemanVirtWhoConfigure
4
4
  let(:config) { FactoryGirl.create(:virt_who_config) }
5
5
  let(:generator) { OutputGenerator.new(config) }
6
6
  let(:output) { generator.virt_who_output }
7
+ let(:bash_script_output) { generator.virt_who_output(:bash_script) }
7
8
 
8
9
  describe 'filtering' do
9
10
  test 'it should not filter anything for unlimited configs' do
@@ -85,5 +86,33 @@ module ForemanVirtWhoConfigure
85
86
  assert_includes generator.proxy_strings, "\nno_proxy=xyz"
86
87
  end
87
88
  end
89
+
90
+ describe 'error codes' do
91
+ test 'returns code number for known error name specified as symbol' do
92
+ assert_equal 1, generator.error_code(:virt_who_too_old)
93
+ end
94
+
95
+ test 'returns code number for known error name specified as string' do
96
+ assert_equal 0, generator.error_code('success')
97
+ end
98
+
99
+ test 'returns nil for unknown error name' do
100
+ assert_nil generator.error_code('unknown')
101
+ end
102
+ end
103
+
104
+ describe 'output format' do
105
+ test 'it returns the inline content of script if no format is specified' do
106
+ assert_not_includes output, '#!/usr/bin/bash'
107
+ assert_not_includes output, 'exit $result_code'
108
+ assert_includes output, 'echo "Installing virt-who.."'
109
+ end
110
+
111
+ test 'it returns the bash script with shebang and exit code for :bash_script format' do
112
+ assert_includes bash_script_output, "#!/usr/bin/bash\n"
113
+ assert_includes bash_script_output, 'exit $result_code'
114
+ assert_includes bash_script_output, 'echo "Installing virt-who.."'
115
+ end
116
+ end
88
117
  end
89
118
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_virt_who_configure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman virt-who-configure team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -62,8 +62,10 @@ files:
62
62
  - LICENSE
63
63
  - README.md
64
64
  - Rakefile
65
+ - app/assets/javascripts/foreman_virt_who_configure/config_copy_and_paste.js
65
66
  - app/assets/javascripts/foreman_virt_who_configure/config_edit.js
66
67
  - app/assets/stylesheets/foreman_virt_who_configure/config.css.scss
68
+ - app/controllers/foreman_virt_who_configure/api/v2/configs_controller.rb
67
69
  - app/controllers/foreman_virt_who_configure/application_controller.rb
68
70
  - app/controllers/foreman_virt_who_configure/concerns/config_parameters.rb
69
71
  - app/controllers/foreman_virt_who_configure/configs_controller.rb
@@ -76,6 +78,13 @@ files:
76
78
  - app/models/foreman_virt_who_configure/service_user.rb
77
79
  - app/services/sso/basic_with_hidden.rb
78
80
  - app/views/dashboard/_foreman_virt_who_configs_status_widget.html.erb
81
+ - app/views/foreman_virt_who_configure/api/v2/configs/base.json.rabl
82
+ - app/views/foreman_virt_who_configure/api/v2/configs/create.json.rabl
83
+ - app/views/foreman_virt_who_configure/api/v2/configs/deploy_script.json.rabl
84
+ - app/views/foreman_virt_who_configure/api/v2/configs/index.json.rabl
85
+ - app/views/foreman_virt_who_configure/api/v2/configs/main.json.rabl
86
+ - app/views/foreman_virt_who_configure/api/v2/configs/show.json.rabl
87
+ - app/views/foreman_virt_who_configure/api/v2/configs/update.json.rabl
79
88
  - app/views/foreman_virt_who_configure/configs/_form.html.erb
80
89
  - app/views/foreman_virt_who_configure/configs/edit.html.erb
81
90
  - app/views/foreman_virt_who_configure/configs/index.html.erb
@@ -99,10 +108,15 @@ files:
99
108
  - lib/foreman_virt_who_configure/version.rb
100
109
  - lib/tasks/foreman_virt_who_configure_tasks.rake
101
110
  - locale/Makefile
111
+ - locale/action_names.rb
112
+ - locale/en/LC_MESSAGES/foreman_virt_who_configure.mo
113
+ - locale/en/foreman_virt_who_configure.edit.po
102
114
  - locale/en/foreman_virt_who_configure.po
115
+ - locale/en/foreman_virt_who_configure.po.time_stamp
103
116
  - locale/foreman_virt_who_configure.pot
104
117
  - locale/gemspec.rb
105
118
  - test/factories/foreman_virt_who_configure_factories.rb
119
+ - test/functional/api/v2/configs_controller_test.rb
106
120
  - test/test_plugin_helper.rb
107
121
  - test/unit/config_test.rb
108
122
  - test/unit/output_generator_test.rb
@@ -131,7 +145,8 @@ signing_key:
131
145
  specification_version: 4
132
146
  summary: A plugin to make virt-who configuration easy
133
147
  test_files:
148
+ - test/factories/foreman_virt_who_configure_factories.rb
149
+ - test/test_plugin_helper.rb
134
150
  - test/unit/config_test.rb
135
151
  - test/unit/output_generator_test.rb
136
- - test/test_plugin_helper.rb
137
- - test/factories/foreman_virt_who_configure_factories.rb
152
+ - test/functional/api/v2/configs_controller_test.rb