Revision 84579c3a
Added by David Davis over 8 years ago
.rubocop.yml | ||
---|---|---|
Metrics/ClassLength:
|
||
Exclude:
|
||
- 'test/**/*'
|
||
|
||
Performance/FixedSize:
|
||
Exclude:
|
||
- 'test/**/*'
|
.rubocop_todo.yml | ||
---|---|---|
Lint/AssignmentInCondition:
|
||
Enabled: false
|
||
|
||
# Offense count: 1
|
||
Lint/DuplicateMethods:
|
||
Enabled: false
|
||
|
||
# Offense count: 6
|
||
Lint/DuplicatedKey:
|
||
Enabled: false
|
||
|
||
# Offense count: 5
|
||
# Cop supports --auto-correct.
|
||
# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
|
||
... | ... | |
Metrics/PerceivedComplexity:
|
||
Max: 24
|
||
|
||
# Offense count: 20
|
||
# Cop supports --auto-correct.
|
||
Performance/Count:
|
||
Exclude:
|
||
- 'test/unit/orchestration/compute_test.rb'
|
||
- 'test/unit/orchestration/dhcp_test.rb'
|
||
|
||
# Offense count: 7
|
||
# Cop supports --auto-correct.
|
||
Performance/Detect:
|
||
Exclude:
|
||
- 'app/models/compute_resources/foreman/model/gce.rb'
|
||
- 'app/models/nic/interface.rb'
|
||
- 'app/services/smart_proxies/puppet_ca.rb'
|
||
- 'app/services/sso.rb'
|
||
- 'test/unit/usergroup_test.rb'
|
||
|
||
# Offense count: 4
|
||
Performance/FixedSize:
|
||
Exclude:
|
||
- 'test/unit/hostgroup_test.rb'
|
||
- 'test/unit/location_test.rb'
|
||
|
||
# Offense count: 3
|
||
# Cop supports --auto-correct.
|
||
Performance/ReverseEach:
|
||
Exclude:
|
||
- 'app/models/hostgroup.rb'
|
||
- 'app/services/classification/base.rb'
|
||
|
||
# Offense count: 2
|
||
# Cop supports --auto-correct.
|
||
Performance/StringReplacement:
|
||
Exclude:
|
||
- 'app/models/operatingsystem.rb'
|
||
- 'app/models/operatingsystems/windows.rb'
|
||
|
||
# Offense count: 247
|
||
# Cop supports --auto-correct.
|
||
# Configuration parameters: EnforcedStyle, SupportedStyles, Include.
|
app/models/compute_resources/foreman/model/gce.rb | ||
---|---|---|
|
||
if args[:volumes].present?
|
||
if args[:image_id].present?
|
||
args[:volumes].first[:source_image] = client.images.select { |i| i.id == args[:image_id] }.first.name
|
||
args[:volumes].first[:source_image] = client.images.find { |i| i.id == args[:image_id] }.name
|
||
end
|
||
args[:disks] = []
|
||
args[:volumes].each_with_index do |vol_args,i|
|
app/models/hostgroup.rb | ||
---|---|---|
end
|
||
|
||
def inherited_lookup_value(key)
|
||
ancestors.reverse.each do |hg|
|
||
ancestors.reverse_each do |hg|
|
||
if (v = LookupValue.where(:lookup_key_id => key.id, :id => hg.lookup_values).first)
|
||
return v.value, hg.to_label
|
||
end
|
||
... | ... | |
private
|
||
|
||
def nested_root_pw
|
||
Hostgroup.sort_by_ancestry(ancestors).reverse.each do |a|
|
||
Hostgroup.sort_by_ancestry(ancestors).reverse_each do |a|
|
||
return a.root_pass unless a.root_pass.blank?
|
||
end if ancestry.present?
|
||
nil
|
app/models/operatingsystem.rb | ||
---|---|---|
|
||
# sets the prefix for the tfp files based on the os / arch combination
|
||
def pxe_prefix(arch)
|
||
"boot/#{self}-#{arch}".gsub(" ","-")
|
||
"boot/#{self}-#{arch}".tr(" ","-")
|
||
end
|
||
|
||
def pxe_files(medium, arch, host = nil)
|
app/models/operatingsystems/windows.rb | ||
---|---|---|
end
|
||
|
||
def pxe_prefix(arch)
|
||
"boot/windows-#{arch}/".gsub(" ","-")
|
||
"boot/windows-#{arch}/".tr(" ","-")
|
||
end
|
||
|
||
def bootfile arch, type
|
app/services/classification/base.rb | ||
---|---|---|
|
||
# to make sure seep merge overrides by priority, putting in the values with the lower priority first
|
||
# and then merging with higher priority
|
||
lookup_values.reverse.each do |lookup_value|
|
||
lookup_values.reverse_each do |lookup_value|
|
||
element, element_name = get_element_and_element_name(lookup_value)
|
||
next if ((options[:skip_fqdn] && element=="fqdn") || lookup_value.use_puppet_default)
|
||
elements << element
|
app/services/puppet_class_importer.rb | ||
---|---|---|
classes.not_in_any_environment.destroy_all
|
||
end
|
||
|
||
def logger
|
||
@logger ||= Rails.logger
|
||
end
|
||
|
||
def find_existing_foreman_classes(klasses = [])
|
||
Puppetclass.where(:name => klasses)
|
||
end
|
app/services/smart_proxies/puppet_ca.rb | ||
---|---|---|
end
|
||
|
||
def find(proxy, name)
|
||
all(proxy).select{|c| c.name == name}.first
|
||
all(proxy).find{|c| c.name == name}
|
||
end
|
||
|
||
def find_by_state(proxy, state)
|
app/services/sso.rb | ||
---|---|---|
|
||
def self.get_available(controller)
|
||
all_methods = all.map { |method| method.new(controller) }
|
||
all_methods.select(&:available?).first
|
||
all_methods.find(&:available?)
|
||
end
|
||
|
||
def self.all
|
test/unit/host_test.rb | ||
---|---|---|
test "should save if neither ptable or disk are defined when the host is not managed" do
|
||
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "2.3.4.03", :medium => media(:one),
|
||
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:two), :puppet_proxy => smart_proxies(:puppetmaster),
|
||
:subnet => subnets(:two), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => false
|
||
:architecture => architectures(:x86_64), :environment => environments(:production), :managed => false
|
||
assert host.valid?
|
||
end
|
||
|
||
... | ... | |
if unattended?
|
||
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03", :ptable => FactoryGirl.create(:ptable),
|
||
:domain => domains(:mydomain), :operatingsystem => Operatingsystem.first, :subnet => subnets(:two), :managed => true, :medium => media(:one),
|
||
:architecture => Architecture.first, :environment => Environment.first, :ptable => Ptable.first, :puppet_proxy => smart_proxies(:puppetmaster)
|
||
:architecture => Architecture.first, :environment => Environment.first, :puppet_proxy => smart_proxies(:puppetmaster)
|
||
assert !host.valid?
|
||
end
|
||
end
|
||
... | ... | |
host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "3.3.4.03",
|
||
:ptable => FactoryGirl.create(:ptable, :operatingsystem_ids => [operatingsystems(:redhat).id]), :medium => media(:one),
|
||
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:two), :puppet_proxy => smart_proxies(:puppetmaster),
|
||
:subnet => subnets(:two), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => true,
|
||
:architecture => architectures(:x86_64), :environment => environments(:production), :managed => true,
|
||
:owner_type => "User", :root_pass => "xybxa6JUkz63w"
|
||
assert host.valid?
|
||
end
|
||
... | ... | |
test "should not save if owner_type is not User or Usergroup" do
|
||
host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "3.3.4.03", :medium => media(:one),
|
||
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:two), :puppet_proxy => smart_proxies(:puppetmaster),
|
||
:subnet => subnets(:two), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => true,
|
||
:architecture => architectures(:x86_64), :environment => environments(:production), :managed => true,
|
||
:owner_type => "UserGr(up" # should be Usergroup
|
||
assert !host.valid?
|
||
end
|
||
... | ... | |
test "should not save if installation media is missing" do
|
||
host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "3.3.4.03", :ptable => FactoryGirl.create(:ptable),
|
||
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:two), :puppet_proxy => smart_proxies(:puppetmaster),
|
||
:subnet => subnets(:two), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => true, :build => true,
|
||
:architecture => architectures(:x86_64), :environment => environments(:production), :managed => true, :build => true,
|
||
:owner_type => "User", :root_pass => "xybxa6JUkz63w"
|
||
refute host.valid?
|
||
assert_equal "can't be blank", host.errors[:medium_id][0]
|
||
... | ... | |
test "should save if owner_type is empty and Host is unmanaged" do
|
||
host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "3.3.4.03", :medium => media(:one),
|
||
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :subnet => subnets(:two), :puppet_proxy => smart_proxies(:puppetmaster),
|
||
:subnet => subnets(:two), :architecture => architectures(:x86_64), :environment => environments(:production), :managed => false
|
||
:architecture => architectures(:x86_64), :environment => environments(:production), :managed => false
|
||
assert host.valid?
|
||
end
|
||
|
test/unit/orchestration/compute_test.rb | ||
---|---|---|
attrs = {}
|
||
@host.stubs(:compute_attributes).returns(attrs)
|
||
@host.send :add_interfaces_to_compute_attrs
|
||
assert_equal 1, attrs['nics_attributes'].select { |k, v| v.present? }.size
|
||
assert_equal 1, attrs['nics_attributes'].count { |k, v| v.present? }
|
||
end
|
||
end
|
||
|
test/unit/orchestration/dhcp_test.rb | ||
---|---|---|
assert h.new_record?
|
||
|
||
assert h.valid?
|
||
assert_equal h.queue.items.select {|x| x.action.last == :set_dhcp }.size, 1
|
||
assert_equal h.queue.items.count {|x| x.action.last == :set_dhcp }, 1
|
||
assert h.queue.items.select {|x| x.action.last == :del_dhcp }.empty?
|
||
end
|
||
|
||
... | ... | |
primary_interface_tasks = h.queue.items.select { |t| t.action.first == h.primary_interface }
|
||
interface_tasks = h.queue.items.select { |t| t.action.first == bmc }
|
||
|
||
assert_equal 1, primary_interface_tasks.select { |t| t.action.last == :set_dhcp }.size
|
||
assert_equal 1, primary_interface_tasks.count { |t| t.action.last == :set_dhcp }
|
||
assert_empty primary_interface_tasks.select { |t| t.action.last == :del_dhcp }
|
||
assert_equal 1, interface_tasks.select { |t| t.action.last == :set_dhcp }.size
|
||
assert_equal 1, interface_tasks.count { |t| t.action.last == :set_dhcp }
|
||
assert_empty interface_tasks.select { |t| t.action.last == :del_dhcp }
|
||
end
|
||
|
||
... | ... | |
h.ip = h.ip.succ
|
||
assert h.valid?
|
||
# 1st is creation from factory, 2nd is triggered by h.valid?
|
||
assert_equal 2, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 2, h.queue.items.count {|x| x.action == [ h.primary_interface, :set_dhcp ] }
|
||
# and also one deletion (of original creation)
|
||
assert_equal 1, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
assert_equal 1, h.primary_interface.queue.items.count {|x| x.action.last == :del_dhcp }
|
||
end
|
||
|
||
test "when an existing host change its bmc ip address, its dhcp record should be updated" do
|
||
... | ... | |
bmc = h.interfaces.bmc.first
|
||
bmc.ip = bmc.ip.succ
|
||
assert bmc.valid?
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc, :set_dhcp ] }.size
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc.old, :del_dhcp ] }.size
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc, :set_dhcp ] }
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc.old, :del_dhcp ] }
|
||
end
|
||
|
||
test "when an existing host change its mac address, its dhcp record should be updated" do
|
||
h = FactoryGirl.create(:host, :with_dhcp_orchestration)
|
||
h.mac = next_mac(h.mac)
|
||
assert h.valid?
|
||
assert_equal 2, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 1, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
assert_equal 2, h.queue.items.count {|x| x.action == [ h.primary_interface, :set_dhcp ] }
|
||
assert_equal 1, h.primary_interface.queue.items.count {|x| x.action.last == :del_dhcp }
|
||
end
|
||
|
||
test "when an existing host trigger a 'rebuild', its dhcp record should be updated if no dhcp record is found" do
|
||
... | ... | |
h.build = true
|
||
|
||
assert h.valid?, h.errors.messages.to_s
|
||
assert_equal 2, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 1, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
assert_equal 2, h.queue.items.count {|x| x.action == [ h.primary_interface, :set_dhcp ] }
|
||
assert_equal 1, h.primary_interface.queue.items.count {|x| x.action.last == :del_dhcp }
|
||
end
|
||
|
||
test "when an existing host trigger a 'rebuild', its dhcp record should not be updated if valid dhcp record is found" do
|
||
... | ... | |
h.build = true
|
||
|
||
assert h.valid?, h.errors.messages.to_s
|
||
assert_equal 1, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 0, h.primary_interface.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
assert_equal 1, h.queue.items.count {|x| x.action == [ h.primary_interface, :set_dhcp ] }
|
||
assert_equal 0, h.primary_interface.queue.items.count {|x| x.action.last == :del_dhcp }
|
||
end
|
||
|
||
test "when an existing host change its bmc mac address, its dhcp record should be updated" do
|
||
... | ... | |
bmc.mac = next_mac(bmc.mac)
|
||
assert h.valid?
|
||
assert bmc.valid?
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc, :set_dhcp ] }.size
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc.old, :del_dhcp ] }.size
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc, :set_dhcp ] }
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc.old, :del_dhcp ] }
|
||
end
|
||
|
||
test "when an existing host change multiple attributes, both his dhcp and bmc dhcp records should be updated" do
|
||
... | ... | |
bmc.mac = next_mac(bmc.mac)
|
||
assert h.valid?
|
||
assert bmc.valid?
|
||
assert_equal 2, h.queue.items.select {|x| x.action == [ h.primary_interface, :set_dhcp ] }.size
|
||
assert_equal 1, h.queue.items.select {|x| x.action.last == :del_dhcp }.size
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc, :set_dhcp ] }.size
|
||
assert_equal 1, bmc.queue.items.select {|x| x.action == [ bmc.old, :del_dhcp ] }.size
|
||
assert_equal 2, h.queue.items.count {|x| x.action == [ h.primary_interface, :set_dhcp ] }
|
||
assert_equal 1, h.queue.items.count {|x| x.action.last == :del_dhcp }
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc, :set_dhcp ] }
|
||
assert_equal 1, bmc.queue.items.count {|x| x.action == [ bmc.old, :del_dhcp ] }
|
||
end
|
||
|
||
test "new host with dhcp and no operating system should show correct validation on save" do
|
test/unit/usergroup_test.rb | ||
---|---|---|
@usergroup.save
|
||
|
||
AuthSourceLdap.any_instance.expects(:users_in_group).with('aname').returns([])
|
||
@usergroup.external_usergroups.select { |eu| eu.name == 'aname'}.first.refresh
|
||
@usergroup.external_usergroups.find { |eu| eu.name == 'aname'}.refresh
|
||
|
||
refute_includes @usergroup.users, users(:one)
|
||
end
|
||
... | ... | |
@usergroup.save
|
||
|
||
AuthSourceLdap.any_instance.expects(:users_in_group).with('aname').returns([users(:one).login])
|
||
@usergroup.external_usergroups.select { |eu| eu.name == 'aname'}.first.refresh
|
||
@usergroup.external_usergroups.find { |eu| eu.name == 'aname'}.refresh
|
||
assert_includes @usergroup.users, users(:one)
|
||
end
|
||
|
||
... | ... | |
@usergroup.save
|
||
|
||
AuthSourceLdap.any_instance.expects(:users_in_group).with('aname').returns([users(:one).login])
|
||
@usergroup.external_usergroups.select { |eu| eu.name == 'aname'}.first.refresh
|
||
@usergroup.external_usergroups.find { |eu| eu.name == 'aname'}.refresh
|
||
assert_includes @usergroup.users, users(:one)
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #12911 - Turning on 0.35.1 cops