Skip to content

Commit

Permalink
Merge pull request #55 from vinted/feature/rocky_linux_support
Browse files Browse the repository at this point in the history
Add RockyLinux 8 support
  • Loading branch information
vbalys authored Aug 26, 2022
2 parents b19261b + 7065ec7 commit a407b97
Show file tree
Hide file tree
Showing 26 changed files with 84 additions and 111 deletions.
11 changes: 6 additions & 5 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ driver:

provisioner:
name: chef_zero
product_name: cinc
product_version: 17
nodes_path: 'test/integration/nodes'
data_bags_path: 'test/integration/data_bags'
environments_path: 'test/integration/environments'
roles_path: 'test/integration/roles'
require_chef_omnibus: 12

verifier:
name: inspec
Expand All @@ -21,14 +22,14 @@ platforms:
- name: centos-7
driver_plugin: docker
driver:
image: ernestasposkus/centos7
image: centos:7
run_command: '/usr/lib/systemd/systemd'
run_options: '--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro'
- name: ubuntu-1604
- name: rockylinux-8
driver_plugin: docker
driver:
image: ernestasposkus/ubuntu1604
run_command: '/lib/systemd/systemd'
image: rockylinux:8
run_command: '/usr/lib/systemd/systemd'
run_options: '--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro'

suites:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.1
TargetRubyVersion: 2.7
Exclude:
- 'cookbooks/*/.kitchen/*'

Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.3
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- docker

rvm:
- 2.3.1
- 3.0.3

install: bundle install --jobs=3 --retry=3
cache:
Expand Down
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://supermarket.chef.io'

metadata
Expand Down
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ source 'https://rubygems.org'

group :lint do
gem 'cookstyle'
gem 'foodcritic', '~> 6.0'
end

group :unit do
gem 'berkshelf', '~> 5.0'
gem 'chef-sugar'
gem 'berkshelf'
gem 'chefspec', '>= 4.2'
gem 'molinillo', '>= 0.5', '< 0.6.0'
gem 'chef-sugar'
end

group :kitchen_common do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ end
## Attributes

```ruby
default['proxysql']['version'] = '1.4.13'
default['proxysql']['version'] = '1.4.16'

default['proxysql']['user'] = 'proxysql'
default['proxysql']['group'] = 'proxysql'
Expand Down
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default['proxysql']['version'] = '1.4.15'
default['proxysql']['version'] = '1.4.16'

# Meant for easier contributing to this cookbook
default['proxysql']['lock_version'] = true
Expand Down
16 changes: 2 additions & 14 deletions attributes/repository.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
default['proxysql']['repository']['name'] = 'percona-original-release.repo'

case node['platform']
when 'rhel', 'centos'
default['proxysql']['repository']['url'] = 'http://repo.percona.com/yum/percona-release-latest.noarch.rpm'
default['proxysql']['package_release'] = "1.1.el#{node['platform_version'].to_i}"
when 'debian', 'ubuntu'
lsb_release = Mixlib::ShellOut.new('lsb_release -sc')
lsb_release.run_command
lsb_release.error!
lsb_release = lsb_release.stdout.chomp

default['proxysql']['package_release'] = "1.1.#{lsb_release}"
default['proxysql']['repository']['url'] = "http://repo.percona.com/apt/percona-release_latest.#{lsb_release}_all.deb"
end
default['proxysql']['repository']['url'] = 'http://repo.percona.com/yum/percona-release-latest.noarch.rpm'
default['proxysql']['package_release'] = "1.1.el#{node['platform_version'].to_i}"
35 changes: 6 additions & 29 deletions libraries/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def validate!

def platform_supported?
platform = node['platform']
return if %w[redhat centos debian ubuntu].include?(platform)
return if %w[centos redhat rocky].include?(platform)

raise "Platform #{platform} is not supported"
end

Expand Down Expand Up @@ -93,37 +94,13 @@ def create_user
end
end

# rubocop:disable Metrics/AbcSize
def install_proxysql_repository
url = node['proxysql']['repository']['url']
name = node['proxysql']['repository']['name']

case node['platform']
when 'rhel', 'centos'
execute "rpm -Uhv #{url}" do
creates "/etc/yum.repos.d/#{name}"
end
when 'ubuntu', 'debian'
basename = ::File.basename(url)
repo_deb = Chef::Config[:file_cache_path] + "/#{basename}"

# Using execute because apt_update is available only in Chef Client 12.7.
execute 'apt_update_for_repo' do
command %(apt-get update)
action :nothing
end
repo = node['proxysql']['repository']

dpkg_package basename do
source repo_deb
action :nothing
notifies :run, 'execute[apt_update_for_repo]', :immediate
end
package 'findutils' if node['platform_version'].to_i >= 8

remote_file repo_deb do
source url
notifies :install, "dpkg_package[#{basename}]", :immediate
not_if { ::File.exist?(repo_deb) }
end
execute "rpm -Uhv #{repo['url']}" do
creates "/etc/yum.repos.d/#{repo['name']}"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def to_cnf(obj, comma: false)
end
output.string
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/AbcSize

def for_instance(instance, config)
{
Expand Down
1 change: 1 addition & 0 deletions libraries/proxysql_admin_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def admin_variables
read_write_mode: new_resource.read_write_mode
}
end
# rubocop:enable Metrics/AbcSize

def install_admin_config
variables = admin_variables
Expand Down
1 change: 1 addition & 0 deletions libraries/proxysql_config_mysql_query_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def config(match_pattern:, config: {})
def validate(match_pattern:)
raise 'Provide String for match_pattern' unless match_pattern.is_a?(String)
return unless (match_pattern =~ /^\^/).nil?

raise 'match_pattern: must begin ^..'
end
module_function :validate
Expand Down
1 change: 1 addition & 0 deletions libraries/proxysql_config_mysql_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def config(
)
raise 'Provide String for monitor_username' unless monitor_username.is_a?(String)
raise 'Provide String for monitor_password' unless monitor_password.is_a?(String)

{
monitor_username: monitor_username,
monitor_password: monitor_password,
Expand Down
1 change: 1 addition & 0 deletions libraries/proxysql_config_replication_hostgroups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ReplicationHostgroups
def config(writer_hostgroup:, reader_hostgroup:, comment: '')
raise 'Provide Integer for writer_hostgroup' unless writer_hostgroup.is_a?(Integer)
raise 'Provide Integer for reader_hostgroup' unless reader_hostgroup.is_a?(Integer)

{
writer_hostgroup: writer_hostgroup,
reader_hostgroup: reader_hostgroup,
Expand Down
1 change: 1 addition & 0 deletions libraries/proxysql_config_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Servers
# "max_replication_lag": 10
def config(address:, port: 3306, hostgroup: 0, config: {})
raise 'Provide Integer for hostgroup' unless hostgroup.is_a?(Integer)

{
address: address,
hostgroup: hostgroup,
Expand Down
5 changes: 2 additions & 3 deletions libraries/proxysql_config_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ module Users
# frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1,
# max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000,
def config(username:, password:, default_hostgroup: 0, config: {})
unless default_hostgroup.is_a?(Integer)
raise 'Provide Integer for default_hostgroup'
end
raise 'Provide Integer for default_hostgroup' unless default_hostgroup.is_a?(Integer)

{
username: username,
password: password,
Expand Down
27 changes: 18 additions & 9 deletions libraries/proxysql_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ def service_data_dir
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Style/GuardClause
def validate!
super
if admin_mysql_ifaces
# Check for .sock or IP:PORT
unless admin_mysql_ifaces =~ /\.sock|\:\d+/
unless admin_mysql_ifaces =~ /\.sock|:\d+/
raise "Provide admin_variables['mysql_ifaces'] in a form of "\
"'127.0.0.1:6032' or '/var/lib/mysql/mysql.sock'"
end
Expand All @@ -168,6 +167,8 @@ def validate!
'config to RUNTIME'
end
end
# rubocop:enable Style/GuardClause
# rubocop:enable Metrics/AbcSize

def admin_variables
new_resource.admin_variables
Expand Down Expand Up @@ -197,21 +198,23 @@ def mysql_cmd
%(mysql --user="#{user}" --password="#{pass}" #{connection})
end

# rubocop:disable Metrics/AbcSize
def config_variables
{
data_dir: service_data_dir,
admin_variables: admin_variables,
mysql_variables: new_resource.mysql_variables,

schedulers: make_config(new_resource.schedulers),
mysql_users: make_config(new_resource.mysql_users),
mysql_servers: make_config(new_resource.mysql_servers),
mysql_query_rules: make_config(new_resource.mysql_query_rules),
schedulers: make_config(new_resource.schedulers),
mysql_users: make_config(new_resource.mysql_users),
mysql_servers: make_config(new_resource.mysql_servers),
mysql_query_rules: make_config(new_resource.mysql_query_rules),
mysql_replication_hostgroups: make_config(new_resource.mysql_replication_hostgroups),
proxysql_servers: make_config(new_resource.proxysql_servers)
proxysql_servers: make_config(new_resource.proxysql_servers)
}
end
# rubocop:enable Metrics/AbcSize

# rubocop:disable Metrics/AbcSize
def install_config
pre_st = new_resource.pre_statements.map { |st| "#{st};" }
post_st = new_resource.post_statements.map { |st| "#{st};" }
Expand All @@ -236,6 +239,7 @@ def install_config
cookbook 'proxysql'
end
end
# rubocop:enable Metrics/AbcSize

def service_args
flags = new_resource.flags
Expand All @@ -252,6 +256,7 @@ def service_args
config.flatten.join(' ')
end

# rubocop:disable Metrics/AbcSize
def install_service
exec_start = "#{new_resource.bin} #{service_args}"
systemd_service new_resource.service_name do
Expand All @@ -276,20 +281,22 @@ def install_service
end
end
end
# rubocop:enable Metrics/AbcSize

def make_config(obj)
hash_type = [Hash, Chef::Node::ImmutableMash]
unless hash_type.include?(obj.class)
raise "Provided #{obj} must be Chef::Node::ImmutableMash"\
'or Array'
end
values = obj.values
values = obj.to_h.values
return [] if values.empty?

array_type = [Array, Chef::Node::ImmutableArray]
# Validating that each provided value is Array
obj.each do |k, val|
next if array_type.include?(val.class)

raise "Provided key #{k} value #{val.class} must be of type"\
'Chef::Node::ImmutableArray or Array'
end
Expand All @@ -303,6 +310,7 @@ def package_version
def install_proxysql
v = package_version
package 'proxysql' do
flush_cache [:before]
version v if new_resource.lock_version
end

Expand All @@ -324,5 +332,6 @@ def install_proxysql
end
end
end
# rubocop:enable Metrics/ClassLength
end
end
16 changes: 8 additions & 8 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
license 'MIT'
description 'Installs/Configures ProxySQL'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
issues_url 'https://github.com/vinted/chef-proxysql/issues'
source_url 'https://github.com/vinted/chef-proxysql'
chef_version '>= 12.1' if respond_to?(:chef_version)
version '4.2.0'

supports 'redhat'
supports 'centos'
supports 'ubuntu'
supports 'debian'
version '5.0.0'

depends 'poise', '~> 2.8.1'
depends 'systemd', '~> 3.2.3'

source_url 'https://github.com/vinted/chef-proxysql'
issues_url 'https://github.com/vinted/chef-proxysql/issues'

supports centos
supports redhat
supports rocky
9 changes: 2 additions & 7 deletions test/integration/2mysql/proxysql.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# Inspec test for recipe proxysql::default

# The Inspec reference, with examples and extensive documentation, can be
# found at http://inspec.io/docs/reference/resources/

# ProxySQL admin
describe port(6033) do
it { should be_listening }
its('protocols') { should include('tcp') }
end

sql = mysql_session('admin', 'admin', '127.0.0.1', 6032)
query = 'SELECT count(*) FROM monitor.mysql_server_ping_log WHERE ping_error IS NOT NULL;'
cmd = "mysql -h 127.0.0.1 -P 6032 -u admin -padmin --execute=\"#{query}\""

describe sql.query(query) do
describe command(cmd) do
its('stderr') { should_not match(/Can't connect to local MySQL server through socket/) }
its('stdout') { should match(/0$/) }
end
1 change: 1 addition & 0 deletions test/integration/cookbooks/test-proxysql/Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://supermarket.chef.io'

metadata
Expand Down
8 changes: 4 additions & 4 deletions test/integration/cookbooks/test-proxysql/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
license 'MIT'
description 'Tests proxysql'
chef_version '>= 12.1' if respond_to?(:chef_version)
issues_url 'https://github.com/vinted/chef-proxysql/issues'
source_url 'https://github.com/vinted/chef-proxysql'
version '0.1.0'

depends 'mysql'
depends 'proxysql'
depends 'mysql', '~> 8.5.1'
depends 'yum-mysql-community'

source_url 'https://github.com/vinted/chef-proxysql'
issues_url 'https://github.com/vinted/chef-proxysql/issues'
Loading

0 comments on commit a407b97

Please sign in to comment.