Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replset with gha and modulesync #752

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

name: CI

on:
pull_request: {}
push:
branches:
- main
- master

concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true

jobs:
puppet:
name: Puppet
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2
with:
pidfile_workaround: 'false'
beaker_facter: 'mongodb_repo_version:MongoDB:4.4,5.0,6.0,7.0'
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

name: CI

on:
pull_request: {}
push:
branches:
- main
- master

concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true

jobs:
puppet:
name: Puppet
uses: StatensPensjonskasse/gha-puppet/.github/workflows/beaker.yml@add-metadata2gha-option-beaker-hosts
with:
pidfile_workaround: 'false'
beaker_hosts: 'host1:shard.ma;host2:slave,router.a'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you raise another PR where beaker_hosts isn't set so we can ensure the change in gha-puppet doens't break existing setups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All green here now. I'll just do another force push here and remove beaker_hosts to test that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, thanks for having me test that. Ends up with env var BEAKER_SETFILE empty .....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working testrun without beaker_hosts https://github.com/voxpupuli/puppet-mongodb/actions/runs/8834718677

I'm going to add beaker_hosts again to verify that with puppet_metadata 3.7.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beaker_facter: 'mongodb_repo_version:MongoDB:4.4,5.0,6.0,7.0'
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
appveyor.yml:
delete: true
.github/workflows/ci.yml:
beaker_hosts: 'host1:shard.ma;host2:slave,router.a'
beaker_facter: 'mongodb_repo_version:MongoDB:4.4,5.0,6.0,7.0'
14 changes: 9 additions & 5 deletions lib/puppet/provider/mongodb_database/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
def self.instances
require 'json'

pre_cmd = 'db.getMongo().setReadPref("primaryPreferred")'
dbs = JSON.parse mongo_eval("#{pre_cmd};EJSON.stringify(db.getMongo().getDBs())")
if db_ismaster
dbs = JSON.parse mongo_eval('EJSON.stringify(db.getMongo().getDBs())')

dbs['databases'].map do |db|
new(name: db['name'],
ensure: :present)
dbs['databases'].map do |db|
new(name: db['name'],
ensure: :present)
end
else
Puppet.warning 'Database info is available only from master host'
[]
end
end

Expand Down
16 changes: 9 additions & 7 deletions lib/puppet/provider/mongodb_replset/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ def create_replica_set(alive_hosts)
retry_sleep = 3

retry_limit.times do |n|
if db_ismaster(alive_hosts[0]['host'])['ismaster']
Puppet.debug 'Replica set initialization has successfully ended'
return true
else
Puppet.debug "Waiting for replica initialization. Retry: #{n}"
sleep retry_sleep
next
alive_hosts.each do |alive_host|
if db_ismaster(alive_host['host'])['ismaster']
Puppet.debug 'Replica set initialization has successfully ended'
return true
else
Puppet.debug "Waiting for replica initialization. Retry: #{n}"
sleep retry_sleep
next
end
end
end
raise Puppet::Error, "rs.initiate() failed for replicaset #{name}"
Expand Down
62 changes: 2 additions & 60 deletions lib/puppet/provider/mongodb_shard/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def self.shard_collection_details(obj, shard_name)

def self.shard_properties(shard)
properties = {}
output = mongo_command('sh.status()')
output = mongo_command('sh.status()')['value']
output['shards'].each do |s|
next unless s['_id'] == shard

Expand All @@ -118,7 +118,7 @@ def self.shard_properties(shard)
end

def self.shards_properties
output = mongo_command('sh.status()')
output = mongo_command('sh.status()')['value']
properties = if output['shards'].empty?
[]
else
Expand Down Expand Up @@ -163,64 +163,6 @@ def self.mongo_command(command, host = nil, _retries = 4)
retry
end

# NOTE: (spredzy) : sh.status()
# does not return a json stream
# we jsonify it so it is easier
# to parse and deal with it
if command == 'sh.status()'
myarr = output.split("\n")
myarr.shift
myarr.pop
myarr.pop
final_stream = []
prev_line = nil
in_shard_list = 0
in_chunk = 0
myarr.each do |line|
line.gsub!(%r{sharding version:}, '{ "sharding version":')
line.gsub!(%r{shards:}, ',"shards":[')
line.gsub!(%r{databases:}, '], "databases":[')
line.gsub!(%r{"clusterId" : ObjectId\("(.*)"\)}, '"clusterId" : "ObjectId(\'\1\')"')
line.gsub!(%r{\{ "_id" :}, ',{ "_id" :') if %r{_id} =~ prev_line
# Modification for shard
line = '' if line =~ %r{on :.*Timestamp}
if line =~ %r{_id} && in_shard_list == 1
in_shard_list = 0
last_line = final_stream.pop.strip
proper_line = "#{last_line}]},"
final_stream << proper_line
end
if line =~ %r{shard key} && in_shard_list == 1
shard_name = final_stream.pop.strip
proper_line = ",{\"#{shard_name}\":"
final_stream << proper_line
end
if line =~ %r{shard key} && in_shard_list.zero?
in_shard_list = 1
shard_name = final_stream.pop.strip
id_line = "#{final_stream.pop[0..-2]}, \"shards\": "
proper_line = "[{\"#{shard_name}\":"
final_stream << id_line
final_stream << proper_line
end
if in_chunk == 1
in_chunk = 0
line = "\"#{line.strip}\"}}"
end
in_chunk = 1 if line =~ %r{chunks} && in_chunk.zero?
line.gsub!(%r{shard key}, '{"shard key"')
line.gsub!(%r{chunks}, ',"chunks"')
final_stream << line unless line.empty?
prev_line = line
end
final_stream << ' ] }' if in_shard_list == 1
final_stream << ' ] }'
output = final_stream.join("\n")
end

# Hack to avoid non-json empty sets
output = '{}' if output == "null\n"
output.gsub!(%r{\s*}, '')
JSON.parse(output)
end
end
Loading