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

[WIP] Add ServiceAnsiblePlaybook.check_connection #20645

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
14 changes: 14 additions & 0 deletions app/models/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def self.delete_repo_dir(id, directory_name)
FileUtils.rm_rf(directory_name)
end

# Check the connection for the remote.
#
# Does not clone a repo or use an existing one, and instead initializes a
# repo in a temp path to check the remote to see if it can accept
# connections.
def check_connection
Dir.mktmpdir do |tmp_repo_dir|
Copy link
Member Author

Choose a reason for hiding this comment

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

Doing this as a block to make sure the tmp dir is removed once we are done with the .check_connection call.

The result of the block is what is returned, so the directory being deleted is just a side effect of that.

repo_opts = worktree_params.merge(:new => true, :path => tmp_repo_dir)
NickLaMuro marked this conversation as resolved.
Show resolved Hide resolved
tmp_worktree = GitWorktree.new(repo_opts)

tmp_worktree.check_connection(url)
end
end

def refresh
update_repo
transaction do
Expand Down
6 changes: 5 additions & 1 deletion app/models/service_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ServiceAnsiblePlaybook < ServiceGeneric
include AnsibleExtraVarsMixin
include AnsiblePlaybookMixin

delegate :playbook, :to => :service_template, :allow_nil => true
delegate :playbook, :repository, :to => :service_template, :allow_nil => true

# A chance for taking options from automate script to override options from a service dialog
def preprocess(action, add_options = {})
Expand All @@ -18,6 +18,10 @@ def execute(action)
launch_ansible_job_queue(action)
end

def check_connection(action)
Copy link
Member Author

Choose a reason for hiding this comment

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

The action argument here is just in line with how playbook also works. If this interface, and the one in ServiceTemplateAnsiblePlaybook, are incorrect, we can change, but it seems like this is how these methods function.

(by that, I mean they pass around a :provision keyword to access specific attributes in config_info)

repository(action).check_connection
end

def launch_ansible_job_queue(action)
task_opts = {
:action => "Launching Ansible Job",
Expand Down
4 changes: 4 additions & 0 deletions app/models/service_template_ansible_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def playbook(action)
ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook.find(config_info[action.downcase.to_sym][:playbook_id])
end

def repository(action)
GitRepository.find(config_info[action.downcase.to_sym][:repository_id])
end

def update_catalog_item(options, auth_user = nil)
config_info = validate_update_config_info(options)
unless config_info
Expand Down
8 changes: 8 additions & 0 deletions lib/git_worktree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ def checkout
end
end

def check_connection(url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is closed, but just as a note for me so I don't lose context, we were in the process of replacing this method with Net::Ping::HTTP.new(url).ping? when we hit the subsequent error about the job not existing.

with_remote_options do |remote_options|
@repo.remotes
.create_anonymous(url)
.check_connection(:fetch, remote_options)
Copy link
Member Author

Choose a reason for hiding this comment

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

remote_options here has our credentials and proxy info, so if that is configured, it will be used as it is with other methods in this class.

Copy link
Member

Choose a reason for hiding this comment

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

Is check_connection here a rugged method?

Copy link
Member Author

Choose a reason for hiding this comment

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

end
end

def with_remote_options
if @ssh_private_key
@ssh_private_key_file = Tempfile.new
Expand Down