Revision d7c67746
Added by Michael Moll almost 6 years ago
.rubocop_todo.yml | ||
---|---|---|
Style/MixinUsage:
|
||
Enabled: false
|
||
|
||
# Offense count: 37
|
||
# Cop supports --auto-correct.
|
||
Style/MultilineIfModifier:
|
||
Enabled: false
|
||
|
||
# Offense count: 3
|
||
Style/MultipleComparison:
|
||
Enabled: false
|
app/controllers/operatingsystems_controller.rb | ||
---|---|---|
|
||
def edit
|
||
# Generates default OS template entries
|
||
@operatingsystem.provisioning_templates.map(&:template_kind_id).uniq.each do |kind|
|
||
if @operatingsystem.os_default_templates.where(:template_kind_id => kind).blank?
|
||
@operatingsystem.os_default_templates.build(:template_kind_id => kind)
|
||
if SETTINGS[:unattended]
|
||
@operatingsystem.provisioning_templates.map(&:template_kind_id).uniq.each do |kind|
|
||
if @operatingsystem.os_default_templates.where(:template_kind_id => kind).blank?
|
||
@operatingsystem.os_default_templates.build(:template_kind_id => kind)
|
||
end
|
||
end
|
||
end if SETTINGS[:unattended]
|
||
end
|
||
end
|
||
|
||
def update
|
app/helpers/audits_helper.rb | ||
---|---|---|
|
||
def audited_icon(audit)
|
||
style = 'label-info'
|
||
style = case audit.action
|
||
when 'create'
|
||
'label-success'
|
||
when 'update'
|
||
'label-info'
|
||
when 'destroy'
|
||
'label-danger'
|
||
else
|
||
''
|
||
end if main_object? audit
|
||
if main_object? audit
|
||
style = case audit.action
|
||
when 'create'
|
||
'label-success'
|
||
when 'update'
|
||
'label-info'
|
||
when 'destroy'
|
||
'label-danger'
|
||
else
|
||
''
|
||
end
|
||
end
|
||
style += " label"
|
||
|
||
type = audited_type(audit)
|
app/helpers/compute_resources_vms_helper.rb | ||
---|---|---|
:port => console[:proxy_port],
|
||
:password => console[:password]
|
||
}
|
||
options.merge!(
|
||
:address => console[:address],
|
||
:secure_port => console[:secure_port],
|
||
:subject => console[:subject],
|
||
:title => _("%s - Press Shift-F12 to release the cursor.") % console[:name]
|
||
) if supports_spice_xpi?
|
||
if supports_spice_xpi?
|
||
options.merge!(
|
||
:address => console[:address],
|
||
:secure_port => console[:secure_port],
|
||
:subject => console[:subject],
|
||
:title => _("%s - Press Shift-F12 to release the cursor.") % console[:name]
|
||
)
|
||
end
|
||
options[:ca_cert] = URI.escape(console[:ca_cert]) if console[:ca_cert].present?
|
||
options
|
||
end
|
app/helpers/home_helper.rb | ||
---|---|---|
def render_vertical_menu(menu_name, mobile = false)
|
||
authorized_menu_actions(Menu::Manager.items(menu_name).children).map do |menu|
|
||
items = authorized_menu_actions(menu.children)
|
||
render "home/vertical_menu", :menu_items => items, :menu_title => _(menu.caption), :menu_icon => menu.icon,
|
||
:menu_name => menu.name, :mobile_class => mobile ? 'visible-xs-block' : '' if items.any?
|
||
if items.any?
|
||
render "home/vertical_menu", :menu_items => items, :menu_title => _(menu.caption), :menu_icon => menu.icon,
|
||
:menu_name => menu.name, :mobile_class => mobile ? 'visible-xs-block' : ''
|
||
end
|
||
end.join(' ').html_safe
|
||
end
|
||
|
app/helpers/hosts_helper.rb | ||
---|---|---|
end
|
||
|
||
def randomize_mac_link
|
||
link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default',
|
||
:title => _('Generate new random name. Visit Settings to disable this feature.')) if NameGenerator.random_based?
|
||
if NameGenerator.random_based?
|
||
link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default',
|
||
:title => _('Generate new random name. Visit Settings to disable this feature.'))
|
||
end
|
||
end
|
||
|
||
def power_status_visible?
|
app/helpers/lookup_keys_helper.rb | ||
---|---|---|
def show_puppet_class(f)
|
||
# In case of a new smart-var inside a puppetclass (REST nesting only), or a class parameter:
|
||
# Show the parent puppetclass as a context, but permit no change.
|
||
if params["puppetclass_id"]
|
||
select_f f, :puppetclass_id, [Puppetclass.find(params["puppetclass_id"])], :id, :to_label, {}, {:label => _("Puppet class"), :disabled => true}
|
||
elsif f.object.puppet? && f.object.param_class
|
||
text_f(f, :puppetclass_id, :label => _('Puppet Class'), :value => f.object.param_class, :disabled => true)
|
||
else # new smart-var with no particular context
|
||
# Give a select for choosing the parent puppetclass
|
||
puppetclasses = accessible_resource(f.object, :puppetclass)
|
||
select_f(f, :puppetclass_id, puppetclasses, :id, :to_label, { :include_blank => true }, {:label => _("Puppet class")})
|
||
end unless @puppetclass # nested smart-vars form in a tab of puppetclass/_form: no edition allowed, and the puppetclass is already visible as a context
|
||
unless @puppetclass
|
||
if params["puppetclass_id"]
|
||
select_f f, :puppetclass_id, [Puppetclass.find(params["puppetclass_id"])], :id, :to_label, {}, {:label => _("Puppet class"), :disabled => true}
|
||
elsif f.object.puppet? && f.object.param_class
|
||
text_f(f, :puppetclass_id, :label => _('Puppet Class'), :value => f.object.param_class, :disabled => true)
|
||
else # new smart-var with no particular context
|
||
# Give a select for choosing the parent puppetclass
|
||
puppetclasses = accessible_resource(f.object, :puppetclass)
|
||
select_f(f, :puppetclass_id, puppetclasses, :id, :to_label, { :include_blank => true }, {:label => _("Puppet class")})
|
||
end
|
||
end # nested smart-vars form in a tab of puppetclass/_form: no edition allowed, and the puppetclass is already visible as a context
|
||
end
|
||
|
||
def param_type_selector(f, options = {})
|
app/helpers/settings_helper.rb | ||
---|---|---|
module SettingsHelper
|
||
def value(setting)
|
||
return readonly_field(setting, :value,
|
||
{:title => _("This setting is defined in the configuration file '%{filename}' and is read-only.") % {:filename => setting.class.config_file}, :helper => :show_value}) if setting.readonly?
|
||
if setting.readonly?
|
||
return readonly_field(setting, :value,
|
||
{:title => _("This setting is defined in the configuration file '%{filename}' and is read-only.") % {:filename => setting.class.config_file}, :helper => :show_value})
|
||
end
|
||
|
||
return edit_select(setting, :value,
|
||
{:title => setting.full_name_with_default, :select_values => self.send("#{setting.name}_collection") }) if self.respond_to? "#{setting.name}_collection"
|
||
if self.respond_to? "#{setting.name}_collection"
|
||
return edit_select(setting, :value,
|
||
{:title => setting.full_name_with_default, :select_values => self.send("#{setting.name}_collection") })
|
||
end
|
||
|
||
return edit_textarea(setting, :value, {:title => setting.full_name_with_default, :helper => :show_value}) if setting.settings_type == 'array'
|
||
edit_textfield(setting, :value, {:title => setting.full_name_with_default, :helper => :show_value})
|
app/helpers/users_helper.rb | ||
---|---|---|
end
|
||
|
||
def user_taxonomies_html_options(user)
|
||
{
|
||
:location => { :onchange => 'tfm.users.taxonomyAdded(this, "location")'},
|
||
:organization => { :onchange => 'tfm.users.taxonomyAdded(this, "organization")'}
|
||
} unless user.admin?
|
||
unless user.admin?
|
||
{
|
||
:location => { :onchange => 'tfm.users.taxonomyAdded(this, "location")'},
|
||
:organization => { :onchange => 'tfm.users.taxonomyAdded(this, "organization")'}
|
||
}
|
||
end
|
||
end
|
||
|
||
def mail_notification_query_builder(mail_notification, f)
|
app/models/compute_resources/foreman/model/openstack.rb | ||
---|---|---|
:openstack_user_domain => domain,
|
||
:openstack_endpoint_type => "publicURL"
|
||
}.tap do |h|
|
||
h.merge!(:openstack_domain_name => domain,
|
||
:openstack_project_name => tenant) if tenant
|
||
if tenant
|
||
h.merge!(:openstack_domain_name => domain,
|
||
:openstack_project_name => tenant)
|
||
end
|
||
end
|
||
end
|
||
|
app/models/concerns/has_many_common.rb | ||
---|---|---|
# SETTER _name= method
|
||
define_method "#{assoc_name}=" do |name_value|
|
||
assoc_id = assoc_klass(association).send("find_by_#{assoc_klass(association).attribute_name}", name_value).try(:id)
|
||
raise Foreman::AssociationNotFound
|
||
.new(_("Could not find %{association} with name: %{name}") % { name: name_value, association: association }) unless assoc_id
|
||
unless assoc_id
|
||
raise Foreman::AssociationNotFound
|
||
.new(_("Could not find %{association} with name: %{name}") % { name: name_value, association: association })
|
||
end
|
||
self.send("#{assoc}_id=", assoc_id)
|
||
end
|
||
|
app/models/concerns/orchestration/compute.rb | ||
---|---|---|
end
|
||
|
||
def queue_compute_create
|
||
queue.create(:name => _("Render user data template for %s") % self, :priority => 1,
|
||
:action => [self, :setUserData]) if find_image.try(:user_data)
|
||
if find_image.try(:user_data)
|
||
queue.create(:name => _("Render user data template for %s") % self, :priority => 1,
|
||
:action => [self, :setUserData])
|
||
end
|
||
queue.create(:name => _("Set up compute instance %s") % self, :priority => 2,
|
||
:action => [self, :setCompute])
|
||
queue.create(:name => _("Acquire IP addresses for %s") % self, :priority => 3,
|
||
:action => [self, :setComputeIP]) if compute_provides?(:ip) || compute_provides?(:ip6)
|
||
if compute_provides?(:ip) || compute_provides?(:ip6)
|
||
queue.create(:name => _("Acquire IP addresses for %s") % self, :priority => 3,
|
||
:action => [self, :setComputeIP])
|
||
end
|
||
queue.create(:name => _("Query instance details for %s") % self, :priority => 4,
|
||
:action => [self, :setComputeDetails])
|
||
queue.create(:name => _("Set IP addresses for %s") % self, :priority => 5,
|
||
:action => [self, :setComputeIPAM]) if compute_provides?(:mac) && (mac_based_ipam?(:subnet) || mac_based_ipam?(:subnet6))
|
||
queue.create(:name => _("Power up compute instance %s") % self, :priority => 1000,
|
||
:action => [self, :setComputePowerUp]) if compute_attributes && compute_attributes[:start] == '1'
|
||
if compute_provides?(:mac) && (mac_based_ipam?(:subnet) || mac_based_ipam?(:subnet6))
|
||
queue.create(:name => _("Set IP addresses for %s") % self, :priority => 5,
|
||
:action => [self, :setComputeIPAM])
|
||
end
|
||
if compute_attributes && compute_attributes[:start] == '1'
|
||
queue.create(:name => _("Power up compute instance %s") % self, :priority => 1000,
|
||
:action => [self, :setComputePowerUp])
|
||
end
|
||
end
|
||
|
||
def queue_compute_update
|
app/models/concerns/orchestration/dns.rb | ||
---|---|---|
def queue_dns_create
|
||
logger.debug "Scheduling new DNS entries"
|
||
DnsInterface::RECORD_TYPES.each do |record_type|
|
||
queue.create(:name => _("Create %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 10,
|
||
:action => [self, :set_dns_record, record_type]) if dns_feasible?(record_type)
|
||
if dns_feasible?(record_type)
|
||
queue.create(:name => _("Create %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 10,
|
||
:action => [self, :set_dns_record, record_type])
|
||
end
|
||
end
|
||
end
|
||
|
||
def queue_dns_update
|
||
return unless pending_dns_record_changes?
|
||
DnsInterface::RECORD_TYPES.each do |record_type|
|
||
queue.create(:name => _("Remove %{type} for %{host}") % {:host => old, :type => dns_class(record_type).human }, :priority => 9,
|
||
:action => [old, :del_dns_record, record_type]) if old.dns_feasible?(record_type)
|
||
if old.dns_feasible?(record_type)
|
||
queue.create(:name => _("Remove %{type} for %{host}") % {:host => old, :type => dns_class(record_type).human }, :priority => 9,
|
||
:action => [old, :del_dns_record, record_type])
|
||
end
|
||
end
|
||
queue_dns_create
|
||
end
|
||
... | ... | |
def queue_dns_destroy
|
||
return unless errors.empty?
|
||
DnsInterface::RECORD_TYPES.each do |record_type|
|
||
queue.create(:name => _("Remove %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 1,
|
||
:action => [self, :del_dns_record, record_type]) if dns_feasible?(record_type)
|
||
if dns_feasible?(record_type)
|
||
queue.create(:name => _("Remove %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 1,
|
||
:action => [self, :del_dns_record, record_type])
|
||
end
|
||
end
|
||
end
|
||
|
||
... | ... | |
return unless overwrite?
|
||
logger.debug "Scheduling DNS conflict removal"
|
||
DnsInterface::RECORD_TYPES.each do |record_type|
|
||
queue.create(:name => _("Remove conflicting %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 0,
|
||
:action => [self, :del_conflicting_dns_record, record_type]) if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting?
|
||
if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting?
|
||
queue.create(:name => _("Remove conflicting %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 0,
|
||
:action => [self, :del_conflicting_dns_record, record_type])
|
||
end
|
||
end
|
||
end
|
||
|
app/models/filter.rb | ||
---|---|---|
# if we have 0 types, empty validation will set error, we can't have more than one type
|
||
def same_resource_type_permissions
|
||
types = self.permissions.map(&:resource_type).uniq
|
||
errors.add(
|
||
:permissions,
|
||
_('must be of same resource type (%s) - Role (%s)') %
|
||
[
|
||
types.join(','),
|
||
self.role.name
|
||
]
|
||
) if types.size > 1
|
||
if types.size > 1
|
||
errors.add(
|
||
:permissions,
|
||
_('must be of same resource type (%s) - Role (%s)') %
|
||
[
|
||
types.join(','),
|
||
self.role.name
|
||
]
|
||
)
|
||
end
|
||
end
|
||
|
||
def not_empty_permissions
|
app/models/host/managed.rb | ||
---|---|---|
end
|
||
|
||
def ipmi_boot(booting_device)
|
||
raise Foreman::Exception.new(
|
||
_("No BMC NIC available for host %s") % self) unless bmc_available?
|
||
unless bmc_available?
|
||
raise Foreman::Exception.new(
|
||
_("No BMC NIC available for host %s") % self)
|
||
end
|
||
bmc_proxy.boot({:function => 'bootdevice', :device => booting_device})
|
||
end
|
||
|
||
... | ... | |
# checks if the host association is a valid association for this host
|
||
def ensure_associations
|
||
status = true
|
||
%w{ptable medium architecture}.each do |e|
|
||
value = self.send(e.to_sym)
|
||
next if value.blank?
|
||
unless os.send(e.pluralize.to_sym).include?(value)
|
||
errors.add("#{e}_id".to_sym, _("%{value} does not belong to %{os} operating system") % { :value => value, :os => os })
|
||
status = false
|
||
if SETTINGS[:unattended] && managed? && os && pxe_build?
|
||
%w{ptable medium architecture}.each do |e|
|
||
value = self.send(e.to_sym)
|
||
next if value.blank?
|
||
unless os.send(e.pluralize.to_sym).include?(value)
|
||
errors.add("#{e}_id".to_sym, _("%{value} does not belong to %{os} operating system") % { :value => value, :os => os })
|
||
status = false
|
||
end
|
||
end
|
||
end if SETTINGS[:unattended] && managed? && os && pxe_build?
|
||
end
|
||
|
||
puppetclasses.select("puppetclasses.id,puppetclasses.name").distinct.each do |e|
|
||
unless environment.puppetclasses.map(&:id).include?(e.id)
|
||
errors.add(:puppetclasses, _("%{e} does not belong to the %{environment} environment") % { :e => e, :environment => environment })
|
||
status = false
|
||
if environment
|
||
puppetclasses.select("puppetclasses.id,puppetclasses.name").distinct.each do |e|
|
||
unless environment.puppetclasses.map(&:id).include?(e.id)
|
||
errors.add(:puppetclasses, _("%{e} does not belong to the %{environment} environment") % { :e => e, :environment => environment })
|
||
status = false
|
||
end
|
||
end
|
||
end if environment
|
||
end
|
||
status
|
||
end
|
||
|
app/models/hostgroup.rb | ||
---|---|---|
end
|
||
|
||
def inherited_lookup_value(key)
|
||
ancestors.reverse_each do |hg|
|
||
if (v = LookupValue.find_by(:lookup_key_id => key.id, :id => hg.lookup_values))
|
||
return v.value, hg.to_label
|
||
if key.path_elements.flatten.include?("hostgroup") && Setting["host_group_matchers_inheritance"]
|
||
ancestors.reverse_each do |hg|
|
||
if (v = LookupValue.find_by(:lookup_key_id => key.id, :id => hg.lookup_values))
|
||
return v.value, hg.to_label
|
||
end
|
||
end
|
||
end if key.path_elements.flatten.include?("hostgroup") && Setting["host_group_matchers_inheritance"]
|
||
end
|
||
[key.default_value, _("Default value")]
|
||
end
|
||
|
||
... | ... | |
private
|
||
|
||
def nested_root_pw
|
||
Hostgroup.sort_by_ancestry(ancestors).reverse_each do |a|
|
||
return a.root_pass if a.root_pass.present?
|
||
end if ancestry.present?
|
||
if ancestry.present?
|
||
Hostgroup.sort_by_ancestry(ancestors).reverse_each do |a|
|
||
return a.root_pass if a.root_pass.present?
|
||
end
|
||
end
|
||
nil
|
||
end
|
||
|
app/models/lookup_keys/lookup_key.rb | ||
---|---|---|
|
||
def value_before_type_cast(val)
|
||
return val if val.nil? || val.contains_erb?
|
||
case key_type.to_sym
|
||
when :json, :array
|
||
val = JSON.dump(val)
|
||
when :yaml, :hash
|
||
val = YAML.dump val
|
||
val.sub!(/\A---\s*$\n/, '')
|
||
end if key_type.present?
|
||
if key_type.present?
|
||
case key_type.to_sym
|
||
when :json, :array
|
||
val = JSON.dump(val)
|
||
when :yaml, :hash
|
||
val = YAML.dump val
|
||
val.sub!(/\A---\s*$\n/, '')
|
||
end
|
||
end
|
||
val
|
||
end
|
||
|
app/services/classification/matches_generator.rb | ||
---|---|---|
match = generate_match(rule)
|
||
matches << match.join(LookupKey::KEY_DELM)
|
||
|
||
hostgroup_matches.each do |hostgroup_match|
|
||
match[match.index { |m| m =~ /hostgroup\s*=/ }] = hostgroup_match
|
||
matches << match.join(LookupKey::KEY_DELM)
|
||
end if add_hostgroup_matches?(rule)
|
||
if add_hostgroup_matches?(rule)
|
||
hostgroup_matches.each do |hostgroup_match|
|
||
match[match.index { |m| m =~ /hostgroup\s*=/ }] = hostgroup_match
|
||
matches << match.join(LookupKey::KEY_DELM)
|
||
end
|
||
end
|
||
end
|
||
matches
|
||
end
|
app/services/foreman/importer_puppetclass.rb | ||
---|---|---|
def self.suggest_key_type(value, default = nil, detect_json_or_yaml = false)
|
||
case value
|
||
when String
|
||
begin
|
||
return "json" if JSON.load value
|
||
rescue
|
||
return "yaml" if YAML.load value
|
||
end if detect_json_or_yaml
|
||
if detect_json_or_yaml
|
||
begin
|
||
return "json" if JSON.load value
|
||
rescue
|
||
return "yaml" if YAML.load value
|
||
end
|
||
end
|
||
"string"
|
||
when TrueClass, FalseClass
|
||
"boolean"
|
config/environments/development.rb | ||
---|---|---|
# Raise exception on mass assignment of unfiltered parameters
|
||
config.action_controller.action_on_unpermitted_parameters = :strict
|
||
|
||
config.after_initialize do
|
||
Bullet.enable = true
|
||
Bullet.bullet_logger = true
|
||
Bullet.console = true
|
||
Bullet.rails_logger = true
|
||
Bullet.add_footer = true
|
||
Bullet.counter_cache_enable = false
|
||
Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :environments
|
||
Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :class_params
|
||
end if defined?(Bullet)
|
||
if defined?(Bullet)
|
||
config.after_initialize do
|
||
Bullet.enable = true
|
||
Bullet.bullet_logger = true
|
||
Bullet.console = true
|
||
Bullet.rails_logger = true
|
||
Bullet.add_footer = true
|
||
Bullet.counter_cache_enable = false
|
||
Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :environments
|
||
Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :class_params
|
||
end
|
||
end
|
||
|
||
# Allow disabling the webpack dev server from the settings
|
||
config.webpack.dev_server.enabled = SETTINGS.fetch(:webpack_dev_server, true)
|
config/initializers/apipie.rb | ||
---|---|---|
roots << Rails.root
|
||
roots.each do |root|
|
||
path = "#{root}/app/controllers/api"
|
||
Find.find(path) do |e|
|
||
t = File.mtime(e)
|
||
max = t if t > max
|
||
end if File.exist?(path)
|
||
if File.exist?(path)
|
||
Find.find(path) do |e|
|
||
t = File.mtime(e)
|
||
max = t if t > max
|
||
end
|
||
end
|
||
end
|
||
if !$ARGV.nil? && $ARGV.first != "apipie:cache" && max > target
|
||
puts "API controllers newer than Apipie cache! Run apipie:cache rake task to regenerate cache."
|
db/migrate/20130520152000_remove_duplicate_fact_names.rb | ||
---|---|---|
unique_names = FactName.group(:name).maximum(:id)
|
||
unique_names.each do |fact_name, fact_name_id|
|
||
duplicates = FactName.where("name=? and id<>?", fact_name, fact_name_id).select(:id)
|
||
ActiveRecord::Base.transaction do
|
||
FactValue.update_all(
|
||
["fact_name_id=?", fact_name_id],
|
||
["fact_name_id in (?)", duplicates]
|
||
)
|
||
UserFact.update_all(
|
||
["fact_name_id=?", fact_name_id],
|
||
["fact_name_id in (?)", duplicates]
|
||
)
|
||
FactName.where(["id in (?)", duplicates]).delete_all
|
||
end if duplicates.any?
|
||
if duplicates.any?
|
||
ActiveRecord::Base.transaction do
|
||
FactValue.update_all(
|
||
["fact_name_id=?", fact_name_id],
|
||
["fact_name_id in (?)", duplicates]
|
||
)
|
||
UserFact.update_all(
|
||
["fact_name_id=?", fact_name_id],
|
||
["fact_name_id in (?)", duplicates]
|
||
)
|
||
FactName.where(["id in (?)", duplicates]).delete_all
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
db/seeds.d/160-mail_notifications.rb | ||
---|---|---|
mail.save! if mail.changed?
|
||
else
|
||
created_notification = MailNotification.create(notification)
|
||
raise ::Foreman::Exception.new(N_("Unable to create mail notification: %s"),
|
||
format_errors(created_notification)) if created_notification.nil? || created_notification.errors.any?
|
||
if created_notification.nil? || created_notification.errors.any?
|
||
raise ::Foreman::Exception.new(N_("Unable to create mail notification: %s"),
|
||
format_errors(created_notification))
|
||
end
|
||
end
|
||
end
|
lib/foreman/telemetry.rb | ||
---|---|---|
:minor_gc_count => :ruby_gc_minor_count
|
||
}
|
||
def register_rails
|
||
ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
|
||
event = ActiveSupport::Notifications::Event.new(*args)
|
||
controller = event.payload[:controller].underscore
|
||
action = event.payload[:action].underscore
|
||
status = event.payload[:status]
|
||
|
||
increment_counter(:http_requests, 1, :controller => controller, :action => action, :status => status)
|
||
observe_histogram(:http_request_total_duration, event.duration || 0, :controller => controller, :action => action)
|
||
observe_histogram(:http_request_db_duration, event.payload[:db_runtime] || 0, :controller => controller, :action => action)
|
||
observe_histogram(:http_request_view_duration, event.payload[:view_runtime] || 0, :controller => controller, :action => action)
|
||
|
||
# measure GC stats for each request
|
||
before = Thread.current[:foreman_telemetry_gcstats]
|
||
after = GC.stat
|
||
GC_METRICS.each do |ruby_key, metric_name|
|
||
if after.include?(ruby_key)
|
||
count = after[ruby_key] - before[ruby_key]
|
||
increment_counter(metric_name, count, :controller => controller, :action => action) if count > 0
|
||
if enabled?
|
||
ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
|
||
event = ActiveSupport::Notifications::Event.new(*args)
|
||
controller = event.payload[:controller].underscore
|
||
action = event.payload[:action].underscore
|
||
status = event.payload[:status]
|
||
|
||
increment_counter(:http_requests, 1, :controller => controller, :action => action, :status => status)
|
||
observe_histogram(:http_request_total_duration, event.duration || 0, :controller => controller, :action => action)
|
||
observe_histogram(:http_request_db_duration, event.payload[:db_runtime] || 0, :controller => controller, :action => action)
|
||
observe_histogram(:http_request_view_duration, event.payload[:view_runtime] || 0, :controller => controller, :action => action)
|
||
|
||
# measure GC stats for each request
|
||
before = Thread.current[:foreman_telemetry_gcstats]
|
||
after = GC.stat
|
||
if before
|
||
GC_METRICS.each do |ruby_key, metric_name|
|
||
if after.include?(ruby_key)
|
||
count = after[ruby_key] - before[ruby_key]
|
||
increment_counter(metric_name, count, :controller => controller, :action => action) if count > 0
|
||
end
|
||
end
|
||
end
|
||
end if before
|
||
end if enabled?
|
||
|
||
ActiveSupport::Notifications.subscribe(/instantiation.active_record/) do |*args|
|
||
event = ActiveSupport::Notifications::Event.new(*args)
|
||
class_name = event.payload[:class_name]
|
||
record_count = event.payload[:record_count]
|
||
increment_counter(:activerecord_instances, record_count, :class => class_name) if record_count > 0
|
||
end if enabled?
|
||
end
|
||
end
|
||
|
||
if enabled?
|
||
ActiveSupport::Notifications.subscribe(/instantiation.active_record/) do |*args|
|
||
event = ActiveSupport::Notifications::Event.new(*args)
|
||
class_name = event.payload[:class_name]
|
||
record_count = event.payload[:record_count]
|
||
increment_counter(:activerecord_instances, record_count, :class => class_name) if record_count > 0
|
||
end
|
||
end
|
||
end
|
||
|
||
def register_ruby
|
lib/tasks/backup.rake | ||
---|---|---|
END_DESC
|
||
|
||
task :import_dump => :environment do
|
||
puts "Run this task with a file argument with the location of your db dump,
|
||
'rake db:import_dump file=DBDUMPLOCATION" and return unless ENV['file']
|
||
unless ENV['file']
|
||
puts "Run this task with a file argument with the location of your db dump,
|
||
'rake db:import_dump file=DBDUMPLOCATION" and return
|
||
end
|
||
config = Rails.configuration.database_configuration[Rails.env]
|
||
|
||
puts "Your backup is going to be imported from: #{ENV['file']}"
|
test/active_support_test_case_helper.rb | ||
---|---|---|
if field
|
||
model_errors = model.errors.map { |a, m| model.errors.full_message(a, m) unless field == a }.compact
|
||
assert model_errors.blank?, "#{model} contains #{model_errors}, it should not contain any"
|
||
assert model.errors[field].find { |e| e.match(match) }.present?,
|
||
"#{field} error matching #{match} not found: #{model.errors[field].inspect}" if match
|
||
if match
|
||
assert model.errors[field].find { |e| e.match(match) }.present?,
|
||
"#{field} error matching #{match} not found: #{model.errors[field].inspect}"
|
||
end
|
||
end
|
||
end
|
||
alias_method :assert_not_with_errors, :refute_with_errors
|
test/controllers/api/v2/fact_values_controller_test.rb | ||
---|---|---|
get :index
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
|
||
expected_hash = {@host.name => {"kernelversion" => "2.6.9"}}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
... | ... | |
get :index, params: {:host_id => @host.name}
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
|
||
expected_hash = {@host.name => {"kernelversion" => "2.6.9"}, "kernelversion" => "2.6.9"}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
... | ... | |
get :index, params: {:host_id => @host.id}
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
|
||
expected_hash = {@host.name => {"kernelversion" => "2.6.9"}, "kernelversion" => "2.6.9"}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
||
... | ... | |
end
|
||
assert_response :success
|
||
fact_values = ActiveSupport::JSON.decode(@response.body)['results']
|
||
expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
|
||
expected_hash = {@host.name => {"kernelversion" => "2.6.9"}}
|
||
assert_equal expected_hash, fact_values
|
||
end
|
||
|
Also available in: Unified diff
Fixes #19873 - Fix Style/MultilineIfModifier cop (#5705)