예제 #1
0
 def test_init_nousers(self):
     d = {
         'billing-frac': 0.5,
         'global-quota': 1,
         'usage': {},
     }
     a = Alerter(d)
     self.assertEqual(d['usage'], a.usage())
     self.assertEqual(d['global-quota'], a.globalQuota())
     self.assertEqual(0, a.globalUsed())
예제 #2
0
 def test_john_01(self):
     d = {
         'billing-frac': 0.2,  # One-fifth into the billing cycle.
         'global-quota': 6,  # GB
         'usage': {
             'John the Hermit': {
                 'quota': 2,  # GB
                 'used': 0.1,  # GB
             },
         },
     }
     a = Alerter(d)
     self.assertEqual(
         a.userStatus('John the Hermit')['warning-code'], Warn.Local.Ok)
예제 #3
0
 def test_yuri_01(self):
     d = {
         'billing-frac': 1.0 / 30,
         'global-quota': 6,  # GB
         'usage': {
             'Yuri the Streamer': {
                 'quota': 1,  # GB
                 'used': 0.5,  # GB
             },
         },
     }
     a = Alerter(d)
     self.assertEqual(a.accountHealth(), Warn.Global.Ok)
     self.assertEqual(
         a.userStatus('Yuri the Streamer')['warning-code'], Warn.Local.Ok)
예제 #4
0
 def test_john_02(self):
     d = {
         'billing-frac': 0.8,  # Four-fifths into the billing cycle.
         'global-quota': 6,  # GB
         'usage': {
             'John the Hermit': {
                 'quota': 2,  # GB
                 'used': 0.1,  # GB
             },
         },
     }
     a = Alerter(d)
     self.assertEqual(a.accountHealth(), Warn.Global.Underuse)
     self.assertEqual(
         a.userStatus('John the Hermit')['warning-code'],
         Warn.Local.Underuse)
예제 #5
0
 def test_john_04(self):
     d = {
         'billing-frac': 0.85,
         'global-quota': 6,  # GB
         'usage': {
             'John the Hermit': {
                 'quota': 2,  # GB
                 'used': 1.9,  # GB
             },
         },
     }
     a = Alerter(d)
     self.assertEqual(a.accountHealth(), Warn.Global.Underuse)
     self.assertEqual(
         a.userStatus('John the Hermit')['warning-code'],
         Warn.Local.Overuse)
예제 #6
0
 def test_init_01(self):
     d = {
         'billing-frac': 0.8,  # Four-fifths into the billing cycle.
         'global-quota': 6,  # GB
         'usage': {
             'Philip the Model Citizen': {
                 'quota': 2,  # GB
                 'used': 1,  # GB
             },
             'John the Hermit': {
                 'quota': 2,  # GB
                 'used': 0.1,  # GB
             },
             'Yuri the Streamer': {
                 'quota': 1,  # GB
                 'used': 1.2,  # GB
             },
             'David the Downloader': {
                 'quota': 1,  # GB
                 'used': 1.1,  # GB
             },
         },
     }
     a = Alerter(d)
     self.assertEqual(d['billing-frac'], a.billingFraction())
     self.assertEqual(d['usage'], a.usage())
     self.assertEqual(d['global-quota'], a.globalQuota())
     self.assertEqual(sum(u['used'] for u in d['usage'].values()),
                      a.globalUsed())
예제 #7
0
 def test_init_02(self):
     d = {
         'billing-frac': 0.8,  # Four-fifths into the billing cycle.
         'global-quota': 1,  # GB
         'usage': {
             'Philip the Model Citizen': {
                 'quota': 2,  # GB
                 'used': 1,  # GB
             },
         },
     }
     with self.assertRaises(SuaError):
         a = Alerter(d)
예제 #8
0
def showDataAlerts(d):
    resource = "data"
    coopMode = False
    of = OutputFormatter(resource)
    a = Alerter(d)
    email = EmailTunnel()
    # EOBC: End Of Billing Cycle
    print("== DATA ALERTS ==")
    globalWarning = a.getGlobalWarnText(a.accountHealth())
    print(
        "Global status (%.1f / %.1f GB) is %s.  Estimated usage by EOBC: %.1f GB."
        % (a.globalUsed(), a.globalQuota(), globalWarning,
           a.globalUsagePrediction()))
    print("Message to admin: %s" % of.warningAdminTextMap[a.accountHealth()])
    email.alertAdminGlobally(resource, a.accountHealth(), globalWarning)

    for (name, usage) in d['usage'].items():
        status = a.userStatus(name)
        localquota = usage['quota'] if 'quota' in usage else "inf"
        print("%s (used %.1f / %.1f GB):" % (name, usage['used'], localquota))
        print(
            "\tto account admin: %s.  Est. local use by EOBC: %.1f / %.1f GB."
            % (a.getLocalWarnText(
                status['warning-code']), status['used-eobc'], localquota))
        if 'max-daily-use-to-eobc' in status and status[
                'max-daily-use-to-eobc'] > 0:
            print(
                "\tto user: you can use up to %.2f GB/day until the end of the billing cycle."
                % status['max-daily-use-to-eobc'])
        print("\tto user (coop mode): %s" % getUserWarningTextCooperative(
            of, status['warning-code'], a.accountHealth()))
        print("\tto user (ind mode):  %s" %
              getUserWarningTextIndependent(of, status['warning-code']))
        email.alertAdminAboutUser(name, resource, status['warning-code'],
                                  a.getLocalWarnText(status['warning-code']))
        if coopMode:
            email.alertUser(
                name, resource, status['warning-code'],
                getUserWarningTextCooperative(of, status['warning-code'],
                                              a.accountHealth()))
        else:
            email.alertUser(
                name, resource, status['warning-code'],
                getUserWarningTextIndependent(of, status['warning-code']))