[Neutron] How to add Fake ML2 extension to Neutron?

Igor Zhukov fsb4000 at yandex.ru
Mon Aug 29 16:35:32 UTC 2022


Hi.
I think I finished it.
I did similar to https://github.com/salv-orlando/hdn/commit/8a82edcd1abb5d9f381b166b539efdcd82cceb03 but I also created EXPAND_HEAD and CONTRACT_HEAD
But I got errors with neutron-db-manage revision command and I just added myself `op.create_table...` to `liberty_exp_placeholder.py` to `def upgrade():`
and now my extension driver works and new neutron maria db table also is created when I run `neutron-db-manage upgrade heads`
I need more experience with python itself and neutron in particular, but I'm glad that I was able to add new attributes to networks in neutron.
Thank you for your time!

> Hi,1.) The migration files are responsible to create the schema during deployment, and there is a helper utility for it neutron-db-manage (see [1], actually similar tools exists for all openstack projects at least I know many)
> With this tool you can generate an empty migration template (see the neutron-db-manage revision command for help)
> The Neutron migration scripts can be found here: https://opendev.org/openstack/neutron/src/branch/master/neutron/db/migration/alembic_migrations/versions
> Of course there fill be a similar tree for all Networking projects.
> (NOTE: Since perhaps Ocata we have only expand scripts to make upgrade easier for example)
> Devstack and other deployment tools upgrade the db, but with neutron-db-manage you can do it manually with neutron-db-manage upgrade heads, you can check in the db after it if the schema is as you expected.
> 
> 2.) For Neutron the schema again written under models, here: https://opendev.org/openstack/neutron/src/branch/master/neutron/db/models, it looks like a duplication as it is nearly the same as the migration script, but this code will be used by Neutron itself not only during the deployment or upgrade.
> For some stadium projects it is possible as I remember the *_db file contains the schema description and the code that actually uses the db to fetch or store values in it, like bgpvpn (See [2]).
> In Neutron (and in many other Openstack projects, if not all) we have another layer over the the which is the OVO (Oslo Versioned Objects), and that is used in most places and that hides the actual accessing of the db with high level python classes (see: https://opendev.org/openstack/neutron/src/branch/master/neutron/objects )
> 
> [1]: https://docs.openstack.org/neutron/latest/contributor/alembic_migrations.html
> [2]: https://opendev.org/openstack/networking-bgpvpn/src/branch/master/networking_bgpvpn/neutron/db/bgpvpn_db.py
> 
> Igor Zhukov <fsb4000 at yandex.ru> ezt írta (időpont: 2022. aug. 25., Cs, 2:48):
> 
>> Hi Lajos.
>>
>> Thank you.
>>
>> I have a progress. I think my fake extension works.
>>
>> I added
>>
>> ```
>>
>> extensions.register_custom_supported_check(
>>
>> "vpc_extension", lambda: True, plugin_agnostic=False
>>
>> )
>>
>> ```
>>
>> to
>>
>> ```
>>
>> class Vpc(api_extensions.ExtensionDescriptor):
>>
>> extensions.register_custom_supported_check(
>>
>> "vpc_extension", lambda: True, plugin_agnostic=False
>>
>> )
>>
>> ...
>>
>> ```
>>
>> and I use ml2 extension driver without any new plugin. https://github.com/openstack/neutron/blob/master/neutron/tests/unit/plugins/ml2/drivers/ext_test.py#L44
>>
>> I tested it with python neutronclientapi. So I can change my new attribute (neutron.update_network(id, {'network': {'new_attribute': some string }}))
>>
>> and I see my changes (neutron.list_networks(name='demo-net'))
>>
>> I'm close to the end.
>>
>> Now I'm using modifed `TestExtensionDriver(TestExtensionDriverBase):`. It works but It stores the data locally.
>>
>> And I want to use class TestDBExtensionDriver(TestExtensionDriverBase): (https://github.com/openstack/neutron/blob/master/neutron/tests/unit/plugins/ml2/drivers/ext_test.py#L169)
>>
>> I tried to use it but I got such errors in neutron-server.log: "Table 'neutron.myextension.networkextensions' doesn't exist"
>>
>> How can I create a new table?
>>
>> I saw https://docs.openstack.org/neutron/latest/contributor/alembic_migrations.html and https://github.com/openstack/neutron-vpnaas/tree/master/neutron_vpnaas/db but I still don't understand.
>>
>> I mean I think some of the neutron_vpnaas/db files are generated. Are neutron_vpnaas/db/migration/alembic_migrations/versions generated?
>>
>> Which files I should create(their names, I think I can copy from neutron_vpnaas/db/) and what commands to type to create one new table: https://github.com/openstack/neutron/blob/master/neutron/tests/unit/plugins/ml2/drivers/ext_test.py#L136-L144 ?
>>
>>> Hi Igor,The line which is interesting for you: "Extension vpc_extension not supported by any of loaded plugins"
>>
>>> In core Neutron for ml2 there is a list of supported extension aliases:
>>
>>> https://opendev.org/openstack/neutron/src/branch/master/neutron/plugins/ml2/plugin.py#L200-L239
>>
>>>
>>
>>> And there is a similar for l3 also:
>>
>>> https://opendev.org/openstack/neutron/src/branch/master/neutron/services/l3_router/l3_router_plugin.py#L98-L110
>>
>>>
>>
>>> Or similarly for QoS:
>>
>>> https://opendev.org/openstack/neutron/src/branch/master/neutron/services/qos/qos_plugin.py#L76-L90
>>
>>>
>>
>>> So you need a plugin that uses the extension.
>>
>>>
>>
>>> Good luck :-)
>>
>>> Lajos Katona (lajoskatona)
>>
>>>
>>
>>> Igor Zhukov <fsb4000 at yandex.ru> ezt írta (időpont: 2022. aug. 23., K, 16:04):
>>
>>>
>>
>>>> Hi again!
>>
>>>>
>>
>>>> Do you know how to debug ML2 extension drivers?
>>
>>>>
>>
>>>> I created folder with two python files: vpc/extensions/vpc.py and vpc/plugins/ml2/drivers/vpc.py (also empty __init__.py files)
>>
>>>>
>>
>>>> I added to neuron.conf
>>
>>>>
>>
>>>> api_extensions_path = /path/to/vpc/extensions
>>
>>>>
>>
>>>> and I added to ml2_ini.conf
>>
>>>>
>>
>>>> extension_drivers = port_security, vpc.plugins.ml2.drivers.vpc:VpcExtensionDriver
>>
>>>>
>>
>>>> and my neutron.server.log has:
>>
>>>>
>>
>>>> INFO neutron.plugins.ml2.managers [-] Configured extension driver names: ['port_security', 'vpc_neutron.plugins.ml2.drivers.vpc:VpcExtensionDriver']
>>
>>>>
>>
>>>> WARNING stevedore.named [-] Could not load vpc_neutron.plugins.ml2.drivers.vpc:VpcExtensionDriver
>>
>>>>
>>
>>>> ....
>>
>>>>
>>
>>>> INFO neutron.api.extensions [req-fd226631-b0cd-4ff8-956b-9470e7f26ebe - - - - -] Extension vpc_extension not supported by any of loaded plugins
>>
>>>>
>>
>>>> How can I find why the extension driver could not be loaded?
>>
>>>>
>>
>>>>> Hi,The fake_extension is used only in unit tests to test the extension framework, i.e. :
>>
>>>>
>>
>>>>> https://opendev.org/openstack/neutron/src/branch/master/neutron/tests/unit/plugins/ml2/drivers/ext_test.py#L37
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> If you would like to write an API extension check neutron-lib/api/definitions/ (and you can find the extensions "counterpart" under neutron/extensions in neutron repository)
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> You can also check other Networking projects like networking-bgvpn, neutron-dynamic-routing to have examples of API extensions.
>>
>>>>
>>
>>>>> If you have an extension under neutron/extensions and there's somebody who uses it (see [1]) you will see it is loaded in neutron servers logs (something like this: "Loaded extension: address-group") and you can find it in the output of openstack extension list --network
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> [1]: https://opendev.org/openstack/neutron/src/branch/master/neutron/plugins/ml2/plugin.py#L200
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> Best wishes
>>
>>>>
>>
>>>>> Lajos Katona
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>> Igor Zhukov <fsb4000 at yandex.ru> ezt írta (időpont: 2022. aug. 22., H, 19:41):
>>
>>>>
>>
>>>>>
>>
>>>>
>>
>>>>>> Hi all!
>>
>>>>
>>
>>>>>>
>>
>>>>
>>
>>>>>> Sorry for a complete noob question but I can't figure it out 😿
>>
>>>>
>>
>>>>>>
>>
>>>>
>>
>>>>>> So if I want to add Fake ML2 extension what should I do?
>>
>>>>
>>
>>>>>>
>>
>>>>
>>
>>>>>> I have neutron server installed and I have the file: https://github.com/openstack/neutron/blob/master/neutron/tests/unit/plugins/ml2/extensions/fake_extension.py
>>
>>>>
>>
>>>>>>
>>
>>>>
>>
>>>>>> How to configure neutron server, where should I put the file, should I create another files? How can I test that it works?



More information about the openstack-discuss mailing list