Переглянути джерело

Use coriolis-writer v2 API

The v1 coriolis-writer API only accepts device names such as /dev/vdb.

Device names are unreliable and can change depending on the order
in which the devices are identified.

For this reason, most Coriolis providers attach one device at a time
and then check the device name that was identified by the VM.

This is unnecessary for providers that can predentermine the SCSI
ID or address of the device and use that instead of device names.

As such, we'll use the v2 API of the Coriolis writer, which also
accepts udev links such as /dev/disk/by-id/<disk-id>. The Coriolis
writer will still resolve those links to ensure that there aren't
multiple lock owners of the same device.

The main difference is that the disk path is passed as a b64 encoded
string. Also, the lock acquire/release now became POST requests,
which are more appropriate than using GET for this purpose.
Lucian Petrut 3 місяців тому
батько
коміт
f45d9821e0

+ 6 - 4
coriolis/providers/backup_writers.py

@@ -2,6 +2,7 @@
 # All Rights Reserved.
 
 import abc
+import base64
 import contextlib
 import copy
 import datetime
@@ -574,8 +575,9 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
 
     @property
     def _uri(self):
-        return "https://%s:%s/api/v1/%s" % (
-            self._ip, self._port, self._path.lstrip('/')
+        b64_path = base64.b64encode(self._path.encode()).decode()
+        return "https://%s:%s/api/v2/device/%s" % (
+            self._ip, self._port, b64_path
         )
 
     @utils.retry_on_error()
@@ -583,7 +585,7 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
         self._ensure_session()
         uri = "%s/acquire" % self._uri
         headers = {"X-Client-Token": self._id}
-        resp = self._session.get(
+        resp = self._session.post(
             uri, headers=headers, timeout=CONF.default_requests_timeout)
         LOG.debug("Returned code: %d. Msg: %s" % (
             resp.status_code, resp.content))
@@ -594,7 +596,7 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
         self._ensure_session()
         uri = "%s/release" % self._uri
         headers = {"X-Client-Token": self._id}
-        resp = self._session.get(
+        resp = self._session.post(
             uri, headers=headers, timeout=CONF.default_requests_timeout)
         LOG.debug("Returned code: %d. Msg: %s" %
                   (resp.status_code, resp.content))

+ 6 - 6
coriolis/tests/providers/test_backup_writers.py

@@ -743,8 +743,8 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
 
         result = self.writer._uri
 
-        self.assertEqual(result, "https://%s:%s/api/v1/%s" % (
-            self.writer._ip, self.writer._port, self.writer._path))
+        self.assertEqual(result, "https://%s:%s/api/v2/device/%s" % (
+            self.writer._ip, self.writer._port, "cGF0aC90ZXN0X3BhdGg="))
 
     @mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_ensure_session')
     @mock.patch.object(backup_writers.HTTPBackupWriterImpl, '_uri')
@@ -757,7 +757,7 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
         mock_response.content = 'OK'
 
         mock_session = mock_session_class.return_value
-        mock_session.get.return_value = mock_response
+        mock_session.post.return_value = mock_response
 
         self.writer._session = mock_session
 
@@ -766,7 +766,7 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
         original_acquire(self.writer)
 
         mock_ensure_session.assert_called_once()
-        mock_session.get.assert_called_once_with(
+        mock_session.post.assert_called_once_with(
             f"{mock_uri}/acquire",
             headers={"X-Client-Token": self.writer._id},
             timeout=mock_conf.default_requests_timeout)
@@ -783,7 +783,7 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
         mock_response.content = 'OK'
 
         mock_session = mock_session_class.return_value
-        mock_session.get.return_value = mock_response
+        mock_session.post.return_value = mock_response
 
         self.writer._session = mock_session
 
@@ -792,7 +792,7 @@ class HTTPBackupWriterImplTestCase(test_base.CoriolisBaseTestCase):
         original_release(self.writer)
 
         mock_ensure_session.assert_called_once()
-        mock_session.get.assert_called_once_with(
+        mock_session.post.assert_called_once_with(
             f"{mock_uri}/release",
             headers={"X-Client-Token": self.writer._id},
             timeout=mock_conf.default_requests_timeout)