Add 'fuel2 graph delete' command

Currently Nailgun supports DELETE deployment graph operation
3d1f96e529c62b34877216411fc7545b84666d4b. However
python-fuelclient doesn't implement this feature. This patch
adds 'fuel2 graph delete' command to support deployment graph
removal process:

 fuel2 graph delete [-h] (-e ENV | -r RELEASE | -p PLUGIN)
                    -t GRAPH_TYPE

DocImpact
Closes-Bug: 1624918

Change-Id: If49d4f10d404edbd04bb9f1a976b36de1cb1dcfe
This commit is contained in:
tivaliy 2016-09-21 21:23:09 +03:00
parent 9dfb28e33c
commit d4140d5472
5 changed files with 78 additions and 0 deletions

View File

@ -352,3 +352,53 @@ class GraphList(base.BaseListCommand):
scolumn_ids = [self.columns.index(col) for col in args.sort_columns]
data.sort(key=lambda x: [x[scolumn_id] for scolumn_id in scolumn_ids])
return self.columns, data
class GraphDelete(base.BaseCommand):
"""Delete deployment graph."""
entity_name = 'graph'
def get_parser(self, prog_name):
parser = super(GraphDelete, self).get_parser(prog_name)
graph_class = parser.add_mutually_exclusive_group(required=True)
graph_class.add_argument('-e',
'--environment',
type=int,
help='Id of the environment')
graph_class.add_argument('-r',
'--release',
type=int,
help='Id of the release')
graph_class.add_argument('-p',
'--plugin',
type=int,
help='Id of the plugin')
parser.add_argument('-t',
'--graph-type',
required=True,
help='Type of the deployment graph')
return parser
def take_action(self, parsed_args):
parameters_to_graph_class = (
('environment', 'clusters'),
('release', 'releases'),
('plugin', 'plugins'),
)
msg = ''
for parameter, graph_class in parameters_to_graph_class:
model_id = getattr(parsed_args, parameter)
if model_id:
self.client.delete(
related_model=graph_class,
related_id=model_id,
graph_type=parsed_args.graph_type
)
msg = ("Deployment graph '{0}' for {1} with id {2} was "
"deleted.\n".format(parsed_args.graph_type,
parameter,
model_id))
break
self.app.stdout.write(msg)

View File

@ -327,3 +327,14 @@ class TestGraphActions(test_engine.BaseCLITest):
mock.call(env_id=None, filters=['cluster']),
mock.call(env_id=None, filters=None)
])
def test_delete(self):
self._test_cmd(
'delete',
'--env 1 --graph-type custom_graph',
dict(
graph_type='custom_graph',
related_id=1,
related_model='clusters'
)
)

View File

@ -330,3 +330,13 @@ class TestDeploymentGraphFacade(test_api.BaseLibTest):
self.client.download(env_id=1, level='cluster',
graph_type='custom_graph')
self.assertTrue(matcher_get.called)
def test_graph_delete(self):
matcher_delete = self.m_request.delete(
'/api/v1/clusters/1/deployment_graphs/custom_graph',
json={}
)
self.client.delete(graph_type='custom_graph',
related_id=1,
related_model='clusters')
self.assertTrue(matcher_delete.called)

View File

@ -266,6 +266,12 @@ class GraphClient(base_v1.BaseV1Client):
return graphs_list
def delete(self, related_model, related_id, graph_type):
return self.connection.delete_request(
self.related_graph_api_path.format(related_model=related_model,
related_model_id=related_id,
graph_type=graph_type))
def get_client(connection):
return GraphClient(connection)

View File

@ -61,6 +61,7 @@ fuelclient =
env_update=fuelclient.commands.environment:EnvUpdate
extension_list=fuelclient.commands.extension:ExtensionList
fuel-version=fuelclient.commands.fuelversion:FuelVersion
graph_delete=fuelclient.commands.graph:GraphDelete
graph_download=fuelclient.commands.graph:GraphDownload
graph_execute=fuelclient.commands.graph:GraphExecute
graph_list=fuelclient.commands.graph:GraphList