foreman_default_hostgroup 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ for how to install Foreman plugins
13
13
  | Foreman Version | Plugin Version |
14
14
  | --------------- | --------------:|
15
15
  | <= 1.2 | 0.1.0 |
16
- | >= 1.3 | 1.0.0 |
16
+ | >= 1.3 | 1.0.1 |
17
17
 
18
18
  ## Usage
19
19
 
File without changes
@@ -0,0 +1,15 @@
1
+ namespace :test do
2
+ desc "Test DefaultHostgroup plugin"
3
+ Rake::TestTask.new(:default_hostgroup) do |t|
4
+ test_dir = File.join(File.dirname(__FILE__), '..', 'test')
5
+ t.libs << ["test",test_dir]
6
+ t.pattern = "#{test_dir}/**/*_test.rb"
7
+ t.verbose = true
8
+ end
9
+
10
+ end
11
+
12
+ Rake::Task[:test].enhance do
13
+ Rake::Task['test:default_hostgroup'].invoke
14
+ end
15
+
@@ -13,6 +13,12 @@ module DefaultHostgroupManagedHostPatch
13
13
  def importHostAndFacts_with_apply_hostgroup hostname, facts, certname = nil
14
14
  host, result = importHostAndFacts_without_apply_hostgroup(hostname, facts, certname)
15
15
  Rails.logger.debug "DefaultHostgroup: performing Hostgroup check"
16
+
17
+ unless valid_hostgroup?
18
+ Rails.logger.debug "DefaultHostgroup: Could not find Hostgroup '#{Setting[:default_hostgroup]}'"
19
+ return host, result
20
+ end
21
+
16
22
  # host.new_record? will only test for the early return in the core method, a real host
17
23
  # will have already been saved at least once.
18
24
  if host.present? && !host.new_record? && host.hostgroup.nil? && host.reports.empty?
@@ -22,5 +28,9 @@ module DefaultHostgroupManagedHostPatch
22
28
  end
23
29
  return host, result
24
30
  end
31
+
32
+ def valid_hostgroup?
33
+ Hostgroup.find_by_label(Setting[:default_hostgroup]) ? true : false
34
+ end
25
35
  end
26
36
  end
@@ -15,5 +15,9 @@ module ForemanDefaultHostgroup
15
15
  ::Host::Managed.send :include, DefaultHostgroupManagedHostPatch
16
16
  end
17
17
 
18
+ rake_tasks do
19
+ load "default_hostgroup.rake"
20
+ end
21
+
18
22
  end
19
23
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanDefaultHostgroup
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultHostgroupTest < ActiveSupport::TestCase
4
+ setup do
5
+ disable_orchestration
6
+ User.current = User.find_by_login "admin"
7
+
8
+ # this is not being run automatically by the
9
+ # initializers, for some strange reason....
10
+ Setting::DefaultHostgroup.load_defaults
11
+ end
12
+
13
+ def parse_json_fixture(relative_path)
14
+ return JSON.parse(File.read(File.expand_path(File.dirname(__FILE__) + relative_path)))
15
+ end
16
+
17
+ def setup_hostgroup
18
+ @hostgroup = Hostgroup.create :name => "MyGroup"
19
+ Setting[:default_hostgroup] = @hostgroup.name
20
+ end
21
+
22
+ test "a new, fact-imported, host has a default hostgroup set" do
23
+ setup_hostgroup
24
+ raw = parse_json_fixture('/facts.json')
25
+ assert Host.importHostAndFacts(raw['name'], raw['facts'])
26
+ assert_equal @hostgroup, Host.find_by_name('sinn1636.lan').hostgroup
27
+ end
28
+
29
+ test "an invalid hostgroup setting does nothing" do
30
+ setup_hostgroup
31
+ Setting[:default_hostgroup] = "doesnotexist"
32
+ raw = parse_json_fixture('/facts.json')
33
+ assert Host.importHostAndFacts(raw['name'], raw['facts'])
34
+ refute Host.find_by_name('sinn1636.lan').hostgroup
35
+ end
36
+
37
+ end
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "sinn1636.lan",
3
+ "facts": {
4
+ "processor3": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
5
+ "productname": "IBM System x -[7870K4G]-",
6
+ "kernelmajversion": "2.6",
7
+ "kernelversion": "2.6.32",
8
+ "macaddress_vnet0": "FE:54:00:1E:45:13",
9
+ "macaddress_br181": "E4:1F:13:CC:36:58",
10
+ "macaddress_usb0": "E6:1F:13:D0:43:A3",
11
+ "macaddress_vnet1": "FE:54:00:45:E5:3E",
12
+ "rubysitedir": "/usr/lib/ruby/site_ruby/1.8",
13
+ "macaddress_br182": "E4:1F:13:CC:36:58",
14
+ "processor4": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
15
+ "macaddress_vnet2": "FE:54:00:93:F5:56",
16
+ "macaddress_br183": "E4:1F:13:CC:36:58",
17
+ "ps": "ps -ef",
18
+ "processor5": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
19
+ "macaddress_vnet10": "FE:54:00:7D:F8:24",
20
+ "uniqueid": "230a021b",
21
+ "macaddress_vnet3": "FE:54:00:05:49:DE",
22
+ "lsbdistcodename": "Santiago",
23
+ "hardwareisa": "x86_64",
24
+ "lsbdistrelease": "6.2",
25
+ "processor6": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
26
+ "serialnumber": "abcdefg",
27
+ "processor7": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
28
+ "macaddress_vnet4": "FE:54:00:62:53:67",
29
+ "hostname": "h02",
30
+ "osfamily": "RedHat",
31
+ "gateway_if": "br180",
32
+ "lsbrelease": ":core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch",
33
+ "kernelrelease": "2.6.32-131.12.1.el6.x86_64",
34
+ "kernel": "Linux",
35
+ "facterversion": "1.6.2",
36
+ "uptime_seconds": "13651752",
37
+ "macaddress_vnet5": "FE:54:00:01:B9:9C",
38
+ "interfaces": "br180,br181,br182,br183,eth0,eth0_181,eth0_182,eth0_183,eth1,lo,usb0,vnet0,vnet1,vnet2,vnet3,vnet4,vnet5,vnet7,vnet10",
39
+ "macaddress_vnet7": "FE:54:00:D8:F9:38",
40
+ "netmask_br180": "255.255.255.192",
41
+ "macaddress_eth0": "E4:1F:13:CC:36:58",
42
+ "is_virtual": "false",
43
+ "macaddress": "E4:1F:13:CC:36:58",
44
+ "sshdsakey": "AAAAB3NzaC1kc3MAAACBAIbK60jlhYKSd4Nx6LCQPMUZcq/P1lTY3sQVrwpmfbF7d4JOGed2RWSoTBAzP3/Tjwlf+8DZ3Jd8a6Yhd6WuBzinE+owym8LXo2gDTvelhnzOVrTytM8hAi8uFEiBTGbnN1zka2y7qCPVxEu+kV20qC3mPODGxpV6y/4KOZ5Y4SHAAAAFQCyjeF+Jy9CDhiD2tfnmtMGAn1xzQAAAIBwtnUhhkB0r3ivPdQZgVy6qha8AJQG94I9FU9FnGJJEjkkfqlgNrj9SxV6Cg9EcrntnAKxZxk7PQhgvDesx69Lap9PAx3Ffb5Pl47cd7ilOXv2RJGKuxZQHNdKUF2445POwNjxSuhEkIB3/zpFXBB/zPMRfqUtlXJEwP9m6z9UFgAAAIAQDBpmcGChFP7i8T2RdMZo3hSMnU4y5lpEGhmwfbODoLSAX37wWQwUmwRP8byTEqFL0+5bp3hRbt/67EoD1O6n39/We19g/UqHkbUdZQqLqFjJfyzqfepq4HXtIIT8GbqW+FGJkH9x2fY5gtQrn9nVdmPDTwERFS98qU9glufbIw==",
45
+ "uptime": "158 days",
46
+ "manufacturer": "IBM",
47
+ "macaddress_eth1": "E4:1F:13:CC:36:5A",
48
+ "timezone": "GMT",
49
+ "fqdn": "a.server.b.domain",
50
+ "ipaddress_br180": "10.35.27.2",
51
+ "puppetversion": "2.6.12",
52
+ "path": "/root/.gem/bin:/root/.gem/ruby/1.8/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/usr/sbin:/root/scripts",
53
+ "hardwaremodel": "x86_64",
54
+ "macaddress_eth0_181": "E4:1F:13:CC:36:58",
55
+ "netmask_lo": "255.0.0.0",
56
+ "uptime_days": "158",
57
+ "virtual": "physical",
58
+ "operatingsystemrelease": "6.2",
59
+ "processorcount": "8",
60
+ "sshrsakey": "AAAAB3NzaC1xcEabbAABIwAAAQEAwXfnuA0+6C6G152kzCbSZvTyUBrMwc0PGnmZgFpC3x4SkcMgRmtayPNqmY1vyYwyka1lNUoyU9u3TXOUkd7WrodoNYBbDQXWCAVpUci5099zUuZ8RVLcokKwNmQO0d1URgSLt2TtuLiUDB7JU2mHkoOuW9n7ODq+UzYsd2wf+/TQrvgsuyi25MROH2Z3WfMO+fmsj77h34gkuaavwB4e6lNRynjZLuEc4POFvDEW6kGCYm1g/8kRwUlB/Z1Cu0egxtxnTjILFFwfYFQu2Ksig020q1gLX3o4YL9X/YZz+JQuAOLGpK3F0owQUL7Ie3vokDsVmz2AweuLDFeh54i2Bw==",
61
+ "macaddress_eth0_182": "E4:1F:13:CC:36:58",
62
+ "memorysize": "15.57 GB",
63
+ "ipaddress": "10.35.27.2",
64
+ "rubyversion": "1.8.7",
65
+ "macaddress_eth0_183": "E4:1F:13:CC:36:58",
66
+ "physicalprocessorcount": "1",
67
+ "network_lo": "127.0.0.0",
68
+ "gateway": "10.35.27.62",
69
+ "lsbdistid": "RedHatEnterpriseServer",
70
+ "network_br180": "10.35.27.0",
71
+ "lsbdistdescription": "Red Hat Enterprise Linux Server release 6.2 (Santiago)",
72
+ "swapsize": "17.70 GB",
73
+ "processor0": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
74
+ "processor1": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
75
+ "macaddress_br180": "E4:1F:13:CC:36:58",
76
+ "selinux": "false",
77
+ "domain": "server.b.domain",
78
+ "architecture": "x86_64",
79
+ "uptime_hours": "3792",
80
+ "memoryfree": "6.87 GB",
81
+ "augeasversion": "0.9.0",
82
+ "operatingsystem": "RedHat",
83
+ "ipaddress_lo": "127.0.0.1",
84
+ "processor2": "Intel(R) Xeon(R) CPU E5620 @ 2.40GHz",
85
+ "type": "Main Server Chassis",
86
+ "id": "root",
87
+ "vlans": "181,182,183",
88
+ "lsbmajdistrelease": "6",
89
+ "swapfree": "16.72 GB",
90
+ "netmask": "255.255.255.192"
91
+ }
92
+ }
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_default_hostgroup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Greg Sutcliffe
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
12
+ date: 2013-10-10 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: Adds the option to specify a default hostgroup for new hosts created
14
15
  from facts/reports
@@ -20,35 +21,41 @@ extra_rdoc_files:
20
21
  - README.md
21
22
  files:
22
23
  - app/models/setting/default_hostgroup.rb
24
+ - config/environment.rb
25
+ - lib/default_hostgroup.rake
23
26
  - lib/default_hostgroup_managed_host_patch.rb
24
- - lib/foreman_default_hostgroup.rb
25
- - lib/foreman_default_hostgroup/version.rb
26
27
  - lib/foreman_default_hostgroup/engine.rb
28
+ - lib/foreman_default_hostgroup/version.rb
29
+ - lib/foreman_default_hostgroup.rb
27
30
  - LICENSE
28
- - Rakefile
29
31
  - README.md
32
+ - test/unit/facts.json
33
+ - test/unit/default_hostgroup_test.rb
30
34
  homepage: http://github.com/GregSutcliffe/foreman_default_hostgroup
31
35
  licenses:
32
36
  - GPL-3
33
- metadata: {}
34
37
  post_install_message:
35
38
  rdoc_options: []
36
39
  require_paths:
37
40
  - lib
38
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
39
43
  requirements:
40
- - - '>='
44
+ - - ! '>='
41
45
  - !ruby/object:Gem::Version
42
46
  version: '0'
43
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
44
49
  requirements:
45
- - - '>='
50
+ - - ! '>='
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
48
53
  requirements: []
49
54
  rubyforge_project:
50
- rubygems_version: 2.0.3
55
+ rubygems_version: 1.8.23
51
56
  signing_key:
52
- specification_version: 4
57
+ specification_version: 3
53
58
  summary: Default Hostgroup Plugin for Foreman
54
- test_files: []
59
+ test_files:
60
+ - test/unit/facts.json
61
+ - test/unit/default_hostgroup_test.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 80eeeefe5330eb909cbff3b1945df18fd64b5270
4
- data.tar.gz: a31c296a3e787879056a7f167f6ae4e31a9ce999
5
- SHA512:
6
- metadata.gz: df1e1a9fbf5adefc691245525c284125a3e7f19f29043189e5a0c402dd9468ad860326feee0fb0195fd32d14a809e2abd67f98dac397017f29256df0a873b1f5
7
- data.tar.gz: 3d03a685af3174d5ba437330fee1172539b2cdd4961aa4e67bc7dcefadfb4b6228ea7d3e7e9df6595b7b24be17ab3c4d6e8575ca4904d7d5ea6e33a0f4ad3824
data/Rakefile DELETED
@@ -1,111 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'rake'
5
- require 'fileutils'
6
-
7
- task :default => :test
8
-
9
- ENGINE_DIR = File.expand_path('..', __FILE__)
10
- FOREMAN_DIR = 'test/foreman_app'
11
-
12
- namespace :test do
13
- desc "Download latest foreman devel source and install dependencies"
14
- task :foreman_prepare do
15
- foreman_repo = 'https://github.com/theforeman/foreman.git'
16
- foreman_gemfile = File.join(FOREMAN_DIR, "Gemfile")
17
- unless File.exists?(foreman_gemfile)
18
- puts "Foreman source code is not present at #{FOREMAN_DIR}"
19
- puts "Downloading latest Foreman development branch into #{FOREMAN_DIR}..."
20
- FileUtils.mkdir_p(FOREMAN_DIR)
21
-
22
- unless system("git clone #{foreman_repo} #{FOREMAN_DIR}")
23
- puts "Error while getting latest Foreman code from #{foreman_repo} into #{FOREMAN_DIR}"
24
- fail
25
- end
26
- end
27
-
28
- gemfile_content = File.read(foreman_gemfile)
29
- unless gemfile_content.include?('FOREMAN_GEMFILE')
30
- puts 'Preparing Gemfile'
31
- gemfile_content.gsub!('__FILE__', 'FOREMAN_GEMFILE')
32
- gemfile_content.insert(0, "FOREMAN_GEMFILE = __FILE__ unless defined? FOREMAN_GEMFILE\n")
33
- File.open(foreman_gemfile, 'w') { |f| f << gemfile_content }
34
- end
35
-
36
- settings_file = "#{FOREMAN_DIR}/config/settings.yaml"
37
- unless File.exists?(settings_file)
38
- puts 'Preparing settings file'
39
- FileUtils.copy("#{settings_file}.example", settings_file)
40
- settings_content = File.read(settings_file)
41
- settings_content.sub!('organizations_enabled: false', 'organizations_enabled: true')
42
- settings_content << ":puppetgem: true\n"
43
- File.open(settings_file, 'w') { |f| f << settings_content }
44
- end
45
-
46
- db_file = "#{FOREMAN_DIR}/config/database.yml"
47
- unless File.exists?(db_file)
48
- puts 'Preparing database file'
49
- FileUtils.copy("#{db_file}.example", db_file)
50
- end
51
-
52
- ["#{ENGINE_DIR}/.bundle/config", "#{FOREMAN_DIR}/.bundle/config"].each do |bundle_file|
53
- unless File.exists?(bundle_file)
54
- FileUtils.mkdir_p(File.dirname(bundle_file))
55
- puts 'Preparing bundler configuration'
56
- File.open(bundle_file, 'w') { |f| f << <<FILE }
57
- ---
58
- BUNDLE_WITHOUT: console:development:fog:jsonp:libvirt:mysql:mysql2:ovirt:postgresql:vmware
59
- FILE
60
- end
61
- end
62
-
63
- local_gemfile = "#{FOREMAN_DIR}/bundler.d/Gemfile.local.rb"
64
- unless File.exist?(local_gemfile)
65
- File.open(local_gemfile, 'w') { |f| f << <<GEMFILE }
66
- gem "puppet"
67
- gem "facter"
68
- GEMFILE
69
- end
70
-
71
- puts 'Installing dependencies...'
72
- unless system('bundle install')
73
- fail
74
- end
75
- end
76
-
77
- task :db_prepare do
78
- unless File.exists?(FOREMAN_DIR)
79
- puts <<MESSAGE
80
- Foreman source code not prepared. Run
81
-
82
- rake test:foreman_prepare
83
-
84
- to download foreman source and its dependencies
85
- MESSAGE
86
- fail
87
- end
88
-
89
- # once we are Ruby19 only, switch to block variant of cd
90
- pwd = FileUtils.pwd
91
- FileUtils.cd(FOREMAN_DIR)
92
- unless system('rake db:test:prepare RAILS_ENV=test')
93
- puts "Migrating database first"
94
- system('rake db:migrate db:schema:dump db:test:prepare RAILS_ENV=test') || fail
95
- end
96
- FileUtils.cd(pwd)
97
- end
98
-
99
- task :set_loadpath do
100
- %w[lib test].each do |dir|
101
- $:.unshift(File.expand_path(dir, ENGINE_DIR))
102
- end
103
- end
104
-
105
- task :all => [:db_prepare, :set_loadpath] do
106
- Dir.glob('test/**/*_test.rb') { |f| require f.sub('test/','') unless f.include? '/foreman_app/' }
107
- end
108
-
109
- end
110
-
111
- task :test => 'test:all'