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

Error: Could not prefetch mongodb_replset provider 'mongo': 765: unexpected token at 'WARNING: ) is deprecated and may be removed in the next major release. Please use secondaryOk() #612

Closed
bimcas opened this issue Jul 12, 2021 · 5 comments

Comments

@bimcas
Copy link

bimcas commented Jul 12, 2021

  • Puppet: 6.22.1
  • Ruby: 2.5.9p229
  • Distribution: CentOS 7.8.2003
  • Module version: 3.1.0
  • MongoDB: 4.2.14

When I run puppet on the MongoDB node (mongo service is running) I'm getting the message:
Error: Could not prefetch mongodb_replset provider 'mongo': 765: unexpected token at 'WARNING: ) is deprecated and may be removed in the next major release. Please use secondaryOk() instead of slaveOk()

I see such content in mongorc.js file after the puppet was run:

if (authRequired()) {
try {
rs.slaveOk()
var prev_db = db
db = db.getSiblingDB('admin')
db.auth('admin', 'xxxxxxxxxxxxx')
db = db.getSiblingDB(prev_db)
}
catch (err) {
// This isn't catching authentication errors as I'd expect...
abort('Unknown error')
}
}

So, it seems that the previous fix (link 80f47d5) to use rs.secondaryOk() on versions that deprecated rs.slaveOk() isn't working.

How we can solve this issue?

@cmseal
Copy link

cmseal commented Jul 15, 2021

I've got a similar issue on Ubuntu 20.04 LTS, with module v3.1.0, Puppet 6 on a new deployment (clean VM):

Debug: Executing: '/usr/bin/mongo admin --quiet --host 127.0.0.1:27017 --eval rs.slaveOk();printjson(db.getMongo().getDBs())'
Debug: Storing state
Debug: Pruned old state cache entries in 0.00 seconds
Debug: Stored state in 0.08 seconds
Error: Failed to apply catalog: 783: unexpected token at 'WARNING: ) is deprecated and may be removed in the next major release. Please use secondaryOk( instead.

@cmseal
Copy link

cmseal commented Jul 15, 2021

It appears that the current usage of rs.slaveOk() disrupts the manifest continuing. A cursory glance of v3.1.0 shows it exists in a few places.

I've no objection to creating a PR to swap out rs.slaveOk() with rs.secondaryOk(), if that's what it takes?

lib/puppet/provider/mongodb_database/mongodb.rb:

    7    def self.instances
    8      require 'json'
    9:     dbs = JSON.parse mongo_eval('rs.slaveOk();printjson(db.getMongo().getDBs())')
   10  
   11      dbs['databases'].map do |db|

spec/acceptance/replset_spec.rb:

   68      it 'checks the data on the slave' do
   69        sleep(10)
   70:       on hosts_as('slave'), %{mongo --verbose --eval 'rs.slaveOk(); printjson(db.test.findOne({name:"test1"}))'} do |r|
   71          expect(r.stdout).to match %r{some value}
   72        end
   ..
  199      it 'checks the data on the slave' do
  200        sleep(10)
  201:       on hosts_as('slave'), %{mongo test --verbose --eval 'load("/root/.mongorc.js");rs.slaveOk();printjson(db.dummyData.findOne())'} do |r|
  202          expect(r.stdout).to match %r{created_by_puppet}
  203        end

spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb:

   37      mongodconffile = tmp.path
   38      allow(provider.class).to receive(:mongod_conf_file).and_return(mongodconffile)
   39:     allow(provider.class).to receive(:mongo_eval).with('rs.slaveOk();printjson(db.getMongo().getDBs())').and_return(raw_dbs)
   40      allow(provider.class).to receive(:db_ismaster).and_return(true)
   41    end

templates/mongorc.js.erb:

   28    try {
   29  <% if @replset -%>
   30:     rs.slaveOk()
   31  <% end -%>
   32      var prev_db = db

@cmseal
Copy link

cmseal commented Jul 15, 2021

@bimcas FYI, I believe this is fixed with what's currently in master at present. I did open a PR, only to realise better fixes existed there already, vs what's in v3.1.0.

@bimcas
Copy link
Author

bimcas commented Jul 16, 2021

@cmseal Thanks for your response.
I manually change rs.slaveOk() to rs.secondaryOk() in file mongorc.js on all nodes.
But when I run puppet I got:

_Notice: /Stage[main]/Mongodb::Server::Config/File[/root/.mongorc.js]/content:
--- /root/.mongorc.js 2021-07-13 10:15:56.781233361 +0200
+++ /tmp/puppet-file20210716-884-181og2b 2021-07-16 08:47:35.042430183 +0200
@@ -26,7 +26,7 @@

if (authRequired()) {
try {
-- rs.secondaryOk()
++ rs.slaveOk()
var prev_db = db_

So, as you see puppet by itself restore my correct setting rs.secondaryOk() to rs.slaveOk() again, and of course I'm again getting the message:
Error: Failed to apply catalog: 765: unexpected token at 'WARNING: ) is deprecated and may be removed in the next major release. Please use secondaryOk()

What exact version and commit of mongo module I should use to fix this issue?
Why puppet is setting rs.slaveOk() instead of rs.secondaryOk()?

@bimcas bimcas closed this as completed Oct 26, 2021
@bimcas
Copy link
Author

bimcas commented Oct 26, 2021

Problem has gone when I'm start using module with commit a59b99e. No more such issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants