diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index a1056867..9457f808 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -1844,6 +1844,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 e791b765..0a119b4f 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -177,6 +177,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'),