foreman_discovery 2.0.0.rc1 → 2.0.0.rc2

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: 4b30c810a94650d5f72b8592168e2f2afd5d0854
4
- data.tar.gz: 77645786d40659c4205c4f02ed2eb0a426f3fb62
3
+ metadata.gz: 4867b305c73d5a8a992739eb70afeb56d9f81208
4
+ data.tar.gz: 5c458bfbefdec94578c3a7d2be4247352e3e9e82
5
5
  SHA512:
6
- metadata.gz: fc9544ac861a5a08b494b8a9089fbc4ce25bc2641f79877f85636927cb4d702ffd9b01d6bf266b0574068ae69d66884e7c71223159984e6e61fe8d445d7b4e49
7
- data.tar.gz: bee1405da6e16b59b45fad2d4eb88da763b3af79e12de6fd1b1e24e95931ee69054d49796d83a58dac87ed1107a0d055b2434ad78853248a4174bc60792b9f94
6
+ metadata.gz: bd114518a9ae24804c244261ae205a10d913493d72128233d7d68927d1f0ffe98926569c799ce904e6fbbbececed87a100e8daf19724e10fa3bcb80cce9dea3d
7
+ data.tar.gz: 37e81bd18f86d2e3ab0a3460f55a2e88ae44dc768a804bac5347e269b7350d450aa62b11a1df6ff50c2371ee76ba7b2429d2c37c2a795203aba9c7884d2e1a3d
@@ -105,11 +105,13 @@ module Api
105
105
  Host.transaction do
106
106
  @discovered_host, state = Host::Discovered.import_host_and_facts(params[:facts])
107
107
  end
108
- @discovered_host.transaction do
109
- if state && rule = find_discovery_rule(@discovered_host)
110
- state = perform_auto_provision(@discovered_host, rule) if Setting['discovery_auto']
111
- else
112
- Rails.logger.warn "Discovered facts import unsuccessful, skipping auto provisioning" if Setting['discovery_auto']
108
+ if Setting['discovery_auto']
109
+ @discovered_host.transaction do
110
+ if state && rule = find_discovery_rule(@discovered_host)
111
+ state = perform_auto_provision(@discovered_host, rule)
112
+ else
113
+ Rails.logger.warn "Discovered facts import unsuccessful, skipping auto provisioning"
114
+ end
113
115
  end
114
116
  end
115
117
  process_response state
@@ -33,10 +33,14 @@ module Foreman::Controller::DiscoveredExtensions
33
33
  host.type = 'Host::Managed'
34
34
  host.managed = true
35
35
  host.build = true
36
- host.name = host.render_template(rule.hostname) unless rule.hostname.empty?
37
36
  host.hostgroup_id = rule.hostgroup_id
38
37
  host.comment = "Auto-discovered and provisioned via rule '#{rule.name}'"
39
38
  host.discovery_rule = rule
39
+ # render hostname only when all other fields are set
40
+ original_name = host.name
41
+ host.name = host.render_template(rule.hostname) unless rule.hostname.empty?
42
+ # fallback to the original if template did not expand
43
+ host.name = original_name if host.name.empty?
40
44
  Host.transaction do
41
45
  if host.save #save! does not work here
42
46
  delete_discovery_attribute_set(host.id)
@@ -240,7 +240,7 @@ class DiscoveredHostsController < ::ApplicationController
240
240
  def find_multiple
241
241
  # Lets search by name or id and make sure one of them exists first
242
242
  if params[:host_names].present? or params[:host_ids].present?
243
- @hosts = Host::Discovered.where("id IN (?) or name IN (?)", params[:host_ids], params[:host_names] )
243
+ @hosts = Host::Discovered.includes(:model, :fact_values, :interfaces, :location, :organization).where("id IN (?) or name IN (?)", params[:host_ids], params[:host_names] )
244
244
  if @hosts.empty?
245
245
  error _('No hosts were found with that id or name')
246
246
  redirect_to(discovered_hosts_path) and return false
@@ -12,8 +12,8 @@ class DiscoveryRule < ActiveRecord::Base
12
12
  validates :hostname, :format => { :with => /\A[a-zA-Z<]/, :message => N_("must start with a letter or ERB.") },
13
13
  :allow_blank => true
14
14
  validates :hostgroup_id, :presence => true
15
- validates :max_count, :numericality => { only_integer: true }
16
- validates :priority, :presence => true, numericality: true
15
+ validates :max_count, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
16
+ validates :priority, :presence => true, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
17
17
  validates_lengths_from_database
18
18
 
19
19
  belongs_to :hostgroup
@@ -21,4 +21,6 @@ class DiscoveryRule < ActiveRecord::Base
21
21
 
22
22
  scoped_search :on => :name, :complete_value => :true
23
23
  scoped_search :on => :priority
24
+ scoped_search :on => :search
25
+ scoped_search :on => :enabled
24
26
  end
@@ -54,7 +54,16 @@ class Host::Discovered < ::Host::Base
54
54
  h = ::Host::Discovered.find_by_name hostname
55
55
  h ||= Host.new :name => hostname, :type => "Host::Discovered"
56
56
  h.type = "Host::Discovered"
57
- h.mac = facts[fact_name].try(:downcase)
57
+
58
+ macfact = facts[fact_name].try(:downcase)
59
+ begin
60
+ macfact = Net::Validations.normalize_mac(macfact)
61
+ rescue ArgumentError => e
62
+ macfact = facts['discovery_bootif'].try(:downcase)
63
+ h.name = facts['discovery_bootif'].try(:downcase).try(:gsub,/:/,'').try(:sub,/^/, hostname_prefix)
64
+ end
65
+ h.mac = macfact
66
+
58
67
 
59
68
  if SETTINGS[:locations_enabled]
60
69
  begin
@@ -110,7 +119,8 @@ class Host::Discovered < ::Host::Base
110
119
  if disks.any?
111
120
  disks.values.each { |size| disks_size += (size.to_f rescue 0) }
112
121
  disk_count = disks.size
113
- disks_size = disks_size.ceil
122
+ # Turning disks_size to closest Mega for easier to read UI
123
+ disks_size = (disks_size / 1024 / 1024).ceil if disks_size > 0
114
124
  end
115
125
 
116
126
  {:cpu_count => cpu_count, :memory => memory, :disk_count => disk_count, :disks_size => disks_size}
@@ -2,7 +2,8 @@ object @discovered_host
2
2
 
3
3
  extends "api/v2/discovered_hosts/base"
4
4
 
5
- attributes :ip, :mac, :last_report, :subnet_id, :subnet_name, :cpu, :memory, :disk_count, :disks_size
5
+ attributes :ip, :mac, :last_report, :subnet_id, :subnet_name, :memory, :disk_count, :disks_size
6
+ attribute :cpu_count => :cpus
6
7
 
7
8
  if SETTINGS[:organizations_enabled]
8
9
  attributes :organization_id, :organization_name
@@ -3,7 +3,7 @@
3
3
  <th><%= _('Host') %></th>
4
4
  <th><%= _('Model') %></th>
5
5
  <th><%= _('IP Address') %></th>
6
- <th><%= _('CPU') %></th>
6
+ <th><%= _('CPUs') %></th>
7
7
  <th><%= _('Memory') %></th>
8
8
  </thead>
9
9
  <tbody>
@@ -5,7 +5,7 @@
5
5
  <td class="hidden-tablet hidden-xs"><%= number_to_human_size(discovery_attribute(host, :memory, 0) * 1024 * 1024) %></td>
6
6
  <% unless defined? hide_disk %>
7
7
  <td class="hidden-tablet hidden-xs"><%= discovery_attribute(host, :disk_count) %></td>
8
- <td class="hidden-tablet hidden-xs"><%= number_to_human_size(discovery_attribute(host, :disks_size, 0)) %></td>
8
+ <td class="hidden-tablet hidden-xs"><%= number_to_human_size(discovery_attribute(host, :disks_size, 0) * 1024 * 1024) %></td>
9
9
  <% if Setting['discovery_fact_column'].present? %>
10
10
  <td class="hidden-tablet hidden-xs"><%= host.facts_hash[Setting['discovery_fact_column']] || 'N/A' %></td>
11
11
  <% end %>
@@ -6,7 +6,7 @@
6
6
  <th class=''><%= sort :name, :as => _('Name') %></th>
7
7
  <th class="hidden-tablet hidden-xs"><%= sort :model, :as => _('Model') %></th>
8
8
  <th class="hidden-tablet hidden-xs"><%= sort :ip, :as => _('IP Address') %></th>
9
- <th class="hidden-tablet hidden-xs"><%= sort :cpu_count, :as => _('CPU') %></th>
9
+ <th class="hidden-tablet hidden-xs"><%= sort :cpu_count, :as => _('CPUs') %></th>
10
10
  <th class="hidden-tablet hidden-xs"><%= sort :memory, :as => _('Memory') %></th>
11
11
  <th class="hidden-tablet hidden-xs"><%= sort :disk_count, :as => _('Disk count') %></th>
12
12
  <th class="hidden-tablet hidden-xs"><%= sort :disks_size, :as => _('Disks size') %></th>
@@ -6,7 +6,27 @@
6
6
  :control_group_id => 'search_group', :size => 'col-md-9' %>
7
7
  <%= select_f f, :hostgroup_id, accessible_hostgroups, :id, :to_label, { :include_blank => false },
8
8
  { :help_inline => _('Target host group for this rule with all properties set')} %>
9
- <%= text_f f, :hostname, :help_inline => _('Target hostname template pattern (empty for MAC)') %>
9
+ <%= text_f f, :hostname, :help_inline => popover(
10
+ _("Template"),
11
+ "<div>" +
12
+ _("Specify target hostname template pattern in the same syntax as in Provisioning Templates (ERB).") +
13
+ "</div>"+
14
+ "<div>" +
15
+ _("Domain will be appended automatically. A hostname based on MAC address will be used when left blank. In addition to @host attribute function rand for random integers is available. Examples:") +
16
+ "</div>"+
17
+ "<pre>"+
18
+ "myhost-&lt;%= rand(99999) %&gt;" + "\n\n" +
19
+ "abc-&lt;%= @host.facts['bios_vendor'] + " + "\n" +
20
+ " '-' + rand(99999) %&gt;" + "\n\n" +
21
+ "xyz-&lt;%= @host.hostgroup.name %&gt;" + "\n\n" +
22
+ "srv-&lt;%= @host.discovery_rule.name %&gt;" + "\n\n" +
23
+ "server-&lt;%= @host.ip.gsub('.','-') + " + "\n" +
24
+ " '-' + @host.hostgroup.subnet.name %&gt;" + "\n" +
25
+ "</pre>"+
26
+ "</div>"+
27
+ "<div>"+
28
+ _("When creating hostname patterns, make sure the resulting host names are unique. Hostnames must not start with numbers. A good approach is to use unique information provided by facter (MAC address, BIOS or serial ID).") +
29
+ "</div>", :title => _("Hostname for provisioned hosts")).html_safe %>
10
30
  <%= text_f f, :max_count, :label => _('Hosts limit'), :help_inline => _('Maximum hosts provisioned with this rule (0 = unlimited)') %>
11
31
  <%= text_f f, :priority, :help_inline => _('Rule priority (lower integer means higher priority)') %>
12
32
  <%= checkbox_f f, :enabled %>
@@ -13,7 +13,7 @@
13
13
  </tr>
14
14
  <% for rule in @discovery_rules %>
15
15
  <tr>
16
- <td class='col-md-3'><%= link_to_if_authorized(trunc(rule.name), hash_for_edit_discovery_rule_path(:id => rule).merge(:auth_object => rule, :authorizer => authorizer)) %></td>
16
+ <td class='col-md-3 display-two-pane'><%= link_to_if_authorized(rule.name, hash_for_edit_discovery_rule_path(:id => rule).merge(:auth_object => rule, :authorizer => authorizer)) %></td>
17
17
  <td><%= rule.priority %></td>
18
18
  <td><%= rule.search %></td>
19
19
  <td><%= rule.hostgroup.name %></td>
@@ -36,7 +36,7 @@ module ForemanDiscovery
36
36
 
37
37
  initializer 'foreman_discovery.register_plugin', :after=> :finisher_hook do |app|
38
38
  Foreman::Plugin.register :foreman_discovery do
39
- requires_foreman '>= 1.6'
39
+ requires_foreman '~> 1.7.0'
40
40
 
41
41
  # discovered hosts permissions
42
42
  security_block :discovery do
@@ -104,13 +104,7 @@ module ForemanDiscovery
104
104
  widget 'discovery_widget', :name=>N_('Discovery widget'), :sizex => 7, :sizey =>1
105
105
 
106
106
  # add template helpers
107
- allowed_template_helpers :rand, :facts_hash
108
-
109
- # apipie API documentation
110
- # Only available in 1.8, otherwise it has to be in the initializer below
111
- if (SETTINGS[:version].to_s.include?('develop') or Gem::Version.new(SETTINGS[:version]) >= Gem::Version.new('1.8'))
112
- apipie_documented_controllers ["#{ForemanDiscovery::Engine.root}/app/controllers/api/v2/*.rb"]
113
- end
107
+ allowed_template_helpers :rand
114
108
  end
115
109
  end
116
110
 
@@ -1,3 +1,3 @@
1
1
  module ForemanDiscovery
2
- VERSION = "2.0.0.rc1"
2
+ VERSION = "2.0.0.rc2"
3
3
  end
@@ -1,21 +1,22 @@
1
- # Template file for strings which can be localized in the Foreman Application.
2
- #
3
- # This file is distributed under the same license as the Foreman.
4
- #
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the foreman package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
5
  #
6
+ #, fuzzy
6
7
  msgid ""
7
8
  msgstr ""
8
- "Project-Id-Version: version 0.0.1\n"
9
+ "Project-Id-Version: foreman 1.0.0\n"
9
10
  "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2014-08-20 08:33+0100\n"
11
- "PO-Revision-Date: 2013-03-01 15:45-0500\n"
12
- "Last-Translator: \n"
13
- "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
11
+ "POT-Creation-Date: 2015-01-28 17:53+0100\n"
12
+ "PO-Revision-Date: 2015-01-28 17:53+0100\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
15
  "Language: \n"
15
16
  "MIME-Version: 1.0\n"
16
17
  "Content-Type: text/plain; charset=UTF-8\n"
17
18
  "Content-Transfer-Encoding: 8bit\n"
18
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
19
20
 
20
21
  msgid "%s - The following hosts are about to be changed"
21
22
  msgstr ""
@@ -32,15 +33,30 @@ msgstr ""
32
33
  msgid "Assign Organization"
33
34
  msgstr ""
34
35
 
36
+ msgid "Auto Provision"
37
+ msgstr ""
38
+
39
+ msgid "Auto Provision All"
40
+ msgstr ""
41
+
42
+ msgid "Automatically provision newly discovered hosts, according to the provisioning rules"
43
+ msgstr ""
44
+
45
+ msgid "CPUs"
46
+ msgstr ""
47
+
35
48
  msgid "Cancel"
36
49
  msgstr ""
37
50
 
38
- msgid "Could not get facts from proxy: %s"
51
+ msgid "Could not get facts from proxy %{url}: %{error}"
39
52
  msgstr ""
40
53
 
41
54
  msgid "Create a discovered host"
42
55
  msgstr ""
43
56
 
57
+ msgid "Create a discovery rule"
58
+ msgstr ""
59
+
44
60
  msgid "Delete"
45
61
  msgstr ""
46
62
 
@@ -50,12 +66,21 @@ msgstr ""
50
66
  msgid "Delete a discovered host"
51
67
  msgstr ""
52
68
 
69
+ msgid "Delete a rule"
70
+ msgstr ""
71
+
53
72
  msgid "Delete hosts"
54
73
  msgstr ""
55
74
 
56
75
  msgid "Destroyed selected hosts"
57
76
  msgstr ""
58
77
 
78
+ msgid "Disable"
79
+ msgstr ""
80
+
81
+ msgid "Disable rule?"
82
+ msgstr ""
83
+
59
84
  msgid "Discovered Host Pool"
60
85
  msgstr ""
61
86
 
@@ -65,9 +90,57 @@ msgstr ""
65
90
  msgid "Discovered hosts"
66
91
  msgstr ""
67
92
 
93
+ msgid "Discovered hosts are provisioning now"
94
+ msgstr ""
95
+
96
+ msgid "Discovery Rules"
97
+ msgstr ""
98
+
99
+ msgid "Discovery rules"
100
+ msgstr ""
101
+
68
102
  msgid "Discovery widget"
69
103
  msgstr ""
70
104
 
105
+ msgid "DiscoveryRule|Enabled"
106
+ msgstr ""
107
+
108
+ msgid "DiscoveryRule|Name"
109
+ msgstr ""
110
+
111
+ msgid "DiscoveryRule|Priority"
112
+ msgstr ""
113
+
114
+ msgid "DiscoveryRule|Query"
115
+ msgstr ""
116
+
117
+ msgid "Disk count"
118
+ msgstr ""
119
+
120
+ msgid "Disks size"
121
+ msgstr ""
122
+
123
+ msgid "Domain will be appended automatically. A hostname based on MAC address will be used when left blank. In addition to @host attribute function rand for random integers is available. Examples:"
124
+ msgstr ""
125
+
126
+ msgid "Edit Discovery Rule"
127
+ msgstr ""
128
+
129
+ msgid "Enable"
130
+ msgstr ""
131
+
132
+ msgid "Enable rule?"
133
+ msgstr ""
134
+
135
+ msgid "Errors during auto provisioning: %s"
136
+ msgstr ""
137
+
138
+ msgid "Execute rules against a discovered host"
139
+ msgstr ""
140
+
141
+ msgid "Execute rules against all currently discovered hosts"
142
+ msgstr ""
143
+
71
144
  msgid "Fact"
72
145
  msgstr ""
73
146
 
@@ -77,19 +150,49 @@ msgstr ""
77
150
  msgid "Facts refreshed for %s"
78
151
  msgstr ""
79
152
 
80
- msgid "Failed to import facts for Host::Discovered"
153
+ msgid "Failed to auto provision host %s: %s"
154
+ msgstr ""
155
+
156
+ msgid "Failed to import facts for discovered host"
157
+ msgstr ""
158
+
159
+ msgid "Failed to import facts for discovered host: %s"
81
160
  msgstr ""
82
161
 
83
- msgid "Failed to import facts for Host::Discovered: %s"
162
+ msgid "Failed to reboot host %s"
84
163
  msgstr ""
85
164
 
86
- msgid "Failed to reboot: %s"
165
+ msgid "Failed to reboot host %{hostname} with error %{error_message}"
87
166
  msgstr ""
88
167
 
89
168
  msgid "Failed to refresh facts for %s"
90
169
  msgstr ""
91
170
 
92
- msgid "Imported Host::Discovered"
171
+ msgid "Host"
172
+ msgstr ""
173
+
174
+ msgid "Host %{host} was provisioned with rule %{rule}"
175
+ msgstr ""
176
+
177
+ msgid "Host group"
178
+ msgstr ""
179
+
180
+ msgid "Host of type %s can not be rebooted"
181
+ msgstr ""
182
+
183
+ msgid "Hostname for provisioned hosts"
184
+ msgstr ""
185
+
186
+ msgid "Hosts limit"
187
+ msgstr ""
188
+
189
+ msgid "Hosts/limit"
190
+ msgstr ""
191
+
192
+ msgid "IP Address"
193
+ msgstr ""
194
+
195
+ msgid "Imported discovered host"
93
196
  msgstr ""
94
197
 
95
198
  msgid "Invalid facts, must be a Hash"
@@ -107,24 +210,48 @@ msgstr ""
107
210
  msgid "List all discovered hosts"
108
211
  msgstr ""
109
212
 
213
+ msgid "List all discovery rules"
214
+ msgstr ""
215
+
110
216
  msgid "Location"
111
217
  msgstr ""
112
218
 
219
+ msgid "Maximum hosts provisioned with this rule (0 = unlimited)"
220
+ msgstr ""
221
+
222
+ msgid "Memory"
223
+ msgstr ""
224
+
113
225
  msgid "Model"
114
226
  msgstr ""
115
227
 
228
+ msgid "N/A"
229
+ msgstr ""
230
+
116
231
  msgid "Name"
117
232
  msgstr ""
118
233
 
234
+ msgid "New Discovery Rule"
235
+ msgstr ""
236
+
237
+ msgid "New Rule"
238
+ msgstr ""
239
+
119
240
  msgid "No discovered hosts available"
120
241
  msgstr ""
121
242
 
243
+ msgid "No discovered hosts to provision"
244
+ msgstr ""
245
+
122
246
  msgid "No hosts selected"
123
247
  msgstr ""
124
248
 
125
249
  msgid "No hosts were found with that id or name"
126
250
  msgstr ""
127
251
 
252
+ msgid "No rule found for host %s"
253
+ msgstr ""
254
+
128
255
  msgid "Organization"
129
256
  msgstr ""
130
257
 
@@ -137,12 +264,33 @@ msgstr ""
137
264
  msgid "Provision a discovered host"
138
265
  msgstr ""
139
266
 
267
+ msgid "Reboot"
268
+ msgstr ""
269
+
140
270
  msgid "Rebooting %s"
141
271
  msgstr ""
142
272
 
273
+ msgid "Rebooting a discovered host"
274
+ msgstr ""
275
+
276
+ msgid "Rebooting host %s"
277
+ msgstr ""
278
+
143
279
  msgid "Refresh facts"
144
280
  msgstr ""
145
281
 
282
+ msgid "Refreshing the facts of a discovered host"
283
+ msgstr ""
284
+
285
+ msgid "Rule disabled"
286
+ msgstr ""
287
+
288
+ msgid "Rule enabled"
289
+ msgstr ""
290
+
291
+ msgid "Rule priority (lower integer means higher priority)"
292
+ msgstr ""
293
+
146
294
  msgid "Select Action"
147
295
  msgstr ""
148
296
 
@@ -158,15 +306,30 @@ msgstr ""
158
306
  msgid "Show a discovered host"
159
307
  msgstr ""
160
308
 
309
+ msgid "Show a discovery rule"
310
+ msgstr ""
311
+
312
+ msgid "Show fact as an extra column in the discovered hosts list"
313
+ msgstr ""
314
+
161
315
  msgid "Something went wrong while selecting hosts - %s"
162
316
  msgstr ""
163
317
 
318
+ msgid "Specify target hostname template pattern in the same syntax as in Provisioning Templates (ERB)."
319
+ msgstr ""
320
+
164
321
  msgid "Submit"
165
322
  msgstr ""
166
323
 
167
324
  msgid "Subnet"
168
325
  msgstr ""
169
326
 
327
+ msgid "Target host group for this rule with all properties set"
328
+ msgstr ""
329
+
330
+ msgid "Template"
331
+ msgstr ""
332
+
170
333
  msgid "The default fact name to use for the MAC of the system"
171
334
  msgstr ""
172
335
 
@@ -176,6 +339,9 @@ msgstr ""
176
339
  msgid "The default organization to place discovered hosts in"
177
340
  msgstr ""
178
341
 
342
+ msgid "The default prefix to use for the host name, must start with a letter"
343
+ msgstr ""
344
+
179
345
  msgid "The following hosts were not deleted: %s"
180
346
  msgstr ""
181
347
 
@@ -190,6 +356,9 @@ msgstr[1] ""
190
356
  msgid "UUID to track orchestration tasks status, GET /api/orchestration/:UUID/tasks"
191
357
  msgstr ""
192
358
 
359
+ msgid "Update a rule"
360
+ msgstr ""
361
+
193
362
  msgid "Upload facts for a host, creating the host if required"
194
363
  msgstr ""
195
364
 
@@ -199,6 +368,12 @@ msgstr ""
199
368
  msgid "Warning"
200
369
  msgstr ""
201
370
 
371
+ msgid "When creating hostname patterns, make sure the resulting host names are unique. Hostnames must not start with numbers. A good approach is to use unique information provided by facter (MAC address, BIOS or serial ID)."
372
+ msgstr ""
373
+
374
+ msgid "can't contain white spaces."
375
+ msgstr ""
376
+
202
377
  msgid "filter results"
203
378
  msgstr ""
204
379
 
@@ -208,6 +383,9 @@ msgstr ""
208
383
  msgid "items selected. Uncheck to Clear"
209
384
  msgstr ""
210
385
 
386
+ msgid "must start with a letter or ERB."
387
+ msgstr ""
388
+
211
389
  msgid "not required if it's a virtual machine"
212
390
  msgstr ""
213
391
 
@@ -220,5 +398,8 @@ msgstr ""
220
398
  msgid "paginate results"
221
399
  msgstr ""
222
400
 
401
+ msgid "required if value is not inherited from host group or default password in settings"
402
+ msgstr ""
403
+
223
404
  msgid "sort results"
224
405
  msgstr ""
@@ -95,12 +95,81 @@ class FindDiscoveryRulesTest < ActiveSupport::TestCase
95
95
  assert_equal host.name, "macaabbccddeeff"
96
96
  end
97
97
 
98
- test "hostname is rendered after auto provisioning" do
99
- facts = @facts.merge({"somefact" => "abc"})
100
- host = Host::Discovered.import_host_and_facts(facts).first
101
- r1 = FactoryGirl.create(:discovery_rule, :priority => 1, :search => "facts.somefact = abc", :hostname => 'x<%= 1+1 %>')
102
- perform_auto_provision host, r1
103
- assert_equal host.name, "x2"
98
+ def setup_normal_renderer
99
+ Setting[:safemode_render] = false
100
+ @facts.merge!({"somefact" => "abc"})
101
+ end
102
+
103
+ def setup_safemode_renderer
104
+ Setting[:safemode_render] = true
105
+ @facts.merge!({"somefact" => "abc"})
106
+ end
107
+
108
+ [:normal_renderer, :safemode_renderer].each do |renderer_name|
109
+ test "#{renderer_name} is properly configured" do
110
+ send "setup_#{renderer_name}"
111
+ if renderer_name == :normal_renderer
112
+ assert Setting[:safemode_render] == false
113
+ else
114
+ assert Setting[:safemode_render] == true
115
+ end
116
+ end
117
+
118
+ test "hostname falls back to original name on empty response via #{renderer_name}" do
119
+ host = Host::Discovered.import_host_and_facts(@facts).first
120
+ r1 = FactoryGirl.create(:discovery_rule,
121
+ :search => "facts.somefact = abc",
122
+ :hostname => '<%= "" %>')
123
+ perform_auto_provision host, r1
124
+ assert_equal "macaabbccddeeff", host.name
125
+ end
126
+
127
+ test "hostname is rendered after auto provisioning using #{renderer_name}" do
128
+ host = Host::Discovered.import_host_and_facts(@facts).first
129
+ r1 = FactoryGirl.create(:discovery_rule,
130
+ :search => "facts.somefact = abc",
131
+ :hostname => 'x<%= 1+1 %>')
132
+ perform_auto_provision host, r1
133
+ assert_equal "x2", host.name
134
+ end
135
+
136
+ test "function rand is renderer properly using #{renderer_name}" do
137
+ host = Host::Discovered.import_host_and_facts(@facts).first
138
+ r1 = FactoryGirl.create(:discovery_rule,
139
+ :search => "facts.somefact = abc",
140
+ :hostname => 'x<%= rand(4) %>')
141
+ perform_auto_provision host, r1
142
+ assert_match(/x[0123]/, host.name)
143
+ end
144
+
145
+ test "hostname attribute name is renderer properly using #{renderer_name}" do
146
+ host = Host::Discovered.import_host_and_facts(@facts).first
147
+ r1 = FactoryGirl.create(:discovery_rule,
148
+ :search => "facts.somefact = abc",
149
+ :hostname => 'x<%= @host.name %>')
150
+ perform_auto_provision host, r1
151
+ assert_equal "xmacaabbccddeeff", host.name
152
+ end
153
+
154
+ test "hostname attribute ip is renderer properly using #{renderer_name}" do
155
+ host = Host::Discovered.import_host_and_facts(@facts).first
156
+ r1 = FactoryGirl.create(:discovery_rule,
157
+ :search => "facts.somefact = abc",
158
+ :hostname => 'x<%= @host.ip.gsub(".","-") %>')
159
+ perform_auto_provision host, r1
160
+ assert_equal "x192-168-100-42", host.name
161
+ end
162
+
163
+ test "hostname attribute facts_hash is renderer properly using #{renderer_name}" do
164
+ skip "until http://projects.theforeman.org/issues/2948 is fixed"
165
+ host = Host::Discovered.import_host_and_facts(@facts).first
166
+ r1 = FactoryGirl.create(:discovery_rule,
167
+ :search => "facts.somefact = abc",
168
+ :hostname => 'x<%= @host.facts["somefact"] %>')
169
+ perform_auto_provision host, r1
170
+ assert_equal "xabc", host.name
171
+ end
172
+
104
173
  end
105
174
 
106
175
  end
@@ -31,9 +31,10 @@ class DiscoveryAttributeSetTest < ActiveSupport::TestCase
31
31
  test "can search discovered hosts by disks_size" do
32
32
  raw = parse_json_fixture('/facts.json')
33
33
  host = Host::Discovered.import_host_and_facts(raw['facts']).first
34
- results = Host::Discovered.search_for("disks_size = #{host.facts_hash['blockdevice_sda_size'].to_f.ceil}")
34
+ disks_size = (host.facts_hash['blockdevice_sda_size'].to_f / 1024 / 1024).ceil
35
+ results = Host::Discovered.search_for("disks_size = #{disks_size}")
35
36
  assert_equal 1, results.count
36
- results = Host::Discovered.search_for("disks_size > #{host.facts_hash['blockdevice_sda_size'].to_f.ceil}")
37
+ results = Host::Discovered.search_for("disks_size > #{disks_size}")
37
38
  assert_equal 0, results.count
38
39
  end
39
40
 
data/test/unit/facts.json CHANGED
@@ -88,7 +88,7 @@
88
88
  "lsbmajdistrelease": "6",
89
89
  "swapfree": "16.72 GB",
90
90
  "netmask": "255.255.255.192",
91
- "discovery_bootif": "AA:BB:CC:DD:EE:FF",
91
+ "discovery_bootif": "AA:BB:CC:DD:EE:F5",
92
92
  "memorysize_mb": "742.13",
93
93
  "blockdevice_sda_size": "214749184"
94
94
  }
@@ -21,7 +21,7 @@ class HostDiscoveredTest < ActiveSupport::TestCase
21
21
  test "should import facts from yaml as Host::Discovered" do
22
22
  raw = parse_json_fixture('/facts.json')
23
23
  assert Host::Discovered.import_host_and_facts(raw['facts'])
24
- assert Host::Discovered.find_by_name('macaabbccddeeff')
24
+ assert Host::Discovered.find_by_name('macaabbccddeef5')
25
25
  end
26
26
 
27
27
  test "should raise when fact_name setting isn't present" do
@@ -39,19 +39,29 @@ class HostDiscoveredTest < ActiveSupport::TestCase
39
39
  assert host.refresh_facts
40
40
  end
41
41
 
42
- test "should create discovered host with fact_name as a name" do
42
+ test "should create discovered host with fact_name as a name if it is a valid mac" do
43
+ raw = parse_json_fixture('/facts.json')
44
+ Setting[:discovery_fact] = 'somefact'
45
+ facts = raw['facts'].merge({"somefact" => "bb:aa:cc:dd:ee:ff"})
46
+ host = Host::Discovered.import_host_and_facts(facts).first
47
+ assert_equal 'macbbaaccddeeff', host.name
48
+ assert_equal 'bb:aa:cc:dd:ee:ff', host.mac
49
+ end
50
+
51
+ test "should create discovered host with default name if fact_name isn't a valid mac" do
52
+ skip "until http://projects.theforeman.org/issues/9044 is fixed in 1.7.3"
43
53
  raw = parse_json_fixture('/facts.json')
44
54
  Setting[:discovery_fact] = 'lsbdistcodename'
45
55
  host = Host::Discovered.import_host_and_facts(raw['facts']).first
46
- assert_equal 'macsantiago', host.name
56
+ assert_equal 'macaabbccddeef5', host.name
57
+ assert_equal 'aa:bb:cc:dd:ee:f5', host.mac
47
58
  end
48
59
 
49
60
  test "should create discovered host with prefix" do
50
61
  raw = parse_json_fixture('/facts.json')
51
62
  Setting[:discovery_prefix] = 'test'
52
- Setting[:discovery_fact] = 'lsbdistcodename'
53
63
  host = Host::Discovered.import_host_and_facts(raw['facts']).first
54
- assert_equal 'testsantiago', host.name
64
+ assert_equal 'testaabbccddeef5', host.name
55
65
  end
56
66
 
57
67
  test "should not name discovered host with prefix that starts with a number, fallback to 'mac'" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface