Added --rmdir flag to workspace remove
* tempest workspace remove --name command just remove the workspace entry from ~/.tempest/workspace.yaml and it does not deletes the workspace. * by adding tempest workspace remove --name --rmdir removes the workspace as well as entry. * renamed remove_workspace to remove_workspace_entry Change-Id: I4528a23ca4933fdb7a3168f8dc99bbf0497ae5cc
This commit is contained in:
parent
08688c6858
commit
b78e2575e0
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added tempest workspace remove --name <workspace_name> --rmdir
|
||||
feature to delete the workspace directory as well as entry.
|
@ -40,6 +40,8 @@ remove
|
||||
------
|
||||
Deletes the entry for a given tempest workspace --name
|
||||
|
||||
--rmdir Deletes the given tempest workspace directory
|
||||
|
||||
General Options
|
||||
===============
|
||||
|
||||
@ -49,6 +51,7 @@ General Options
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from cliff import command
|
||||
@ -102,11 +105,16 @@ class WorkspaceManager(object):
|
||||
sys.exit(1)
|
||||
|
||||
@lockutils.synchronized('workspaces', external=True)
|
||||
def remove_workspace(self, name):
|
||||
def remove_workspace_entry(self, name):
|
||||
self._populate()
|
||||
self._name_exists(name)
|
||||
self.workspaces.pop(name)
|
||||
workspace_path = self.workspaces.pop(name)
|
||||
self._write_file()
|
||||
return workspace_path
|
||||
|
||||
@lockutils.synchronized('workspaces', external=True)
|
||||
def remove_workspace_directory(self, workspace_path):
|
||||
shutil.rmtree(workspace_path)
|
||||
|
||||
@lockutils.synchronized('workspaces', external=True)
|
||||
def list_workspaces(self):
|
||||
@ -226,12 +234,16 @@ class TempestWorkspaceRemove(command.Command):
|
||||
parser = super(TempestWorkspaceRemove, self).get_parser(prog_name)
|
||||
add_global_arguments(parser)
|
||||
parser.add_argument('--name', required=True)
|
||||
parser.add_argument('--rmdir', action='store_true',
|
||||
help='Deletes the given workspace directory')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.manager = WorkspaceManager(parsed_args.workspace_path)
|
||||
self.manager.remove_workspace(parsed_args.name)
|
||||
workspace_path = self.manager.remove_workspace_entry(parsed_args.name)
|
||||
if parsed_args.rmdir:
|
||||
self.manager.remove_workspace_directory(workspace_path)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
@ -80,13 +80,20 @@ class TestTempestWorkspace(TestTempestWorkspaceBase):
|
||||
self.assertEqual(
|
||||
self.workspace_manager.get_workspace(self.name), new_path)
|
||||
|
||||
def test_run_workspace_remove(self):
|
||||
def test_run_workspace_remove_entry(self):
|
||||
cmd = ['tempest', 'workspace', 'remove',
|
||||
'--workspace-path', self.store_file,
|
||||
'--name', self.name]
|
||||
self._run_cmd_gets_return_code(cmd, 0)
|
||||
self.assertIsNone(self.workspace_manager.get_workspace(self.name))
|
||||
|
||||
def test_run_workspace_remove_directory(self):
|
||||
cmd = ['tempest', 'workspace', 'remove',
|
||||
'--workspace-path', self.store_file,
|
||||
'--name', self.name, '--rmdir']
|
||||
self._run_cmd_gets_return_code(cmd, 0)
|
||||
self.assertIsNone(self.workspace_manager.get_workspace(self.name))
|
||||
|
||||
|
||||
class TestTempestWorkspaceManager(TestTempestWorkspaceBase):
|
||||
def setUp(self):
|
||||
@ -117,8 +124,13 @@ class TestTempestWorkspaceManager(TestTempestWorkspaceBase):
|
||||
self.assertEqual(
|
||||
self.workspace_manager.get_workspace(self.name), new_path)
|
||||
|
||||
def test_workspace_manager_remove(self):
|
||||
self.workspace_manager.remove_workspace(self.name)
|
||||
def test_workspace_manager_remove_entry(self):
|
||||
self.workspace_manager.remove_workspace_entry(self.name)
|
||||
self.assertIsNone(self.workspace_manager.get_workspace(self.name))
|
||||
|
||||
def test_workspace_manager_remove_directory(self):
|
||||
path = self.workspace_manager.remove_workspace_entry(self.name)
|
||||
self.workspace_manager.remove_workspace_directory(path)
|
||||
self.assertIsNone(self.workspace_manager.get_workspace(self.name))
|
||||
|
||||
def test_path_expansion(self):
|
||||
|
Loading…
Reference in New Issue
Block a user