Skip to content

Commit

Permalink
Filter hidden modules (#3036)
Browse files Browse the repository at this point in the history
backports #2997 to 3.0.

auto_modules needs to filter hidden modules so they don't show up in the UI.
  • Loading branch information
johrstrom authored Sep 15, 2023
1 parent baed336 commit cb65bd3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
10 changes: 6 additions & 4 deletions apps/dashboard/app/models/hpc_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def all(cluster)
begin
JSON.parse(File.read(file)).map do |name, spider_output|
spider_output.map do |_, mod|
HpcModule.new(name, version: mod['Version'])
HpcModule.new(name, version: mod['Version'], hidden: mod['hidden'])
end
end.flatten.uniq
end.flatten.uniq.reject(&:hidden?)
rescue StandardError => e
Rails.logger.warn("Did not read #{file} correctly because #{e.class}:#{e.message}")
[]
Expand All @@ -31,11 +31,13 @@ def all_versions(module_name)
end
end

attr_reader :name, :version
attr_reader :name, :version, :hidden
alias hidden? hidden

def initialize(name, version: nil)
def initialize(name, version: nil, hidden: false)
@name = name
@version = version.to_s if version
@hidden = hidden
end

def to_s
Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def find_option_style(ele, opt)
end

def find_all_options(ele, opt)
all("##{bc_ele_id(ele)} option[value='#{opt}']")
if opt.nil?
all("##{bc_ele_id(ele)} option")
else
all("##{bc_ele_id(ele)} option[value='#{opt}']")
end
end

def find_max(ele)
Expand Down
17 changes: 15 additions & 2 deletions apps/dashboard/test/models/hpc_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def fixture_dir
end
end

test 'all versions is corrrect, sorted and unique' do
test 'all_versions is corrrect, sorted and unique' do
stub_sys_apps
with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do
# "app_jupyter/1.2.21" in oakley.json is hidden
expected = [
'app_jupyter/3.1.18', 'app_jupyter/3.0.17', 'app_jupyter/2.3.2', 'app_jupyter/2.2.10',
'app_jupyter/1.2.21', 'app_jupyter/1.2.16', 'app_jupyter/0.35.6'
'app_jupyter/1.2.21', 'app_jupyter/0.35.6'
]
assert_equal(expected, HpcModule.all_versions('app_jupyter').map(&:to_s))
end
Expand Down Expand Up @@ -63,4 +64,16 @@ def fixture_dir
assert !m.default?
assert_equal m.version, '9001' # we gave an int, got back a string
end

test 'hidden modules are filtered' do
stub_sys_apps
with_modified_env({ OOD_MODULE_FILE_DIR: fixture_dir }) do
# "mkl/.2019.0.5" in oakley.json is hidden
expected = [
'mkl/2019.0.5', 'mkl/2019.0.3', 'mkl/2018.0.3', 'mkl/2017.0.7',
'mkl/2017.0.4', 'mkl/2017.0.2', 'mkl/11.3.3'
]
assert_equal(expected, HpcModule.all_versions('mkl').map(&:to_s))
end
end
end
25 changes: 23 additions & 2 deletions apps/dashboard/test/system/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,13 @@ def stub_scontrol(dir, cluster)
assert_equal 'owens', find_value('cluster')
# versions not available on owens
assert_equal 'display: none;', find_option_style('auto_modules_app_jupyter', 'app_jupyter/3.1.18')
assert_equal 'display: none;', find_option_style('auto_modules_app_jupyter', 'app_jupyter/1.2.16')
assert_equal 'display: none;', find_option_style('auto_modules_app_jupyter', 'app_jupyter/0.35.6')
assert_equal 'display: none;', find_option_style('auto_modules_intel', 'intel/18.0.4')

# select oakley and now they're available
select('oakley', from: bc_ele_id('cluster'))
assert_equal 'app_jupyter', find_value('auto_modules_app_jupyter')
assert_equal '', find_option_style('auto_modules_app_jupyter', 'app_jupyter/3.1.18')
assert_equal '', find_option_style('auto_modules_app_jupyter', 'app_jupyter/1.2.16')
assert_equal '', find_option_style('auto_modules_app_jupyter', 'app_jupyter/0.35.6')

# and lots of intel versions aren't
Expand Down Expand Up @@ -653,6 +651,29 @@ def stub_scontrol(dir, cluster)
end
end

test 'auto generated modules hide hidden modules' do
with_modified_env({ OOD_MODULE_FILE_DIR: 'test/fixtures/modules' }) do
visit new_batch_connect_session_context_url('sys/bc_jupyter')

# defaults, note that intel doesn't show the default version
assert_equal 'app_jupyter', find_value('auto_modules_app_jupyter')
assert_equal 'intel/2021.3.0', find_value('auto_modules_intel')
assert_equal 'owens', find_value('cluster')

# oakley has the hidden intel module 'intel/2021.4.0'
select('oakley', from: bc_ele_id('cluster'))

actual_options = find_all_options('auto_modules_intel', nil).map(&:text)

# '2021.4.0' is not listed here.
expected_options = [
'2021.3.0', '19.1.3', '19.0.5', '19.0.3', '18.0.4', '18.0.3', '18.0.2',
'18.0.0', '17.0.7', '17.0.5', '17.0.2', '16.0.8', '16.0.3'
]
assert_equal(expected_options, actual_options)
end
end

test 'auto accounts are cluster aware' do
Dir.mktmpdir do |dir|
"#{dir}/app".tap { |d| Dir.mkdir(d) }
Expand Down

0 comments on commit cb65bd3

Please sign in to comment.