summaryrefslogtreecommitdiff
blob: 5b697741e40850f50d936f7896e40c154035bb04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 88f92eb11d556bf43e2800a05973ad2da0db0195 Mon Sep 17 00:00:00 2001
From: Flavio Percoco <flaper87@gmail.com>
Date: Fri, 8 May 2015 11:44:14 +0200
Subject: [PATCH] Save image data after setting the data

The image's locations are missing when image's are imported using tasks
because the ImportToStore task is not saving the image metadata after
the import. This patch fixes that.

Change-Id: I43dec450d5fc4bee2131d78dbe3c2b2373c3f739
Closes-bug: #1453068
(cherry picked from commit 4efb56aae9288952bdb0d368a7c307e8524b80d8)
---
 glance/async/flows/base_import.py            | 4 ++++
 glance/tests/unit/async/flows/test_import.py | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/glance/async/flows/base_import.py b/glance/async/flows/base_import.py
index 487247c..7656bde 100644
--- a/glance/async/flows/base_import.py
+++ b/glance/async/flows/base_import.py
@@ -283,6 +283,10 @@ class _ImportToStore(task.Task):
 
         image_import.set_image_data(image, file_path or self.uri, None)
 
+        # NOTE(flaper87): We need to save the image again after the locations
+        # have been set in the image.
+        self.image_repo.save(image)
+
 
 class _SaveImage(task.Task):
 
diff --git a/glance/tests/unit/async/flows/test_import.py b/glance/tests/unit/async/flows/test_import.py
index 0f355bc..7acd599 100644
--- a/glance/tests/unit/async/flows/test_import.py
+++ b/glance/tests/unit/async/flows/test_import.py
@@ -112,6 +112,10 @@ class TestImportTask(test_utils.BaseTestCase):
                                           "%s.tasks_import" % image_path)
             self.assertFalse(os.path.exists(tmp_image_path))
             self.assertTrue(os.path.exists(image_path))
+            self.assertEqual(1, len(list(self.image.locations)))
+            self.assertEqual("file://%s/%s" % (self.test_dir,
+                                               self.image.image_id),
+                             self.image.locations[0]['url'])
 
     def test_import_flow_missing_work_dir(self):
         self.config(engine_mode='serial', group='taskflow_executor')
-- 
2.3.6