foreman_virt_who_configure 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9eb40a56ab4846ea5460f26ea9d55ee1bd2e27ad
4
- data.tar.gz: 7e4395fd51902f7c8ae1eaa96357a633b76e943e
3
+ metadata.gz: fc18a0a6855645558a541c028fdbc976a1e82a28
4
+ data.tar.gz: c665d9f4302ec737940875c5c668af1eeaf84588
5
5
  SHA512:
6
- metadata.gz: ccf5ac80e8e889e1845d774f18e5d8d7214916d98ef22cc19eb7051f935a5f5c4e9975c80188187a2b9f6e1b3b2639e8e3c696078e69d4095f375c047d3d33e7
7
- data.tar.gz: d9b59a96009c0817998f473c62e244484e3210745499a2eae696b195be94af3fc0769ad8d2c58d9d511927454a58c100109b4975cca13cf973d397ecd1564a00
6
+ metadata.gz: 94a21f9543e5519eadfda90acdddc83f5d035e14eca3c1952d5228e79eb608a6658c7852166fee9a3b320bdc56fded20291f8e036abe86bc2415f647e0136f32
7
+ data.tar.gz: 4727236938d4b4e145fb6452698985173f6292d476ea123362b83a3b55674e9eaefa942d7c2896acaf09255846f852ee98d87d68b946584b56551dfaa93f1464
@@ -84,7 +84,7 @@ module ForemanVirtWhoConfigure
84
84
  private
85
85
 
86
86
  def apply_organization_filter(scope)
87
- Organization.current ? scope.where(:organization_id => Organization.current) : scope
87
+ scope.for_organization(Organization.current)
88
88
  end
89
89
 
90
90
  def resource_scope(*args)
@@ -1,7 +1,7 @@
1
1
  module ForemanVirtWhoConfigure
2
2
  module ConfigsHelper
3
3
  def hypervisor_server_help_data
4
- {
4
+ @hypervisor_server_help_data ||= {
5
5
  'esx' => _('VMware vCenter server’s fully qualified host name or IP address.'),
6
6
  'rhevm' => _('Red Hat Virtualization Manager’s fully qualified host name or IP address. For example, <code>https://hostname:443/ovirt-engine/</code> for v4, <code>https://hostname_or_IP:443</code> for v3'),
7
7
  # 'vdsm' => 'Red Hat Enterprise Linux Hypervisor (vdsm)',
@@ -12,7 +12,7 @@ module ForemanVirtWhoConfigure
12
12
  end
13
13
 
14
14
  def hypervisor_username_help_data
15
- {
15
+ @hypervisor_username_help_data ||= {
16
16
  'esx' => _('Account name by which virt-who is to connect to the hypervisor, in the format <code>domain_name\account_name</code>. Note that only a single backslash separates the values for domain_name and account_name. If you are using a domain account, and the global configuration file <code>/etc/sysconfig/virt-who</code>, then <b>two</b> backslashes are required. For further details, see <a href="https://access.redhat.com/solutions/1270223">Red Hat Knowledgebase solution How to use a windows domain account with virt-who</a> for more information.'),
17
17
  'rhevm' => _('Account name by which virt-who is to connect to the Red Hat Enterprise Virtualization Manager instance. The username option requires input in the format username@domain.'),
18
18
  # 'vdsm' => '',
@@ -21,5 +21,52 @@ module ForemanVirtWhoConfigure
21
21
  'libvirt' => _('Account name by which virt-who is to connect to the hypervisor.')
22
22
  }
23
23
  end
24
+
25
+ def config_report_status(config)
26
+ message = case config.status
27
+ when :unknown
28
+ _('No Report Yet')
29
+ when :ok
30
+ l(config.last_report_at, :format => :long)
31
+ when :error
32
+ l(config.last_report_at, :format => :long)
33
+ else
34
+ _('Unknown configuration status')
35
+ end
36
+
37
+ config_report_status_icon(config) + content_tag(:span, message, :class => config.status)
38
+ end
39
+
40
+ def config_report_status_icon(config)
41
+ content_tag(:span, ''.html_safe, :class => report_status_class(config.status), :title => config.status_description) + '&nbsp;'.html_safe
42
+ end
43
+
44
+ def report_status_class(status)
45
+ icon_class = case status
46
+ when :ok
47
+ 'pficon-ok'
48
+ when :error
49
+ 'pficon-error-circle-o'
50
+ when :unknown
51
+ 'pficon-info'
52
+ else
53
+ 'pficon-help'
54
+ end
55
+
56
+ "virt-who-config-report-status #{icon_class} #{status_class(status)}"
57
+ end
58
+
59
+ def status_class(status)
60
+ case status
61
+ when :ok
62
+ 'status-ok'.html_safe
63
+ when :unknown
64
+ 'status-info'.html_safe
65
+ when :error
66
+ 'status-error'.html_safe
67
+ else
68
+ 'status-warn'.html_safe
69
+ end
70
+ end
24
71
  end
25
72
  end
@@ -0,0 +1,37 @@
1
+ module Actions
2
+ module ForemanVirtWhoConfigure
3
+ module Config
4
+ class Report < Actions::EntryAction
5
+ middleware.use Actions::Middleware::KeepCurrentUser
6
+
7
+ def self.subscribe
8
+ Actions::Katello::Host::HypervisorsUpdate
9
+ end
10
+
11
+ def plan(hypervisors)
12
+ plan_self(:hypervisors => hypervisors)
13
+ end
14
+
15
+ def run
16
+ # this is how we could do mapping to hypervisor hosts based on UUID provided by candelpin
17
+ # input['hypervisors'].each do |hv_attrs|
18
+ # # should always exist, Actions::Katello::Host::HypervisorsUpdate should create it
19
+ # # but we should be careful anyway
20
+ # hypervisor = ::Host.joins(:subscription_facet).where(:'katello_subscription_facets.uuid' => hv_attrs['uuid']).first
21
+ # end
22
+
23
+ config = ::ForemanVirtWhoConfigure::ServiceUser.find_by_user_id(User.current.id).try(:config)
24
+ if config.present?
25
+ config.virt_who_touch!
26
+ end
27
+
28
+ # if config was not found, the report is coming from unknown virt-who reporter, we could create a notification
29
+ # that this plugin can be used for configuration
30
+
31
+ # this could be used for mapping to existing compute resource
32
+ # config.hypervisor_server
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -3,7 +3,7 @@ module ForemanVirtWhoConfigure
3
3
  PERMITTED_PARAMS = [
4
4
  :interval, :organization_id, :compute_resource_id, :whitelist, :blacklist, :listing_mode, :hypervisor_id,
5
5
  :hypervisor_type, :hypervisor_server, :hypervisor_username, :hypervisor_password, :debug,
6
- :satellite_url, :proxy, :no_proxy
6
+ :satellite_url, :proxy, :no_proxy, :name
7
7
  ]
8
8
  include Authorizable
9
9
  audited
@@ -47,6 +47,20 @@ module ForemanVirtWhoConfigure
47
47
 
48
48
  DEFAULT_INTERVAL = 120
49
49
 
50
+ STATUSES = {
51
+ 'ok' => N_('OK'),
52
+ 'error' => N_('Error'),
53
+ 'unknown' => N_('Unknown')
54
+ }
55
+
56
+ STATUS_DESCRIPTIONS = Hash.new(N_('Unknown configuration status, caused by unexpected conditions')).merge(
57
+ {
58
+ :unknown => N_('The configuration was not deployed yet or the virt-who was unable to report the status'),
59
+ :ok => N_('The virt-who report arrived within the interval'),
60
+ :error => N_('The virt-who report has not arrived within the interval, please check the virt-who reporter status and logs')
61
+ }
62
+ )
63
+
50
64
  include Encryptable
51
65
  encrypts :hypervisor_password
52
66
 
@@ -57,8 +71,22 @@ module ForemanVirtWhoConfigure
57
71
  belongs_to :service_user
58
72
 
59
73
  scoped_search :on => :interval, :complete_value => true
74
+ scoped_search :on => :name
75
+ scoped_search :on => :status, :complete_value => true, :only_explicit => true, :operators => ['= '], :ext_method => :search_by_status
76
+ scoped_search :on => :out_of_date_at, :complete_value => true, :only_explicit => true
77
+ scoped_search :on => :last_report_at, :complete_value => true, :only_explicit => true
60
78
  # TODO add more related objects and attributes
61
79
 
80
+ # Foreman 1.11 specifics, can be removed later, otherwise when string does not start with "encrypts" prefix
81
+ # we get 500 when we try to create log message that relies on name method
82
+ def name
83
+ title
84
+ end
85
+
86
+ def title
87
+ compute_resource ? compute_resource.name : hypervisor_server
88
+ end
89
+
62
90
  # compatibility layer for 1.11 - pre strong params patch
63
91
  if self.respond_to?(:attr_accessible)
64
92
  attr_accessible(*PERMITTED_PARAMS)
@@ -68,7 +96,7 @@ module ForemanVirtWhoConfigure
68
96
  after_destroy :destroy_service_user
69
97
 
70
98
  validates :interval, :hypervisor_type, :hypervisor_server, :hypervisor_username, :hypervisor_password,
71
- :satellite_url, :hypervisor_id, :organization_id,
99
+ :satellite_url, :hypervisor_id, :organization_id, :name,
72
100
  :presence => true
73
101
  validates :hypervisor_type, :inclusion => HYPERVISOR_TYPES.keys
74
102
  validates :hypervisor_id, :inclusion => HYPERVISOR_IDS
@@ -80,6 +108,21 @@ module ForemanVirtWhoConfigure
80
108
 
81
109
  before_validation :remove_whitespaces
82
110
 
111
+ scope :out_of_date, ->(deadline = DateTime.now.utc) { where(["out_of_date_at < ?", deadline.utc.to_s(:db)]) }
112
+ scope :for_organization, ->(org) { org.nil? ? where(nil) : where(:organization_id => org) }
113
+
114
+ def self.search_by_status(key, operator, value)
115
+ condition = case value
116
+ when 'ok'
117
+ sanitize_sql_for_conditions([' out_of_date_at >= ? ', DateTime.now.utc.to_s(:db)])
118
+ when 'unknown'
119
+ sanitize_sql_for_conditions({:last_report_at => nil})
120
+ when 'error'
121
+ sanitize_sql_for_conditions([' out_of_date_at < ? ', DateTime.now.utc.to_s(:db)])
122
+ end
123
+ { :conditions => condition }
124
+ end
125
+
83
126
  def create_service_user
84
127
  password = User.random_password
85
128
  service_user = self.build_service_user
@@ -117,20 +160,14 @@ module ForemanVirtWhoConfigure
117
160
  # raise 'unsupported compute resource type'
118
161
  # end
119
162
 
120
- # Foreman 1.11 specifics, can be removed later, otherwise when string does not start with "encrypts" prefix
121
- # we get 500 when we try to create log message that relies on name method
122
- def name
123
- title
124
- end
125
-
126
- def title
127
- compute_resource ? compute_resource.name : hypervisor_server
128
- end
129
-
130
163
  def humanized_interval
131
164
  _("every %s hours") % (self.interval / 60)
132
165
  end
133
166
 
167
+ def out_of_date?(deadline = DateTime.now.utc)
168
+ self.out_of_date_at.present? && self.out_of_date_at < deadline
169
+ end
170
+
134
171
  def step_name(step_key)
135
172
  WIZARD_STEPS[step_key]
136
173
  end
@@ -148,6 +185,27 @@ module ForemanVirtWhoConfigure
148
185
  end
149
186
  end
150
187
 
188
+ def virt_who_touch!
189
+ self.last_report_at = DateTime.now.utc
190
+ self.out_of_date_at = self.last_report_at + self.interval.minutes
191
+ self.save!
192
+ end
193
+
194
+ def status
195
+ case
196
+ when self.last_report_at.nil?
197
+ :unknown
198
+ when !self.out_of_date?
199
+ :ok
200
+ else
201
+ :error
202
+ end
203
+ end
204
+
205
+ def status_description
206
+ _(STATUS_DESCRIPTIONS[status])
207
+ end
208
+
151
209
  private
152
210
 
153
211
  def remove_whitespaces
@@ -6,7 +6,7 @@ module ForemanVirtWhoConfigure
6
6
  encrypts :encrypted_password
7
7
 
8
8
  belongs_to :user
9
- has_many :configs
9
+ has_one :config
10
10
 
11
11
  # Foreman 1.11 specifics, can be removed later, otherwise when string does not start with "encrypts" prefix
12
12
  # we get 500 when we try to create log message that relies on name method
@@ -0,0 +1,59 @@
1
+ <% scope = ForemanVirtWhoConfigure::Config.for_organization(Organization.current) %>
2
+ <% scope = scope.authorized(:view_virt_who_config) %>
3
+ <% out_of_date = scope.out_of_date.order('out_of_date_at DESC') %>
4
+
5
+ <h4 class="header ca"><%= _('Virt-who Configurations Statistics') %></h4>
6
+ <table class="table table-striped ellipsis">
7
+ <thead>
8
+ <tr>
9
+ <th><%= _("Status") %></th>
10
+ <th><%= _("Count") %></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <tr>
15
+ <td><%= link_to _("Configurations Without Single Report"), foreman_virt_who_configure_configs_path(:search => "status = unknown") %></td>
16
+ <td><%= scope.where(:last_report_at => nil).count %></td>
17
+ </tr>
18
+ <tr>
19
+ <td><%= link_to _("Configurations Out Of Date"), foreman_virt_who_configure_configs_path(:search => "status = error") %></td>
20
+ <td><%= out_of_date.count %></td>
21
+ </tr>
22
+ <tr>
23
+ <td><%= link_to _("Configurations Up To Date"), foreman_virt_who_configure_configs_path(:search => "status = ok") %></td>
24
+ <td><%= scope.where.not(:last_report_at => nil).count - out_of_date.count %></td>
25
+ </tr>
26
+ <tr>
27
+ <td><%= link_to _("Total Configurations"), foreman_virt_who_configure_configs_path %></td>
28
+ <td><%= scope.count %></td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+
33
+
34
+ <h5 class="ca"><%= _('Out of Date Virt-who Configurations') %></h5>
35
+ <% if out_of_date.empty? %>
36
+ <%= _("No configuration for which the report has not been received during expected interval") %>
37
+ <% else %>
38
+ <table class="table table-striped ellipsis">
39
+ <thead>
40
+ <tr>
41
+ <th><%= s_("Config|Name") %></th>
42
+ <th><%= s_("Config|Last Report") %></th>
43
+ <th><%= s_("Config|Interval") %></th>
44
+ </tr>
45
+ </thead>
46
+ <tbody>
47
+ <% out_of_date.limit(3).each do |config| %>
48
+ <tr>
49
+ <td><%= config_report_status_icon(config) %><%= link_to config.name, foreman_virt_who_configure_config_path(config) %></td>
50
+ <td><%= l(config.last_report_at, :format => :long) %></td>
51
+ <td><%= config.humanized_interval %></td>
52
+ </tr>
53
+ <% end %>
54
+ </tbody>
55
+ </table>
56
+ <% end %>
57
+
58
+
59
+
@@ -1,3 +1,3 @@
1
- <% title _("Edit Config") %>
1
+ <% title _("Edit Virt-who Config") %>
2
2
 
3
3
  <%= render :partial => 'form' %>
@@ -1,23 +1,25 @@
1
- <% title _("Configs") %>
1
+ <% title _("Virt-who Configurations") %>
2
2
 
3
3
  <% title_actions new_config_link, help_button_or_path %>
4
4
 
5
5
  <table class="<%= table_css_classes 'table-fixed' %>">
6
6
  <thead>
7
7
  <tr>
8
- <th class="col-md-8"><%= sort :name, :as => s_("Config|Title") %></th>
9
- <th><%= s_("Config|Interval") %></th>
8
+ <th class="col-md-8"><%= sort :name, :as => s_("Config|Name") %></th>
9
+ <th><%= sort :interval, :as => s_("Config|Interval") %></th>
10
+ <th class="col-md-2"><%= sort :last_report_at, :as => _("Status") %></th>
10
11
  <th><%= _('Actions') %></th>
11
12
  </tr>
12
13
  </thead>
13
14
  <tbody>
14
15
  <% @configs.each do |config| %>
15
16
  <tr>
16
- <td class="display-two-pane ellipsis"><%= link_to_if_authorized (config.title), hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer) %></td>
17
+ <td class="display-two-pane ellipsis"><%= link_to_if_authorized config.name, hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer) %></td>
17
18
  <td><%= config.humanized_interval %></td>
19
+ <td><%= config_report_status(config) %></td>
18
20
  <td class="col-md-1"><%= action_buttons(
19
21
  display_link_if_authorized(_('Edit'), hash_for_edit_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer)),
20
- display_delete_if_authorized((hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer)), :data => { :confirm => _("Delete virt-who configuration %s?") % config.title })
22
+ display_delete_if_authorized((hash_for_foreman_virt_who_configure_config_path(:id => config).merge(:auth_object => config, :authorizer => authorizer)), :data => { :confirm => _("Delete virt-who configuration %s?") % config.name })
21
23
  ) %></td>
22
24
  </tr>
23
25
  <% end %>
@@ -1,3 +1,3 @@
1
- <% title _("New Virt Who Config") %>
1
+ <% title _("New Virt-who Config") %>
2
2
 
3
3
  <%= render :partial => "foreman_virt_who_configure/configs/form" %>
@@ -6,9 +6,10 @@
6
6
  <div class="col-md-12">
7
7
  <label><%= _("Run this script on the target host which will run virt-who reporting, preferably Satellite host:") %></label>
8
8
  <p>
9
- <%= _("1. Copy this configuration script to a safe directory on the host.") %></br>
10
- <%= _("2. Make the script executable and run it on the host.") %></br>
11
- <%= _("3. Delete the script on the host.") %></br>
9
+ <%= _("On the target virt-who host:") %></br>
10
+ <%= _("1. Copy this configuration script to a safe directory.") %></br>
11
+ <%= _("2. Make the script executable and run it.") %></br>
12
+ <%= _("3. Delete the script.") %></br>
12
13
  </p>
13
14
  </div>
14
15
  </div>
@@ -1,4 +1,6 @@
1
1
  <div id="config_general_information">
2
+ <%= text_f f, :name, :help_inline => popover('', _('Name of this configuration, e.g. the name of the hypervisor')) %>
3
+
2
4
  <% if f.object.organization_id.present? %>
3
5
  <%= f.hidden_field :organization_id %>
4
6
  <% else %>
@@ -0,0 +1,6 @@
1
+ class AddLastReportInfoToConfig < ActiveRecord::Migration
2
+ def change
3
+ add_column :foreman_virt_who_configure_configs, :last_report_at, :datetime
4
+ add_column :foreman_virt_who_configure_configs, :out_of_date_at, :datetime
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddNameToConfig < ActiveRecord::Migration
2
+ def change
3
+ add_column :foreman_virt_who_configure_configs, :name, :string, :null => false, :default => ''
4
+ end
5
+ end
@@ -7,6 +7,7 @@ module ForemanVirtWhoConfigure
7
7
  config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
8
8
  config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
9
9
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
10
+ config.autoload_paths += Dir["#{config.root}/app/lib"]
10
11
  config.autoload_paths += Dir["#{config.root}/test/"]
11
12
 
12
13
  # Add any db migrations
@@ -23,10 +24,11 @@ module ForemanVirtWhoConfigure
23
24
 
24
25
  # Add permissions
25
26
  security_block :foreman_virt_who_configure do
26
- permission :view_virt_who_config, :'foreman_virt_who_configure/configs' => [:index, :show, :auto_complete_search], :resource_type => 'ForemanVirtWhoConfigure::Config'
27
- permission :create_virt_who_config, :'foreman_virt_who_configure/configs' => [:new, :create], :resource_type => 'ForemanVirtWhoConfigure::Config'
28
- permission :edit_virt_who_config, :'foreman_virt_who_configure/configs' => [:edit, :update], :resource_type => 'ForemanVirtWhoConfigure::Config'
29
- permission :destroy_virt_who_config, :'foreman_virt_who_configure/configs' => [:destroy], :resource_type => 'ForemanVirtWhoConfigure::Config'
27
+ permission_options = { :resource_type => 'ForemanVirtWhoConfigure::Config' }
28
+ permission :view_virt_who_config, { :'foreman_virt_who_configure/configs' => [:index, :show, :auto_complete_search] }, permission_options
29
+ permission :create_virt_who_config, { :'foreman_virt_who_configure/configs' => [:new, :create] }, permission_options
30
+ permission :edit_virt_who_config, { :'foreman_virt_who_configure/configs' => [:edit, :update] }, permission_options
31
+ permission :destroy_virt_who_config, { :'foreman_virt_who_configure/configs' => [:destroy] }, permission_options
30
32
  end
31
33
 
32
34
  reporter_permissions = [ :create_hosts, :edit_hosts, :view_lifecycle_environments, :my_organizations ]
@@ -48,6 +50,9 @@ module ForemanVirtWhoConfigure
48
50
  role 'Virt-who Manager', [ :view_virt_who_config, :create_virt_who_config, :edit_virt_who_config, :destroy_virt_who_config ]
49
51
  role 'Virt-who Viewer', [ :view_virt_who_config ]
50
52
 
53
+ # Available since Foreman 1.15
54
+ add_all_permissions_to_default_roles if respond_to?(:add_all_permissions_to_default_roles)
55
+
51
56
  # add menu entry
52
57
  menu :top_menu, :virt_who_configs,
53
58
  url_hash: { controller: 'foreman_virt_who_configure/configs', action: :index },
@@ -56,7 +61,7 @@ module ForemanVirtWhoConfigure
56
61
  after: :compute_resources
57
62
 
58
63
  # add dashboard widget
59
- # widget 'foreman_virt_who_configure_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
64
+ widget 'foreman_virt_who_configs_status_widget', :name => N_('Virt-who Configs Status'), sizex: 6, sizey: 1
60
65
  end
61
66
  end
62
67
 
@@ -76,6 +81,10 @@ module ForemanVirtWhoConfigure
76
81
  SETTINGS[:foreman_virt_who_configure] = { assets: { precompile: assets_to_precompile } }
77
82
  end
78
83
 
84
+ initializer 'foreman_virt_who_configure.register_paths' do |_app|
85
+ ForemanTasks.dynflow.config.eager_load_paths.concat(%W(#{ForemanVirtWhoConfigure::Engine.root}/app/lib/actions))
86
+ end
87
+
79
88
  # Include concerns in this config.to_prepare block
80
89
  config.to_prepare do
81
90
  SSO::METHODS.unshift SSO::BasicWithHidden
@@ -1,3 +1,3 @@
1
1
  module ForemanVirtWhoConfigure
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -1,5 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :virt_who_config, :class => ::ForemanVirtWhoConfigure::Config do
3
+ sequence(:name) { |n| "config #{n}" }
3
4
  organization
4
5
  interval 120
5
6
  hypervisor_id 'hostname'
@@ -10,4 +11,14 @@ FactoryGirl.define do
10
11
  satellite_url 'foreman.example.com'
11
12
  listing_mode ForemanVirtWhoConfigure::Config::UNLIMITED
12
13
  end
14
+
15
+ trait :out_of_date do
16
+ last_report_at (1.minute.ago - 120.minutes).utc
17
+ out_of_date_at (1.minute.ago).utc
18
+ end
19
+
20
+ trait :ok do
21
+ last_report_at (1.minute.ago).utc
22
+ out_of_date_at (1.minute.ago + 120.minutes).utc
23
+ end
13
24
  end
@@ -61,5 +61,84 @@ module ForemanVirtWhoConfigure
61
61
  assert config.valid?
62
62
  end
63
63
  end
64
+
65
+ describe 'organization scoping' do
66
+ let(:another_org) { FactoryGirl.create(:organization) }
67
+ let(:config_1) { FactoryGirl.create(:virt_who_config) }
68
+ let(:config_2) { FactoryGirl.create(:virt_who_config, :organization => another_org) }
69
+
70
+ before do
71
+ # let is lazy
72
+ preload = config_1, config_2
73
+ end
74
+
75
+ test '.for_organization does not scope on any organization for nil' do
76
+ # useful for just passing Organization.current which can be nil
77
+ assert_includes ForemanVirtWhoConfigure::Config.for_organization(nil), config_1
78
+ assert_includes ForemanVirtWhoConfigure::Config.for_organization(nil), config_2
79
+ end
80
+
81
+ test '.for_organization scoped to specified organization' do
82
+ assert_includes ForemanVirtWhoConfigure::Config.for_organization(another_org), config_2
83
+ refute_includes ForemanVirtWhoConfigure::Config.for_organization(another_org), config_1
84
+ end
85
+
86
+ end
87
+
88
+ describe 'statuses and expiration' do
89
+ let(:out_of_date_config) { FactoryGirl.create(:virt_who_config, :out_of_date) }
90
+ let(:ok_config) { FactoryGirl.create(:virt_who_config, :ok) }
91
+ let(:unknown_config) { FactoryGirl.create(:virt_who_config) }
92
+ before do
93
+ # let is lazy
94
+ preload = out_of_date_config, ok_config, unknown_config
95
+ end
96
+
97
+ test 'scoped search definitions work correctly' do
98
+ assert_equal [ok_config], ForemanVirtWhoConfigure::Config.search_for('status = ok')
99
+ assert_equal [out_of_date_config], ForemanVirtWhoConfigure::Config.search_for('status = error')
100
+ assert_equal [unknown_config], ForemanVirtWhoConfigure::Config.search_for('status = unknown')
101
+ end
102
+
103
+ test '.out_of_date scope lists only out_of_date configs' do
104
+ assert_includes ForemanVirtWhoConfigure::Config.out_of_date, out_of_date_config
105
+ assert_not_includes ForemanVirtWhoConfigure::Config.out_of_date, ok_config
106
+ assert_not_includes ForemanVirtWhoConfigure::Config.out_of_date, unknown_config
107
+ end
108
+
109
+ test '#out_of_date?' do
110
+ assert out_of_date_config.out_of_date?
111
+ refute ok_config.out_of_date?
112
+ refute unknown_config.out_of_date?
113
+ end
114
+
115
+ test '#virt_who_touch! sets last_report_at to now' do
116
+ now = DateTime.now.utc
117
+ unknown_config.virt_who_touch!
118
+ assert now <= unknown_config.last_report_at
119
+ end
120
+
121
+ test '#virt_who_touch! makes out_of_date config ok again' do
122
+ out_of_date_config.virt_who_touch!
123
+ refute out_of_date_config.out_of_date?
124
+ end
125
+
126
+ test '#virt_who_touch! sets out_of_date_at based on interval and last_report_at' do
127
+ out_of_date_config.virt_who_touch!
128
+ assert_equal out_of_date_config.out_of_date_at, out_of_date_config.last_report_at + out_of_date_config.interval.minutes
129
+ end
130
+
131
+ test '#status returns the symbol representing the current status' do
132
+ assert_equal :ok, ok_config.status
133
+ assert_equal :error, out_of_date_config.status
134
+ assert_equal :unknown, unknown_config.status
135
+ end
136
+
137
+ test '#status description returns string describing the status' do
138
+ assert_kind_of String, ok_config.status_description
139
+ assert_kind_of String, out_of_date_config.status_description
140
+ assert_kind_of String, unknown_config.status_description
141
+ end
142
+ end
64
143
  end
65
144
  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.1
4
+ version: 0.0.2
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-03-13 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -69,12 +69,13 @@ files:
69
69
  - app/controllers/foreman_virt_who_configure/configs_controller.rb
70
70
  - app/helpers/foreman_virt_who_configure/compatibility_helper.rb
71
71
  - app/helpers/foreman_virt_who_configure/configs_helper.rb
72
+ - app/lib/actions/foreman_virt_who_configure/config/report.rb
72
73
  - app/models/foreman_virt_who_configure/auth_source_hidden_with_authentication.rb
73
74
  - app/models/foreman_virt_who_configure/config.rb
74
75
  - app/models/foreman_virt_who_configure/output_generator.rb
75
76
  - app/models/foreman_virt_who_configure/service_user.rb
76
77
  - app/services/sso/basic_with_hidden.rb
77
- - app/views/dashboard/_foreman_virt_who_configure_widget.html.erb
78
+ - app/views/dashboard/_foreman_virt_who_configs_status_widget.html.erb
78
79
  - app/views/foreman_virt_who_configure/configs/_form.html.erb
79
80
  - app/views/foreman_virt_who_configure/configs/edit.html.erb
80
81
  - app/views/foreman_virt_who_configure/configs/index.html.erb
@@ -91,6 +92,8 @@ files:
91
92
  - db/migrate/20170102152851_add_satellite_url_to_config.rb
92
93
  - db/migrate/20170215152851_change_default_interval.rb
93
94
  - db/migrate/20170309161551_add_proxy_and_no_proxy_to_config.rb
95
+ - db/migrate/20170404152851_add_last_report_info_to_config.rb
96
+ - db/migrate/20170407152851_add_name_to_config.rb
94
97
  - lib/foreman_virt_who_configure.rb
95
98
  - lib/foreman_virt_who_configure/engine.rb
96
99
  - lib/foreman_virt_who_configure/version.rb
@@ -1,2 +0,0 @@
1
- <h4 class="header ca"><%= _('ForemanVirtWhoConfigure') %></h4>
2
- <%= _('Widget content') %>