foreman_discovery 12.0.1 → 12.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
  SHA256:
3
- metadata.gz: 98a080f7ad2a14e13a076a7494394840496744de18693ddc452f350c8c901faf
4
- data.tar.gz: 36b67cccee6114006973102a963bc599ffd28a7821dbae30616602f6e9b1acd5
3
+ metadata.gz: c74650551a3323dcaa112a06e384b8bd5038df5622b71e327585cfa134efeb86
4
+ data.tar.gz: 3e5dacb7e4c536048b38156ec69b265d79724424ab0917d239ec9144a52802f5
5
5
  SHA512:
6
- metadata.gz: 54765d0d9f705a926be0dcde3514de726ef2403e64cd565abaa9398d1189dabfbc4fd1d43dad0a2ea46ce6b5924858f3b68736363ce67dd0e83f169aba53dcde
7
- data.tar.gz: 8c0569417e8d35fb6a040af15d3709b8673ac4a91764156d3c257de0ddb5bd6f5ddd31c29a20d20c69ed3f691e85215497377ca3c76e906825139d22a2d7fb89
6
+ metadata.gz: 2d6770e0543989dfa2270ece14eb165d45f2a6ccf82795247c372fc14dc81bff5efe87b3abf4964ce366fe1032b96d95e56777b6986fe61f1ce86851d734ce22
7
+ data.tar.gz: 0f7262e88dbe6e92ebd3aff9bb888ede73744d250d7b308b99b3a39d6a992a9652ca422be8032e0a6c6090c2adcf6f5dd7ef62763a5e0fcb796f71e25d8aed36
@@ -46,6 +46,7 @@ module Api
46
46
 
47
47
  def create
48
48
  @discovery_rule = DiscoveryRule.new(discovery_rule_params)
49
+ @discovery_rule.priority = DiscoveryRule.suggest_priority if discovery_rule_params[:priority].blank?
49
50
  process_response @discovery_rule.save
50
51
  end
51
52
 
@@ -12,7 +12,7 @@ class DiscoveryRulesController < ApplicationController
12
12
  end
13
13
 
14
14
  def new
15
- @discovery_rule = DiscoveryRule.new
15
+ @discovery_rule = DiscoveryRule.new(:priority => DiscoveryRule.suggest_priority)
16
16
  end
17
17
 
18
18
  def create
@@ -1,4 +1,5 @@
1
1
  class DiscoveryRule < ApplicationRecord
2
+ STEP = 100
2
3
  audited :associated_with => :hostgroup
3
4
  include Authorizable
4
5
  extend FriendlyId
@@ -40,6 +41,10 @@ class DiscoveryRule < ApplicationRecord
40
41
  self.priority ||= 0
41
42
  end
42
43
 
44
+ def self.suggest_priority
45
+ self.unscoped.maximum(:priority).to_i + STEP
46
+ end
47
+
43
48
  def enforce_taxonomy
44
49
  return if hostgroup.nil?
45
50
  if SETTINGS[:organizations_enabled]
@@ -24,7 +24,7 @@
24
24
  :label_help => render('discovery_rules/template_inline').html_safe,
25
25
  :label_help_options => {:title => _("Hostname for provisioned hosts"), :'data-placement' => 'bottom' } %>
26
26
  <%= counter_f f, :max_count, :label => _('Hosts Limit'), :help_inline => _('Maximum hosts provisioned with this rule (0 = unlimited)'), :min => 0 %>
27
- <%= counter_f f, :priority, :help_inline => _('Rule priority (lower integer means higher priority)'), step: 100, value: 0 %>
27
+ <%= counter_f f, :priority, :help_inline => _('Rule priority (lower integer means higher priority)'), step: DiscoveryRule::STEP %>
28
28
  <%= checkbox_f f, :enabled %>
29
29
  </div>
30
30
  <%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @discovery_rule %>
@@ -1,3 +1,3 @@
1
1
  module ForemanDiscovery
2
- VERSION = "12.0.1"
2
+ VERSION = "12.0.2"
3
3
  end
@@ -31,7 +31,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
31
31
  assert_equal "Location 1", discovery_rule['locations'].first['name']
32
32
  end
33
33
 
34
- test_attributes :pid => '121e0a30-8a24-47d7-974d-998886ed1ea7'
35
34
  test "should create discovery rule with taxonomy" do
36
35
  hostgroup = FactoryBot.create(:hostgroup, :with_os, :with_rootpass, :organizations => [organization_one], :locations => [location_one])
37
36
  valid_attributes = {
@@ -65,7 +64,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
65
64
  assert_response :success
66
65
  end
67
66
 
68
- test_attributes :pid => '769c0739-538b-4451-af7b-deb2ecd3dc0d'
69
67
  test "should update discovery rule name" do
70
68
  rule = FactoryBot.create(:discovery_rule)
71
69
  new_name = 'new_rule_name'
@@ -81,7 +79,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
81
79
  assert_response :success
82
80
  end
83
81
 
84
- test_attributes :pid => '0f8ec302-f9de-4713-87b7-0f1aca515149'
85
82
  test "should update taxonomies for discovery rule" do
86
83
  min_required_attr = { :name => 'new_rule', :search => 'CPU_Count = 1', :hostgroup_id => hostgroups(:unusual).id }
87
84
  rule = DiscoveryRule.new(min_required_attr)
@@ -100,7 +97,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
100
97
  assert_equal [location_one.id], rule.locations.map {|loc| loc.id}
101
98
  end
102
99
 
103
- test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
104
100
  test "should update search rule" do
105
101
  rule = FactoryBot.create(:discovery_rule)
106
102
  new_search = 'Location = Default_Location'
@@ -110,7 +106,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
110
106
  assert_equal new_search, rule.search
111
107
  end
112
108
 
113
- test_attributes :pid => '33084060-2866-46b9-bfab-23d91aea73d8'
114
109
  test "should update host limit" do
115
110
  rule = FactoryBot.create(:discovery_rule)
116
111
  new_max_count = 150
@@ -121,7 +116,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
121
116
  assert_equal new_max_count, rule.max_count
122
117
  end
123
118
 
124
- test_attributes :pid => '330aa943-167b-46dd-b434-1a6e5fe8f283'
125
119
  test "test_positive_disable" do
126
120
  rule = FactoryBot.create(:discovery_rule)
127
121
  assert rule.enabled
@@ -131,7 +125,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
131
125
  refute rule.enabled
132
126
  end
133
127
 
134
- test_attributes :pid => '9fdba953-dcc7-4532-9204-17a45b0d9e05'
135
128
  test "should destroy discovery rule" do
136
129
  rule = FactoryBot.create(:discovery_rule)
137
130
  assert_difference('DiscoveryRule.unscoped.count', -1) do
@@ -141,7 +134,6 @@ class Api::V2::DiscoveryRulesControllerTest < ActionController::TestCase
141
134
  refute DiscoveryRule.unscoped.exists?(rule.id)
142
135
  end
143
136
 
144
- test_attributes :pid => '415379b7-0134-40b9-adb1-2fe0adb1ac36'
145
137
  test "should not create with too long name" do
146
138
  assert_difference('DiscoveryRule.unscoped.count', 0) do
147
139
  post :create, params: {:discovery_rule => {
@@ -5,14 +5,12 @@ class Api::V2::SettingsControllerTest < ActionController::TestCase
5
5
  FactoryBot.create(:setting, :name => 'discovery_prefix', :value => 'mac', :category => 'Setting::Discovered')
6
6
  end
7
7
 
8
- test_attributes :pid => '2c5ecb7e-87bc-4980-9620-7ae00e3f360e'
9
8
  test "should update hostname prefix without value" do
10
9
  setting = Setting.find_by_name("discovery_prefix")
11
10
  put :update, params: { :id => setting.id, :setting => { :value => '' } }
12
11
  assert_equal JSON.parse(@response.body)['value'], '', "Can't update discovery_prefix setting with empty value"
13
12
  end
14
13
 
15
- test_attributes :pid => '4969994d-f934-4f0e-9a98-476b87eb0527'
16
14
  test "should update hostname prefix" do
17
15
  value = RFauxFactory.gen_alpha
18
16
  setting = Setting.find_by_name("discovery_prefix")
@@ -294,6 +294,9 @@ class DiscoveredHostsControllerTest < ActionController::TestCase
294
294
  hostgroup = prepare_hostgroup_for_dns_rebuild(host)
295
295
  Nic::Managed.any_instance.expects(:rebuild_dns).never
296
296
  Host::Managed.any_instance.stubs(:skip_orchestration?).returns(false)
297
+ Host::Managed.any_instance.stubs(:queue_puppetca_create).returns(true)
298
+ Host::Managed.any_instance.stubs(:queue_puppetca_certname_reset).returns(true)
299
+ Host::Managed.any_instance.stubs(:queue_puppetca_autosign_destroy).returns(true)
297
300
  put :update, params: {:commit => "Update", :id => host.id,
298
301
  :host => {
299
302
  :name => 'mytest',
@@ -55,7 +55,6 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
55
55
  end
56
56
  end
57
57
 
58
- test_attributes :pid => 'b8ae7a80-b9a8-4924-808c-482a2b4102c4'
59
58
  test "should create discovery rule with name and minimum required attributes" do
60
59
  rule = DiscoveryRule.new(:name => 'new_rule', :search => 'cpu_count = 1', :hostgroup_id => hostgroups(:unusual).id)
61
60
  assert_valid rule
@@ -101,7 +100,6 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
101
100
  assert_equal "must be present.", rule.errors[:hostgroup].first
102
101
  end
103
102
 
104
- test_attributes :pid => '4ec7d76a-22ba-4c3e-952c-667a6f0a5728'
105
103
  test "should not create with invalid priority type" do
106
104
  rule = DiscoveryRule.new(
107
105
  :name => 'new_rule',
@@ -125,7 +123,6 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
125
123
  assert_equal "must be less than 2147483648", rule.errors[:priority].first
126
124
  end
127
125
 
128
- test_attributes :pid => '84503d8d-86f6-49bf-ab97-eff418d3e3d0'
129
126
  test "should not create with invalid max count type" do
130
127
  rule = DiscoveryRule.new(
131
128
  :name => 'new_rule',
@@ -210,5 +207,13 @@ class DiscoveryRuleTest < ActiveSupport::TestCase
210
207
  hostgroup_one.save!
211
208
  end
212
209
  end
210
+
211
+ test 'should be able to suggest next priority' do
212
+ existing = FactoryBot.create(:discovery_rule)
213
+ first_new = FactoryBot.create(:discovery_rule, :priority => DiscoveryRule.suggest_priority)
214
+ assert first_new.priority > 0
215
+ second_new = FactoryBot.create(:discovery_rule, :priority => DiscoveryRule.suggest_priority)
216
+ assert_equal DiscoveryRule::STEP, second_new.priority - first_new.priority
217
+ end
213
218
  end
214
219
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.0.1
4
+ version: 12.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alongoldboim
@@ -64,7 +64,7 @@ authors:
64
64
  autorequire:
65
65
  bindir: bin
66
66
  cert_chain: []
67
- date: 2018-06-26 00:00:00.000000000 Z
67
+ date: 2018-07-13 00:00:00.000000000 Z
68
68
  dependencies: []
69
69
  description: MaaS Discovery Plugin engine for Foreman
70
70
  email: gsutclif@redhat.com