Added invalid id exceptions when filtering snapshots and volumes
This commit is contained in:
parent
298772ca92
commit
08c4eff0b2
@ -1775,11 +1775,17 @@ class EBSBackend(object):
|
|||||||
self.volumes[volume_id] = volume
|
self.volumes[volume_id] = volume
|
||||||
return volume
|
return volume
|
||||||
|
|
||||||
def describe_volumes(self, filters=None):
|
def describe_volumes(self, volume_ids=None, filters=None):
|
||||||
|
matches = self.volumes.values()
|
||||||
|
if volume_ids:
|
||||||
|
matches = [vol for vol in matches
|
||||||
|
if vol.id in volume_ids]
|
||||||
|
if len(volume_ids) > len(matches):
|
||||||
|
unknown_ids = set(volume_ids) - set(matches)
|
||||||
|
raise InvalidVolumeIdError(unknown_ids)
|
||||||
if filters:
|
if filters:
|
||||||
volumes = self.volumes.values()
|
matches = generic_filter(filters, matches)
|
||||||
return generic_filter(filters, volumes)
|
return matches
|
||||||
return self.volumes.values()
|
|
||||||
|
|
||||||
def get_volume(self, volume_id):
|
def get_volume(self, volume_id):
|
||||||
volume = self.volumes.get(volume_id, None)
|
volume = self.volumes.get(volume_id, None)
|
||||||
@ -1827,11 +1833,17 @@ class EBSBackend(object):
|
|||||||
self.snapshots[snapshot_id] = snapshot
|
self.snapshots[snapshot_id] = snapshot
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
def describe_snapshots(self, filters=None):
|
def describe_snapshots(self, snapshot_ids=None, filters=None):
|
||||||
|
matches = self.snapshots.values()
|
||||||
|
if snapshot_ids:
|
||||||
|
matches = [vol for vol in matches
|
||||||
|
if vol.id in snapshot_ids]
|
||||||
|
if len(snapshot_ids) > len(matches):
|
||||||
|
unknown_ids = set(snapshot_ids) - set(matches)
|
||||||
|
raise InvalidSnapshotIdError(unknown_ids)
|
||||||
if filters:
|
if filters:
|
||||||
snapshots = self.snapshots.values()
|
matches = generic_filter(filters, matches)
|
||||||
return generic_filter(filters, snapshots)
|
return matches
|
||||||
return self.snapshots.values()
|
|
||||||
|
|
||||||
def get_snapshot(self, snapshot_id):
|
def get_snapshot(self, snapshot_id):
|
||||||
snapshot = self.snapshots.get(snapshot_id, None)
|
snapshot = self.snapshots.get(snapshot_id, None)
|
||||||
|
@ -54,20 +54,14 @@ class ElasticBlockStore(BaseResponse):
|
|||||||
def describe_snapshots(self):
|
def describe_snapshots(self):
|
||||||
filters = filters_from_querystring(self.querystring)
|
filters = filters_from_querystring(self.querystring)
|
||||||
snapshot_ids = self._get_multi_param('SnapshotId')
|
snapshot_ids = self._get_multi_param('SnapshotId')
|
||||||
snapshots = self.ec2_backend.describe_snapshots(filters=filters)
|
snapshots = self.ec2_backend.describe_snapshots(snapshot_ids=snapshot_ids, filters=filters)
|
||||||
# Describe snapshots to handle filter on snapshot_ids
|
|
||||||
snapshots = [
|
|
||||||
s for s in snapshots if s.id in snapshot_ids] if snapshot_ids else snapshots
|
|
||||||
template = self.response_template(DESCRIBE_SNAPSHOTS_RESPONSE)
|
template = self.response_template(DESCRIBE_SNAPSHOTS_RESPONSE)
|
||||||
return template.render(snapshots=snapshots)
|
return template.render(snapshots=snapshots)
|
||||||
|
|
||||||
def describe_volumes(self):
|
def describe_volumes(self):
|
||||||
filters = filters_from_querystring(self.querystring)
|
filters = filters_from_querystring(self.querystring)
|
||||||
volume_ids = self._get_multi_param('VolumeId')
|
volume_ids = self._get_multi_param('VolumeId')
|
||||||
volumes = self.ec2_backend.describe_volumes(filters=filters)
|
volumes = self.ec2_backend.describe_volumes(volume_ids=volume_ids, filters=filters)
|
||||||
# Describe volumes to handle filter on volume_ids
|
|
||||||
volumes = [
|
|
||||||
v for v in volumes if v.id in volume_ids] if volume_ids else volumes
|
|
||||||
template = self.response_template(DESCRIBE_VOLUMES_RESPONSE)
|
template = self.response_template(DESCRIBE_VOLUMES_RESPONSE)
|
||||||
return template.render(volumes=volumes)
|
return template.render(volumes=volumes)
|
||||||
|
|
||||||
|
@ -83,6 +83,12 @@ def test_filter_volume_by_id():
|
|||||||
vol2 = conn.get_all_volumes(volume_ids=[volume1.id, volume2.id])
|
vol2 = conn.get_all_volumes(volume_ids=[volume1.id, volume2.id])
|
||||||
vol2.should.have.length_of(2)
|
vol2.should.have.length_of(2)
|
||||||
|
|
||||||
|
with assert_raises(EC2ResponseError) as cm:
|
||||||
|
conn.get_all_volumes(volume_ids=['vol-does_not_exist'])
|
||||||
|
cm.exception.code.should.equal('InvalidVolume.NotFound')
|
||||||
|
cm.exception.status.should.equal(400)
|
||||||
|
cm.exception.request_id.should_not.be.none
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2_deprecated
|
@mock_ec2_deprecated
|
||||||
def test_volume_filters():
|
def test_volume_filters():
|
||||||
@ -302,6 +308,12 @@ def test_filter_snapshot_by_id():
|
|||||||
s.volume_id.should.be.within([volume2.id, volume3.id])
|
s.volume_id.should.be.within([volume2.id, volume3.id])
|
||||||
s.region.name.should.equal(conn.region.name)
|
s.region.name.should.equal(conn.region.name)
|
||||||
|
|
||||||
|
with assert_raises(EC2ResponseError) as cm:
|
||||||
|
conn.get_all_snapshots(snapshot_ids=['snap-does_not_exist'])
|
||||||
|
cm.exception.code.should.equal('InvalidSnapshot.NotFound')
|
||||||
|
cm.exception.status.should.equal(400)
|
||||||
|
cm.exception.request_id.should_not.be.none
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2_deprecated
|
@mock_ec2_deprecated
|
||||||
def test_snapshot_filters():
|
def test_snapshot_filters():
|
||||||
|
Loading…
Reference in New Issue
Block a user