Skip to content

Commit b5cc7be

Browse files
jstack-godaddyjst-cyr
authored andcommitted
Attempt at remediateing rubocop hiera failures
1 parent 0c521c2 commit b5cc7be

5 files changed

Lines changed: 24 additions & 33 deletions

File tree

lib/puppet/provider/mysql_database/mysql.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
def self.instances(managed_databases = nil)
1010
db_list = if managed_databases && !managed_databases.empty?
11-
managed_databases
12-
else
13-
mysql_caller('show databases', 'regular').split("\n")
14-
end
15-
db_list.map do |name|
11+
managed_databases
12+
else
13+
mysql_caller('show databases', 'regular').split("\n")
14+
end
15+
db_list.map { |name|
1616
attributes = {}
1717
begin
1818
mysql_caller(["show variables like '%_database'", name], 'regular').split("\n").each do |line|
@@ -24,11 +24,11 @@ def self.instances(managed_databases = nil)
2424

2525
next
2626
end
27-
new(name: name,
27+
new(name:,
2828
ensure: :present,
2929
charset: attributes['character_set_database'],
3030
collate: attributes['collation_database'])
31-
end.compact
31+
}.compact
3232
end
3333

3434
# We iterate over each mysql_database entry in the catalog and compare it against

lib/puppet/provider/mysql_grant/mysql.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def self.instances(managed_users = nil)
1010
instance_configs = {}
11-
user_list = managed_users && !managed_users.empty? ? managed_users : users
11+
user_list = (managed_users && !managed_users.empty?) ? managed_users : users
1212
user_list.map do |user|
1313
user_string = cmd_user(user)
1414
query = "SHOW GRANTS FOR #{user_string};"

spec/unit/puppet/provider/mysql_database/mysql_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444

4545
it 'skips managed databases that no longer exist' do
4646
allow(provider.class).to receive(:mysql_caller).with(["show variables like '%_database'", 'managed_existing'], 'regular').and_return("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") # rubocop:disable Layout/LineLength
47-
allow(provider.class).to receive(:mysql_caller).with(["show variables like '%_database'", 'managed_missing'], 'regular').and_raise(Puppet::ExecutionFailure, 'ERROR 1049 (42000): Unknown database')
47+
allow(provider.class).to receive(:mysql_caller)
48+
.with(["show variables like '%_database'", 'managed_missing'], 'regular')
49+
.and_raise(Puppet::ExecutionFailure, 'ERROR 1049 (42000): Unknown database')
4850

4951
databases = provider.class.instances(['managed_existing', 'managed_missing']).map(&:name)
5052
expect(databases).to eq(['managed_existing'])
@@ -77,11 +79,10 @@
7779
'db_two' => instance_double(Puppet::Type.type(:mysql_database))
7880
}
7981

80-
allow(provider.class).to receive(:instances).with(['db_one', 'db_two']).and_return([])
81-
resources.values.each { |res| allow(res).to receive(:provider=) }
82+
expect(provider.class).to receive(:instances).with(['db_one', 'db_two']).and_return([])
83+
resources.each_value { |res| allow(res).to receive(:provider=) }
8284

8385
provider.class.prefetch(resources)
84-
expect(provider.class).to have_received(:instances).with(['db_one', 'db_two'])
8586
end
8687
end
8788

spec/unit/puppet/provider/mysql_grant/mysql_spec.rb

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@
66
describe 'self.instances' do
77
it 'loads grants only for the managed users list' do
88
allow(described_class).to receive(:newer_than).and_return(false)
9-
allow(described_class).to receive(:users).and_return(['unused@localhost'])
10-
allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n")
11-
allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular').and_return("GRANT INSERT ON `db_two`.* TO 'bob'@'localhost'\n")
9+
expect(described_class).not_to receive(:users)
10+
expect(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n")
11+
expect(described_class).not_to receive(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular')
1212

1313
instances = described_class.instances(['alice@localhost'])
1414

15-
expect(described_class).not_to have_received(:users)
16-
expect(described_class).to have_received(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular')
17-
expect(described_class).not_to have_received(:mysql_caller).with("SHOW GRANTS FOR 'bob'@'localhost';", 'regular')
1815
expect(instances.map(&:name)).to eq(['alice@localhost/db_one.*'])
1916
end
2017

2118
it 'falls back to full user scan when managed user list is empty' do
2219
allow(described_class).to receive(:newer_than).and_return(false)
23-
allow(described_class).to receive(:users).and_return(['alice@localhost'])
20+
expect(described_class).to receive(:users).and_return(['alice@localhost'])
2421
allow(described_class).to receive(:mysql_caller).with("SHOW GRANTS FOR 'alice'@'localhost';", 'regular').and_return("GRANT SELECT ON `db_one`.* TO 'alice'@'localhost'\n")
2522

2623
instances = described_class.instances([])
2724

28-
expect(described_class).to have_received(:users)
2925
expect(instances.map(&:name)).to eq(['alice@localhost/db_one.*'])
3026
end
3127
end
@@ -45,17 +41,12 @@
4541
alice_provider = instance_double(described_class, name: 'alice@localhost/db_one.*')
4642
bob_provider = instance_double(described_class, name: 'bob@localhost/db_one.*')
4743

48-
allow(described_class).to receive(:instances).with(['alice@localhost', 'bob@localhost']).and_return([alice_provider, bob_provider])
49-
allow(grant_one).to receive(:provider=)
50-
allow(grant_two).to receive(:provider=)
51-
allow(grant_three).to receive(:provider=)
44+
expect(described_class).to receive(:instances).with(['alice@localhost', 'bob@localhost']).and_return([alice_provider, bob_provider])
45+
expect(grant_one).to receive(:provider=).with(alice_provider)
46+
expect(grant_two).not_to receive(:provider=)
47+
expect(grant_three).to receive(:provider=).with(bob_provider)
5248

5349
described_class.prefetch(resources)
54-
55-
expect(described_class).to have_received(:instances).with(['alice@localhost', 'bob@localhost'])
56-
expect(grant_one).to have_received(:provider=).with(alice_provider)
57-
expect(grant_two).not_to have_received(:provider=)
58-
expect(grant_three).to have_received(:provider=).with(bob_provider)
5950
end
6051
end
6152
end

spec/unit/puppet/provider/mysql_user/mysql_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
end
171171

172172
it 'queries only managed users when user list is provided' do
173-
managed_users = ["joe@localhost", "o'reilly@localhost"]
173+
managed_users = ['joe@localhost', "o'reilly@localhost"]
174174
user_query = "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user WHERE HOST IS NOT NULL AND HOST != '' AND CONCAT(User, '@', Host) IN ('joe@localhost', 'o''reilly@localhost')"
175175

176176
allow(provider.class).to receive(:mysql_caller).with(user_query, 'regular').and_return("joe@localhost\no'reilly@localhost")
@@ -221,11 +221,10 @@
221221
'jane@localhost' => instance_double(Puppet::Type.type(:mysql_user))
222222
}
223223

224-
allow(provider.class).to receive(:instances).with(['joe@localhost', 'jane@localhost']).and_return([])
225-
resources.values.each { |res| allow(res).to receive(:provider=) }
224+
expect(provider.class).to receive(:instances).with(['joe@localhost', 'jane@localhost']).and_return([])
225+
resources.each_value { |res| allow(res).to receive(:provider=) }
226226

227227
provider.class.prefetch(resources)
228-
expect(provider.class).to have_received(:instances).with(['joe@localhost', 'jane@localhost'])
229228
end
230229
end
231230

0 commit comments

Comments
 (0)