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

Fixes #29799 - Move --clear-pulp-content to hooks/ #540

Merged
merged 3 commits into from
Sep 4, 2020

Conversation

wbclark
Copy link
Contributor

@wbclark wbclark commented Jul 15, 2020

I implemented this as separate options for Pulp2 and Pulpcore. This has at least two key advantages -- first, the user may wish to clear one but not the other. Second, when Pulp2 is later removed it makes it very easy to remove --clear-pulp-data without touching --clear-pulpcore-data.

@wbclark
Copy link
Contributor Author

wbclark commented Jul 31, 2020

@ehelms I introduced hooks/boot/05-data-helpers.rb. Now we have minimal hooks/pre/{10-reset_data.rb,12-clear_pulp_content.rb,13-clear_pulpcore_content.rb} which call the reusable helpers.


def pg_command_base(config, command, args)
port = "-p #{config[:port]}" if config[:port]
"PGPASSWORD='#{config[:password]}' #{command} -U #{config[:username]} -h #{config[:host]} #{port} #{args}"
Copy link
Member

Choose a reason for hiding this comment

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

The downside of using it like this is that you can see the password in ps aux. It would be much better to pass an environment variable via native Ruby methods rather than relying on shell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@ehelms ehelms left a comment

Choose a reason for hiding this comment

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

Untested, but the structure looks good

end

if app_value(:clear_pulpcore_content) && !app_value(:noop)
response = ask('Are you sure you want to continue? This will clear all Pulpcore content including repositories and synced content. [y/n]')
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't remove synced content, only the database. Not sure it matters to end users, but they may be surprised to find the disk usage is still high.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took inspiration from (read: shamelessly copied) @ianballou 's work on #504 into a new helper in hooks/boot/05-data-helpers.rb and incorporated it in hooks/pre/13-clear_pulpcore_content.rb

content_dir = '/var/lib/pulp/content'
if File.directory?(content_dir)
logger.debug "Removing Pulp content inside \'#{content_dir}\'."
FileUtils.rm_rf('/var/lib/pulp/content/*')
Copy link
Member

Choose a reason for hiding this comment

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

https://ruby-doc.org/stdlib-2.4.1/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_r suggests you need to call glob explicitly.

Suggested change
FileUtils.rm_rf('/var/lib/pulp/content/*')
FileUtils.rm_rf(Dir.glob(File.join(content_dir, '*')))

I'm also wondering about the docs for it that mention a security risk. I guess this is a timing attack where it would start to process it, read a directory and then replace that with a symlink. I wouldn't be too worried about this.

@wbclark wbclark force-pushed the 29799_clear_pulp_content branch from 66cfbb7 to 5006d58 Compare September 2, 2020 16:03
@wbclark
Copy link
Contributor Author

wbclark commented Sep 2, 2020

Thanks for the reviews @ekohl . It is updated with proper escaping

@wbclark
Copy link
Contributor Author

wbclark commented Sep 3, 2020

@ekohl I fixed the remaining issues with escaping and now use a single method reset_repo_importers for both local and remote mongodb.

I then added a 2nd commit which moves shared helpers to the hook context extension.

@wbclark wbclark force-pushed the 29799_clear_pulp_content branch from bbd53fb to 234e0ab Compare September 3, 2020 16:18
@wbclark
Copy link
Contributor Author

wbclark commented Sep 3, 2020

@ekohl Updated the first commit to address the above comments, except the one about the --reset-data warning... please see above discussion about it and let me know your thoughts.

@wbclark wbclark force-pushed the 29799_clear_pulp_content branch from 234e0ab to d7e0490 Compare September 4, 2020 14:07
if !pulp_enabled?
logger.warn 'Skipping Pulp content reset because Pulp feature is disabled in scenario answers.'
elsif app_value(:reset_data)
logger.debug "Skipping \'--clear-pulp-content\' because Pulp data and content will be reset with '\--reset-data\'."
Copy link
Member

Choose a reason for hiding this comment

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

Still has redundant escaping. The warn below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this should be in single quotes I think. Once that is fixed, the escaping becomes necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ekohl There are similar issues in hooks/pre/10-data_reset.rb so I added a 3rd commit that fixes them. But if you prefer I can move that commit to a new branch and PR.

@wbclark wbclark force-pushed the 29799_clear_pulp_content branch from d7e0490 to df30ac0 Compare September 4, 2020 14:32
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Untested, but the code looks good to me.

@wbclark wbclark merged commit 4548bcc into theforeman:develop Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants