def test_create_baymodel_with_no_exist_image_name(self, mock_image_data): mock_image_data.side_effect = exception.ResourceNotFound('test-img') bdict = apiutils.baymodel_post_data() del bdict['uuid'] response = self.post_json('/baymodels', bdict, expect_errors=True) self.assertEqual(404, response.status_int)
def get_openstack_resource(manager, resource_ident, resource_type): """Get the openstack resource from the uuid or logical name. :param manager: the resource manager class. :param resource_ident: the UUID or logical name of the resource. :param resource_type: the type of the resource :returns: The openstack resource. :raises: ResourceNotFound if the openstack resource is not exist. Conflict if multi openstack resources have same name. """ if uuidutils.is_uuid_like(resource_ident): resource_data = manager.get(resource_ident) else: filters = {'name': resource_ident} matches = list(manager.list(filters=filters)) if len(matches) == 0: raise exception.ResourceNotFound(name=resource_type, id=resource_ident) if len(matches) > 1: msg = ("Multiple %(resource_type)s exist with same name " "%(resource_ident)s. Please use the resource id " "instead." % { 'resource_type': resource_type, 'resource_ident': resource_ident }) raise exception.Conflict(msg) resource_data = matches[0] return resource_data
def test_ResourceNotFound(self): self.assertRaises(exception.ResourceNotFound, lambda: self.raise_(exception.ResourceNotFound()))