Ejemplo n.º 1
0
 def test_create_swift_client(self):
     mock_resp = mock(dict)
     when(swiftclient.client.Connection).get_container("bob").thenReturn(["text", mock_resp])
     client = remote.create_swift_client(TroveContext(tenant="123"))
     headers, container = client.get_container("bob")
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 2
0
 def delete_files_from_swift(cls, context, filename):
     container = CONF.backup_swift_container
     client = remote.create_swift_client(context)
     obj = client.head_object(container, filename)
     manifest = obj.get('x-object-manifest', '')
     cont, prefix = cls._parse_manifest(manifest)
     if all([cont, prefix]):
         # This is a manifest file, first delete all segments.
         LOG.info(
             _("Deleting files with prefix: %(cont)s/%(prefix)s") % {
                 'cont': cont,
                 'prefix': prefix
             })
         # list files from container/prefix specified by manifest
         headers, segments = client.get_container(cont, prefix=prefix)
         LOG.debug(headers)
         for segment in segments:
             name = segment.get('name')
             if name:
                 LOG.info(
                     _("Deleting file: %(cont)s/%(name)s") % {
                         'cont': cont,
                         'name': name
                     })
                 client.delete_object(cont, name)
     # Delete the manifest file
     LOG.info(
         _("Deleting file: %(cont)s/%(filename)s") % {
             'cont': cont,
             'filename': filename
         })
     client.delete_object(container, filename)
Ejemplo n.º 3
0
 def test_create_with_catalog_all_opts(self):
     cfg.CONF.set_override('swift_service_type', 'object-storev3')
     cfg.CONF.set_override('os_region_name', 'RegionTwo')
     client = remote.create_swift_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.swiftv3_public_url_region_two,
                      client.url)
Ejemplo n.º 4
0
 def test_create_with_catalog_all_opts(self):
     cfg.CONF.set_override('swift_service_type', 'object-storev3')
     cfg.CONF.set_override('os_region_name', 'RegionTwo')
     client = remote.create_swift_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.swiftv3_public_url_region_two,
                      client.url)
Ejemplo n.º 5
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     swiftclient.client.Connection.get_container = MagicMock(
         return_value=["text", mock_resp])
     client = remote.create_swift_client(TroveContext(tenant='123'))
     headers, container = client.get_container('bob')
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 6
0
 def test_create_swift_client(self):
     mock_resp = mock(dict)
     when(swiftclient.client.Connection).get_container('bob').thenReturn(
         ["text", mock_resp])
     client = remote.create_swift_client(TroveContext(tenant='123'))
     headers, container = client.get_container('bob')
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 7
0
 def __init__(self, context, **kwargs):
     self.process = None
     self.pid = None
     self.cmd = self.cmd % kwargs
     self.container = kwargs.get('container')
     self.filename = kwargs.get('filename')
     self.original_backup_checksum = kwargs.get('backup_checksum', None)
     self.swift_client = create_swift_client(context)
Ejemplo n.º 8
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     swiftclient.client.Connection.get_container = MagicMock(
         return_value=["text", mock_resp])
     client = remote.create_swift_client(TroveContext(tenant='123'))
     headers, container = client.get_container('bob')
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 9
0
 def verify_swift_auth_token(cls, context):
     try:
         client = create_swift_client(context)
         client.get_account()
     except ClientException:
         raise exception.SwiftAuthError(tenant_id=context.tenant)
     except exception.NoServiceEndpoint:
         raise exception.SwiftNotFound(tenant_id=context.tenant)
Ejemplo n.º 10
0
 def __init__(self, context, **kwargs):
     self.process = None
     self.pid = None
     self.cmd = self.cmd % kwargs
     self.container = kwargs.get('container')
     self.filename = kwargs.get('filename')
     self.original_backup_checksum = kwargs.get('backup_checksum', None)
     self.swift_client = create_swift_client(context)
Ejemplo n.º 11
0
 def verify_swift_auth_token(cls, context):
     try:
         client = create_swift_client(context)
         client.get_account()
     except ClientException:
         raise exception.SwiftAuthError(tenant_id=context.tenant)
     except exception.NoServiceEndpoint:
         raise exception.SwiftNotFound(tenant_id=context.tenant)
Ejemplo n.º 12
0
    def test_create_with_conf_override(self):
        swift_url_from_conf = 'http://example.com/AUTH_'
        tenant_from_ctx = 'abc'
        cfg.CONF.set_override('swift_url', swift_url_from_conf)

        client = remote.create_swift_client(
            TroveContext(tenant=tenant_from_ctx))
        self.assertEqual('%s%s' % (swift_url_from_conf, tenant_from_ctx),
                         client.url)
Ejemplo n.º 13
0
    def test_create_with_conf_override(self):
        swift_url_from_conf = 'http://example.com/AUTH_'
        tenant_from_ctx = uuid.uuid4().hex
        cfg.CONF.set_override('swift_url', swift_url_from_conf)

        client = remote.create_swift_client(
            TroveContext(tenant=tenant_from_ctx))
        self.assertEqual('%s%s' % (swift_url_from_conf, tenant_from_ctx),
                         client.url)
Ejemplo n.º 14
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     swiftclient.client.Connection.get_container = MagicMock(
         return_value=["text", mock_resp])
     service_catalog = [{'endpoints': [{'publicURL': 'example.com'}],
                         'type': 'object-store'}]
     client = remote.create_swift_client(TroveContext(
         tenant='123',
         service_catalog=service_catalog))
     headers, container = client.get_container('bob')
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 15
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     with patch.object(swiftclient.client.Connection, 'get_container',
                       MagicMock(return_value=["text", mock_resp])):
         service_catalog = [{'endpoints': [{'region': 'RegionOne',
                                            'publicURL': 'example.com'}],
                             'type': 'object-store'}]
         client = remote.create_swift_client(TroveContext(
             tenant=uuid.uuid4().hex,
             service_catalog=service_catalog))
         headers, container = client.get_container('bob')
         self.assertIs(headers, "text")
         self.assertIs(container, mock_resp)
Ejemplo n.º 16
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     with patch.object(swiftclient.client.Connection, 'get_container',
                       MagicMock(return_value=["text", mock_resp])):
         service_catalog = [{'endpoints': [{'region': 'RegionOne',
                                            'publicURL': 'example.com'}],
                             'type': 'object-store'}]
         client = remote.create_swift_client(TroveContext(
             tenant=uuid.uuid4().hex,
             service_catalog=service_catalog))
         headers, container = client.get_container('bob')
         self.assertIs(headers, "text")
         self.assertIs(container, mock_resp)
Ejemplo n.º 17
0
 def check_object_exist(cls, context, location):
     try:
         parts = location.split('/')
         obj = parts[-1]
         container = parts[-2]
         client = create_swift_client(context)
         client.head_object(container, obj)
         return True
     except ClientException as e:
         if e.http_status == 404:
             return False
         else:
             raise exception.SwiftAuthError(tenant_id=context.tenant)
Ejemplo n.º 18
0
 def check_object_exist(cls, context, location):
     try:
         parts = location.split('/')
         obj = parts[-1]
         container = parts[-2]
         client = create_swift_client(context)
         client.head_object(container, obj)
         return True
     except ClientException as e:
         if e.http_status == 404:
             return False
         else:
             raise exception.SwiftAuthError(tenant_id=context.tenant)
Ejemplo n.º 19
0
    def delete_files_from_swift(cls, context, filename):
        client = remote.create_swift_client(context)
        # Delete the manifest
        if client.head_object(CONF.backup_swift_container, filename):
            client.delete_object(CONF.backup_swift_container, filename)

        # Delete the segments
        if client.head_container(filename + "_segments"):

            for obj in client.get_container(filename + "_segments")[1]:
                client.delete_object(filename + "_segments", obj['name'])

            # Delete the segments container
            client.delete_container(filename + "_segments")
Ejemplo n.º 20
0
 def test_create_swift_client(self):
     mock_resp = MagicMock()
     swiftclient.client.Connection.get_container = MagicMock(
         return_value=["text", mock_resp])
     service_catalog = [{
         'endpoints': [{
             'publicURL': 'example.com'
         }],
         'type': 'object-store'
     }]
     client = remote.create_swift_client(
         TroveContext(tenant='123', service_catalog=service_catalog))
     headers, container = client.get_container('bob')
     self.assertIs(headers, "text")
     self.assertIs(container, mock_resp)
Ejemplo n.º 21
0
 def delete_files_from_swift(cls, context, filename):
     container = CONF.backup_swift_container
     client = remote.create_swift_client(context)
     obj = client.head_object(container, filename)
     manifest = obj.get('x-object-manifest', '')
     cont, prefix = cls._parse_manifest(manifest)
     if all([cont, prefix]):
         # This is a manifest file, first delete all segments.
         LOG.info("Deleting files with prefix: %s/%s", cont, prefix)
         # list files from container/prefix specified by manifest
         headers, segments = client.get_container(cont, prefix=prefix)
         LOG.debug(headers)
         for segment in segments:
             name = segment.get('name')
             if name:
                 LOG.info("Deleting file: %s/%s", cont, name)
                 client.delete_object(cont, name)
         # Delete the manifest file
     LOG.info("Deleting file: %s/%s", container, filename)
     client.delete_object(container, filename)
Ejemplo n.º 22
0
 def check_swift_object_exist(self, context, verify_checksum=False):
     try:
         parts = self.location.split("/")
         obj = parts[-1]
         container = parts[-2]
         client = create_swift_client(context)
         LOG.info(_("Checking if backup exist in '%s'") % self.location)
         resp = client.head_object(container, obj)
         if verify_checksum:
             LOG.info(_("Checking if backup checksum matches swift."))
             # swift returns etag in double quotes
             # e.g. '"dc3b0827f276d8d78312992cc60c2c3f"'
             swift_checksum = resp["etag"].strip('"')
             if self.checksum != swift_checksum:
                 raise exception.RestoreBackupIntegrityError(backup_id=self.id)
         return True
     except ClientException as e:
         if e.http_status == 404:
             return False
         else:
             raise exception.SwiftAuthError(tenant_id=context.tenant)
Ejemplo n.º 23
0
 def check_swift_object_exist(self, context, verify_checksum=False):
     try:
         parts = self.location.split('/')
         obj = parts[-1]
         container = parts[-2]
         client = create_swift_client(context)
         LOG.info(_("Checking if backup exist in '%s'") % self.location)
         resp = client.head_object(container, obj)
         if verify_checksum:
             LOG.info(_("Checking if backup checksum matches swift."))
             # swift returns etag in double quotes
             # e.g. '"dc3b0827f276d8d78312992cc60c2c3f"'
             swift_checksum = resp['etag'].strip('"')
             if self.checksum != swift_checksum:
                 raise exception.RestoreBackupIntegrityError(
                     backup_id=backup_id)
         return True
     except ClientException as e:
         if e.http_status == 404:
             return False
         else:
             raise exception.SwiftAuthError(tenant_id=context.tenant)
Ejemplo n.º 24
0
 def __init__(self, *args, **kwargs):
     super(SwiftStorage, self).__init__(*args, **kwargs)
     self.connection = create_swift_client(self.context)
Ejemplo n.º 25
0
 def get_client(cls, context, region_name):
     return remote.create_swift_client(context, region_name)
Ejemplo n.º 26
0
 def get_client(cls, context):
     return remote.create_swift_client(context)
Ejemplo n.º 27
0
 def swift_client(self):
     if not self._cached_swift_client or (
             self._cached_context != self.context):
         self._cached_swift_client = create_swift_client(self.context)
         self._cached_context = self.context
     return self._cached_swift_client
Ejemplo n.º 28
0
 def test_create_with_catalog_and_default_service_type(self):
     client = remote.create_swift_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.swift_public_url,
                      client.url)
Ejemplo n.º 29
0
 def __init__(self, context):
     super(SwiftStorage, self).__init__()
     self.connection = create_swift_client(context)
Ejemplo n.º 30
0
Archivo: models.py Proyecto: zh-f/trove
 def get_client(cls, context, region_name):
     return remote.create_swift_client(context, region_name)
Ejemplo n.º 31
0
 def swift_client(self):
     if not self._cached_swift_client or (self._cached_context !=
                                          self.context):
         self._cached_swift_client = create_swift_client(self.context)
         self._cached_context = self.context
     return self._cached_swift_client
Ejemplo n.º 32
0
 def test_create_with_catalog_and_default_service_type(self):
     client = remote.create_swift_client(
         TroveContext(service_catalog=self.service_catalog))
     self.assertEqual(self.swift_public_url, client.url)
Ejemplo n.º 33
0
 def __init__(self, context):
     super(SwiftStorage, self).__init__()
     self.connection = create_swift_client(context)