foreman_expire_hosts 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +54 -0
- data/.rubocop_todo.yml +74 -0
- data/Gemfile +3 -0
- data/LICENSE +674 -0
- data/README.md +124 -0
- data/app/assets/javascripts/foreman_expire_hosts/application.js +3 -0
- data/app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js +27 -0
- data/app/assets/stylesheets/foreman_expire_hosts/application.scss +4 -0
- data/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb +73 -0
- data/app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb +41 -0
- data/app/helpers/expire_hosts_mailer_helper.rb +15 -0
- data/app/mailers/expire_hosts_mailer.rb +37 -0
- data/app/models/concerns/foreman_expire_hosts/host_ext.rb +86 -0
- data/app/models/host_status/expiration_status.rb +57 -0
- data/app/models/setting/expire_hosts.rb +21 -0
- data/app/overrides/add_expired_on_field_to_host_form.rb +6 -0
- data/app/overrides/add_expired_on_field_to_host_show.rb +6 -0
- data/app/overrides/add_js_to_host_index.rb +6 -0
- data/app/overrides/deleted_expired_host_comment_in_audits.rb +13 -0
- data/app/views/expire_hosts_mailer/_hosts_table.html.erb +40 -0
- data/app/views/expire_hosts_mailer/deleted_hosts_notification.html.erb +3 -0
- data/app/views/expire_hosts_mailer/expiry_warning_notification.html.erb +4 -0
- data/app/views/expire_hosts_mailer/failed_to_delete_hosts_notification.html.erb +4 -0
- data/app/views/expire_hosts_mailer/failed_to_stop_hosts_notification.html.erb +4 -0
- data/app/views/expire_hosts_mailer/stopped_hosts_notification.html.erb +4 -0
- data/app/views/hosts/_expired_message.html.erb +4 -0
- data/app/views/hosts/_expired_on_field.html.erb +20 -0
- data/app/views/hosts/select_multiple_expiration.html.erb +23 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20150427101516_add_expiry_on_to_hosts.rb +5 -0
- data/foreman_expire_hosts.gemspec +26 -0
- data/lib/expire_hosts_notifications.rb +121 -0
- data/lib/foreman_expire_hosts/engine.rb +61 -0
- data/lib/foreman_expire_hosts/version.rb +3 -0
- data/lib/foreman_expire_hosts.rb +3 -0
- data/lib/tasks/expired_hosts.rake +46 -0
- data/test/factories/foreman_expire_hosts_factories.rb +15 -0
- data/test/functional/concerns/hosts_controller_extensions_test.rb +45 -0
- data/test/test_plugin_helper.rb +10 -0
- data/test/unit/concerns/host_extensions_test.rb +136 -0
- data/test/unit/host_status/expiration_status_test.rb +28 -0
- metadata +153 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../lib/foreman_expire_hosts/version', __FILE__)
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'foreman_expire_hosts'
|
6
|
+
s.version = ForemanExpireHosts::VERSION
|
7
|
+
s.date = Date.today.to_s
|
8
|
+
s.authors = ['Nagarjuna Rachaneni', 'Timo Goebel']
|
9
|
+
s.email = ['nn.nagarjuna@gmail.com', 'mail@timogoebel.name']
|
10
|
+
s.summary = 'Foreman plugin for limiting host lifetime'
|
11
|
+
s.description = 'This Plugin will add new column expired_on to hosts to limit the lifetime of a host.'
|
12
|
+
s.homepage = 'https://github.com/theforeman/foreman_expire_hosts'
|
13
|
+
s.licenses = ['GPL-3.0']
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files test`.split("\n")
|
17
|
+
s.extra_rdoc_files = `git ls-files doc`.split("\n") + Dir['README*', 'LICENSE']
|
18
|
+
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_dependency 'deface'
|
22
|
+
s.add_dependency 'bootstrap-datepicker-rails'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rubocop'
|
25
|
+
s.add_development_dependency 'rdoc'
|
26
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module ExpireHostsNotifications
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def admin_email
|
5
|
+
[(Setting[:host_expiry_email_recipients] || Setting[:administrator])]
|
6
|
+
end
|
7
|
+
|
8
|
+
def days_to_delete_after_expired
|
9
|
+
Setting[:days_to_delete_after_host_expiration].to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def catch_delivery_errors(message, hosts = [])
|
13
|
+
yield
|
14
|
+
rescue => error
|
15
|
+
message = "#{message} for Hosts #{hosts.map(&:name).to_sentence}"
|
16
|
+
Foreman::Logging.exception(message, error)
|
17
|
+
end
|
18
|
+
|
19
|
+
# This method to deliver deleted host details to its owner
|
20
|
+
def delete_expired_hosts
|
21
|
+
deletable_hosts = Host.expired_past_grace_period
|
22
|
+
failed_delete_hosts = []
|
23
|
+
deleted_hosts = []
|
24
|
+
deletable_hosts.each do |deletable_host|
|
25
|
+
Rails.logger.info "Deleting expired host #{deletable_host}"
|
26
|
+
deletable_host.audit_comment = _('Destroyed since it got expired on %s') % deletable_host.expired_on
|
27
|
+
if deletable_host # .destroy
|
28
|
+
deleted_hosts << deletable_host
|
29
|
+
else
|
30
|
+
failed_delete_hosts << deletable_host
|
31
|
+
end
|
32
|
+
end
|
33
|
+
unless deleted_hosts.empty?
|
34
|
+
ExpireHostsNotifications.hosts_by_user(deleted_hosts).each do |user_id, hosts_hash|
|
35
|
+
catch_delivery_errors(_('Failed to deliver deleted hosts notification'), deleted_hosts) do
|
36
|
+
ExpireHostsMailer.deleted_hosts_notification(hosts_hash['email'], hosts_hash['hosts']).deliver_now
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return if failed_delete_hosts.empty?
|
41
|
+
catch_delivery_errors(_('Failed to deliver deleted hosts notification failed status'), failed_delete_hosts) do
|
42
|
+
ExpireHostsMailer.failed_to_delete_hosts_notification(self.admin_email, failed_delete_hosts).deliver_now
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def stop_expired_hosts
|
47
|
+
stoppable_hosts = Host.expired
|
48
|
+
failed_stop_hosts = []
|
49
|
+
stopped_hosts = []
|
50
|
+
stoppable_hosts.each do |stoppable_host|
|
51
|
+
next unless stoppable_host.supports_power_and_running?
|
52
|
+
Rails.logger.info "Powering down expired host in grace period #{stoppable_host}"
|
53
|
+
host_status = begin
|
54
|
+
stoppable_host.power.stop
|
55
|
+
rescue
|
56
|
+
false
|
57
|
+
end
|
58
|
+
if host_status
|
59
|
+
stopped_hosts << stoppable_host
|
60
|
+
else
|
61
|
+
failed_stop_hosts << stoppable_host
|
62
|
+
end
|
63
|
+
end
|
64
|
+
unless stopped_hosts.empty?
|
65
|
+
delete_date = (Date.today + self.days_to_delete_after_expired.to_i)
|
66
|
+
hosts_by_user(stopped_hosts).each do |user_id, hosts_hash|
|
67
|
+
catch_delivery_errors(_('Failed to deliver stopped hosts notification'), stopped_hosts) do
|
68
|
+
ExpireHostsMailer.stopped_hosts_notification(hosts_hash['email'], delete_date, hosts_hash['hosts']).deliver_now
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
return if failed_stop_hosts.empty?
|
73
|
+
catch_delivery_errors(_('Failed to deliver stopped hosts notification failed status'), failed_stop_hosts) do
|
74
|
+
ExpireHostsMailer.failed_to_stop_hosts_notification(self.admin_email, failed_stop_hosts).deliver_now
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def deliver_expiry_warning_notification(num = 1) # notify1_days_before_expiry
|
79
|
+
return unless [1, 2].include?(num)
|
80
|
+
days_before_expiry = Setting["notify#{num}_days_before_host_expiry"].to_i
|
81
|
+
expiry_date = (Date.today + days_before_expiry)
|
82
|
+
notifiable_hosts = Host.with_expire_date(expiry_date)
|
83
|
+
unless notifiable_hosts.empty?
|
84
|
+
hosts_by_user(notifiable_hosts).each do |user_id, hosts_hash|
|
85
|
+
catch_delivery_errors(_('Failed to deliver expiring hosts notification'), notifiable_hosts) do
|
86
|
+
ExpireHostsMailer.expiry_warning_notification(hosts_hash['email'], expiry_date, hosts_hash['hosts']).deliver_now
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def hosts_by_user(hosts)
|
93
|
+
emails = self.admin_email
|
94
|
+
hosts_hash = {}
|
95
|
+
hosts.each do |host|
|
96
|
+
if host.owner_type == 'User'
|
97
|
+
unless hosts_hash.key?(host.owner_id.to_s)
|
98
|
+
email_recipients = emails + [host.owner.mail]
|
99
|
+
hosts_hash[host.owner_id.to_s] = { 'id' => host.owner_id, 'name' => host.owner.name, 'email' => email_recipients, 'hosts' => [] }
|
100
|
+
end
|
101
|
+
hosts_hash[host.owner_id.to_s]['hosts'] << host
|
102
|
+
elsif host.owner_type == 'Usergroup'
|
103
|
+
host.owner.users.each do |owner|
|
104
|
+
unless hosts_hash.key?(owner.id.to_s)
|
105
|
+
email_recipients = emails + [owner.mail]
|
106
|
+
hosts_hash[owner.id.to_s] = { 'id' => owner.id, 'name' => owner.name, 'email' => email_recipients, 'hosts' => [] }
|
107
|
+
end
|
108
|
+
hosts_hash[owner.id.to_s]['hosts'] << host
|
109
|
+
end
|
110
|
+
else
|
111
|
+
email = (!emails.empty? ? emails : [Setting[:administrator]])
|
112
|
+
unless hosts_hash.key?(owner.id.to_s)
|
113
|
+
hosts_hash['admin'] = { 'id' => nil, 'name' => 'Admin', 'email' => email, 'hosts' => [] }
|
114
|
+
end
|
115
|
+
hosts_hash['admin']['hosts'] << host
|
116
|
+
end
|
117
|
+
end
|
118
|
+
hosts_hash
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'deface'
|
2
|
+
require 'bootstrap-datepicker-rails'
|
3
|
+
|
4
|
+
module ForemanExpireHosts
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
engine_name 'foreman_expire_hosts'
|
7
|
+
|
8
|
+
config.autoload_paths += Dir["#{config.root}/lib"]
|
9
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
10
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
11
|
+
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
12
|
+
|
13
|
+
# Add any db migrations
|
14
|
+
initializer 'foreman_plugin_template.load_app_instance_data' do |app|
|
15
|
+
ForemanExpireHosts::Engine.paths['db/migrate'].existent.each do |path|
|
16
|
+
app.config.paths['db/migrate'] << path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
initializer 'foreman_expire_hosts.load_default_settings', :before => :load_config_initializers do
|
21
|
+
require_dependency File.expand_path('../../../app/models/setting/expire_hosts.rb', __FILE__) if (Setting.table_exists? rescue(false))
|
22
|
+
end
|
23
|
+
|
24
|
+
initializer 'foreman_expire_hosts.register_plugin', :before => :finisher_hook do |app|
|
25
|
+
Foreman::Plugin.register :foreman_expire_hosts do
|
26
|
+
requires_foreman '>= 1.10'
|
27
|
+
register_custom_status HostStatus::ExpirationStatus
|
28
|
+
|
29
|
+
security_block :hosts do
|
30
|
+
permission :edit_hosts, {:hosts => [:select_multiple_expiration, :update_multiple_expiration]}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
config.to_prepare do
|
36
|
+
begin
|
37
|
+
Host::Managed.send :include, ForemanExpireHosts::HostExt
|
38
|
+
HostsHelper.send :include, ForemanExpireHosts::HostsHelperExtensions
|
39
|
+
HostsController.send :include, ForemanExpireHosts::HostControllerExtensions
|
40
|
+
rescue => e
|
41
|
+
Rails.logger.warn "ForemanExpireHosts: skipping engine hook (#{e})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Precompile any JS or CSS files under app/assets/
|
46
|
+
# If requiring files from each other, list them explicitly here to avoid precompiling the same
|
47
|
+
# content twice.
|
48
|
+
assets_to_precompile =
|
49
|
+
Dir.chdir(root) do
|
50
|
+
Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
|
51
|
+
f.split(File::SEPARATOR, 4).last
|
52
|
+
end
|
53
|
+
end
|
54
|
+
initializer 'foreman_expire_hosts.assets.precompile' do |app|
|
55
|
+
app.config.assets.precompile += assets_to_precompile
|
56
|
+
end
|
57
|
+
initializer 'foreman_expire_hosts.configure_assets', group: :assets do
|
58
|
+
SETTINGS[:foreman_expire_hosts] = { assets: { precompile: assets_to_precompile } }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Tasks
|
2
|
+
namespace :expired_hosts do
|
3
|
+
desc 'Delete all expired hosts, send notification email about expiring hosts'
|
4
|
+
task :deliver_notifications => :environment do
|
5
|
+
ExpireHostsNotifications.delete_expired_hosts
|
6
|
+
ExpireHostsNotifications.stop_expired_hosts
|
7
|
+
ExpireHostsNotifications.deliver_expiry_warning_notification(1)
|
8
|
+
ExpireHostsNotifications.deliver_expiry_warning_notification(2)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Tests
|
13
|
+
namespace :test do
|
14
|
+
desc 'Test ForemanExpireHosts'
|
15
|
+
Rake::TestTask.new(:foreman_expire_hosts) do |t|
|
16
|
+
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
17
|
+
t.libs << ['test', test_dir]
|
18
|
+
t.pattern = "#{test_dir}/**/*_test.rb"
|
19
|
+
t.verbose = true
|
20
|
+
t.warning = false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :foreman_expire_hosts do
|
25
|
+
task :rubocop do
|
26
|
+
begin
|
27
|
+
require 'rubocop/rake_task'
|
28
|
+
RuboCop::RakeTask.new(:rubocop_foreman_expire_hosts) do |task|
|
29
|
+
task.patterns = ["#{ForemanExpireHosts::Engine.root}/app/**/*.rb",
|
30
|
+
"#{ForemanExpireHosts::Engine.root}/lib/**/*.rb",
|
31
|
+
"#{ForemanExpireHosts::Engine.root}/test/**/*.rb"]
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
puts 'Rubocop not loaded.'
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::Task['rubocop_foreman_expire_hosts'].invoke
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::Task[:test].enhance ['test:foreman_expire_hosts']
|
42
|
+
|
43
|
+
load 'tasks/jenkins.rake'
|
44
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
45
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_expire_hosts', 'foreman_expire_hosts:rubocop']
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class HostsControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
setup_settings
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'setting expiration date on multiple hosts' do
|
9
|
+
before do
|
10
|
+
as_admin do
|
11
|
+
@hosts = FactoryGirl.create_list(:host, 2, :with_puppet)
|
12
|
+
end
|
13
|
+
@request.env['HTTP_REFERER'] = hosts_path
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'should set expiration date' do
|
17
|
+
expiration_date = Date.today + 14
|
18
|
+
params = { :host_ids => @hosts.map(&:id),
|
19
|
+
:host => { :expired_on => expiration_date } }
|
20
|
+
|
21
|
+
post :update_multiple_expiration, params,
|
22
|
+
set_session_user.merge(:user => users(:admin).id)
|
23
|
+
|
24
|
+
assert_empty flash[:error]
|
25
|
+
|
26
|
+
@hosts.each do |host|
|
27
|
+
assert_equal expiration_date, host.reload.expired_on
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should clear the expiration date of multiple hosts' do
|
32
|
+
params = { :host_ids => @hosts.map(&:id),
|
33
|
+
:host => { :expired_on => '' } }
|
34
|
+
|
35
|
+
post :update_multiple_expiration, params,
|
36
|
+
set_session_user.merge(:user => users(:admin).id)
|
37
|
+
|
38
|
+
assert_empty flash[:error]
|
39
|
+
|
40
|
+
@hosts.each do |host|
|
41
|
+
assert_equal nil, host.reload.expired_on
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,10 @@
|
|
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
|
7
|
+
|
8
|
+
def setup_settings
|
9
|
+
Setting::ExpireHosts.load_defaults
|
10
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class ForemanExpireHostsHostExtTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryGirl.build(:user, :admin)
|
6
|
+
setup_settings
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'without required expiration date' do
|
10
|
+
setup do
|
11
|
+
Setting[:is_host_expiry_date_mandatory] = false
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should not require expired on' do
|
15
|
+
host = FactoryGirl.build(:host)
|
16
|
+
assert host.valid?, "Should be valid without expiration date: : #{host.errors.messages}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with required expiration date' do
|
21
|
+
setup do
|
22
|
+
Setting[:is_host_expiry_date_mandatory] = true
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'should require expired on' do
|
26
|
+
host = FactoryGirl.build(:host)
|
27
|
+
refute host.valid?, "Can not be valid without expiration date: #{host.errors.messages}"
|
28
|
+
assert_includes host.errors.messages.keys, :expired_on
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'a host without expiration' do
|
33
|
+
setup do
|
34
|
+
@host = FactoryGirl.build(:host)
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should not expire' do
|
38
|
+
refute @host.expires?
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'should not expire today' do
|
42
|
+
refute @host.expires_today?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'should not be expired' do
|
46
|
+
refute @host.expired?
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'should not be expired past grace period' do
|
50
|
+
refute @host.expired_past_grace_period?
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should not be pending expiration' do
|
54
|
+
refute @host.pending_expiration?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'a expired host' do
|
59
|
+
setup do
|
60
|
+
@host = FactoryGirl.build(:host, :expired)
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'should expire' do
|
64
|
+
assert @host.expires?
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'should not expire today' do
|
68
|
+
refute @host.expires_today?
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'should be expired' do
|
72
|
+
assert @host.expired?
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'should be expired past grace period' do
|
76
|
+
assert @host.expired_past_grace_period?
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'should not be pending expiration' do
|
80
|
+
refute @host.pending_expiration?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'a host expiring today' do
|
85
|
+
setup do
|
86
|
+
@host = FactoryGirl.build(:host, :expires_today)
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should expire' do
|
90
|
+
assert_equal Date.today, @host.expired_on
|
91
|
+
assert @host.expires?
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'should expire today' do
|
95
|
+
assert @host.expires_today?
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'should not be expired' do
|
99
|
+
refute @host.expired?
|
100
|
+
end
|
101
|
+
|
102
|
+
test 'should not be expired past grace period' do
|
103
|
+
refute @host.expired_past_grace_period?
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'should be pending expiration' do
|
107
|
+
assert @host.pending_expiration?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'a host in grace period' do
|
112
|
+
setup do
|
113
|
+
@host = FactoryGirl.build(:host, :expired_grace)
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'should expire' do
|
117
|
+
assert @host.expires?
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'should not expire today' do
|
121
|
+
refute @host.expires_today?
|
122
|
+
end
|
123
|
+
|
124
|
+
test 'should be expired' do
|
125
|
+
assert @host.expired?
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'should not be expired past grace period' do
|
129
|
+
refute @host.expired_past_grace_period?
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'should not be pending expiration' do
|
133
|
+
refute @host.pending_expiration?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class ExpirationStatusTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
@host = FactoryGirl.build(:host)
|
6
|
+
@status = HostStatus::ExpirationStatus.new(:host => @host)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'is valid' do
|
10
|
+
assert_valid @status
|
11
|
+
end
|
12
|
+
|
13
|
+
test '#to_label changes based on expiration date' do
|
14
|
+
@host.expired_on = '23/11/1900'
|
15
|
+
assert_equal 'Expired on 1900-11-23', @status.to_label
|
16
|
+
|
17
|
+
@host.expired_on = Date.today
|
18
|
+
assert_equal 'Expires today', @status.to_label
|
19
|
+
end
|
20
|
+
|
21
|
+
test '#relevant? is only for expiring hosts' do
|
22
|
+
@host.expired_on = '23/11/1900'
|
23
|
+
assert @status.relevant?
|
24
|
+
|
25
|
+
@host.expired_on = nil
|
26
|
+
refute @status.relevant?
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_expire_hosts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nagarjuna Rachaneni
|
8
|
+
- Timo Goebel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: deface
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bootstrap-datepicker-rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rubocop
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rdoc
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: This Plugin will add new column expired_on to hosts to limit the lifetime
|
71
|
+
of a host.
|
72
|
+
email:
|
73
|
+
- nn.nagarjuna@gmail.com
|
74
|
+
- mail@timogoebel.name
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files:
|
78
|
+
- README.md
|
79
|
+
- LICENSE
|
80
|
+
files:
|
81
|
+
- ".gitignore"
|
82
|
+
- ".rubocop.yml"
|
83
|
+
- ".rubocop_todo.yml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- app/assets/javascripts/foreman_expire_hosts/application.js
|
88
|
+
- app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js
|
89
|
+
- app/assets/stylesheets/foreman_expire_hosts/application.scss
|
90
|
+
- app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
|
91
|
+
- app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
|
92
|
+
- app/helpers/expire_hosts_mailer_helper.rb
|
93
|
+
- app/mailers/expire_hosts_mailer.rb
|
94
|
+
- app/models/concerns/foreman_expire_hosts/host_ext.rb
|
95
|
+
- app/models/host_status/expiration_status.rb
|
96
|
+
- app/models/setting/expire_hosts.rb
|
97
|
+
- app/overrides/add_expired_on_field_to_host_form.rb
|
98
|
+
- app/overrides/add_expired_on_field_to_host_show.rb
|
99
|
+
- app/overrides/add_js_to_host_index.rb
|
100
|
+
- app/overrides/deleted_expired_host_comment_in_audits.rb
|
101
|
+
- app/views/expire_hosts_mailer/_hosts_table.html.erb
|
102
|
+
- app/views/expire_hosts_mailer/deleted_hosts_notification.html.erb
|
103
|
+
- app/views/expire_hosts_mailer/expiry_warning_notification.html.erb
|
104
|
+
- app/views/expire_hosts_mailer/failed_to_delete_hosts_notification.html.erb
|
105
|
+
- app/views/expire_hosts_mailer/failed_to_stop_hosts_notification.html.erb
|
106
|
+
- app/views/expire_hosts_mailer/stopped_hosts_notification.html.erb
|
107
|
+
- app/views/hosts/_expired_message.html.erb
|
108
|
+
- app/views/hosts/_expired_on_field.html.erb
|
109
|
+
- app/views/hosts/select_multiple_expiration.html.erb
|
110
|
+
- config/routes.rb
|
111
|
+
- db/migrate/20150427101516_add_expiry_on_to_hosts.rb
|
112
|
+
- foreman_expire_hosts.gemspec
|
113
|
+
- lib/expire_hosts_notifications.rb
|
114
|
+
- lib/foreman_expire_hosts.rb
|
115
|
+
- lib/foreman_expire_hosts/engine.rb
|
116
|
+
- lib/foreman_expire_hosts/version.rb
|
117
|
+
- lib/tasks/expired_hosts.rake
|
118
|
+
- test/factories/foreman_expire_hosts_factories.rb
|
119
|
+
- test/functional/concerns/hosts_controller_extensions_test.rb
|
120
|
+
- test/test_plugin_helper.rb
|
121
|
+
- test/unit/concerns/host_extensions_test.rb
|
122
|
+
- test/unit/host_status/expiration_status_test.rb
|
123
|
+
homepage: https://github.com/theforeman/foreman_expire_hosts
|
124
|
+
licenses:
|
125
|
+
- GPL-3.0
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Foreman plugin for limiting host lifetime
|
147
|
+
test_files:
|
148
|
+
- test/factories/foreman_expire_hosts_factories.rb
|
149
|
+
- test/functional/concerns/hosts_controller_extensions_test.rb
|
150
|
+
- test/test_plugin_helper.rb
|
151
|
+
- test/unit/concerns/host_extensions_test.rb
|
152
|
+
- test/unit/host_status/expiration_status_test.rb
|
153
|
+
has_rdoc:
|