Merge "cloud: Stop reimplementing ignore_missing=False"

This commit is contained in:
Zuul 2024-10-02 10:22:57 +00:00 committed by Gerrit Code Review
commit c6e857cf12
6 changed files with 20 additions and 107 deletions

View File

@ -142,12 +142,7 @@ class BlockStorageCloudMixin(openstackcloud._OpenStackCloudMixin):
) )
kwargs['imageRef'] = image['id'] kwargs['imageRef'] = image['id']
else: # object else: # object
image_obj = self.image.find_image(image, ignore_missing=True) image_obj = self.image.find_image(image, ignore_missing=False)
if not image_obj:
raise exceptions.SDKException(
f"Image {image} was requested as the basis for a new "
f"volume but was not found on the cloud"
)
kwargs['imageRef'] = image_obj['id'] kwargs['imageRef'] = image_obj['id']
kwargs = self._get_volume_kwargs(kwargs) kwargs = self._get_volume_kwargs(kwargs)
kwargs['size'] = size kwargs['size'] = size
@ -273,10 +268,8 @@ class BlockStorageCloudMixin(openstackcloud._OpenStackCloudMixin):
params = {} params = {}
if name_or_id: if name_or_id:
project = self.identity.find_project( project = self.identity.find_project(
name_or_id, ignore_missing=True name_or_id, ignore_missing=False
) )
if not project:
raise exceptions.SDKException("project does not exist")
params['project'] = project params['project'] = project
return self.block_storage.get_limits(**params) return self.block_storage.get_limits(**params)

View File

@ -384,13 +384,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
params = {} params = {}
if name_or_id: if name_or_id:
project = self.identity.find_project( project = self.identity.find_project(
name_or_id, ignore_missing=True name_or_id, ignore_missing=False
) )
if not project:
raise exceptions.SDKException(
f"Project {name_or_id} was requested but was not found "
f"on the cloud"
)
params['tenant_id'] = project.id params['tenant_id'] = project.id
return self.compute.get_limits(**params).absolute return self.compute.get_limits(**params).absolute
@ -432,13 +427,12 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
""" """
if not filters: if not filters:
filters = {} filters = {}
flavor = self.compute.find_flavor( return self.compute.find_flavor(
name_or_id, name_or_id,
get_extra_specs=get_extra, get_extra_specs=get_extra,
ignore_missing=True, ignore_missing=True,
**filters, **filters,
) )
return flavor
def get_flavor_by_id(self, id, get_extra=False): def get_flavor_by_id(self, id, get_extra=False):
"""Get a flavor by ID """Get a flavor by ID
@ -843,13 +837,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
group_id = group['id'] group_id = group['id']
else: # object else: # object
group_obj = self.compute.find_server_group( group_obj = self.compute.find_server_group(
group, ignore_missing=True group, ignore_missing=False
) )
if not group_obj:
raise exceptions.SDKException(
"Server Group {group} was requested but was not found"
" on the cloud".format(group=group)
)
group_id = group_obj['id'] group_id = group_obj['id']
if 'scheduler_hints' not in kwargs: if 'scheduler_hints' not in kwargs:
kwargs['scheduler_hints'] = {} kwargs['scheduler_hints'] = {}
@ -884,17 +873,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
network_id = net['id'] network_id = net['id']
else: else:
network_obj = self.network.find_network( network_obj = self.network.find_network(
net, ignore_missing=True net, ignore_missing=False
) )
if not network_obj:
raise exceptions.SDKException(
'Network {network} is not a valid network in'
' {cloud}:{region}'.format(
network=network,
cloud=self.name,
region=self._compute_region,
)
)
network_id = network_obj['id'] network_id = network_obj['id']
nics.append({'net-id': network_id}) nics.append({'net-id': network_id})
@ -915,14 +895,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
elif 'net-name' in nic: elif 'net-name' in nic:
net_name = nic.pop('net-name') net_name = nic.pop('net-name')
nic_net = self.network.find_network( nic_net = self.network.find_network(
net_name, ignore_missing=True net_name, ignore_missing=False
) )
if not nic_net:
raise exceptions.SDKException(
"Requested network {net} could not be found.".format(
net=net_name
)
)
net['uuid'] = nic_net['id'] net['uuid'] = nic_net['id']
for ip_key in ('v4-fixed-ip', 'v6-fixed-ip', 'fixed_ip'): for ip_key in ('v4-fixed-ip', 'v6-fixed-ip', 'fixed_ip'):
fixed_ip = nic.pop(ip_key, None) fixed_ip = nic.pop(ip_key, None)
@ -966,12 +940,7 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
) )
kwargs['imageRef'] = image['id'] kwargs['imageRef'] = image['id']
else: else:
image_obj = self.image.find_image(image, ignore_missing=True) image_obj = self.image.find_image(image, ignore_missing=False)
if not image_obj:
raise exc.OpenStackCloudException(
f"Image {image} was requested but was not found "
f"on the cloud"
)
kwargs['imageRef'] = image_obj.id kwargs['imageRef'] = image_obj.id
if isinstance(flavor, dict): if isinstance(flavor, dict):
@ -1083,13 +1052,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
volume_id = boot_volume['id'] volume_id = boot_volume['id']
else: else:
volume = self.block_storage.find_volume( volume = self.block_storage.find_volume(
boot_volume, ignore_missing=True boot_volume, ignore_missing=False
) )
if not volume:
raise exceptions.SDKException(
f"Volume {volume} was requested but was not found "
f"on the cloud"
)
volume_id = volume['id'] volume_id = volume['id']
block_mapping = { block_mapping = {
'boot_index': '0', 'boot_index': '0',
@ -1111,12 +1075,7 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
) )
image_obj = image image_obj = image
else: else:
image_obj = self.image.find_image(image, ignore_missing=True) image_obj = self.image.find_image(image, ignore_missing=False)
if not image_obj:
raise exceptions.SDKException(
f"Image {image} was requested but was not found "
f"on the cloud"
)
block_mapping = { block_mapping = {
'boot_index': '0', 'boot_index': '0',
@ -1153,13 +1112,8 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
volume_id = volume['id'] volume_id = volume['id']
else: else:
volume_obj = self.block_storage.find_volume( volume_obj = self.block_storage.find_volume(
volume, ignore_missing=True volume, ignore_missing=False
) )
if not volume_obj:
raise exceptions.SDKException(
f"Volume {volume} was requested but was not found "
f"on the cloud"
)
volume_id = volume_obj['id'] volume_id = volume_obj['id']
block_mapping = { block_mapping = {
'boot_index': '-1', 'boot_index': '-1',
@ -1879,14 +1833,9 @@ class ComputeCloudMixin(_network_common.NetworkCommonCloudMixin):
if isinstance(end, str): if isinstance(end, str):
end = parse_date(end) end = parse_date(end)
proj = self.identity.find_project(name_or_id, ignore_missing=True) project = self.identity.find_project(name_or_id, ignore_missing=False)
if not proj:
raise exceptions.SDKException(
f"Project {name_or_id} was requested but was not found "
f"on the cloud"
)
return self.compute.get_usage(proj, start, end) return self.compute.get_usage(project, start, end)
def _encode_server_userdata(self, userdata): def _encode_server_userdata(self, userdata):
if hasattr(userdata, 'read'): if hasattr(userdata, 'read'):

View File

@ -165,10 +165,8 @@ class IdentityCloudMixin(openstackcloud._OpenStackCloudMixin):
project = self.identity.find_project( project = self.identity.find_project(
name_or_id=name_or_id, name_or_id=name_or_id,
domain_id=domain_id, domain_id=domain_id,
ignore_missing=True, ignore_missing=False,
) )
if not project:
raise exceptions.SDKException("Project %s not found." % name_or_id)
if enabled is not None: if enabled is not None:
kwargs.update({'enabled': enabled}) kwargs.update({'enabled': enabled})
project = self.identity.update_project(project, **kwargs) project = self.identity.update_project(project, **kwargs)
@ -950,12 +948,8 @@ class IdentityCloudMixin(openstackcloud._OpenStackCloudMixin):
wrong during the OpenStack API call. wrong during the OpenStack API call.
""" """
group = self.identity.find_group( group = self.identity.find_group(
name_or_id, ignore_missing=True, **kwargs name_or_id, ignore_missing=False, **kwargs
) )
if group is None:
raise exceptions.SDKException(
f"Group {name_or_id} not found for updating"
)
group_ref = {} group_ref = {}
if name: if name:
@ -1218,11 +1212,7 @@ class IdentityCloudMixin(openstackcloud._OpenStackCloudMixin):
# group, role, project # group, role, project
search_args['domain_id'] = data['domain'].id search_args['domain_id'] = data['domain'].id
data['role'] = self.identity.find_role( data['role'] = self.identity.find_role(role, ignore_missing=False)
name_or_id=role, ignore_missing=True
)
if not data['role']:
raise exceptions.SDKException(f'Role {role} not found.')
if user: if user:
# use cloud.get_user to save us from bad searching by name # use cloud.get_user to save us from bad searching by name

View File

@ -122,12 +122,7 @@ class ImageCloudMixin(openstackcloud._OpenStackCloudMixin):
' however only one can be used at once' ' however only one can be used at once'
) )
image = self.image.find_image(name_or_id, ignore_missing=True) image = self.image.find_image(name_or_id, ignore_missing=False)
if not image:
raise exceptions.NotFoundException(
"No images with name or ID %s were found" % name_or_id, None
)
return self.image.download_image( return self.image.download_image(
image, output=output_file or output_path, chunk_size=chunk_size image, output=output_file or output_path, chunk_size=chunk_size
) )

View File

@ -122,15 +122,7 @@ class TestProject(base.TestCase):
), ),
] ]
) )
# NOTE(notmorgan): This test (and shade) does not represent a case with testtools.ExpectedException(exceptions.NotFoundException):
# where the project is in the project list but a 404 is raised when
# the PATCH is issued. This is a bug in shade and should be fixed,
# shade will raise an attribute error instead of the proper
# project not found exception.
with testtools.ExpectedException(
exceptions.SDKException,
"Project %s not found." % project_data.project_id,
):
self.cloud.update_project(project_data.project_id) self.cloud.update_project(project_data.project_id)
self.assert_calls() self.assert_calls()

View File

@ -1742,10 +1742,7 @@ class TestRoleAssignment(base.TestCase):
) )
self.register_uris(uris) self.register_uris(uris)
with testtools.ExpectedException( with testtools.ExpectedException(exceptions.NotFoundException):
exceptions.SDKException,
f'Role {self.role_data.role_name} not found',
):
self.cloud.grant_role( self.cloud.grant_role(
self.role_data.role_name, self.role_data.role_name,
group=self.group_data.group_name, group=self.group_data.group_name,
@ -1782,10 +1779,7 @@ class TestRoleAssignment(base.TestCase):
) )
self.register_uris(uris) self.register_uris(uris)
with testtools.ExpectedException( with testtools.ExpectedException(exceptions.NotFoundException):
exceptions.SDKException,
f'Role {self.role_data.role_name} not found',
):
self.cloud.revoke_role( self.cloud.revoke_role(
self.role_data.role_name, self.role_data.role_name,
group=self.group_data.group_name, group=self.group_data.group_name,