Skip to content

Commit

Permalink
support purging for all types of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Nov 2, 2024
1 parent 22705cc commit 277c7c0
Show file tree
Hide file tree
Showing 25 changed files with 326 additions and 34 deletions.
4 changes: 0 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,8 +1470,6 @@ Valid values: `%r{[01]}`

Backend or not.

Default value: `1`

##### `default_hostgroup`

Valid values: `%r{\d+}`
Expand Down Expand Up @@ -1504,8 +1502,6 @@ Valid values: `%r{[01]}`

Frontend or not.

Default value: `1`

##### `max_connections`

Valid values: `%r{\d+}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
backup_writer_hostgroup = @resource.value(:backup_writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
offline_hostgroup = @resource.value(:offline_hostgroup)
query = 'DELETE FROM `mysql_group_replication_hostgroups` ' \
"WHERE `writer_hostgroup` = #{writer_hostgroup} AND `backup_writer_hostgroup` = #{backup_writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup} AND `offline_hostgroup` = #{offline_hostgroup}"
writer_hostgroup = @property_hash[:writer_hostgroup]
backup_writer_hostgroup = @property_hash[:backup_writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
offline_hostgroup = @property_hash[:offline_hostgroup]
query = 'DELETE FROM `mysql_group_replication_hostgroups`'
query << " WHERE `writer_hostgroup` = #{writer_hostgroup} AND `backup_writer_hostgroup` = #{backup_writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup} AND `offline_hostgroup` = #{offline_hostgroup}"
mysql([defaults_file, '-e', query].compact)

@property_hash.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def create
end

def destroy
rule_id = @resource.value(:rule_id)
rule_id = @property_hash[:rule_id]
mysql([defaults_file, '-e', "DELETE FROM `mysql_query_rules` WHERE `rule_id` = '#{rule_id}'"].compact)

@property_hash.clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
writer_hostgroup = @property_hash[:writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
query = 'DELETE FROM `mysql_replication_hostgroups` ' \
"WHERE `writer_hostgroup` = #{writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup}"
mysql([defaults_file, '-e', query].compact)
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/proxy_mysql_server/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostgroup_id = @resource.value(:hostgroup_id)
hostname = @property_hash[:hostname]
port = @property_hash[:port]
hostgroup_id = @property_hash[:hostgroup_id]
query = 'DELETE FROM `mysql_servers` ' \
"WHERE `hostname` = '#{hostname}' AND `port` = #{port} AND `hostgroup_id` = '#{hostgroup_id}'"
mysql([defaults_file, '-e', query].compact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostname = @property_hash[:hostname]
port = @property_hash[:port]

query = "DELETE FROM `mysql_servers` WHERE `hostname` = '#{hostname}' AND `port` = #{port}"
mysql([defaults_file, '-e', query].compact)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_user/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create
end

def destroy
name = @resource[:name]
name = @property_hash[:name]
mysql([defaults_file, '-e', "DELETE FROM mysql_users WHERE username = '#{name}'"].compact)

@property_hash.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_scheduler/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create
end

def destroy
scheduler_id = @resource.value(:scheduler_id)
scheduler_id = @property_hash[:scheduler_id]

mysql([defaults_file, '-e', "DELETE FROM `scheduler` WHERE `id` = #{scheduler_id}"].compact)

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
raise('backup_writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:backup_writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('offline_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:offline_hostgroup].nil?
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_mysql_query_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
autorequire(:service) { 'proxysql' }

validate do
raise('rule_id parameter is required.') if self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if self[:name] != "mysql_query_rule-#{self[:rule_id]}"
raise('rule_id parameter is required.') if (self[:ensure] == :present) && self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if (self[:ensure] == :present) && self[:name] != "mysql_query_rule-#{self[:rule_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
validate do
raise('writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('name must match writer_hostgroup-reader_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
raise('name must match writer_hostgroup-reader_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname, port and hostgroup_id parameters') if self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
raise('name must match hostname, port and hostgroup_id parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server_no_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname and port') if self[:name] != "#{self[:hostname]}:#{self[:port]}"
raise('name must match hostname and port') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
def initialize(*args)
super

return if self[:ensure] != :present

self[:password] = "*#{Digest::SHA1.hexdigest(Digest::SHA1.digest(self[:password])).upcase}" unless self[:password].start_with?('*') || self[:encrypt_password] != :true
end

Expand Down Expand Up @@ -82,13 +84,11 @@ def initialize(*args)

newproperty(:backend) do
desc 'Backend or not.'
defaultto 1
newvalue(%r{[01]})
end

newproperty(:frontend) do
desc 'Frontend or not.'
defaultto 1
newvalue(%r{[01]})
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
autorequire(:service) { 'proxysql' }

validate do
raise('scheduler_id parameter is required.') if self[:scheduler_id].nil?
raise('scheduler_id parameter is required.') if (self[:ensure] == :present) && self[:scheduler_id].nil?
raise('filename parameter is required.') if (self[:ensure] == :present) && self[:filename].nil?
raise('name must match \'scheduler-\'<scheduler_id> format') if self[:name] != "scheduler-#{self[:scheduler_id]}"
raise('name must match \'scheduler-\'<scheduler_id> format') if (self[:ensure] == :present) && self[:name] != "scheduler-#{self[:scheduler_id]}"
end

newparam(:name, namevar: true) do
Expand Down
32 changes: 32 additions & 0 deletions spec/types/proxy_cluster_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'proxy_cluster' do
let :title do
'some-title'
end

let(:params) do
{
ensure: 'present',
name: 'some-name',
hostname: 'some-host',
port: 1234,
}
end

context 'with ensure => present' do
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[name load_to_runtime save_to_disk]) }
end

context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end

it { is_expected.to be_valid_type }
end
end
19 changes: 19 additions & 0 deletions spec/types/proxy_global_variable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'proxy_global_variable' do
let :title do
'some-variable'
end

let(:params) do
{
value: 'some-value',
}
end

it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[name load_to_runtime save_to_disk]) }
end
28 changes: 24 additions & 4 deletions spec/types/proxy_mysql_galera_hostgroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@
'1-2-3-4'
end

it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[writer_hostgroup backup_writer_hostgroup reader_hostgroup offline_hostgroup load_to_runtime save_to_disk]) }
it { is_expected.to be_valid_type.with_properties(%w[active max_writers writer_is_also_reader max_transactions_behind comment]) }
let(:params) do
{
ensure: 'present',
name: '10-20-30-40',
writer_hostgroup: 10,
backup_writer_hostgroup: 20,
reader_hostgroup: 30,
offline_hostgroup: 40
}
end

context 'with ensure => present' do
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[writer_hostgroup backup_writer_hostgroup reader_hostgroup offline_hostgroup load_to_runtime save_to_disk]) }
end

context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end

it { is_expected.to be_valid_type }
end
end
34 changes: 34 additions & 0 deletions spec/types/proxy_mysql_group_replication_hostgroup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'proxy_mysql_group_replication_hostgroup' do
let :title do
'some-title'
end

let(:params) do
{
ensure: 'present',
name: '10-20-30-40',
writer_hostgroup: 10,
backup_writer_hostgroup: 20,
reader_hostgroup: 30,
offline_hostgroup: 40
}
end

context 'with ensure => present' do
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[name load_to_runtime save_to_disk]) }
end

context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end

it { is_expected.to be_valid_type }
end
end
31 changes: 31 additions & 0 deletions spec/types/proxy_mysql_query_rule_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'proxy_mysql_query_rule' do
let :title do
'some-title'
end

let(:params) do
{
ensure: 'present',
name: 'mysql_query_rule-10',
rule_id: 10,
}
end

context 'with ensure => present' do
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[name load_to_runtime save_to_disk]) }
end

context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end

it { is_expected.to be_valid_type }
end
end
32 changes: 32 additions & 0 deletions spec/types/proxy_mysql_replication_hostgroup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'proxy_mysql_replication_hostgroup' do
let :title do
'some-title'
end

let(:params) do
{
ensure: 'present',
name: '10-30',
writer_hostgroup: 10,
reader_hostgroup: 30
}
end

context 'with ensure => present' do
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:proxysql) }
it { is_expected.to be_valid_type.with_parameters(%w[name load_to_runtime save_to_disk]) }
end

context 'with ensure => absent' do
let(:params) do
super().merge({ 'ensure' => 'absent' })
end

it { is_expected.to be_valid_type }
end
end
Loading

0 comments on commit 277c7c0

Please sign in to comment.