Merge "Add support for network template delete for v1"

This commit is contained in:
Jenkins
2015-08-06 16:57:47 +00:00
committed by Gerrit Code Review
2 changed files with 31 additions and 1 deletions

View File

@@ -104,11 +104,14 @@ class NetworkTemplateAction(Action):
"Download current network template configuration."),
Args.get_upload_arg(
"Upload changed network template configuration."),
Args.get_delete_arg(
"Delete network template configuration."),
required=True))
self.flag_func_map = (
("upload", self.upload),
("download", self.download))
("download", self.download),
("delete", self.delete))
def upload(self, params):
"""Uploads network template from filesystem path
@@ -138,3 +141,13 @@ class NetworkTemplateAction(Action):
print("Network template configuration for environment with id={0}"
" downloaded to {1}".format(env.id, network_template_file_path))
def delete(self, params):
"""Deletes network template for specified environment:
fuel --env 1 --network-template --delete
"""
env = Environment(params.env)
env.delete_network_template_data()
print("Network template configuration for environment id={0}"
" has been deleted.".format(env.id))

View File

@@ -17,6 +17,7 @@
import json
import mock
import requests_mock
import six
import yaml
from fuelclient.tests import base
@@ -147,3 +148,19 @@ class TestNetworkTemplate(base.UnitTestCase):
written_yaml = yaml.safe_load(m_open().write.mock_calls[0][1][0])
expected_yaml = yaml.safe_load(YAML_TEMPLATE)
self.assertEqual(written_yaml, expected_yaml)
def test_delete_action(self):
self.mocker.delete(self.req_path, json={})
cmd = ['fuel', 'network-template', '--env', str(self.env_id),
'--delete']
with mock.patch('sys.stdout', new=six.StringIO()) as m_out:
self.execute(cmd)
self.assertEqual(self.mocker.last_request.method, 'DELETE')
self.assertEqual(self.mocker.last_request.path, self.req_path)
msg = ("Network template configuration for environment id={0}"
" has been deleted.".format(self.env_id))
self.assertIn(msg, m_out.getvalue())