Skip to content

Commit ea35805

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "stop image downloads to memory"
2 parents d4a0bcf + 5bdcd59 commit ea35805

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

openstackclient/image/v1/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,11 @@ def take_action(self, parsed_args):
478478
image_client = self.app.client_manager.image
479479
image = image_client.find_image(parsed_args.image)
480480

481-
image_client.download_image(image.id, output=parsed_args.file)
481+
output_file = parsed_args.file
482+
if output_file is None:
483+
output_file = getattr(sys.stdout, "buffer", sys.stdout)
484+
485+
image_client.download_image(image.id, stream=True, output=output_file)
482486

483487

484488
class SetImage(command.Command):

openstackclient/image/v2/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,11 @@ def take_action(self, parsed_args):
803803
image_client = self.app.client_manager.image
804804
image = image_client.find_image(parsed_args.image)
805805

806-
image_client.download_image(image.id, output=parsed_args.file)
806+
output_file = parsed_args.file
807+
if output_file is None:
808+
output_file = getattr(sys.stdout, "buffer", sys.stdout)
809+
810+
image_client.download_image(image.id, stream=True, output=output_file)
807811

808812

809813
class SetImage(command.Command):

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,14 +1618,15 @@ def test_save_data(self):
16181618

16191619
verifylist = [
16201620
('file', '/path/to/file'),
1621-
('image', self.image.id)
1621+
('image', self.image.id),
16221622
]
16231623
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
16241624

16251625
self.cmd.take_action(parsed_args)
16261626

16271627
self.client.download_image.assert_called_once_with(
16281628
self.image.id,
1629+
stream=True,
16291630
output='/path/to/file')
16301631

16311632

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- Stream image download to avoid buffering data in memory which rapidly
4+
exhausts memory resulting in OOM kill or system crash for all but the
5+
smallest of images. Fixes https://storyboard.openstack.org/#!/story/2007672
6+
- Restore default behavior of 'openstack image save' to send data to stdout
7+
Relates to https://storyboard.openstack.org/#!/story/2007672.

0 commit comments

Comments
 (0)