def test_download_failover_new_redis_driver(self, mock_redis,
                                             mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger
                               )
     exceptions = (ConnectionError, TimeoutError)
     mock_swift.delete_object.return_value = None
     for ex in exceptions:
         store.tier_0.queue.release.side_effect = ex
         # w/o specified container
         rt_no = store.delete(TIER_0,
                              self.user_id,
                              self.uuid,
                              path_format=self.path_format
                              )
         # w/ specified container
         rt_yes = store.delete(TIER_0,
                               self.user_id,
                               self.uuid,
                               container="anan",
                               path_format=self.path_format
                               )
         self.assertIsNone(rt_no)
         self.assertIsNone(rt_yes)
 def test_download_failover_new_redis_driver(self, mock_redis,
                                             mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger
                               )
     exceptions = (ConnectionError, TimeoutError)
     mock_swift.get_object.return_value = 1, self.data
     for ex in exceptions:
         store.tier_0.queue.dequeue.side_effect = ex
         # w/o specified container
         data_no = store.download(TIER_0,
                              self.user_id,
                              self.uuid,
                              chunk_size=512,
                              path_format=self.path_format
                              )
         # w/ specified container
         data_yes = store.download(TIER_0,
                                  self.user_id,
                                  self.uuid,
                                  container="anan",
                                  chunk_size=512,
                                  path_format=self.path_format
                                  )
         self.assertEqual(data_no, self.data)
         self.assertEqual(data_yes, self.data)
Example #3
0
 def test_upload_swift_client_exception(self, mock_redis, mock_swift,
                                        mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     mock_swift.put_object.side_effect = ClientException("fail to upload")
     with self.assertRaises(ClientException) as ar:
         container_no = store.upload(TIER_1,
                                     self.user_id,
                                     self.uuid,
                                     self.data,
                                     ctype="image/jpeg",
                                     chunk_size=512,
                                     path_format=self.path_format)
         container_yes = store.upload(TIER_1,
                                      self.user_id,
                                      self.uuid,
                                      self.data,
                                      container="anan",
                                      ctype="image/jpeg",
                                      chunk_size=512,
                                      path_format=self.path_format)
         self.assertIsNotNone(container_no)
         self.assertIsNotNone(container_yes)
     self.assertIsInstance(ar.exception, ClientException)
     self.assertEqual("fail to upload", str(ar.exception))
    def test_download_swift_client_exception(self, mock_redis,
                                           mock_swift, mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  HashQueue,
                                  has_proxy=True,
                                  logger=mock_logger
                                  )
        mock_swift.get_object.side_effect = ClientException("fail to download")
        with self.assertRaises(ClientException) as ar:
            data_no = store.download(TIER_1,
                                 self.user_id,
                                 self.uuid,
                                 chunk_size=512,
                                 path_format=self.path_format
                                 )

            data_yes = store.download(TIER_1,
                                 self.user_id,
                                 self.uuid,
                                 container="anan",
                                 chunk_size=512,
                                 path_format=self.path_format
                                 )
        self.assertIsInstance(ar.exception, ClientException)
        self.assertEqual("fail to download", str(ar.exception))
 def test_upload_swift_client_exception(self, mock_redis,
                                        mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     mock_swift.put_object.side_effect = ClientException("fail to upload")
     with self.assertRaises(ClientException) as ar:
         container_no = store.upload(TIER_1,
                                     self.user_id,
                                     self.uuid,
                                     self.data,
                                     ctype="image/jpeg",
                                     chunk_size=512,
                                     path_format=self.path_format
                                     )
         container_yes = store.upload(TIER_1,
                                      self.user_id,
                                      self.uuid,
                                      self.data,
                                      container="anan",
                                      ctype="image/jpeg",
                                      chunk_size=512,
                                      path_format=self.path_format
                                      )
         self.assertIsNotNone(container_no)
         self.assertIsNotNone(container_yes)
     self.assertIsInstance(ar.exception, ClientException)
     self.assertEqual("fail to upload", str(ar.exception))
Example #6
0
 def test_download_failover_new_redis_driver(self, mock_redis, mock_swift,
                                             mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger)
     exceptions = (ConnectionError, TimeoutError)
     mock_swift.get_object.return_value = 1, self.data
     for ex in exceptions:
         store.tier_0.queue.dequeue.side_effect = ex
         # w/o specified container
         data_no = store.download(TIER_0,
                                  self.user_id,
                                  self.uuid,
                                  chunk_size=512,
                                  path_format=self.path_format)
         # w/ specified container
         data_yes = store.download(TIER_0,
                                   self.user_id,
                                   self.uuid,
                                   container="anan",
                                   chunk_size=512,
                                   path_format=self.path_format)
         self.assertEqual(data_no, self.data)
         self.assertEqual(data_yes, self.data)
 def test_upload_failover_new_redis_driver(self, mock_redis,
                                           mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger
                               )
     exceptions = (ConnectionError, TimeoutError)
     for ex in exceptions:
         store.tier_0.queue.enqueue.side_effect = ex
         # w/o specified container
         container_no = store.upload(TIER_0,
                              self.user_id,
                              self.uuid,
                              self.data,
                              ctype="image/jpeg",
                              chunk_size=512,
                              path_format=self.path_format
                              )
         # w/ specified container
         container_yes = store.upload(TIER_0,
                                  self.user_id,
                                  self.uuid,
                                  self.data,
                                  container="anan",
                                  ctype="image/jpeg",
                                  chunk_size=512,
                                  path_format=self.path_format
                                  )
         self.assertIsNotNone(container_no)
         self.assertIsNotNone(container_yes)
         self.assertEqual(container_yes, "anan")
Example #8
0
 def test_upload_failover_new_redis_driver(self, mock_redis, mock_swift,
                                           mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger)
     exceptions = (ConnectionError, TimeoutError)
     for ex in exceptions:
         store.tier_0.queue.enqueue.side_effect = ex
         # w/o specified container
         container_no = store.upload(TIER_0,
                                     self.user_id,
                                     self.uuid,
                                     self.data,
                                     ctype="image/jpeg",
                                     chunk_size=512,
                                     path_format=self.path_format)
         # w/ specified container
         container_yes = store.upload(TIER_0,
                                      self.user_id,
                                      self.uuid,
                                      self.data,
                                      container="anan",
                                      ctype="image/jpeg",
                                      chunk_size=512,
                                      path_format=self.path_format)
         self.assertIsNotNone(container_no)
         self.assertIsNotNone(container_yes)
         self.assertEqual(container_yes, "anan")
Example #9
0
 def test_upload_to_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger)
     store.tier_0.queue.enqueue.return_value = 1
     container = store.upload(TIER_0, self.user_id, self.uuid, self.data)
     self.assertIsNone(container)
Example #10
0
 def test_delete_from_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     mock_swift.delete_object.return_value = None
     rt = store.delete(TIER_1,
                       self.user_id,
                       self.uuid,
                       container="anan",
                       path_format=self.path_format)
     self.assertIsNone(rt)
 def test_delete_from_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger
                               )
     store.tier_0.queue.release.return_value = 1, 10
     len, total_len = store.delete(TIER_0,
                              self.user_id,
                              self.uuid,
                              )
     self.assertEqual(len, 1)
     self.assertEqual(total_len, 10)
 def test_download_from_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger
                               )
     store.tier_0.queue.dequeue.return_value = 1, self.data
     k, data = store.download(TIER_0,
                              self.user_id,
                              self.uuid,
                              )
     self.assertEqual(k, 1)
     self.assertEqual(data, self.data)
 def test_upload_to_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger
                               )
     store.tier_0.queue.enqueue.return_value = 1
     container = store.upload(TIER_0,
                              self.user_id,
                              self.uuid,
                              self.data
                              )
     self.assertIsNone(container)
Example #14
0
 def test_download_from_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger)
     store.tier_0.queue.dequeue.return_value = 1, self.data
     k, data = store.download(
         TIER_0,
         self.user_id,
         self.uuid,
     )
     self.assertEqual(k, 1)
     self.assertEqual(data, self.data)
Example #15
0
 def test_delete_from_redis(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(spec=HashQueue),
                               has_proxy=True,
                               logge=mock_logger)
     store.tier_0.queue.release.return_value = 1, 10
     len, total_len = store.delete(
         TIER_0,
         self.user_id,
         self.uuid,
     )
     self.assertEqual(len, 1)
     self.assertEqual(total_len, 10)
 def test_delete_from_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     mock_swift.delete_object.return_value = None
     rt = store.delete(TIER_1,
                       self.user_id,
                       self.uuid,
                       container="anan",
                       path_format=self.path_format
                       )
     self.assertIsNone(rt)
Example #17
0
 def test_download_from_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     mock_swift.get_object.return_value = Mock(), self.data
     data = store.download(TIER_1,
                           self.user_id,
                           self.uuid,
                           ctype="image/jpeg",
                           container="anan",
                           chunk_size=512,
                           path_format=self.path_format)
     self.assertEqual(data, self.data)
Example #18
0
 def test_upload_to_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     container = store.upload(TIER_1,
                              self.user_id,
                              self.uuid,
                              self.data,
                              ctype="image/jpeg",
                              container="anan",
                              chunk_size=512,
                              path_format=self.path_format)
     self.assertIsNotNone(container)
     self.assertEqual(container, 'anan')
Example #19
0
 def test_delete_from_unkown_tier(self, mock_redis, mock_swift,
                                  mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     fake_tiers = (-1, 3, "tier", 2.0, None)
     for tier in fake_tiers:
         with self.assertRaises(ValueError) as ar:
             store.delete(tier,
                          self.user_id,
                          self.uuid,
                          path_format=self.path_format)
         self.assertIsInstance(ar.exception, ValueError)
         self.assertEqual("tier '{}' is not supported!".format(tier),
                          str(ar.exception))
 def test_download_from_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     mock_swift.get_object.return_value = Mock(), self.data
     data = store.download(TIER_1,
                              self.user_id,
                              self.uuid,
                              ctype="image/jpeg",
                              container="anan",
                              chunk_size=512,
                              path_format=self.path_format
                              )
     self.assertEqual(data, self.data)
Example #21
0
    def test_delete_release_error(self, mock_redis, mock_swift, mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  Mock(spec=HashQueue),
                                  has_proxy=True,
                                  logger=mock_logger)

        store.tier_0.queue.release.side_effect = ERedisReleaseError(self.uuid)
        with self.assertRaises(ERedisReleaseError) as ar:
            store.delete(TIER_0,
                         self.user_id,
                         self.uuid,
                         path_format=self.path_format)
        self.assertIsInstance(ar.exception, ERedisReleaseError)
        self.assertEqual(
            "Redis Error: Key {} has not been dequeued!".format(self.uuid),
            str(ar.exception))
 def test_upload_to_swift(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     container = store.upload(TIER_1,
                              self.user_id,
                              self.uuid,
                              self.data,
                              ctype="image/jpeg",
                              container="anan",
                              chunk_size=512,
                              path_format=self.path_format
                              )
     self.assertIsNotNone(container)
     self.assertEqual(container, 'anan')
Example #23
0
 def test_upload_to_unkown_tier(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger)
     fake_tiers = (-1, 3, "tier", 2.0, None)
     for tier in fake_tiers:
         with self.assertRaises(ValueError) as ar:
             container_no = store.upload(tier,
                                         self.user_id,
                                         self.uuid,
                                         self.data,
                                         ctype="image/jpeg",
                                         chunk_size=512,
                                         path_format=self.path_format)
         self.assertIsInstance(ar.exception, ValueError)
         self.assertEqual("tier '{}' is not supported!".format(tier),
                          str(ar.exception))
 def test_delete_from_unkown_tier(self, mock_redis,
                                    mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     fake_tiers = (-1, 3, "tier", 2.0, None)
     for tier in fake_tiers:
         with self.assertRaises(ValueError) as ar:
             store.delete(tier,
                          self.user_id,
                          self.uuid,
                          path_format=self.path_format
                          )
         self.assertIsInstance(ar.exception, ValueError)
         self.assertEqual("tier '{}' is not supported!".format(tier),
                          str(ar.exception))
    def test_delete_release_error(self, mock_redis,
                                       mock_swift, mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  Mock(spec=HashQueue),
                                  has_proxy=True,
                                  logger=mock_logger
                                  )

        store.tier_0.queue.release.side_effect = ERedisReleaseError(self.uuid)
        with self.assertRaises(ERedisReleaseError) as ar:
            store.delete(TIER_0,
                         self.user_id,
                         self.uuid,
                         path_format=self.path_format
                         )
        self.assertIsInstance(ar.exception, ERedisReleaseError)
        self.assertEqual("Redis Error: Key {} has not been dequeued!"
                         .format(self.uuid), str(ar.exception))
 def test_upload_to_unkown_tier(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               HashQueue,
                               has_proxy=True,
                               logger=mock_logger
                               )
     fake_tiers = (-1, 3, "tier", 2.0, None)
     for tier in fake_tiers:
         with self.assertRaises(ValueError) as ar:
             container_no = store.upload(tier,
                                         self.user_id,
                                         self.uuid,
                                         self.data,
                                         ctype="image/jpeg",
                                         chunk_size=512,
                                         path_format=self.path_format
                                         )
         self.assertIsInstance(ar.exception, ValueError)
         self.assertEqual("tier '{}' is not supported!".format(tier),
                          str(ar.exception))
Example #27
0
    def test_download_swift_client_exception(self, mock_redis, mock_swift,
                                             mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  HashQueue,
                                  has_proxy=True,
                                  logger=mock_logger)
        mock_swift.get_object.side_effect = ClientException("fail to download")
        with self.assertRaises(ClientException) as ar:
            data_no = store.download(TIER_1,
                                     self.user_id,
                                     self.uuid,
                                     chunk_size=512,
                                     path_format=self.path_format)

            data_yes = store.download(TIER_1,
                                      self.user_id,
                                      self.uuid,
                                      container="anan",
                                      chunk_size=512,
                                      path_format=self.path_format)
        self.assertIsInstance(ar.exception, ClientException)
        self.assertEqual("fail to download", str(ar.exception))
Example #28
0
 def test_delete_failover(self, mock_redis, mock_swift, mock_logger):
     store = PolarisStageStore(mock_redis,
                               mock_swift,
                               Mock(sepc=HashQueue),
                               has_proxy=True,
                               logger=mock_logger)
     exceptions = (ConnectionError, ERedisReleaseError, ERedisKeyNotFound)
     mock_swift.delete_object.return_value = None
     for ex in exceptions:
         store.tier_0.queue.release.side_effect = ex
         # w/o specified container
         rt_no = store.delete(TIER_0,
                              self.user_id,
                              self.uuid,
                              path_format=self.path_format)
         # w/ specified container
         rt_yes = store.delete(TIER_0,
                               self.user_id,
                               self.uuid,
                               container="anan",
                               path_format=self.path_format)
         self.assertIsNone(rt_no)
         self.assertIsNone(rt_yes)
    def test_delete_swift_client_exception(self, mock_redis,
                                           mock_swift, mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  HashQueue,
                                  has_proxy=True,
                                  logger=mock_logger
                                  )
        mock_swift.delete_object.side_effect = ClientException("fail to delete")
        with self.assertRaises(ClientException) as ar:
            store.delete(TIER_1,
                         self.user_id,
                         self.uuid,
                         path_format=self.path_format
                         )

            store.delete(TIER_1,
                         self.user_id,
                         self.uuid,
                         container="anan",
                         path_format=self.path_format
                         )
        self.assertIsInstance(ar.exception, ClientException)
        self.assertEqual("fail to delete", str(ar.exception))
Example #30
0
    def test_delete_swift_client_exception(self, mock_redis, mock_swift,
                                           mock_logger):
        store = PolarisStageStore(mock_redis,
                                  mock_swift,
                                  HashQueue,
                                  has_proxy=True,
                                  logger=mock_logger)
        mock_swift.delete_object.side_effect = ClientException(
            "fail to delete")
        with self.assertRaises(ClientException) as ar:
            store.delete(TIER_1,
                         self.user_id,
                         self.uuid,
                         path_format=self.path_format)

            store.delete(TIER_1,
                         self.user_id,
                         self.uuid,
                         container="anan",
                         path_format=self.path_format)
        self.assertIsInstance(ar.exception, ClientException)
        self.assertEqual("fail to delete", str(ar.exception))