Fixes for Ocata, define socket for MySQL

- bumped chefdk to 1.5
- bumped mariadb to 1.5
- style fixes to make rubocop/foodcritic happy
- rewrote metadata.rb for readability
- removed ancient Gemfile
- removed openshift rubygems mirror since it doesn't help us

Change-Id: I950605f384405b55737af77bc4224f1e18fee8e1
This commit is contained in:
Samuel Cassiba 2017-08-02 01:01:23 -04:00
parent eb465b4f68
commit 479af11fd7
20 changed files with 86 additions and 132 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-02-23 16:58:23 +0100 using RuboCop version 0.39.0.
# on 2017-08-01 09:24:32 -0400 using RuboCop version 0.47.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -15,6 +15,11 @@ Lint/NestedMethodDefinition:
Metrics/AbcSize:
Max: 39
# Offense count: 45
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 203
# Offense count: 1
Metrics/PerceivedComplexity:
Max: 13
@ -33,19 +38,3 @@ Style/ClassAndModuleChildren:
- 'libraries/search.rb'
- 'libraries/uri.rb'
- 'libraries/wrappers.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always
Style/Next:
Exclude:
- 'libraries/parse.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to
Style/SymbolProc:
Exclude:
- 'libraries/parse.rb'

15
Gemfile
View File

@ -1,15 +0,0 @@
## THIS GEMFILE IS DEPRECATED AND WILL BE REMOVED AFTER THE NEXT RELEASE
## THERE WON'T BE ANY UPDATES TO THIS FILE DURING THIS RELEASE CYCLE
## WE SWITCHED TO CHEFDK AS THE BUNDLE FOR THE NEEDED GEMS
source 'https://rubygems.org'
gem 'chef', '~> 11.18.6'
gem 'json', '<= 1.7.7' # chef 11 dependency
gem 'berkshelf', '~> 3.2.1'
gem 'hashie', '~> 2.0'
gem 'chefspec', '~> 4.0.0'
gem 'rspec', '~> 3.0.0'
gem 'foodcritic', '~> 4.0'
gem 'rubocop', '~> 0.29.1'
gem 'chef-vault', '~> 2.3'

View File

@ -88,7 +88,7 @@ default['openstack']['endpoints']['db']['slave_port'] = '3316'
# will work for mysql databases, since it will use a direct connection via
# the socket, so the database does not have not to listen on 127.0.0.1.
# Set this to 'localhost' for mysql to connect via socket.
default['openstack']['endpoints']['db']['host_for_db_root_user'] = nil
default['openstack']['endpoints']['db']['host_for_db_root_user'] = 'localhost'
# Default database attributes
default['openstack']['db']['server_role'] = 'os-ops-database'
@ -135,6 +135,14 @@ when 'debian'
default['openstack']['db']['python_packages']['galera'] = ['python-mysqldb']
end
# database sockets, because different
case node['platform_family']
when 'rhel'
default['openstack']['db']['socket'] = '/var/lib/mysql/mysql.sock'
when 'debian'
default['openstack']['db']['socket'] = '/run/mysql-default/mysqld.sock'
end
# Database used by the OpenStack services
node['openstack']['common']['services'].each do |service, project|
default['openstack']['db'][service]['service_type'] = node['openstack']['db']['service_type']
@ -147,6 +155,8 @@ node['openstack']['common']['services'].each do |service, project|
default['openstack']['db'][service]['slave_host'] = node['openstack']['endpoints']['db']['slave_host']
default['openstack']['db'][service]['slave_port'] = node['openstack']['endpoints']['db']['slave_port']
default['openstack']['db'][service]['socket'] = node['openstack']['db']['socket']
case service
when 'dashboard'
default['openstack']['db'][service]['migrate'] = true

View File

@ -72,7 +72,7 @@ default['openstack']['use_databags'] = true
# feature of the official chef project, you can use 'vault' to
# encrypt your secrets with the method provided in the chef-vault gem.
default['openstack']['databag_type'] = 'encrypted'
default['openstack']['vault_gem_version'] = '~> 2.3'
default['openstack']['vault_gem_version'] = '~> 3.2'
# Default attributes when not using data bags (use_databags = false)
node['openstack']['common']['services'].each_key do |service|

View File

@ -11,7 +11,7 @@ if [ -f /usr/bin/yum ] ; then
sudo pip uninstall requests -y || true
# install chefdk
chefdk=chefdk-1.0.3-1.el7.x86_64.rpm
chefdk=chefdk-1.5.0-1.el7.x86_64.rpm
wget -nv -t 3 https://packages.chef.io/stable/el/7/$chefdk
sudo yum -y install $chefdk
rm $chefdk
@ -26,8 +26,8 @@ elif [ -f /usr/bin/apt-get ]; then
sudo apt-get -y install build-essential liblzma-dev zlib1g-dev
# install chefdk
chefdk=chefdk_1.0.3-1_amd64.deb
wget -nv -t 3 https://packages.chef.io/stable/ubuntu/12.04/$chefdk
chefdk=chefdk_1.5.0-1_amd64.deb
wget -nv -t 3 https://packages.chef.io/stable/ubuntu/16.04/$chefdk
sudo dpkg -i $chefdk
rm $chefdk
@ -46,10 +46,6 @@ if [ -f /etc/nodepool/provider ]; then
CENTOS_MIRROR_HOST=${NODEPOOL_MIRROR_HOST}
UCA_MIRROR_HOST="${NODEPOOL_MIRROR_HOST}/ubuntu-cloud-archive"
CEPH_MIRROR_HOST="${NODEPOOL_MIRROR_HOST}/ceph-deb-jewel"
# due to rubygems.org timeouts, use OpenShift's mirror
chef exec gem sources --remove https://rubygems.org/
chef exec gem sources --add http://mirror.ops.rhcloud.com/mirror/ruby/
chef exec gem sources --list
else
CENTOS_MIRROR_HOST='mirror.centos.org'
UCA_MIRROR_HOST='ubuntu-cloud.archive.canonical.com/ubuntu'

View File

@ -76,8 +76,8 @@ module ::Openstack
# Build uri
case type
when 'mysql', 'postgresql'
"#{type}://#{user}:#{pass}@#{host}:#{port}/#{name}#{options}"
when 'mysql'
"mysql+pymysql://#{user}:#{pass}@#{host}:#{port}/#{name}#{options}"
when 'sqlite'
# SQLite uses filepaths not db name
# README(galstrom): 3 slashes is a relative path, 4 slashes is an absolute path

View File

@ -31,18 +31,17 @@ module ::Openstack
ret = []
return ret if table.nil?
indicies = []
(table.split(/$/).map { |x| x.strip }).each do |line|
unless line.start_with?('+--') || line.empty?
cols = line.split('|').map { |x| x.strip }
cols.shift
if indicies == []
indicies = cols
next
end
newobj = {}
cols.each { |val| newobj[indicies[newobj.length]] = val }
ret.push(newobj)
table.split(/$/).map(&:strip).each do |line|
next if line.start_with?('+--') || line.empty?
cols = line.split('|').map(&:strip)
cols.shift
if indicies == []
indicies = cols
next
end
newobj = {}
cols.each { |val| newobj[indicies[newobj.length]] = val }
ret.push(newobj)
end
# this kinda sucks, but some prettytable data comes

View File

@ -1,12 +1,10 @@
name 'openstack-common'
maintainer 'openstack-chef'
name 'openstack-common'
maintainer 'openstack-chef'
maintainer_email 'openstack-dev@lists.openstack.org'
issues_url 'https://launchpad.net/openstack-chef' if respond_to?(:issues_url)
source_url 'https://github.com/openstack/cookbook-openstack-common' if respond_to?(:source_url)
license 'Apache 2.0'
description 'Common OpenStack attributes, libraries and recipes.'
license 'Apache 2.0'
description 'Common OpenStack attributes, libraries and recipes.'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '15.0.0'
version '15.0.0'
recipe 'openstack-common', 'Installs/Configures common recipes'
recipe 'openstack-common::logging', 'Installs/Configures common logging'
@ -18,8 +16,12 @@ end
depends 'apt', '~> 5.0'
depends 'database', '~> 6.1'
depends 'mariadb', '~> 0.3.3'
depends 'mariadb', '~> 1.5'
depends 'mysql', '~> 8.2'
depends 'yum', '~> 3.13'
depends 'yum-epel', '~> 2.0'
depends 'poise-python', '~> 1.5'
issues_url 'https://launchpad.net/openstack-chef' if respond_to?(:issues_url)
source_url 'https://github.com/openstack/cookbook-openstack-common' if respond_to?(:source_url)
chef_version '>= 12.5' if respond_to?(:chef_version)

View File

@ -27,6 +27,7 @@ def info
@port = service_info['port'] || info['port']
user_key = node['openstack']['db']['root_user_key']
@super_password = get_password 'db', user_key
@socket = node['openstack']['db']['socket']
@db_type = service_info['service_type']
@db_name = service_info['db_name']
@user = new_resource.user
@ -55,7 +56,8 @@ def connection_info
host: @host,
port: @port.to_i,
username: @super_user,
password: @super_password
password: @super_password,
socket: @socket
}
end

View File

@ -21,7 +21,7 @@
directory '/etc/openstack' do
owner 'root'
group 'root'
mode 00755
mode 0o0755
action :create
end
@ -29,7 +29,7 @@ template '/etc/openstack/logging.conf' do
source 'logging.conf.erb'
owner 'root'
group 'root'
mode 00644
mode 0o0644
variables(
loggers: node['openstack']['logging']['loggers'],
formatters: node['openstack']['logging']['formatters'],

View File

@ -21,14 +21,14 @@
directory '/etc/sysctl.d' do
owner 'root'
group 'root'
mode 00755
mode 0o0755
end
template '/etc/sysctl.d/60-openstack.conf' do
source '60-openstack.conf.erb'
owner 'root'
group 'root'
mode 00644
mode 0o0644
end
execute 'sysctl -p /etc/sysctl.d/60-openstack.conf' do

View File

@ -30,7 +30,7 @@ describe 'test-openstack-common-database::default' do
expect(chef_run).to create_database('create database service_db')
.with(
provider: ::Chef::Provider::Database::Mysql,
connection: { host: 'localhost123', port: 3306, username: 'root', password: 'root_pass' },
connection: { host: 'localhost123', port: 3306, username: 'root', password: 'root_pass', socket: '/run/mysql-default/mysqld.sock' },
database_name: 'service_db',
encoding: 'utf8'
)
@ -41,7 +41,7 @@ describe 'test-openstack-common-database::default' do
expect(chef_run).to create_database('create database service_db')
.with(
provider: ::Chef::Provider::Database::Mysql,
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
connection: { host: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/run/mysql-default/mysqld.sock' },
database_name: 'service_db',
encoding: 'utf8'
)
@ -51,7 +51,7 @@ describe 'test-openstack-common-database::default' do
expect(chef_run).to create_database_user('create database user db_user')
.with(
provider: ::Chef::Provider::Database::MysqlUser,
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
connection: { host: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/run/mysql-default/mysqld.sock' },
username: 'db_user',
password: 'db_pass'
)
@ -61,7 +61,7 @@ describe 'test-openstack-common-database::default' do
expect(chef_run).to grant_database_user('grant database user db_user')
.with(
provider: ::Chef::Provider::Database::MysqlUser,
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
connection: { host: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/run/mysql-default/mysqld.sock' },
username: 'db_user',
password: 'db_pass',
database_name: 'service_db',
@ -70,45 +70,6 @@ describe 'test-openstack-common-database::default' do
)
end
context 'postgresql' do
before do
node.override['openstack']['db']['service'] = { service_type: 'postgresql', port: 5432, db_name: 'service_postgres' }
end
it 'creates the database with the database resource' do
expect(chef_run).to create_database('create database service_postgres')
.with(
provider: ::Chef::Provider::Database::Postgresql,
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
database_name: 'service_postgres',
encoding: 'DEFAULT'
)
end
it 'creates the database use with the database_user resource' do
expect(chef_run).to create_database_user('create database user db_user')
.with(
provider: ::Chef::Provider::Database::PostgresqlUser,
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
username: 'db_user',
password: 'db_pass'
)
end
it 'grants database privileges to the user with the database_user resource' do
expect(chef_run).to grant_database_user('grant database user db_user')
.with(
provider: ::Chef::Provider::Database::PostgresqlUser,
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
username: 'db_user',
password: 'db_pass',
database_name: 'service_postgres',
host: '%',
privileges: [:all]
)
end
end
context 'galera' do
before do
node.override['openstack']['db']['service'] = { service_type: 'galera', port: 3306, db_name: 'service_db' }

View File

@ -30,7 +30,8 @@ describe 'openstack-common::default' do
expect(chef_run).to add_apt_repository('openstack-ppa').with(
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
distribution: 'xenial-updates/ocata',
components: ['main'])
components: ['main']
)
end
it 'disables openstack live updates' do
@ -38,7 +39,8 @@ describe 'openstack-common::default' do
expect(chef_run).to_not add_apt_repository('openstack-ppa').with(
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
distribution: 'xenial-updates/ocata',
components: ['main'])
components: ['main']
)
end
it 'does not install the gem chef-vault by default' do
@ -48,7 +50,7 @@ describe 'openstack-common::default' do
it 'installs the gem chef-vault if databag_type is vault' do
node.set['openstack']['databag_type'] = 'vault'
expect(chef_run).to install_chef_gem('chef-vault')
.with(version: '~> 2.3')
.with(version: '~> 3.2')
end
context 'rabbit mq' do

View File

@ -158,7 +158,7 @@ describe 'openstack-common::default' do
it 'returns compute db info hash when service found for default mysql' do
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expect(
subject.db_uri('compute', 'user', 'pass')
).to eq(expected)
@ -178,7 +178,7 @@ describe 'openstack-common::default' do
it 'returns compute db info hash when service found for mariadb' do
node.set['openstack']['db']['service_type'] = 'mariadb'
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expect(
subject.db_uri('compute', 'user', 'pass')
).to eq(expected)
@ -188,7 +188,7 @@ describe 'openstack-common::default' do
it "returns compute db info hash when service found for #{db}" do
node.set['openstack']['db']['service_type'] = db
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
expect(
subject.db_uri('compute', 'user', 'pass')
).to eq(expected)
@ -198,7 +198,7 @@ describe 'openstack-common::default' do
it 'returns compute slave db info hash when service found for default mysql' do
node.set['openstack']['endpoints']['db']['enabled_slave'] = true
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3316/nova?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3316/nova?charset=utf8'
expect(
subject.db_uri('compute', 'user', 'pass', true)
).to eq(expected)
@ -208,7 +208,7 @@ describe 'openstack-common::default' do
node.set['openstack']['db']['service_type'] = 'mariadb'
node.set['openstack']['endpoints']['db']['enabled_slave'] = true
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3316/glance?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3316/glance?charset=utf8'
expect(
subject.db_uri('image', 'user', 'pass', true)
).to eq(expected)
@ -219,7 +219,7 @@ describe 'openstack-common::default' do
node.set['openstack']['db']['service_type'] = db
node.set['openstack']['endpoints']['db']['enabled_slave'] = true
allow(subject).to receive(:node).and_return(chef_run.node)
expected = 'mysql://user:pass@127.0.0.1:3316/neutron?charset=utf8'
expected = 'mysql+pymysql://user:pass@127.0.0.1:3316/neutron?charset=utf8'
expect(
subject.db_uri('network', 'user', 'pass', true)
).to eq(expected)

View File

@ -14,7 +14,7 @@ describe 'openstack-common::logging' do
expect(chef_run).to create_directory('/etc/openstack').with(
owner: 'root',
group: 'root',
mode: 00755
mode: 0o0755
)
end
end
@ -26,7 +26,7 @@ describe 'openstack-common::logging' do
expect(chef_run).to create_template(file.name).with(
owner: 'root',
group: 'root',
mode: 00644
mode: 0o0644
)
end

View File

@ -12,8 +12,8 @@ describe 'openstack-common::default' do
'::1' => { 'family' => 'inet6', 'prefixlen' => '128', 'scope' => 'Node' },
'2001:db8::1' => { 'family' => 'inet6', 'prefixlen' => '64', 'scope' => 'Node' } } },
'eth0' => { 'addresses' => { '10.0.0.2' => { 'family' => 'inet', 'prefixlen' => '32', 'netmask' => '255.255.255.255', 'scope' => 'Node' },
'10.0.0.3' => { 'family' => 'inet', 'prefixlen' => '24', 'netmask' => '255.255.255.0', 'scope' => 'Node' }
} } }
'10.0.0.3' => { 'family' => 'inet', 'prefixlen' => '24', 'netmask' => '255.255.255.0', 'scope' => 'Node' } } }
}
runner.converge(described_recipe)
end

View File

@ -29,7 +29,8 @@ describe 'Openstack parse' do
).to eq(
[{ 'tenant' => 'service',
'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
)
end
it 'returns proper array of hashes when proper table provided including whitespace' do
table =
@ -46,7 +47,8 @@ describe 'Openstack parse' do
).to eq(
[{ 'tenant' => 'service',
'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
)
end
it 'returns a flatten hash when provided a Property/Value table' do
table =
@ -64,7 +66,8 @@ describe 'Openstack parse' do
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5',
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
)
end
it 'returns a flatten hash when provided a Property/Value table including whitespace' do
table =
@ -82,7 +85,8 @@ describe 'Openstack parse' do
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
'access' => '91af731b3be244beb8f30fc59b7bc96d',
'secret' => 'ce811442cfb549c39390a203778a4bf5',
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
)
end
end
end

View File

@ -50,9 +50,11 @@ describe 'openstack-common::default' do
it 'returns tokens from the secrets_data_bag' do
bag_content = { 'nova' => 'mysecret' }
allow(Chef::EncryptedDataBagItem).to receive(:load_secret).with(
'/etc/chef/openstack_data_bag_secret').and_return('secret')
'/etc/chef/openstack_data_bag_secret'
).and_return('secret')
allow(Chef::EncryptedDataBagItem).to receive(:load).with(
'secrets', 'nova', 'secret').and_return(bag_content)
'secrets', 'nova', 'secret'
).and_return(bag_content)
expect(subject.get_password('token', 'nova')).to eq('mysecret')
end
end
@ -84,7 +86,8 @@ describe 'openstack-common::default' do
it 'returns tokens from the secrets_data_bag' do
bag_content = { 'nova' => 'mysecret' }
allow(Chef::DataBagItem).to receive(:load).with(
'secrets', 'nova').and_return(bag_content)
'secrets', 'nova'
).and_return(bag_content)
expect(subject.get_password('token', 'nova')).to eq('mysecret')
end
end

View File

@ -110,7 +110,8 @@ describe 'openstack-common::default' do
allow(subject).to receive(:search_for)
.and_return(nodes)
expect(
subject.rabbit_servers).to eq('1.1.1.1:5672,2.2.2.2:5672')
subject.rabbit_servers
).to eq('1.1.1.1:5672,2.2.2.2:5672')
end
it 'returns sorted rabbit servers' do

View File

@ -20,7 +20,7 @@ describe 'openstack-common::sysctl' do
expect(chef_run).to create_template('/etc/sysctl.d/60-openstack.conf').with(
owner: 'root',
group: 'root',
mode: 0644
mode: 0o644
)
end