On 7/16/20 2:56 PM, Thomas Goirand wrote:
On 7/15/20 4:09 PM, Rodolfo Alonso Hernandez wrote:
Hi Thomas:
If I'm not wrong, the goal of this filtering is to remove all those subnets with service_type='network:routed'. Maybe you can check implementing an easier query: SELECT subnets.segment_id AS subnets_segment_id FROM subnets WHERE subnets.network_id = %(network_id_1)s AND NOT (EXISTS (SELECT * FROM subnet_service_types WHERE subnets.id <http://subnets.id> = subnet_service_types.subnet_id AND subnet_service_types.service_type = %(service_type_1)s))
That will be translated to python as:
query = test_db.context.session.query(subnet_obj.Subnet.db_model.segment_id) query = query.filter(subnet_obj.Subnet.db_model.network_id == network_id) if filtered_service_type: query = query.filter(~exists().where(and_( subnet_obj.Subnet.db_model.id <http://subnet_obj.Subnet.db_model.id> == service_type_model.subnet_id, service_type_model.service_type == filtered_service_type)))
Can you provide a UTs or a way to check the problem you are experiencing?
Regards.
Hi Rodolfo,
Thanks for your help.
I tried translating what you wrote above into a working code (ie: fixing a few variables here and there), which I sent as a new PR here: https://review.opendev.org/#/c/741429/
However, printing the result from SQLAlchemy shows that get_subnet_segment_ids() still returns None together with my other 2 subnets, so something must still be wrong.
I'm not yet to the point I can write unit tests, just trying the code locally for the moment.
Cheers,
Thomas Goirand (zigo)
Rodolfo, You are right that the purpose is to filter subnets with service_type='network:routed' However, if I add: if segment_id in the: return [segment_id for (segment_id,) in query.all() if segment_id] then this doesn't work, because _validate_segment will never return 400 whenever there is a non-valid request, which defeats the purpose of this function. I removed the "if segment_id" and now the patch passes unit tests. See: https://review.opendev.org/669395 However, it's still not possible to provision a subnet with --service-type='network:routed', and at this point, I don't understand what's going wrong, and why get_subnet_segment_ids is returning None for the new subnet I'm trying to create, when this is supposed to be filtered. Is it possible that the service_type table isn't written yet at the time of the call of get_subnet_segment_ids()? I'd like to add a test, to me it looks like I should do it here: neutron/tests/unit/extensions/test_segment.py using as model: test_only_some_subnets_associated_not_allowed() by just adding service_type='network:routed', and expecting it to succeed. However, how do I add a service-type when creating the subnet? It doesn't look like this exists in this test framework. Any suggestion? Cheers, Thomas Goirand (zigo)