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

Proxy support for cloning ansible repo and add provider #15762

Merged
merged 3 commits into from
Sep 25, 2017
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
8 changes: 8 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,19 @@
:password:
:port:
:user:
:scheme:
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change being made?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's for socks5 proxy. If leave empty or "http", VMDB::Util.http_uri_proxy will return a http proxy uri. If scheme is "socks5", it will construct a socks5://... proxy. Both http proxy and socks5 proxy works when putting in http_proxy env var.
VMDB::Util.http_uri_proxy: https://github.com/ManageIQ/manageiq/blob/master/lib/vmdb/util.rb#L3

:gce:
:host:
:password:
:port:
:user:
:scheme:
:embedded_ansible:
:host:
:password:
:port:
:user:
:scheme:
:ldap_synchronization:
:ldap_synchronization_schedule: "0 2 * * *"
:log:
Expand Down
17 changes: 17 additions & 0 deletions lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class EmbeddedAnsible
ANSIBLE_ROLE = "embedded_ansible".freeze
SETUP_SCRIPT = "ansible-tower-setup".freeze
SECRET_KEY_FILE = "/etc/tower/SECRET_KEY".freeze
SETTINGS_FILE = "/etc/tower/settings.py".freeze
EXCLUDE_TAGS = "packages,migrations,firewall".freeze
HTTP_PORT = 54_321
HTTPS_PORT = 54_322
Expand Down Expand Up @@ -92,6 +93,7 @@ def self.api_connection

def self.appliance_start
if configured? && !upgrade?
update_proxy_settings
services.each { |service| LinuxAdmin::Service.new(service).start.enable }
else
configure_secret_key
Expand Down Expand Up @@ -185,6 +187,21 @@ def self.configure_secret_key
end
private_class_method :configure_secret_key

def self.update_proxy_settings
current_contents = File.read(SETTINGS_FILE)
new_contents = current_contents.gsub(/^.*AWX_TASK_ENV\['(HTTPS?_PROXY|NO_PROXY)'\].*$/, "")

proxy_uri = VMDB::Util.http_proxy_uri(:embedded_ansible) || VMDB::Util.http_proxy_uri
if proxy_uri
new_contents << "\n" unless new_contents.end_with?("\n")
new_contents << "AWX_TASK_ENV['HTTP_PROXY'] = '#{proxy_uri}'\n"
new_contents << "AWX_TASK_ENV['HTTPS_PROXY'] = '#{proxy_uri}'\n"
new_contents << "AWX_TASK_ENV['NO_PROXY'] = '127.0.0.1'\n"
end
File.write(SETTINGS_FILE, new_contents)
end
private_class_method :update_proxy_settings

def self.generate_admin_authentication
miq_database.set_ansible_admin_authentication(:password => generate_password)
end
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
expect(nginx_service).to receive(:enable).and_return(nginx_service)
expect(supervisord_service).to receive(:enable).and_return(supervisord_service)
expect(rabbitmq_service).to receive(:enable).and_return(rabbitmq_service)
expect(described_class).to receive(:update_proxy_settings)
end

it "waits for Ansible to respond" do
Expand Down Expand Up @@ -481,5 +482,35 @@
expect(auth.password).to eq(password)
end
end

describe ".update_proxy_settings (private)" do
let(:file_content) do
<<-EOF
# Arbitrary line 1

# Arbitrary line 2
AWX_TASK_ENV['HTTP_PROXY'] = 'somehost'
AWX_TASK_ENV['HTTPS_PROXY'] = 'somehost'
AWX_TASK_ENV['NO_PROXY'] = 'somehost'
EOF
end
let(:proxy_uri) { "http://user:password@localhost:3333" }
let(:settings_file) { Tempfile.new("settings.py") }
before do
settings_file.write(file_content)
settings_file.close
stub_const("EmbeddedAnsible::SETTINGS_FILE", settings_file.path)
expect(VMDB::Util).to receive(:http_proxy_uri).and_return(proxy_uri)
end

it "add current proxy info" do
described_class.send(:update_proxy_settings)
new_contents = File.read(settings_file.path)
expect(new_contents).to include("AWX_TASK_ENV['HTTP_PROXY'] = '#{proxy_uri}'\n")
expect(new_contents).to include("AWX_TASK_ENV['HTTPS_PROXY'] = '#{proxy_uri}'\n")
expect(new_contents).to include("AWX_TASK_ENV['NO_PROXY'] = '127.0.0.1'\n")
expect(new_contents).not_to include("'somehost'")
end
end
end
end