Exemplo n.º 1
0
 def test_lifecycle_translation(self):
     """Tests lifecycle translation for various formats."""
     json_text = self.lifecycle_doc
     entries_list = LifecycleTranslation.JsonLifecycleToMessage(json_text)
     boto_lifecycle = LifecycleTranslation.BotoLifecycleFromMessage(
         entries_list)
     converted_entries_list = LifecycleTranslation.BotoLifecycleToMessage(
         boto_lifecycle)
     converted_json_text = LifecycleTranslation.JsonLifecycleFromMessage(
         converted_entries_list)
     self.assertEqual(json.loads(json_text),
                      json.loads(converted_json_text))
Exemplo n.º 2
0
  def test_lifecycle_translation(self):
    """Tests lifecycle translation for various formats."""
    # TODO: Use lifecycle_doc again once Boto is updated to support new fields.
    # json_text = self.lifecycle_doc
    json_text = self.lifecycle_doc_without_storage_class_fields

    entries_list = LifecycleTranslation.JsonLifecycleToMessage(json_text)
    boto_lifecycle = LifecycleTranslation.BotoLifecycleFromMessage(entries_list)
    converted_entries_list = LifecycleTranslation.BotoLifecycleToMessage(
        boto_lifecycle)
    converted_json_text = LifecycleTranslation.JsonLifecycleFromMessage(
        converted_entries_list)
    self.assertEqual(json.loads(json_text), json.loads(converted_json_text))
Exemplo n.º 3
0
  def _GetLifecycleConfig(self):
    """Gets lifecycle configuration for a Google Cloud Storage bucket."""
    bucket_url, bucket_metadata = self.GetSingleBucketUrlFromArg(
        self.args[0], bucket_fields=['lifecycle'])

    if bucket_url.scheme == 's3':
      sys.stdout.write(self.gsutil_api.XmlPassThroughGetLifecycle(
          bucket_url, provider=bucket_url.scheme))
    else:
      if bucket_metadata.lifecycle and bucket_metadata.lifecycle.rule:
        sys.stdout.write(LifecycleTranslation.JsonLifecycleFromMessage(
            bucket_metadata.lifecycle))
      else:
        sys.stdout.write('%s has no lifecycle configuration.\n' % bucket_url)

    return 0