From c2d40fe05c373428ff4edd04904aec5152a0b695 Mon Sep 17 00:00:00 2001 From: neetu Date: Wed, 13 Jan 2016 15:36:37 -0600 Subject: [PATCH] Validate for empty file for stack-adopt Check if adopt-file has content and if not then display error Change-Id: I40efd6ae3ca36f0331a1e4239c5139e0af654272 Closes-Bug: #1299161 --- heatclient/tests/unit/test_shell.py | 10 ++++++++++ heatclient/v1/shell.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index 908f4b7a..04503bf7 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -1765,6 +1765,16 @@ class ShellTestUserPass(ShellBase): self.shell_error('stack-adopt teststack ', failed_msg, exception=exc.CommandError) + def test_stack_adopt_empty_data_file(self): + failed_msg = 'Invalid adopt-file, no data!' + self.register_keystone_auth_fixture() + self.m.ReplayAll() + with tempfile.NamedTemporaryFile() as file_obj: + self.shell_error( + 'stack-adopt teststack ' + '--adopt-file=%s ' % (file_obj.name), + failed_msg, exception=exc.CommandError) + def test_stack_update_enable_rollback(self): self.register_keystone_auth_fixture() template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 1e8a69af..5a33dc79 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -202,6 +202,9 @@ def do_stack_adopt(hc, args): adopt_url = utils.normalise_file_path_to_url(args.adopt_file) adopt_data = request.urlopen(adopt_url).read() + if not len(adopt_data): + raise exc.CommandError('Invalid adopt-file, no data!') + if args.create_timeout: logger.warning(_LW('%(arg1)s is deprecated, ' 'please use %(arg2)s instead'),