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

Use the built-in OpenShift service environment variables #16001

Merged
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
2 changes: 1 addition & 1 deletion app/models/embedded_ansible_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def provider_url
server = MiqServer.my_server(true)

if MiqEnvironment::Command.is_container?
host = ENV["ANSIBLE_SERVICE_NAME"]
host = ENV["ANSIBLE_SERVICE_HOST"]
path = "/api/v1"
else
host = server.hostname || server.ipaddress
Expand Down
4 changes: 2 additions & 2 deletions lib/embedded_ansible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def self.services

def self.api_connection
if MiqEnvironment::Command.is_container?
host = ENV["ANSIBLE_SERVICE_NAME"]
port = 80
host = ENV["ANSIBLE_SERVICE_HOST"]
port = ENV["ANSIBLE_SERVICE_PORT_HTTP"]
else
host = "localhost"
port = HTTP_PORT
Expand Down
6 changes: 5 additions & 1 deletion lib/miq_memcached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

module MiqMemcached
def self.server_address
ENV["MEMCACHED_SERVER"] || ::Settings.session.memcache_server
if ENV["MEMCACHED_SERVICE_HOST"] && ENV["MEMCACHED_SERVICE_PORT"]
"#{ENV["MEMCACHED_SERVICE_HOST"]}:#{ENV["MEMCACHED_SERVICE_PORT"]}"
else
::Settings.session.memcache_server
end
end

class Error < RuntimeError; end
Expand Down
8 changes: 5 additions & 3 deletions spec/lib/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,19 @@

describe ".api_connection" do
around do |example|
ENV["ANSIBLE_SERVICE_NAME"] = "ansible-service"
ENV["ANSIBLE_SERVICE_HOST"] = "192.0.2.1"
ENV["ANSIBLE_SERVICE_PORT_HTTP"] = "1234"
example.run
ENV.delete("ANSIBLE_SERVICE_NAME")
ENV.delete("ANSIBLE_SERVICE_HOST")
ENV.delete("ANSIBLE_SERVICE_PORT_HTTP")
end

it "connects to the ansible service when running in a container" do
miq_database.set_ansible_admin_authentication(:password => "adminpassword")
expect(MiqEnvironment::Command).to receive(:is_container?).and_return(true)

expect(AnsibleTowerClient::Connection).to receive(:new).with(
:base_url => "http://ansible-service/api/v1",
:base_url => "http://192.0.2.1:1234/api/v1",
:username => "admin",
:password => "adminpassword",
:verify_ssl => 0
Expand Down
6 changes: 3 additions & 3 deletions spec/models/embedded_ansible_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
end

around do |example|
ENV["ANSIBLE_SERVICE_NAME"] = "ansible-service"
ENV["ANSIBLE_SERVICE_HOST"] = "192.0.2.1"
example.run
ENV.delete("ANSIBLE_SERVICE_NAME")
ENV.delete("ANSIBLE_SERVICE_HOST")
end

it "creates the provider with the service name for the URL" do
Expand All @@ -84,7 +84,7 @@

provider = ManageIQ::Providers::EmbeddedAnsible::Provider.first
expect(provider.zone).to eq(miq_server.zone)
expect(provider.default_endpoint.url).to eq("https://ansible-service/api/v1")
expect(provider.default_endpoint.url).to eq("https://192.0.2.1/api/v1")
userid, password = provider.auth_user_pwd
expect(userid).to eq("admin")
expect(password).to eq("secret")
Expand Down