Skip to content

Commit

Permalink
Code review updates, to be squashed into prior commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Paradise committed Jan 29, 2016
1 parent a3d0d55 commit 67f728e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
define_upgrade do

if Partybus.config.bootstrap_server

must_be_data_master

username = Partybus.config.postgres['db_superuser']
password = Partybus.config.postgres['db_superuser_password']
# This ensures that sqitch is properly set up, even when upgrading from private chef (which did
# not use sqitch), as well as ensuring the baseline schema is present for opscode_chef.
#
# Note that we only have to apply it in this upgrade, because this is the first sqitch migration
# that will be run. If this doesn't need to be run, that tells us they're upgrading from an installation
# that already has applied it.
run_sqitch('@1.0.4', 'oc_erchef/schema/baseline', 'opscode_chef',
username: username, password: password)

# the actual migration we're concerned with for this release, which
# includes schema upgrade for migration state.
run_sqitch('@2.2.4', 'oc_erchef/schema', 'opscode_chef',
username: username, password: password)
run_sqitch('@1.0.4', 'oc_erchef', path: 'oc_erchef/schema/baseline')

# The actual schema change for this release -
# track more state values in migration_state.
run_sqitch('@2.2.4', 'oc_erchef')
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
define_upgrade do

if Partybus.config.bootstrap_server

must_be_data_master

# run 2.4.0 migrations to update db - includes adding org association/user tables
# schema updates include adding org association/user tables
# and adding the OSC password hash types to the password_hash_type_enum
run_sqitch('@2.4.0', 'oc_erchef/schema', 'opscode_chef',
username: Partybus.config.postgres['db_superuser'],
password: Partybus.config.postgres['db_superuser_password'])

run_sqitch('@2.4.0', 'oc_erchef')
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
define_upgrade do
require "pg"
# sql user info will be in one of two places - under 'postgresql' or under 'opscode-erchef' in more
# recent versions. If someone is upgrading from an earlier versions, it may not yet
# have been moved to its new location.
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch('@2.5.3', 'oc_erchef/schema', 'opscode_chef',
username: Partybus.config.postgres['db_superuser'],
password: Partybus.config.postgres['db_superuser_password'])
# Multi-key support
run_sqitch('@2.5.3', 'oc_erchef')

# Migrate key data to new schema:
# sql user info will be in one of two places - under 'postgresql' or under 'opscode-erchef' in more
# recent versions. If someone is upgrading from an earlier versions, it may not yet
# have been moved to its new location.
running_config = JSON.parse(File.read("/etc/opscode/chef-server-running.json"))
pc = running_config['private_chef']
keyname = pc['opscode-erchef'].has_key?('sql_user') ? 'opscode-erchef' : 'postgresql'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
define_upgrade do
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch('@2.9.0', 'oc_erchef/schema', 'opscode_chef',
username: Partybus.config.postgres['db_superuser'],
password: Partybus.config.postgres['db_superuser_password'])
# 1. cookbook artifacts
# 2. adds last update tracking to keys table.
run_sqitch('@2.9.0', 'oc_erchef')
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
define_upgrade do
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch('@cbv-type', 'oc_erchef/schema', 'opscode_chef',
username: Partybus.config.postgres['db_superuser'],
password: Partybus.config.postgres['db_superuser_password'])
# Performance improvements for cookbook fetching.
run_sqitch('@cbv-type', 'oc_erchef')
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
define_upgrade do
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch('@node-policyfile-fields', 'oc_erchef/schema', 'opscode_chef',
username: Partybus.config.postgres['db_superuser'],
password: Partybus.config.postgres['db_superuser_password'])
# Add policyfile fields to node table
run_sqitch('@node-policyfile-fields', 'oc_erchef')
end
end

44 changes: 29 additions & 15 deletions omnibus/partybus/lib/partybus/migration_api/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,40 @@ def run_command(command, options={})
runner.run_command(command, options)
end

# credentials is a required hash containing
# EITHER: :service - name of key into 'secrets' that should contain
# sql_user and sql_password entries,
# OR: :username, :password for sql auth
def run_sqitch(target, path, database, credentials)
if credentials.has_key? :service
svc = credentials[:service]
credentials[:username] = Partybus.config.secrets[svc]['sql_user']
credentials[:password] = Partybus.config.secrets[svc]['sql_password']
end
command <<-EOM.gsub(/\s+/," ").strip!
# Caller may use 'opts' to override :username :password,
# :database, and/or :path.
def run_sqitch(target, service, opts = {})
options = default_opts_for_service(service).merge(opts)
command = <<-EOM.gsub(/\s+/," ").strip!
sqitch --engine pg
--db-name #{database}
--db-name #{options[:database]}
--db-host #{Partybus.config.postgres['vip']}
--db-port #{Partybus.config.postgres['port']}
--db-user #{credentials[:username]}
--top-dir /opt/opscode/embedded/service/#{path}
--db-user #{options[:username]}
--top-dir /opt/opscode/embedded/service/#{options[:path]}
deploy #{target} --verify
EOM
run_command(command, env: {"PGPASSWORD" => credentials['db_superuser_password']})
run_command(command, env: {"PGPASSWORD" => options[:password]})
end

def default_opts_for_service(service)
username = Partybus.config.secrets[service]['sql_user']
password = Partybus.config.secrets[service]['sql_password']
path = "#{service}/schema"
case service
when 'oc_erchef'
username = Partybus.config.postgres['db_superuser']
password = Partybus.config.postgres['db_superuser_password']
database = 'opscode_chef'
when 'oc_bifrost'
database = 'bifrost'
path = 'oc_bifrost/db'
when 'bookshelf'
database = 'bookshelf'
end

{username: username, password: password,
database: database, path: path }
end


Expand Down
2 changes: 1 addition & 1 deletion src/bookshelf/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ you must add a partybus migration with content similar to the following:
define_upgrade do
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch("target-tag-name", 'bookshelf/schema',
run_sqitch("target-tag-name", 'bookshelf')
'bookshelf', service: 'bookshelf')
end

3 changes: 1 addition & 2 deletions src/oc_bifrost/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ you must add a partybus migration with content similar to the following:
define_upgrade do
if Partybus.config.bootstrap_server
must_be_data_master
run_sqitch("target-tag-name", 'oc_bifrost/schema',
'bifrost', service: "bifrost")
run_sqitch("target-tag-name", 'oc_bifrost')
end


Expand Down

0 comments on commit 67f728e

Please sign in to comment.