Exemple #1
0
 def test_refunds (self):
     user1 = User.fetch("user1")
     user2 = User.fetch("user2")
     project1 = Project.fetch("project1")
     project2 = Project.fetch("project2")
     res1 = Resource.fetch("res1")
     res2 = Resource.fetch("res2")
     start = datetime(2000, 1, 1)
     end = start + timedelta(weeks=1)
     a1 = Allocation(project1, res1, 10, start, end)
     a2 = Allocation(project1, res1, 20, start, end)
     a3 = Allocation(project2, res1, 30, start, end)
     a4 = Allocation(project2, res2, 35, start, end)
     c1 = Charge(a1, 10)
     c2 = Charge(a2, 15)
     c3 = Charge(a2, 5)
     c4 = Charge(a4, 9)
     c5 = Charge(a4, 8)
     for charge in (c1, c2, c3, c4, c5):
         charge.datetime = datetime(2000, 1, 1)
     Refund(c1, 4)
     Refund(c2, 3)
     Refund(c2, 5)
     Refund(c5, 8)
     Session.add_all([a1, a2, a3, a4])
     Session.flush()
     stdout, stderr = capture(lambda:
         print_charges_list([c1, c2, c3, c4, c5]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         1      2000-01-01 res1     project1                  6.0
         2      2000-01-01 res1     project1                  7.0
         3      2000-01-01 res1     project1                  5.0
         4      2000-01-01 res2     project2                  9.0
         5      2000-01-01 res2     project2                  0.0
         """))
     assert_equal_multiline(stderr.getvalue(), dedent("""\
         #      Date       Resource Project               Charged
         ------ ---------- -------- --------------- -------------
                                                    -------------
                                                             27.0
         Units are undefined.
         """))
Exemple #2
0
 def test_upstream_ids (self):
     start = datetime(2000, 1, 1)
     end = start + timedelta(weeks=1)
     a1 = Allocation(Project("-1"), Resource.fetch("-1"), 0, start, end)
     c1 = Charge(a1, 0)
     c1.datetime = datetime(2000, 1, 1)
     Session.add(c1)
     Session.flush()
     stdout, stderr = capture(lambda:
         print_charges_list([c1]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         1      2000-01-01 -1       -1                        0.0
         """))
Exemple #3
0
 def test_holds (self):
     project1 = Project.fetch("project1")
     project2 = Project.fetch("project2")
     res1 = Resource.fetch("res1")
     res2 = Resource.fetch("res2")
     start = datetime(2000, 1, 1)
     end = start + timedelta(weeks=1)
     a1 = Allocation(project1, res1, 10, start, end)
     a2 = Allocation(project1, res1, 20, start, end)
     a3 = Allocation(project2, res1, 30, start, end)
     a4 = Allocation(project2, res2, 35, start, end)
     h1 = Hold(a1, 10)
     h2 = Hold(a2, 15)
     h3 = Hold(a2, 5)
     h4 = Hold(a4, 9)
     h5 = Hold(a4, 8)
     for hold in (h1, h2, h3, h4, h5):
         hold.datetime = datetime(2000, 1, 1)
     Session.add_all([a1, a2, a3, a4])
     Session.flush()
     stdout, stderr = capture(lambda:
         print_holds_list([h1, h2, h3, h4, h5]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         1      2000-01-01 res1     project1                 10.0
         2      2000-01-01 res1     project1                 15.0
         3      2000-01-01 res1     project1                  5.0
         4      2000-01-01 res2     project2                  9.0
         5      2000-01-01 res2     project2                  8.0
         """))
     assert_equal_multiline(stderr.getvalue(), dedent("""\
         #      Date       Resource Project                  Held
         ------ ---------- -------- --------------- -------------
                                                    -------------
                                                             47.0
         Units are undefined.
         """))
Exemple #4
0
 def test_charge (self):
     user1 = User.fetch("user1")
     project1 = Project.fetch("project1")
     res1 = Resource.fetch("res1")
     allocation1 = Allocation(project1, res1, 0,
         datetime(2000, 1, 1), datetime(2001, 1, 1))
     charge = Charge(allocation1, 0)
     charge.datetime = datetime(2000, 1, 1)
     Session.add(charge)
     Session.flush()
     stdout, stderr = capture(lambda:
         print_charges([charge]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         Charge 1 -- 0.0
          * Datetime: 2000-01-01 00:00:00
          * Allocation: 1
          * Project: project1
          * Resource: res1
          * Comment: 
          * Job: None
         """))
Exemple #5
0
 def test_hold (self):
     user1 = User.fetch("user1")
     project1 = Project.fetch("project1")
     res1 = Resource.fetch("res1")
     allocation1 = Allocation(project1, res1, 0,
         datetime(2000, 1, 1), datetime(2001, 1, 1))
     hold = Hold(allocation1, 0)
     hold.datetime = datetime(2000, 1, 1)
     Session.add(hold)
     Session.flush()
     stdout, stderr = capture(lambda:
         print_holds([hold]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         Hold 1 -- 0.0
          * Datetime: 2000-01-01 00:00:00
          * Active: True
          * Allocation: 1
          * Project: project1
          * Resource: res1
          * Comment: 
          * Job: None
         """))
Exemple #6
0
 def test_job_refund (self):
     user1 = User.fetch("user1")
     project1 = Project.fetch("project1")
     res1 = Resource.fetch("res1")
     allocation1 = Allocation(project1, res1, 0,
         datetime(2000, 1, 1), datetime(2001, 1, 1))
     charge = Charge(allocation1, 0)
     charge.job = Job("res1.1")
     refund = Refund(charge, 0)
     refund.datetime = datetime(2000, 1, 1)
     Session.add(refund)
     Session.flush()
     stdout, stderr = capture(lambda:
         print_refunds([refund]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         Refund 1 -- 0.0
          * Datetime: 2000-01-01 00:00:00
          * Charge: 1
          * Allocation: 1
          * Project: project1
          * Resource: res1
          * Comment: 
          * Job: res1.1
         """))
Exemple #7
0
 def test_job (self):
     user1 = User.fetch("user1")
     project1 = Project.fetch("project1")
     res1 = Resource.fetch("res1")
     allocation1 = Allocation(project1, res1, 0,
         datetime(2000, 1, 1), datetime(2001, 1, 1))
     charges = [Charge(allocation1, 0), Charge(allocation1, 0)]
     job = Job("www.example.com.123")
     job.user = user1
     job.group = "agroup"
     job.account = project1
     job.name = "myjob"
     job.queue = "aqueue"
     job.reservation_name = "areservation"
     job.reservation_id = "www.example.com.1"
     job.ctime = datetime(2000, 1, 1)
     job.qtime = datetime(2001, 1, 1)
     job.etime = datetime(2001, 1, 2)
     job.start = datetime(2001, 2, 2)
     job.exec_host = "ANL-R00-M1-512"
     job.resource_list = {'nodes':64, 'walltime':timedelta(minutes=10),
         'otherresource':"stringvalue"}
     job.session = 123
     job.alternate_id = "anotherid"
     job.end = datetime(2001, 2, 3)
     job.exit_status = 128
     job.resources_used = {'nodes':64, 'walltime':timedelta(minutes=10),
         'otherresource':"stringvalue"}
     job.accounting_id = "someaccountingid"
     job.charges = charges
     Session.add(job)
     Session.flush()
     stdout, stderr = capture(lambda:
         print_jobs([job]))
     assert_equal_multiline(stdout.getvalue(), dedent("""\
         Job www.example.com.123
          * User: user1
          * Group: agroup
          * Account: project1
          * Name: myjob
          * Queue: aqueue
          * Reservation name: areservation
          * Reservation id: www.example.com.1
          * Creation time: 2000-01-01 00:00:00
          * Queue time: 2001-01-01 00:00:00
          * Eligible time: 2001-01-02 00:00:00
          * Start: 2001-02-02 00:00:00
          * Execution host: ANL-R00-M1-512
          * Resource list:
             * nodes: 64
             * otherresource: stringvalue
             * walltime: 0:10:00
          * Session: 123
          * Alternate id: anotherid
          * End: 2001-02-03 00:00:00
          * Exit status: 128
          * Resources used:
             * nodes: 64
             * otherresource: stringvalue
             * walltime: 0:10:00
          * Accounting id: someaccountingid
         """))