Skip to content

Commit

Permalink
test: add tests for plugin_factor commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoussa1 committed Jun 3, 2022
1 parent 16bd453 commit 7ad1f14
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/bindings/python/fluxacct/accounting/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TESTSCRIPTS = \
test/test_example.py \
test/test_job_archive_interface.py \
test/test_user_subcommands.py \
test/test_queue_subcommands.py
test/test_queue_subcommands.py \
test/test_plugin_factor_subcommands.py

dist_check_SCRIPTS = \
$(TESTSCRIPTS)
Expand Down
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())
3 changes: 2 additions & 1 deletion t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TESTSCRIPTS = \
t1011-job-archive-interface.t \
t1012-mf-priority-load.t \
t1013-mf-priority-queues.t \
t1014-mf-priority-dne.t
t1014-mf-priority-dne.t \
t1015-mf-priority-weights.t

dist_check_SCRIPTS = \
$(TESTSCRIPTS) \
Expand Down
22 changes: 22 additions & 0 deletions t/t1007-flux-account.t
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ test_expect_success 'remove a queue from the queue_table' '
grep "Queue not found in queue_table" deleted_queue.out
'

test_expect_success 'view plugin factor information' '
flux account -p ${DB_PATH} view-plugin-factor fairshare > fshare_factor.test &&
grep "fairshare 100000" fshare_factor.test
'

test_expect_success 'edit a plugin factor successfully' '
flux account -p ${DB_PATH} edit-plugin-factor fairshare --weight=1234 &&
flux account -p ${DB_PATH} view-plugin-factor fairshare > fshare_factor_edited.test &&
grep "fairshare 1234" fshare_factor_edited.test
'

test_expect_success 'try to edit a plugin factor with a bad type' '
test_must_fail flux account -p ${DB_PATH} edit-plugin-factor fairshare --weight=foo > bad_type.out 2>&1 &&
test_debug "bad_type.out" &&
grep "edit-plugin-factor: error: argument --weight: invalid int value:" bad_type.out
'

test_expect_success 'try to view a plugin factor that does not exist' '
flux account -p ${DB_PATH} view-plugin-factor foo > no_such_factor.out &&
grep "Factor not found in plugin_factor_table" no_such_factor.out
'

test_expect_success 'remove flux-accounting DB' '
rm $(pwd)/FluxAccountingTest.db
'
Expand Down
92 changes: 92 additions & 0 deletions t/t1015-mf-priority-weights.t
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

0 comments on commit 7ad1f14

Please sign in to comment.