Skip to content

Commit 0a62e97

Browse files
committed
remove queue from AccountInfo
1 parent cf9f0c4 commit 0a62e97

File tree

5 files changed

+42
-62
lines changed

5 files changed

+42
-62
lines changed

lib/ood_core/job/account_info.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@ class AccountInfo
1515
# The cluster this account is associated with.
1616
attr_reader :cluster
1717

18-
# The queue this account can use. nil means there is no queue info
19-
# for this account.
20-
attr_reader :queue
21-
2218
def initialize(**opts)
2319
orig_name = opts.fetch(:name, 'unknown')
2420
@name = upcase_accounts? ? orig_name.upcase : orig_name
2521
@qos = opts.fetch(:qos, [])
2622
@cluster = opts.fetch(:cluster, nil)
27-
@queue = opts.fetch(:queue, nil)
2823
end
2924

3025
def to_h

lib/ood_core/job/adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def job_name_illegal_chars
210210
ENV["OOD_JOB_NAME_ILLEGAL_CHARS"].to_s
211211
end
212212

213-
# Retrieve the accounts available to use for the current user.
213+
# Retrieve the accounts available to use for the current user.
214+
# The same account might appear muiltiple times if it has access to multiple clusters.
214215
#
215216
# Subclasses that do not implement this will return empty arrays.
216217
# @return [Array<AccountInfo>] the accounts available to the user.

lib/ood_core/job/adapters/slurm.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,27 @@ def get_jobs(id: "", owner: nil, attrs: nil)
182182

183183
def accounts
184184
user = Etc.getlogin
185-
args = ['-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', "user=#{user}"]
185+
args = ['-nP', 'show', 'users', 'withassoc', 'format=account,cluster,qos', 'where', "user=#{user}"]
186186

187-
[].tap do |accts|
187+
[].tap do |associations|
188188
call('sacctmgr', *args).each_line do |line|
189-
acct, cluster, queue, qos = line.split('|')
189+
acct, cluster, qos = line.split('|')
190190
next if acct.nil? || acct.chomp.empty?
191191

192-
args = {
192+
associations << {
193193
name: acct,
194194
qos: qos.to_s.chomp.split(','),
195195
cluster: cluster,
196-
queue: queue.to_s.empty? ? nil : queue
197196
}
198-
info = OodCore::Job::AccountInfo.new(**args) unless acct.nil?
199-
accts << info unless acct.nil?
200197
end
198+
end.group_by do |x|
199+
[x[:name], x[:cluster]]
200+
end.map do |(name, cluster), assocs|
201+
OodCore::Job::AccountInfo.new(
202+
name: name,
203+
cluster: cluster,
204+
qos: (assocs.flat_map { |x| x[:qos] }).uniq,
205+
)
201206
end
202207
end
203208

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
pzs0715|ascend|partition_a|ascend-default
2-
pzs0714|ascend|partition_b|ascend-default
3-
pzs1124|owens||owens-default,staff,phoenix,geophys,hal,gpt
4-
pzs1118|owens||owens-default
5-
pzs1117|owens||owens-default
6-
pzs1010|owens||owens-default
7-
pzs0715|owens||owens-default
8-
pzs0714|owens||owens-default
9-
pde0006|owens||owens-default
10-
pas2051|owens||owens-default
11-
pas1871|owens||owens-default
12-
pas1754|owens||owens-default
13-
pas1604|owens||owens-default
14-
pzs1124|pitzer||pitzer-default
15-
pzs1118|pitzer||pitzer-default
16-
pzs1117|pitzer||pitzer-default
17-
pzs1010|pitzer||pitzer-default
18-
pzs0715|pitzer||pitzer-default
19-
pzs0714|pitzer||pitzer-default
20-
pde0006|pitzer||pitzer-default
21-
pas2051|pitzer||pitzer-default
22-
pas1871|pitzer||pitzer-default
23-
pas1754|pitzer||pitzer-default
24-
pas1604|pitzer||pitzer-default
25-
26-
27-
1+
pzs1124|owens|owens-default,staff,phoenix,geophys,hal,gpt
2+
pzs1118|owens|owens-default
3+
pzs1117|owens|owens-default
4+
pzs1010|owens|owens-default
5+
pzs0715|owens|owens-default
6+
pzs0714|owens|owens-default
7+
pde0006|owens|owens-default
8+
pas2051|owens|owens-default
9+
pas1871|owens|owens-default
10+
pas1754|owens|owens-default
11+
pas1604|owens|owens-default
12+
pzs1124|pitzer|pitzer-default
13+
pzs1118|pitzer|pitzer-default
14+
pzs1117|pitzer|pitzer-default
15+
pzs1010|pitzer|pitzer-default
16+
pzs0715|pitzer|pitzer-default
17+
pzs0714|pitzer|pitzer-default
18+
pde0006|pitzer|pitzer-default
19+
pas2051|pitzer|pitzer-default
20+
pas1871|pitzer|pitzer-default
21+
pas1754|pitzer|pitzer-default
22+
pas1604|pitzer|pitzer-default

spec/job/adapters/slurm_spec.rb

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,17 +1305,17 @@ def job_info(opts = {})
13051305
it 'returns the correct accounts names' do
13061306
allow(Etc).to receive(:getlogin).and_return('me')
13071307
allow(Open3).to receive(:capture3)
1308-
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', {stdin_data: ''})
1308+
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,qos', 'where', 'user=me', {stdin_data: ''})
13091309
.and_return([File.read('spec/fixtures/output/slurm/sacctmgr_show_accts.txt'), '', double("success?" => true)])
13101310

1311-
expect(subject.accounts.map(&:to_s).uniq).to eq(expected_accounts)
1311+
expect(subject.accounts.map(&:to_s).uniq.to_set).to eq(expected_accounts.to_set)
13121312
end
13131313

13141314
# TODO test for qos & cluster once the API solidifies
13151315
it 'parses qos correctly' do
13161316
allow(Etc).to receive(:getlogin).and_return('me')
13171317
allow(Open3).to receive(:capture3)
1318-
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', {stdin_data: ''})
1318+
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,qos', 'where', 'user=me', {stdin_data: ''})
13191319
.and_return([File.read('spec/fixtures/output/slurm/sacctmgr_show_accts.txt'), '', double("success?" => true)])
13201320

13211321
accts = subject.accounts
@@ -1327,22 +1327,6 @@ def job_info(opts = {})
13271327
expect(acct.qos).to eq(["#{acct.cluster}-default"])
13281328
end
13291329
end
1330-
1331-
it 'parses partition correctly' do
1332-
allow(Etc).to receive(:getlogin).and_return('me')
1333-
allow(Open3).to receive(:capture3)
1334-
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', {stdin_data: ''})
1335-
.and_return([File.read('spec/fixtures/output/slurm/sacctmgr_show_accts.txt'), '', double("success?" => true)])
1336-
1337-
accts = subject.accounts
1338-
acct_w_partitions = accts.select { |a| a.cluster == 'ascend' }
1339-
acct_w_no_partitions = accts.select { |a| a.queue.nil? }
1340-
1341-
expect(acct_w_partitions.size).to eq(2)
1342-
expect(accts - acct_w_no_partitions).to eq(acct_w_partitions)
1343-
expect(acct_w_partitions.select {|a| a.name == 'pzs0715'}.first.queue).to eq('partition_a')
1344-
expect(acct_w_partitions.select {|a| a.name == 'pzs0714'}.first.queue).to eq('partition_b')
1345-
end
13461330
end
13471331

13481332
context 'when sacctmgr fails' do
@@ -1351,7 +1335,7 @@ def job_info(opts = {})
13511335
it 'raises the error' do
13521336
allow(Etc).to receive(:getlogin).and_return('me')
13531337
allow(Open3).to receive(:capture3)
1354-
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', {stdin_data: ''})
1338+
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,qos', 'where', 'user=me', {stdin_data: ''})
13551339
.and_return(['', 'the error message', double("success?" => false)])
13561340

13571341
expect { subject.accounts }.to raise_error(OodCore::Job::Adapters::Slurm::Batch::Error, 'the error message')
@@ -1365,11 +1349,11 @@ def job_info(opts = {})
13651349
it 'returns the correct accounts' do
13661350
allow(Etc).to receive(:getlogin).and_return('me')
13671351
allow(Open3).to receive(:capture3)
1368-
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,partition,qos', 'where', 'user=me', {stdin_data: ''})
1352+
.with({}, 'sacctmgr', '-nP', 'show', 'users', 'withassoc', 'format=account,cluster,qos', 'where', 'user=me', {stdin_data: ''})
13691353
.and_return([File.read('spec/fixtures/output/slurm/sacctmgr_show_accts.txt'), '', double("success?" => true)])
13701354

13711355
with_modified_env({ OOD_UPCASE_ACCOUNTS: 'true'}) do
1372-
expect(subject.accounts.map(&:to_s).uniq).to eq(expected_accounts)
1356+
expect(subject.accounts.map(&:to_s).uniq.to_set).to eq(expected_accounts.to_set)
13731357
end
13741358
end
13751359
end

0 commit comments

Comments
 (0)