foreman_virt_who_configure 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +35 -0
  4. data/Rakefile +47 -0
  5. data/app/assets/javascripts/foreman_virt_who_configure/config_edit.js +31 -0
  6. data/app/assets/stylesheets/foreman_virt_who_configure/config.css.scss +13 -0
  7. data/app/controllers/foreman_virt_who_configure/application_controller.rb +11 -0
  8. data/app/controllers/foreman_virt_who_configure/concerns/config_parameters.rb +22 -0
  9. data/app/controllers/foreman_virt_who_configure/configs_controller.rb +94 -0
  10. data/app/helpers/foreman_virt_who_configure/compatibility_helper.rb +22 -0
  11. data/app/helpers/foreman_virt_who_configure/configs_helper.rb +25 -0
  12. data/app/models/foreman_virt_who_configure/auth_source_hidden_with_authentication.rb +13 -0
  13. data/app/models/foreman_virt_who_configure/config.rb +157 -0
  14. data/app/models/foreman_virt_who_configure/output_generator.rb +152 -0
  15. data/app/models/foreman_virt_who_configure/service_user.rb +21 -0
  16. data/app/services/sso/basic_with_hidden.rb +11 -0
  17. data/app/views/dashboard/_foreman_virt_who_configure_widget.html.erb +2 -0
  18. data/app/views/foreman_virt_who_configure/configs/_form.html.erb +20 -0
  19. data/app/views/foreman_virt_who_configure/configs/edit.html.erb +3 -0
  20. data/app/views/foreman_virt_who_configure/configs/index.html.erb +27 -0
  21. data/app/views/foreman_virt_who_configure/configs/new.html.erb +3 -0
  22. data/app/views/foreman_virt_who_configure/configs/show.html.erb +24 -0
  23. data/app/views/foreman_virt_who_configure/configs/steps/_connection_form.erb +16 -0
  24. data/app/views/foreman_virt_who_configure/configs/steps/_general_information_form.erb +12 -0
  25. data/app/views/foreman_virt_who_configure/configs/steps/_schedule_form.erb +4 -0
  26. data/app/views/foreman_virt_who_configure/configs/welcome.html.erb +14 -0
  27. data/config/routes.rb +9 -0
  28. data/db/migrate/20170102152649_create_service_users.rb +12 -0
  29. data/db/migrate/20170102152650_create_configs.rb +22 -0
  30. data/db/migrate/20170102152751_add_lab_attrs_to_config.rb +9 -0
  31. data/db/migrate/20170102152851_add_satellite_url_to_config.rb +5 -0
  32. data/db/migrate/20170215152851_change_default_interval.rb +9 -0
  33. data/db/migrate/20170309161551_add_proxy_and_no_proxy_to_config.rb +11 -0
  34. data/lib/foreman_virt_who_configure/engine.rb +108 -0
  35. data/lib/foreman_virt_who_configure/version.rb +3 -0
  36. data/lib/foreman_virt_who_configure.rb +4 -0
  37. data/lib/tasks/foreman_virt_who_configure_tasks.rake +47 -0
  38. data/locale/Makefile +60 -0
  39. data/locale/en/foreman_virt_who_configure.po +19 -0
  40. data/locale/foreman_virt_who_configure.pot +19 -0
  41. data/locale/gemspec.rb +2 -0
  42. data/test/factories/foreman_virt_who_configure_factories.rb +13 -0
  43. data/test/test_plugin_helper.rb +6 -0
  44. data/test/unit/config_test.rb +65 -0
  45. data/test/unit/output_generator_test.rb +89 -0
  46. metadata +134 -0
@@ -0,0 +1,3 @@
1
+ module ForemanVirtWhoConfigure
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'foreman_virt_who_configure/engine'
2
+
3
+ module ForemanVirtWhoConfigure
4
+ end
@@ -0,0 +1,47 @@
1
+ require 'rake/testtask'
2
+
3
+ # Tasks
4
+ namespace :foreman_virt_who_configure do
5
+ namespace :example do
6
+ desc 'Example Task'
7
+ task task: :environment do
8
+ # Task goes here
9
+ end
10
+ end
11
+ end
12
+
13
+ # Tests
14
+ namespace :test do
15
+ desc 'Test ForemanVirtWhoConfigure'
16
+ Rake::TestTask.new(:foreman_virt_who_configure) do |t|
17
+ test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
18
+ t.libs << ['test', test_dir]
19
+ t.pattern = "#{test_dir}/**/*_test.rb"
20
+ t.verbose = true
21
+ t.warning = false
22
+ end
23
+ end
24
+
25
+ namespace :foreman_virt_who_configure do
26
+ task :rubocop do
27
+ begin
28
+ require 'rubocop/rake_task'
29
+ RuboCop::RakeTask.new(:rubocop_foreman_virt_who_configure) do |task|
30
+ task.patterns = ["#{ForemanVirtWhoConfigure::Engine.root}/app/**/*.rb",
31
+ "#{ForemanVirtWhoConfigure::Engine.root}/lib/**/*.rb",
32
+ "#{ForemanVirtWhoConfigure::Engine.root}/test/**/*.rb"]
33
+ end
34
+ rescue
35
+ puts 'Rubocop not loaded.'
36
+ end
37
+
38
+ Rake::Task['rubocop_foreman_virt_who_configure'].invoke
39
+ end
40
+ end
41
+
42
+ Rake::Task[:test].enhance ['test:foreman_virt_who_configure']
43
+
44
+ load 'tasks/jenkins.rake'
45
+ if Rake::Task.task_defined?(:'jenkins:unit')
46
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_virt_who_configure', 'foreman_virt_who_configure:rubocop']
47
+ end
data/locale/Makefile ADDED
@@ -0,0 +1,60 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. More info in the README.
3
+ #
4
+ # make all-mo (default) - generate MO files
5
+ # make check - check translations using translate-tool
6
+ # make tx-update - download and merge translations from Transifex
7
+ # make clean - clean everything
8
+ #
9
+ DOMAIN = foreman_virt_who_configure
10
+ VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
+ POTFILE = $(DOMAIN).pot
12
+ MOFILE = $(DOMAIN).mo
13
+ POFILES = $(shell find . -name '$(DOMAIN).po')
14
+ MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
+ POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
+ EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+
18
+ %.mo: %.po
19
+ mkdir -p $(shell dirname $@)/LC_MESSAGES
20
+ msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
21
+
22
+ # Generate MO files from PO files
23
+ all-mo: $(MOFILES)
24
+
25
+ # Check for malformed strings
26
+ %.pox: %.po
27
+ msgfmt -c $<
28
+ pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
29
+ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
30
+ cat $@
31
+ ! grep -q msgid $@
32
+
33
+ %.edit.po:
34
+ touch $@
35
+
36
+ check: $(POXFILES)
37
+
38
+ # Unify duplicate translations
39
+ uniq-po:
40
+ for f in $(shell find ./ -name "*.po") ; do \
41
+ msguniq $$f -o $$f ; \
42
+ done
43
+
44
+ tx-pull: $(EDITFILES)
45
+ tx pull -f
46
+ for f in $(EDITFILES) ; do \
47
+ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
48
+ done
49
+
50
+ tx-update: tx-pull
51
+ @echo
52
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo
54
+
55
+ mo-files: $(MOFILES)
56
+ git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
57
+ git commit -m "i18n - pulling from tx"
58
+ @echo
59
+ @echo Changes commited!
60
+ @echo
@@ -0,0 +1,19 @@
1
+ # foreman_virt_who_configure
2
+ #
3
+ # This file is distributed under the same license as foreman_virt_who_configure.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:54+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+
@@ -0,0 +1,19 @@
1
+ # foreman_virt_who_configure
2
+ #
3
+ # This file is distributed under the same license as foreman_virt_who_configure.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: version 0.0.1\n"
9
+ "Report-Msgid-Bugs-To: \n"
10
+ "POT-Creation-Date: 2014-08-20 08:46+0100\n"
11
+ "PO-Revision-Date: 2014-08-20 08:46+0100\n"
12
+ "Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
13
+ "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
19
+
data/locale/gemspec.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Matches foreman_virt_who_configure.gemspec
2
+ _('A plugin to make virt-who configuration easy')
@@ -0,0 +1,13 @@
1
+ FactoryGirl.define do
2
+ factory :virt_who_config, :class => ::ForemanVirtWhoConfigure::Config do
3
+ organization
4
+ interval 120
5
+ hypervisor_id 'hostname'
6
+ hypervisor_type 'esx'
7
+ hypervisor_server 'vmware.example.com'
8
+ hypervisor_username 'root'
9
+ hypervisor_password 'changeme'
10
+ satellite_url 'foreman.example.com'
11
+ listing_mode ForemanVirtWhoConfigure::Config::UNLIMITED
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+
4
+ # Add plugin to FactoryGirl's paths
5
+ FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
6
+ FactoryGirl.reload
@@ -0,0 +1,65 @@
1
+ require 'test_plugin_helper'
2
+
3
+ module ForemanVirtWhoConfigure
4
+ class ConfigTest < ActiveSupport::TestCase
5
+ let(:config) { FactoryGirl.build(:virt_who_config) }
6
+
7
+ test 'config can be saved' do
8
+ config.save
9
+ assert_empty config.errors
10
+ assert config.persisted?
11
+ end
12
+
13
+ describe 'config is created' do
14
+ let(:existing_config) { config.save; config }
15
+
16
+ test 'config creates service user upon creation' do
17
+ assert existing_config.service_user
18
+ assert_equal "virt_who_reporter_#{config.id}", existing_config.service_user.username
19
+ end
20
+
21
+ test 'config creates hidden user' do
22
+ assert existing_config.service_user.user
23
+ assert_equal existing_config.service_user.username, existing_config.service_user.user.login
24
+ assert_kind_of ForemanVirtWhoConfigure::AuthSourceHiddenWithAuthentication, existing_config.service_user.user.auth_source
25
+ end
26
+
27
+ test 'config deletes service user and user upon removal' do
28
+ service_user = existing_config.service_user
29
+ user = service_user.user
30
+ assert existing_config.destroy
31
+ assert_raises ActiveRecord::RecordNotFound do
32
+ service_user.reload
33
+ end
34
+ assert_raises ActiveRecord::RecordNotFound do
35
+ user.reload
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'listing mode' do
41
+ test 'whitelisting mode requires blacklist to be set' do
42
+ config.listing_mode = ForemanVirtWhoConfigure::Config::WHITELIST
43
+ refute config.valid?
44
+ assert_includes config.errors.keys, :whitelist
45
+
46
+ config.whitelist = 'a.host'
47
+ assert config.valid?
48
+ end
49
+
50
+ test 'blacklisting mode requires blacklist to be set' do
51
+ config.listing_mode = ForemanVirtWhoConfigure::Config::BLACKLIST
52
+ refute config.valid?
53
+ assert_includes config.errors.keys, :blacklist
54
+
55
+ config.blacklist = 'a.host'
56
+ assert config.valid?
57
+ end
58
+
59
+ test 'whitelisting accepts regular expressions' do
60
+ config.whitelist = '^some.*'
61
+ assert config.valid?
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_plugin_helper'
2
+ module ForemanVirtWhoConfigure
3
+ class OutputGeneratorTest < ActiveSupport::TestCase
4
+ let(:config) { FactoryGirl.create(:virt_who_config) }
5
+ let(:generator) { OutputGenerator.new(config) }
6
+ let(:output) { generator.virt_who_output }
7
+
8
+ describe 'filtering' do
9
+ test 'it should not filter anything for unlimited configs' do
10
+ assert_equal ForemanVirtWhoConfigure::Config::UNLIMITED, config.listing_mode.to_i
11
+ assert_not_includes output, 'filter_hosts'
12
+ assert_not_includes output, 'exclude_hosts'
13
+ end
14
+
15
+ test 'whitelisting should set filter_hosts directive' do
16
+ config.listing_mode = ForemanVirtWhoConfigure::Config::WHITELIST
17
+ config.whitelist = 'a.host'
18
+ assert_includes output, 'filter_hosts=a.host'
19
+ end
20
+
21
+ test 'whitelisting should set exclude_hosts directive' do
22
+ config.listing_mode = ForemanVirtWhoConfigure::Config::BLACKLIST
23
+ config.blacklist = 'a.host'
24
+ assert_includes output, 'exclude_hosts=a.host'
25
+ end
26
+
27
+ test 'filtering output is stripped' do
28
+ config.listing_mode = ForemanVirtWhoConfigure::Config::WHITELIST
29
+ config.whitelist = ' name '
30
+ assert_includes output, 'filter_hosts=name'
31
+ end
32
+
33
+ test 'filtering output is stripped for multiple values as well' do
34
+ config.listing_mode = ForemanVirtWhoConfigure::Config::WHITELIST
35
+ config.whitelist = ' host1,host2 '
36
+ assert_includes output, 'filter_hosts=host1,host2'
37
+ end
38
+
39
+ test 'filtering output new line characters are removed' do
40
+ config.listing_mode = ForemanVirtWhoConfigure::Config::WHITELIST
41
+ config.whitelist = "aaaa,bbb,\r\nccc,\r\n\r\nddd\r\n\r\neee"
42
+ assert_includes output, 'filter_hosts=aaaa,bbb,ccc,dddeee'
43
+
44
+ config.whitelist = "aaaa,bbb,\rccc,\n\r\nddd\neee"
45
+ assert_includes output, 'filter_hosts=aaaa,bbb,ccc,dddeee'
46
+ end
47
+ end
48
+
49
+ describe 'proxy attributes' do
50
+ test 'it does not set any proxy attributes by default' do
51
+ assert_nil config.proxy
52
+ assert_nil config.no_proxy
53
+ assert_not_includes output, 'http_proxy'
54
+ assert_not_includes output, 'no_proxy'
55
+ end
56
+
57
+ test 'it configures proxy when set' do
58
+ config.proxy = 'http://proxy.com'
59
+ assert_includes output, 'http_proxy=http://proxy.com'
60
+ end
61
+
62
+ test 'it configures no_proxy when set' do
63
+ config.no_proxy = '*'
64
+ assert_includes output, 'no_proxy=*'
65
+ end
66
+
67
+ test 'proxy_strings prints both proxy and no proxy if present' do
68
+ config.proxy = 'a'
69
+ config.no_proxy = 'b'
70
+ assert_includes generator.proxy_strings, "\nhttp_proxy=a"
71
+ assert_includes generator.proxy_strings, "\nno_proxy=b"
72
+ end
73
+
74
+ test 'proxy_strings ignores empty string values' do
75
+ config.proxy = ''
76
+ config.no_proxy = ''
77
+ assert_not_includes generator.proxy_strings, 'http_proxy'
78
+ assert_not_includes generator.proxy_strings, 'no_proxy'
79
+ end
80
+
81
+ test 'proxy_strings removes any new line chars' do
82
+ config.proxy = "\na\nb\nc\n"
83
+ config.no_proxy = "\nx\ny\nz"
84
+ assert_includes generator.proxy_strings, "\nhttp_proxy=abc"
85
+ assert_includes generator.proxy_strings, "\nno_proxy=xyz"
86
+ end
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman_virt_who_configure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Foreman virt-who-configure team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: katello
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A plugin to make virt-who configuration easy
56
+ email:
57
+ - foreman-dev@googlegroups.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/javascripts/foreman_virt_who_configure/config_edit.js
66
+ - app/assets/stylesheets/foreman_virt_who_configure/config.css.scss
67
+ - app/controllers/foreman_virt_who_configure/application_controller.rb
68
+ - app/controllers/foreman_virt_who_configure/concerns/config_parameters.rb
69
+ - app/controllers/foreman_virt_who_configure/configs_controller.rb
70
+ - app/helpers/foreman_virt_who_configure/compatibility_helper.rb
71
+ - app/helpers/foreman_virt_who_configure/configs_helper.rb
72
+ - app/models/foreman_virt_who_configure/auth_source_hidden_with_authentication.rb
73
+ - app/models/foreman_virt_who_configure/config.rb
74
+ - app/models/foreman_virt_who_configure/output_generator.rb
75
+ - app/models/foreman_virt_who_configure/service_user.rb
76
+ - app/services/sso/basic_with_hidden.rb
77
+ - app/views/dashboard/_foreman_virt_who_configure_widget.html.erb
78
+ - app/views/foreman_virt_who_configure/configs/_form.html.erb
79
+ - app/views/foreman_virt_who_configure/configs/edit.html.erb
80
+ - app/views/foreman_virt_who_configure/configs/index.html.erb
81
+ - app/views/foreman_virt_who_configure/configs/new.html.erb
82
+ - app/views/foreman_virt_who_configure/configs/show.html.erb
83
+ - app/views/foreman_virt_who_configure/configs/steps/_connection_form.erb
84
+ - app/views/foreman_virt_who_configure/configs/steps/_general_information_form.erb
85
+ - app/views/foreman_virt_who_configure/configs/steps/_schedule_form.erb
86
+ - app/views/foreman_virt_who_configure/configs/welcome.html.erb
87
+ - config/routes.rb
88
+ - db/migrate/20170102152649_create_service_users.rb
89
+ - db/migrate/20170102152650_create_configs.rb
90
+ - db/migrate/20170102152751_add_lab_attrs_to_config.rb
91
+ - db/migrate/20170102152851_add_satellite_url_to_config.rb
92
+ - db/migrate/20170215152851_change_default_interval.rb
93
+ - db/migrate/20170309161551_add_proxy_and_no_proxy_to_config.rb
94
+ - lib/foreman_virt_who_configure.rb
95
+ - lib/foreman_virt_who_configure/engine.rb
96
+ - lib/foreman_virt_who_configure/version.rb
97
+ - lib/tasks/foreman_virt_who_configure_tasks.rake
98
+ - locale/Makefile
99
+ - locale/en/foreman_virt_who_configure.po
100
+ - locale/foreman_virt_who_configure.pot
101
+ - locale/gemspec.rb
102
+ - test/factories/foreman_virt_who_configure_factories.rb
103
+ - test/test_plugin_helper.rb
104
+ - test/unit/config_test.rb
105
+ - test/unit/output_generator_test.rb
106
+ homepage: https://github.com/theforeman/foreman_virt_who_configure
107
+ licenses:
108
+ - GPLv3
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A plugin to make virt-who configuration easy
130
+ test_files:
131
+ - test/unit/config_test.rb
132
+ - test/unit/output_generator_test.rb
133
+ - test/test_plugin_helper.rb
134
+ - test/factories/foreman_virt_who_configure_factories.rb