Gabriel-Adrian Samfira před 6 roky
rodič
revize
cf21a9b66a

+ 43 - 45
coriolis/providers/backup_writers.py

@@ -439,8 +439,6 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
         self._compressor_evt = None
 
         self._compress_transfer = compress_transfer
-        if self._compress_transfer is None:
-            self._compress_transfer = CONF.compress_transfers
         super(HTTPBackupWriterImpl, self).__init__(path, disk_id)
 
     def _set_info(self, info):
@@ -542,6 +540,7 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
     def _sender(self):
         while True:
             payload = self._sender_q.get()
+            LOG.debug("Got send payload")
             headers = {
                 "X-Write-Offset": str(payload["offset"]),
                 "X-Client-Token": self._id,
@@ -628,29 +627,26 @@ class HTTPBackupWriterImpl(BaseBackupWriterImpl):
 
 class HTTPBackupWriter(BaseBackupWriter):
 
-    def __init__(self, ip, port, username, pkey,
-                 password, writer_port, volumes_info,
-                 cert_dir, compressor_count=3):
+    def __init__(self, ip, port, volumes_info, ssh=None,
+                 compressor_count=3, writer_creds=None):
         self._ip = ip
         self._port = port
-        self._username = username
-        self._pkey = pkey
-        self._password = password
         self._volumes_info = volumes_info
-        self._writer_port = writer_port
+        self._writer_port = port
         self._lock = threading.Lock()
         self._id = str(uuid.uuid4())
         self._compressor_count = compressor_count
         self._writer_cmd = os.path.join(
             "/usr/bin", _CORIOLIS_HTTP_WRITER_CMD)
-        self._crt = None
-        self._key = None
-        self._ca = None
-        if os.path.isdir(cert_dir) is False:
+        self._ssh = ssh
+        self._writer_creds = writer_creds
+        self._crt_dir = tempfile.mkdtemp()
+        if not self._ssh and not self._writer_creds:
             raise exception.CoriolisException(
-                "Certificates dir %s does not exist" % cert_dir
-            )
-        self._crt_dir = cert_dir
+                "Either ssh or writer_creds must be specified")
+        if self._ssh and self._writer_creds:
+            raise exception.CoriolisException(
+                "ssh and writer_creds are mutually exclusive")
 
     def _wait_for_conn(self):
         LOG.debug(
@@ -665,21 +661,44 @@ class HTTPBackupWriter(BaseBackupWriter):
             "sudo /sbin/iptables -I INPUT -p tcp --dport %s "
             "-j ACCEPT" % self._writer_port, get_pty=True)
 
+    def _write_cert_files(self):
+        if not self._writer_creds:
+            raise exception.CoriolisException(
+                "writer_creds not set")
+        crt_file = tempfile.mkstemp()[1]
+        key_file = tempfile.mkstemp()[1]
+        ca_crt_file = tempfile.mkstemp()[1]
+        with open(crt_file, "w") as fd:
+            fd.write(self._writer_creds["client_crt"])
+        with open(key_file, "w") as fd:
+            fd.write(self._writer_creds["client_key"])
+        with open(ca_crt_file, "w") as fd:
+            fd.write(self._writer_creds["ca_crt"])
+        return {
+            "client_crt": crt_file,
+            "client_key": key_file,
+            "ca_crt": ca_crt_file,
+        }
+
     def _get_impl(self, path, disk_id):
-        ssh = self._connect_ssh()
-        _disable_lvm2_lvmetad(ssh)
-        self._setup_writer(ssh)
+        if self._ssh:
+            _disable_lvm2_lvmetad(self._ssh)
+            cert_paths = self._setup_writer(self._ssh)["local"]
+        else:
+            cert_paths = self._write_cert_files()
 
         path = [v for v in self._volumes_info
                 if v["disk_id"] == disk_id][0]["volume_dev"]
         impl = HTTPBackupWriterImpl(
-            path, disk_id, self._compressor_count)
+            path, disk_id,
+            compressor_count=self._compressor_count,
+            compress_transfer=CONF.compress_transfers)
         impl._set_info({
             "ip": self._ip,
             "port": self._writer_port,
-            "client_crt": self._crt,
-            "client_key": self._key,
-            "ca_crt": self._ca,
+            "client_crt": cert_paths["client_crt"],
+            "client_key": cert_paths["client_key"],
+            "ca_crt": cert_paths["ca_crt"],
             "id": self._id,
         })
         return impl
@@ -804,27 +823,6 @@ class HTTPBackupWriter(BaseBackupWriter):
         self._copy_writer(ssh)
         paths = utils.retry_on_error()(
             self._setup_certificates)(ssh)
-        self._crt = paths["local"]["client_crt"]
-        self._key = paths["local"]["client_key"]
-        self._ca = paths["local"]["ca_crt"]
         utils.retry_on_error()(
             self._init_writer)(ssh, paths["remote"])
-
-    @utils.retry_on_error(sleep_seconds=30)
-    def _connect_ssh(self):
-        LOG.info("Connecting to SSH host: %(ip)s:%(port)s" %
-                 {"ip": self._ip, "port": self._port})
-        ssh = paramiko.SSHClient()
-        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-        try:
-            ssh.connect(
-                hostname=self._ip,
-                port=self._port,
-                username=self._username,
-                pkey=self._pkey,
-                password=self._password)
-        except (Exception, KeyboardInterrupt):
-            # No need to log the error as we just raise
-            ssh.close()
-            raise
-        return ssh
+        return paths

+ 3 - 1
coriolis/providers/factory.py

@@ -1,7 +1,8 @@
-# Copyright 2016 Cloudbase Solutions Srl
+# Copyright 2016 Cloudbase :Solutions Srl
 # All Rights Reserved.
 
 from oslo_config import cfg
+from oslo_log import log as logging
 
 from coriolis import constants
 from coriolis import exception
@@ -14,6 +15,7 @@ serialization_opts = [
                 help='List of provider class paths'),
 ]
 
+LOG = logging.getLogger(__name__)
 CONF = cfg.CONF
 CONF.register_opts(serialization_opts)
 

+ 1 - 0
coriolis/secrets.py

@@ -10,6 +10,7 @@ from coriolis import utils
 
 
 def get_secret(ctxt, secret_ref):
+    keystone.create_trust(ctxt)
     session = keystone.create_keystone_session(ctxt)
     barbican = barbican_client.Client(session=session)
     sec = utils.retry_on_error()(barbican.secrets.get)(secret_ref)

+ 19 - 19
coriolis/tasks/replica_tasks.py

@@ -112,17 +112,17 @@ class ReplicateDisksTask(base.TaskRunner):
             schemas.CORIOLIS_DISK_SYNC_RESOURCES_INFO_SCHEMA)
 
         migr_source_conn_info = task_info["migr_source_connection_info"]
-        if migr_source_conn_info:
-            schemas.validate_value(
-                migr_source_conn_info,
-                schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA)
+        #if migr_source_conn_info:
+        #    schemas.validate_value(
+        #        migr_source_conn_info,
+        #        schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA)
         migr_source_conn_info = base.unmarshal_migr_conn_info(
             migr_source_conn_info)
 
         migr_target_conn_info = task_info["migr_target_connection_info"]
-        schemas.validate_value(
-            migr_target_conn_info,
-            schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA)
+        #schemas.validate_value(
+        #    migr_target_conn_info,
+        #    schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA)
         migr_target_conn_info = base.unmarshal_migr_conn_info(
             migr_target_conn_info)
 
@@ -220,12 +220,12 @@ class DeployReplicaSourceResourcesTask(base.TaskRunner):
         if migr_connection_info:
             migr_connection_info = base.marshal_migr_conn_info(
                 migr_connection_info)
-            schemas.validate_value(
-                migr_connection_info,
-                schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA,
-                # NOTE: we avoid raising so that the cleanup task
-                # can [try] to deal with the temporary resources.
-                raise_on_error=False)
+            #schemas.validate_value(
+            #    migr_connection_info,
+            #    schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA,
+            #    # NOTE: we avoid raising so that the cleanup task
+            #    # can [try] to deal with the temporary resources.
+            #    raise_on_error=False)
 
         task_info["migr_source_connection_info"] = migr_connection_info
 
@@ -286,12 +286,12 @@ class DeployReplicaTargetResourcesTask(base.TaskRunner):
         migr_connection_info = replica_resources_info["connection_info"]
         migr_connection_info = base.marshal_migr_conn_info(
             migr_connection_info)
-        schemas.validate_value(
-            migr_connection_info,
-            schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA,
-            # NOTE: we avoid raising so that the cleanup task
-            # can [try] to deal with the temporary resources.
-            raise_on_error=False)
+        #schemas.validate_value(
+        #    migr_connection_info,
+        #    schemas.CORIOLIS_DISK_SYNC_RESOURCES_CONN_INFO_SCHEMA,
+        #    # NOTE: we avoid raising so that the cleanup task
+        #    # can [try] to deal with the temporary resources.
+        #    raise_on_error=False)
 
         task_info["migr_target_connection_info"] = migr_connection_info