Example #1
0
  def testDeleteSuccessful(self, exec_mock):
    """Tests successful Delete call."""
    target = 'c/d'
    env_ref = parsers.ParseEnvironment(self.TEST_ENVIRONMENT_NAME)

    self.ExpectEnvironmentGet(
        self.TEST_PROJECT,
        self.TEST_LOCATION,
        self.TEST_ENVIRONMENT_ID,
        response=self.MakeEnvironmentWithBucket())

    fake_exec = kubectl_util.FakeExec()
    exec_mock.side_effect = fake_exec

    fake_exec.AddCallback(
        0,
        self.MakeGsutilExecCallback(
            ['-m', 'rm', '-r',
             '{}/subdir/{}'.format(self.test_gcs_bucket_path, target)]))

    self.ExpectObjectGet(
        gcs_util.ObjectReference(self.test_gcs_bucket, 'subdir/'))

    storage_util.Delete(env_ref, target, 'subdir', release_track=self.track)
    fake_exec.Verify()
Example #2
0
 def Run(self, args):
     env_ref = args.CONCEPTS.environment.Parse()
     subtarget = '[{}] in '.format(args.target) if args.target else ''
     console_io.PromptContinue(
         'Recursively deleting all contents from {}the \'data/\' '
         'subdirectory of environment [{}]'.format(subtarget,
                                                   env_ref.RelativeName()),
         cancel_on_no=True)
     return storage_util.Delete(env_ref, args.target or '*', 'data')
Example #3
0
 def testDeleteTargetIsFile(self):
   env_ref = parsers.ParseEnvironment(self.TEST_ENVIRONMENT_NAME)
   self.ExpectEnvironmentGet(
       self.TEST_PROJECT,
       self.TEST_LOCATION,
       self.TEST_ENVIRONMENT_ID,
       response=self.MakeEnvironmentWithBucket())
   self.ExpectObjectGet(self.object_refs[0])
   self.ExpectObjectDelete(self.object_refs[0])
   self._ExpectEnsureSubdirExists()
   storage_util.Delete(env_ref, 'source/a.txt', 'dags')
Example #4
0
 def testDeleteTargetIsDir(self):
   env_ref = parsers.ParseEnvironment(self.TEST_ENVIRONMENT_NAME)
   self.ExpectEnvironmentGet(
       self.TEST_PROJECT,
       self.TEST_LOCATION,
       self.TEST_ENVIRONMENT_ID,
       response=self.MakeEnvironmentWithBucket())
   self._ExpectFailedGet(self.test_gcs_bucket, 'dags/source/b')
   self.ExpectObjectList(
       self.test_gcs_bucket, 'dags/source/b/',
       responses=[self.storage_messages.Objects(items=[self.objects[1]])])
   self.ExpectObjectDelete(self.object_refs[1])
   self._ExpectEnsureSubdirExists()
   storage_util.Delete(env_ref, 'source/b', 'dags')
Example #5
0
 def testDeleteStar(self):
   env_ref = parsers.ParseEnvironment(self.TEST_ENVIRONMENT_NAME)
   self.ExpectEnvironmentGet(
       self.TEST_PROJECT,
       self.TEST_LOCATION,
       self.TEST_ENVIRONMENT_ID,
       response=self.MakeEnvironmentWithBucket())
   # Star has a special meaning and tells the delete function to not try
   # and get the object. This is necessary because subdirs in the GCS buckets
   # are created as objects to ensure they exist.
   self.ExpectObjectList(
       self.test_gcs_bucket, 'dags/', responses=[self.list_response])
   for obj_ref in self.object_refs:
     self.ExpectObjectDelete(obj_ref)
   self._ExpectEnsureSubdirExists()
   storage_util.Delete(env_ref, '*', 'dags')
Example #6
0
 def _Callback():
   env_ref = parsers.ParseEnvironment(self.TEST_ENVIRONMENT_NAME)
   storage_util.Delete(env_ref, 'file', 'subdir', release_track=self.track)