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

Fix replset acceptance testing #749

Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

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

jobs:
puppet:
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/ci2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: 'Multinode Acceptance Testing'

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

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

jobs:
setup_matrix:
name: 'Static validations'
runs-on: ubuntu-latest
timeout-minutes: 40
outputs:
puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }}
puppet_beaker_test_matrix: ${{ steps.get-outputs.outputs.puppet_beaker_test_matrix }}
env:
BUNDLE_WITHOUT: development:system_tests:release
PUPPET_GEM_VERSION: ">= 7.0"
steps:
- uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Setup Test Matrix
id: get-outputs
run: bundle exec metadata2gha --pidfile-workaround false

acceptance:
needs: setup_matrix
runs-on: ubuntu-20.04
env:
BEAKER_HYPERVISOR: docker
BUNDLE_WITHOUT: development:test:release
strategy:
fail-fast: false
matrix:
puppet: ${{fromJson(needs.setup_matrix.outputs.puppet_beaker_test_matrix)}}
mongodb:
- name: MongoDB 4.4
value: '4.4'
- name: MongoDB 5.0
value: '5.0'
- name: MongoDB 6.0
value: '6.0'
- name: MongoDB 7.0
value: '7.0'
name: ${{ matrix.puppet.name }} - ${{ matrix.mongodb.name }}
steps:
- uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Run tests
run: bundle exec rake beaker
env:
BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.env.BEAKER_PUPPET_COLLECTION }}
BEAKER_setfile: ${{ matrix.puppet.env.BEAKER_SETFILE }}shard.ma{hostname=${{ matrix.puppet.env.BEAKER_SETFILE }}-1-${{ matrix.puppet.env.BEAKER_PUPPET_COLLECTION }}.example.com}-${{ matrix.puppet.env.BEAKER_SETFILE }}slave,router.a{hostname=${{ matrix.puppet.env.BEAKER_SETFILE }}-2-${{ matrix.puppet.env.BEAKER_PUPPET_COLLECTION }}.example.com}
BEAKER_FACTER_mongodb_repo_version: ${{ matrix.mongodb.value }}

tests:
needs:
- acceptance
runs-on: ubuntu-latest
name: Test suite
steps:
- run: echo Test suite completed
# explicitly run at the root dir. In case people set working-directory this will otherwise fail (because this jobs doesn't clone the repo and the subdir doesn't exist)
working-directory: '.'
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
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
Loading