~rlane/nova/lp773690

« back to all changes in this revision

Viewing changes to nova/image/fake.py

  • Committer: rlane at wikimedia
  • Date: 2011-04-29 22:30:40 UTC
  • mfrom: (382.1.655 nova)
  • Revision ID: rlane@wikimedia.org-20110429223040-i0x3ds9eqwrabyru
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
15
#    License for the specific language governing permissions and limitations
16
16
#    under the License.
 
17
 
17
18
"""Implementation of an fake image service"""
18
19
 
19
20
import copy
47
48
                 'container_format': 'ami',
48
49
                 'disk_format': 'raw',
49
50
                 'properties': {'kernel_id': FLAGS.null_kernel,
50
 
                                'ramdisk_id': FLAGS.null_kernel}
51
 
                }
 
51
                                'ramdisk_id': FLAGS.null_kernel}}
52
52
        self.create(None, image)
53
53
        super(FakeImageService, self).__init__()
54
54
 
70
70
        image = self.images.get(image_id)
71
71
        if image:
72
72
            return copy.deepcopy(image)
73
 
        LOG.warn("Unable to find image id %s.  Have images: %s",
 
73
        LOG.warn('Unable to find image id %s.  Have images: %s',
74
74
                 image_id, self.images)
75
 
        raise exception.NotFound
 
75
        raise exception.ImageNotFound(image_id=image_id)
76
76
 
77
77
    def create(self, context, data):
78
78
        """Store the image data and return the new image id.
79
79
 
80
 
        :raises Duplicate if the image already exist.
 
80
        :raises: Duplicate if the image already exist.
81
81
 
82
82
        """
83
83
        image_id = int(data['id'])
89
89
    def update(self, context, image_id, data):
90
90
        """Replace the contents of the given image with the new data.
91
91
 
92
 
        :raises NotFound if the image does not exist.
 
92
        :raises: ImageNotFound if the image does not exist.
93
93
 
94
94
        """
95
95
        image_id = int(image_id)
96
96
        if not self.images.get(image_id):
97
 
            raise exception.NotFound
 
97
            raise exception.ImageNotFound(image_id=image_id)
98
98
        self.images[image_id] = copy.deepcopy(data)
99
99
 
100
100
    def delete(self, context, image_id):
101
101
        """Delete the given image.
102
102
 
103
 
        :raises NotFound if the image does not exist.
 
103
        :raises: ImageNotFound if the image does not exist.
104
104
 
105
105
        """
106
106
        image_id = int(image_id)
107
107
        removed = self.images.pop(image_id, None)
108
108
        if not removed:
109
 
            raise exception.NotFound
 
109
            raise exception.ImageNotFound(image_id=image_id)
110
110
 
111
111
    def delete_all(self):
112
112
        """Clears out all images."""