-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for plugin_factor commands
- Loading branch information
Showing
5 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/bindings/python/fluxacct/accounting/test/test_plugin_factor_subcommands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
|
||
############################################################### | ||
# Copyright 2020 Lawrence Livermore National Security, LLC | ||
# (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
# | ||
# This file is part of the Flux resource manager framework. | ||
# For details, see https://github.com/flux-framework. | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0 | ||
############################################################### | ||
import unittest | ||
import os | ||
import sqlite3 | ||
|
||
from fluxacct.accounting import create_db as c | ||
from fluxacct.accounting import plugin_factor_subcommands as p | ||
|
||
|
||
class TestAccountingCLI(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(self): | ||
# create test accounting database | ||
c.create_db("TestPluginFactorSubcommands.db") | ||
global acct_conn | ||
global cur | ||
|
||
acct_conn = sqlite3.connect("TestPluginFactorSubcommands.db") | ||
cur = acct_conn.cursor() | ||
|
||
# edit the weight for the fairshare factor | ||
def test_01_edit_fairshare_factor_successfully(self): | ||
p.edit_factor(acct_conn, factor="fairshare", weight=1500) | ||
cur.execute("SELECT weight FROM plugin_factor_table WHERE factor='fairshare'") | ||
row = cur.fetchone() | ||
|
||
self.assertEqual(row[0], 1500) | ||
|
||
# edit the weight for the queue factor | ||
def test_02_edit_queue_factor_successfully(self): | ||
p.edit_factor(acct_conn, factor="queue", weight=200) | ||
cur.execute("SELECT weight FROM plugin_factor_table WHERE factor='queue'") | ||
row = cur.fetchone() | ||
|
||
self.assertEqual(row[0], 200) | ||
|
||
# try to edit a factor with a bad type | ||
def test_03_edit_factor_bad_type(self): | ||
with self.assertRaises(ValueError): | ||
p.edit_factor(acct_conn, factor="fairshare", weight="foo") | ||
|
||
# remove database and log file | ||
@classmethod | ||
def tearDownClass(self): | ||
acct_conn.close() | ||
os.remove("TestPluginFactorSubcommands.db") | ||
|
||
|
||
def suite(): | ||
suite = unittest.TestSuite() | ||
|
||
return suite | ||
|
||
|
||
if __name__ == "__main__": | ||
from pycotap import TAPTestRunner | ||
|
||
unittest.main(testRunner=TAPTestRunner()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/bash | ||
|
||
test_description='Test configuring plugin weights and their effects on priority calculation' | ||
|
||
. `dirname $0`/sharness.sh | ||
MULTI_FACTOR_PRIORITY=${FLUX_BUILD_DIR}/src/plugins/.libs/mf_priority.so | ||
DB_PATH=$(pwd)/FluxAccountingTest.db | ||
|
||
export TEST_UNDER_FLUX_NO_JOB_EXEC=y | ||
export TEST_UNDER_FLUX_SCHED_SIMPLE_MODE="limited=1" | ||
test_under_flux 1 job | ||
|
||
flux setattr log-stderr-level 1 | ||
|
||
test_expect_success 'load multi-factor priority plugin' ' | ||
flux jobtap load -r .priority-default ${MULTI_FACTOR_PRIORITY} | ||
' | ||
|
||
test_expect_success 'check that mf_priority plugin is loaded' ' | ||
flux jobtap list | grep mf_priority | ||
' | ||
|
||
test_expect_success 'create flux-accounting DB' ' | ||
flux account -p $(pwd)/FluxAccountingTest.db create-db | ||
' | ||
|
||
test_expect_success 'add some banks to the DB' ' | ||
flux account -p ${DB_PATH} add-bank root 1 && | ||
flux account -p ${DB_PATH} add-bank --parent-bank=root account1 1 | ||
' | ||
|
||
test_expect_success 'add a default queue to the DB' ' | ||
flux account -p ${DB_PATH} add-queue default --priority=100 | ||
' | ||
|
||
test_expect_success 'add a user to the DB' ' | ||
username=$(whoami) && | ||
uid=$(id -u) && | ||
flux account -p ${DB_PATH} add-user --username=$username --userid=$uid --bank=account1 --shares=1 | ||
' | ||
|
||
test_expect_success 'view queue information' ' | ||
flux account -p ${DB_PATH} view-plugin-factor fairshare > fshare_weight.test && | ||
grep "fairshare 100000" fshare_weight.test && | ||
flux account -p ${DB_PATH} view-plugin-factor queue > queue_weight.test && | ||
grep "queue 10000" queue_weight.test | ||
' | ||
|
||
test_expect_success 'send the user, queue, and plugin factor weight information to the plugin' ' | ||
flux account-priority-update -p $(pwd)/FluxAccountingTest.db | ||
' | ||
|
||
test_expect_success 'submit a job using default fshare and queue factor weights' ' | ||
jobid1=$(flux mini submit -n1 hostname) && | ||
flux job wait-event -f json $jobid1 priority | jq '.context.priority' > job1.test && | ||
cat <<-EOF >job1.expected && | ||
1050000 | ||
EOF | ||
test_cmp job1.expected job1.test | ||
' | ||
|
||
test_expect_success 'edit plugin factor weights to give fairshare all the weight' ' | ||
flux account -p ${DB_PATH} edit-plugin-factor fairshare --weight=1000 && | ||
flux account -p ${DB_PATH} edit-plugin-factor queue --weight=0 && | ||
flux account-priority-update -p $(pwd)/FluxAccountingTest.db | ||
' | ||
|
||
test_expect_success 'submit a job using the new fshare and queue factor weights' ' | ||
jobid2=$(flux mini submit -n1 hostname) && | ||
flux job wait-event -f json $jobid2 priority | jq '.context.priority' > job2.test && | ||
cat <<-EOF >job2.expected && | ||
500 | ||
EOF | ||
test_cmp job2.expected job2.test | ||
' | ||
|
||
test_expect_success 'edit plugin factor weights to give queue all the weight' ' | ||
flux account -p ${DB_PATH} edit-plugin-factor fairshare --weight=0 && | ||
flux account -p ${DB_PATH} edit-plugin-factor queue --weight=1000 && | ||
flux account-priority-update -p $(pwd)/FluxAccountingTest.db | ||
' | ||
|
||
test_expect_success 'submit a job using the new fshare and queue factor weights' ' | ||
jobid3=$(flux mini submit -n1 hostname) && | ||
flux job wait-event -f json $jobid3 priority | jq '.context.priority' > job3.test && | ||
cat <<-EOF >job3.expected && | ||
100000 | ||
EOF | ||
test_cmp job3.expected job3.test | ||
' | ||
|
||
test_done |