Skip to content

Commit

Permalink
t: update tests for pop-db and export-db
Browse files Browse the repository at this point in the history
Problem: The sharness tests for the pop-db and export-db commands are
out-of-date in a couple of ways:

- their filenames are not those of the actual table names in the
flux-accounting database
- they do not include the column names in the first line of the .csv
file
- the pop-db command no longer has a "--users" optional argument to
specify a file containing data for the association_table

Update the tests accordingly to account for the improvements made to the
export-db and pop-db commands.
  • Loading branch information
cmoussa1 committed Nov 12, 2024
1 parent f3ed3c3 commit 14c8cbd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 78 deletions.
53 changes: 31 additions & 22 deletions t/t1009-pop-db.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ test_expect_success 'start flux-accounting service' '
flux account-service -p ${DB_PATH} -t
'

test_expect_success 'create a banks.csv file containing bank information' '
cat <<-EOF >banks.csv
test_expect_success 'try to populate flux-accounting DB with a bad filename' '
touch foo.csv &&
test_must_fail flux account pop-db -c foo.csv > error.out 2>&1 &&
grep "table \"foo\" does not exist in the database" error.out
'

test_expect_success 'create bank_table.csv' '
cat <<-EOF >bank_table.csv
bank,parent_bank,shares
root,,1
A,root,1
B,root,1
Expand All @@ -30,41 +37,43 @@ test_expect_success 'create a banks.csv file containing bank information' '
EOF
'

test_expect_success 'populate flux-accounting DB with banks.csv' '
flux account pop-db -b banks.csv
test_expect_success 'populate flux-accounting DB with bank_table.csv' '
flux account pop-db -c bank_table.csv
'

test_expect_success 'create a users.csv file containing user information' '
cat <<-EOF >users.csv
user1000,1000,A,1,10,15,5,""
user1001,1001,A,1,10,15,5,""
user1002,1002,A,1,10,15,5,""
user1003,1003,A,1,10,15,5,""
user1004,1004,A,1,10,15,5,""
test_expect_success 'create association_table.csv' '
cat <<-EOF >association_table.csv
creation_time,username,userid,bank,default_bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues
0,user1000,1000,A,A,1,10,15,5,""
0,user1001,1001,A,A,1,10,15,5,""
0,user1002,1002,A,A,1,10,15,5,""
0,user1003,1003,A,A,1,10,15,5,""
0,user1004,1004,A,A,1,10,15,5,""
EOF
'

test_expect_success 'populate flux-accounting DB with users.csv' '
flux account pop-db -u users.csv
test_expect_success 'populate association_table with association_table.csv' '
flux account pop-db -c association_table.csv
'

test_expect_success 'check database hierarchy to make sure all banks & users were added' '
flux account view-bank root -t > db_hierarchy_base.test &&
test_cmp ${EXPECTED_FILES}/db_hierarchy_base.expected db_hierarchy_base.test
'

test_expect_success 'create a users.csv file with some missing optional user information' '
cat <<-EOF >users_optional_vals.csv
user1005,1005,B,1,5,,5,""
user1006,1006,B,,,,5,""
user1007,1007,B,1,7,,,""
user1008,1008,B,,,,5,""
user1009,1009,B,1,9,,,""
test_expect_success 'create association_table.csv with some missing user information' '
cat <<-EOF >association_table.csv
creation_time,username,userid,bank,default_bank,shares,max_running_jobs,max_active_jobs,max_nodes,queues
0,user1005,1005,B,B,1,5,,5,""
0,user1006,1006,B,B,,,,5,""
0,user1007,1007,B,B,1,7,,,""
0,user1008,1008,B,B,,,,5,""
0,user1009,1009,B,B,1,9,,,""
EOF
'

test_expect_success 'populate flux-accounting DB with users_optional_vals.csv' '
flux account pop-db -u users_optional_vals.csv
test_expect_success 'populate association_table' '
flux account pop-db -c association_table.csv
'

test_expect_success 'check database hierarchy to make sure new users were added' '
Expand Down
75 changes: 21 additions & 54 deletions t/t1016-export-db.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,28 @@ test_expect_success 'export DB information into .csv files' '
'

test_expect_success 'compare banks.csv' '
cat <<-EOF >banks_expected.csv
root,,1
A,root,1
B,root,1
C,root,1
D,root,1
E,D,1
F,D,1
cat <<-EOF >bank_table_expected.csv
bank_id,bank,active,parent_bank,shares,job_usage
1,root,1,,1,0.0
2,A,1,root,1,0.0
3,B,1,root,1,0.0
4,C,1,root,1,0.0
5,D,1,root,1,0.0
6,E,1,D,1,0.0
7,F,1,D,1,0.0
EOF
test_cmp -b banks_expected.csv banks.csv
'

test_expect_success 'compare users.csv' '
cat <<-EOF >users_expected.csv
user5011,5011,A,1,5,7,2147483647,
user5012,5012,A,1,5,7,2147483647,
user5013,5013,B,1,5,7,2147483647,
user5014,5014,C,1,5,7,2147483647,
EOF
test_cmp -b users_expected.csv users.csv
'

test_expect_success 'create hierarchy output of the flux-accounting DB and store it in a file' '
flux account view-bank root -t > db1.test
'

test_expect_success 'shut down flux-accounting service' '
flux python -c "import flux; flux.Flux().rpc(\"accounting.shutdown_service\").get()"
'

test_expect_success 'create a new flux-accounting DB' '
flux account -p $(pwd)/FluxAccountingTestv2.db create-db
'

test_expect_success 'restart service against new DB' '
flux account-service -p ${DB_PATHv2} -t
'

test_expect_success 'import information into new DB' '
flux account pop-db -b banks.csv &&
flux account pop-db -u users.csv
'

test_expect_success 'create hierarchy output of the new DB and store it in a file' '
flux account view-bank root -t > db2.test
'

test_expect_success 'compare DB hierarchies to make sure they are the same' '
test_cmp db1.test db2.test
'

test_expect_success 'specify a different filename for exported users and banks .csv files' '
flux account export-db --users foo.csv --banks bar.csv &&
test_cmp -b users_expected.csv foo.csv &&
test_cmp -b banks_expected.csv bar.csv
test_cmp -b bank_table_expected.csv bank_table.csv
'

# use 'grep' checks here because the contents of association_table also
# store timestamps of when the user was added to the DB, and thus will be
# slightly different every time these tests are run
test_expect_success 'make association_table.csv is populated' '
grep "creation_time,mod_time,active,username" association_table.csv &&
grep "user5011,5011,A,A" association_table.csv &&
grep "user5012,5012,A,A" association_table.csv &&
grep "user5013,5013,B,B" association_table.csv &&
grep "user5014,5014,C,C" association_table.csv
'

test_expect_success 'shut down flux-accounting service' '
Expand Down
3 changes: 1 addition & 2 deletions t/t1026-flux-account-perms.t
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ test_expect_success 'pop-db should not be accessible by all users' '
( export FLUX_HANDLE_ROLEMASK=0x2 &&
export FLUX_HANDLE_USERID=$newid &&
touch users.csv &&
touch banks.csv &&
test_must_fail flux account pop-db -u users.csv -b banks.csv > no_access_pop_db.out 2>&1 &&
test_must_fail flux account pop-db -c association_table.csv > no_access_pop_db.out 2>&1 &&
grep "Request requires owner credentials" no_access_pop_db.out
)
'
Expand Down

0 comments on commit 14c8cbd

Please sign in to comment.