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

load pulpcore db configuration by asking django, not by parsing python #941

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
19 changes: 11 additions & 8 deletions definitions/features/pulpcore_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ def services

private

# rubocop:disable Metrics/AbcSize
def load_configuration
full_config = File.read(PULPCORE_DB_CONFIG).split(/[\s,'":]/).reject(&:empty?)
python_command = <<~PYTHON.strip
from django.conf import settings; import json; print(json.dumps(settings.DATABASES["default"]))
PYTHON
manager_command = pulpcore_manager("shell --command '#{python_command}'")
manager_result = execute!(manager_command)
db_config = JSON.parse(manager_result)

@configuration = {}
@configuration['adapter'] = 'postgresql'
@configuration['host'] = full_config[full_config.index('HOST') + 1]
@configuration['port'] = full_config[full_config.index('PORT') + 1]
@configuration['database'] = full_config[full_config.index('NAME') + 1]
@configuration['username'] = full_config[full_config.index('USER') + 1]
@configuration['password'] = full_config[full_config.index('PASSWORD') + 1]
@configuration['host'] = db_config['HOST']
@configuration['port'] = db_config['PORT']
@configuration['database'] = db_config['NAME']
@configuration['username'] = db_config['USER']
@configuration['password'] = db_config['PASSWORD']
@configuration
end
# rubocop:enable Metrics/AbcSize
end
22 changes: 22 additions & 0 deletions test/definitions/features/pulpcore_database_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test_helper'

describe Features::PulpcoreDatabase do
include DefinitionsTestHelper

subject { Features::PulpcoreDatabase.new }

describe '.configuration' do
it 'returns hash with DB config' do
expected_command = <<~CMD.strip
PULP_SETTINGS=/etc/pulp/settings.py runuser -u pulp -- pulpcore-manager shell --command 'from django.conf import settings; import json; print(json.dumps(settings.DATABASES["default"]))'
CMD
manager_return = <<~JSON
{"ENGINE": "django.db.backends.postgresql", "NAME": "pulpcore", "USER": "pulp", "PASSWORD": "password", "HOST": "remotedb", "PORT": "5432"}
JSON
subject.expects(:execute!).with(expected_command).returns(manager_return)
expected = { "adapter" => "postgresql", "host" => "remotedb", "port" => "5432",
"database" => "pulpcore", "username" => "pulp", "password" => "password" }
assert_equal expected, subject.configuration
end
end
end
Loading