Skip to content

Commit

Permalink
Allow cluster to override OOD_BC_SSH_TO_COMPUTE_NODE (#1173)
Browse files Browse the repository at this point in the history
* Allow cluster to override OOD_BC_SSH_TO_COMPUTE_NODE
Fixes #1157

* Use methods to determine if allowing SSH to compute nodes

* Fix unit tests

* Improved logic for ssh_to_compute_node?
  • Loading branch information
treydock authored Jun 21, 2021
1 parent 5b45899 commit 7eb6ca7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def time(session)
end

def host(session)
if ::Configuration.ood_bc_ssh_to_compute_node
if session.ssh_to_compute_node?
content_tag(:p) do
concat content_tag(:strong, t('dashboard.batch_connect_sessions_stats_host'))
concat " "
Expand Down
20 changes: 20 additions & 0 deletions apps/dashboard/app/models/batch_connect/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,26 @@ def connection_in_info?
info.respond_to?(:ood_connection_info)
end

# Whether to allow SSH to node running the job
# @return [Boolean] whether to allow SSH to node running the job
def ssh_to_compute_node?
if !cluster_ssh_to_compute_node?.nil?
return cluster_ssh_to_compute_node?
else
return global_ssh_to_compute_node?
end
end

# @return [Boolean]
def cluster_ssh_to_compute_node?
cluster.batch_connect_ssh_allow?
end

# @return [Boolean]
def global_ssh_to_compute_node?
Configuration.ood_bc_ssh_to_compute_node
end

# A unique identifier that details the current state of a session
# @return [String] hash of session
def to_hash
Expand Down
27 changes: 27 additions & 0 deletions apps/dashboard/test/models/batch_connect/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,31 @@ def completed?
assert Dir.exist?(session.staged_root)
end
end

test "ssh_to_compute_node? default" do
session = BatchConnect::Session.new
session.stubs(:cluster).returns(OodCore::Cluster.new({id: 'owens', job: {foo: 'bar'}}))
assert session.ssh_to_compute_node?
end

test "ssh_to_compute_node? disabled by cluster" do
session = BatchConnect::Session.new
session.stubs(:cluster).returns(OodCore::Cluster.new({id: 'owens', job: {foo: 'bar'}, batch_connect: {ssh_allow: false}}))
Configuration.stubs(:ood_bc_ssh_to_compute_node).returns(true)
refute session.ssh_to_compute_node?
end

test "ssh_to_compute_node? disabled globally" do
session = BatchConnect::Session.new
session.stubs(:cluster).returns(OodCore::Cluster.new({id: 'owens', job: {foo: 'bar'}}))
Configuration.stubs(:ood_bc_ssh_to_compute_node).returns(false)
refute session.ssh_to_compute_node?
end

test "ssh_to_compute_node? disabled globally allowed for cluster" do
session = BatchConnect::Session.new
session.stubs(:cluster).returns(OodCore::Cluster.new({id: 'owens', job: {foo: 'bar'}, batch_connect: {ssh_allow: true}}))
Configuration.stubs(:ood_bc_ssh_to_compute_node).returns(false)
assert session.ssh_to_compute_node?
end
end

0 comments on commit 7eb6ca7

Please sign in to comment.