Repository: dmwm/wmcore
Issue: Rucio wrapper API has a deprecated client API: get_account_usage

**Impact of the bug**
WMCore in general

**Describe the bug**
While working on the MSTransferor code to support Rucio APIs, I noticed that our code to fetch account usage:
https://github.com/dmwm/WMCore/blob/master/src/python/WMCore/Services/Rucio/Rucio.py#L135

no longer works and it now raises an exception (traceback below).

Investigating the Rucio repository, I found this PR which actually replaces that API by a few others:
https://github.com/rucio/rucio/pull/2797

With this, we should learn that CI tests for Rucio APIs is a must in WMCore.

**How to reproduce it**
Create a rucio client object and call:
```
>>> res = client.get_account_usage("wma_test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Client' object has no attribute 'get_account_usage'
```

**Expected behavior**
We need to find the proper python client API to be used. This API has to provide us with the following information:
```
{'quota': item['bytes_limit'],
 'bytes_limit': item['bytes_limit'],
 'bytes': item['bytes'],
 'bytes_remaining': item['bytes_remaining']})
```
such that our input data placement logic can respect storage limitations.

**Additional context and error message**
```
Traceback (most recent call last):
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/cms/reqmgr2ms/0.2.6.pre4/lib/python2.7/site-packages/WMCore/MicroService/Unified/MSTransferor.py", line 175, in execute
    self.updateCaches()
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/external/py2-retry/0.9.1-comp5/lib/python2.7/site-packages/retry/compat.py", line 16, in wrapper
    return caller(f, *args, **kwargs)
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/external/py2-retry/0.9.1-comp5/lib/python2.7/site-packages/retry/api.py", line 74, in retry_decorator
    logger)
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/external/py2-retry/0.9.1-comp5/lib/python2.7/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/cms/reqmgr2ms/0.2.6.pre4/lib/python2.7/site-packages/WMCore/MicroService/Unified/MSTransferor.py", line 128, in updateCaches
    self.rseQuotas.fetchStorageUsage(getattr(self, "rucio", self.phedex))
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/cms/reqmgr2ms/0.2.6.pre4/lib/python2.7/site-packages/WMCore/MicroService/Unified/RSEQuotas.py", line 150, in fetchStorageUsage
    for item in dataSvcObj.getAccountUsage(self.dataAcct):
  File "/data/srv/HG2007f/sw/slc7_amd64_gcc630/cms/reqmgr2ms/0.2.6.pre4/lib/python2.7/site-packages/WMCore/Services/Rucio/Rucio.py", line 146, in getAccountUsage
    res = list(self.cli.get_account_usage(acct, rse=rse))
AttributeError: 'Client' object has no attribute 'get_account_usage'
```

Changed files:
src/python/WMCore/Services/Rucio/Rucio.py, test/python/WMCore_t/Services_t/Rucio_t/Rucio_t.py

diff --git a/src/python/WMCore/Services/Rucio/Rucio.py b/src/python/WMCore/Services/Rucio/Rucio.py
index 21cbc4edc..b281b0e79 100644
--- a/src/python/WMCore/Services/Rucio/Rucio.py
+++ b/src/python/WMCore/Services/Rucio/Rucio.py
@@ -145,7 +145,7 @@ class Rucio(object):
         """
         res = None
         try:
-            res = list(self.cli.get_account_usage(acct, rse=rse))
+            res = list(self.cli.get_local_account_usage(acct, rse=rse))
         except (AccountNotFound, AccessDenied) as ex:
             self.logger.error("Failed to get account usage information from Rucio. Error: %s", str(ex))
         return res
diff --git a/test/python/WMCore_t/Services_t/Rucio_t/Rucio_t.py b/test/python/WMCore_t/Services_t/Rucio_t/Rucio_t.py
index 446ba1469..e55f13016 100644
--- a/test/python/WMCore_t/Services_t/Rucio_t/Rucio_t.py
+++ b/test/python/WMCore_t/Services_t/Rucio_t/Rucio_t.py
@@ -103,8 +103,21 @@ class RucioTest(EmulatedUnitTestCase):
         """
         Test whether we can fetch data about a specific rucio account
         """
-        res = list(self.client.get_account_usage(self.acct))
+        # test against a specific RSE
+        res = list(self.client.get_local_account_usage(self.acct, rse="T1_US_FNAL_Disk"))
+        res2 = self.myRucio.getAccountUsage(self.acct, rse="T1_US_FNAL_Disk")
+        self.assertEqual(res[0]["rse"], "T1_US_FNAL_Disk")
+        self.assertTrue(res[0]["files"] >= 1)
+        self.assertTrue(res[0]["bytes"] >= 1000)
+        self.assertTrue("bytes_remaining" in res[0])
+        self.assertTrue(res[0]["bytes_limit"] >= 0)
+        self.assertEqual(res, res2)
+
+        # test against all RSEs
+        res = list(self.client.get_local_account_usage(self.acct))
         res2 = self.myRucio.getAccountUsage(self.acct)
+        self.assertTrue(len(res) > 1)
+        self.assertTrue(len(res2) > 1)
         # I have manually created a rule for this account, so it will be there...
         self.assertEqual(res, res2)