![Boden R](/assets/img/avatar_default.png)
Background: Today, extension loading consists of using the global attr map [1] as a registry of the API resources known to neutron. Extension modules are loaded using imp.load_source() [2] and once resolved are allowed to extend other resource attrs (core or other extension resources/attrs) in the map [3]. This is nothing new, for those extensions which do extend others, they are supposed to update the extensions attr map; our docs say it's so [4]. Problem: Using imp.load_source() [2] to load a module, causes it to reinitialize. This includes recreating a copy of the RESOURCE_ATTRIBUTE_MAP for neutron.extensions.**. The result is that the extension module object loaded does not ref the same RESOURCE_ATTRIBUTE_MAP as the actual neutron.extensions.mymodule anymore; it's a deep copy as part of load_source(). This is how things have been for some time it appears. However now we are trying to use API defs from neutron-lib that contain the actual RESOURCE_ATTRIBUTE_MAP; imp.load_source() no longer makes a copy and thus whats used is the single global RESOURCE_ATTRIBUTE_MAP from it's lib definition. While this is fine during service runtime, some tests expect the attribute maps to have only specific values; these values can get muddied during tests since now the single lib map gets updated [5]. This patch adds a fixture to save/restore neutron-lib api definition maps and can be used to modify the attribute map in testing isolation. It also includes update_attributes_map() in the API definition class to further solidify the implementation before we start using it in neutron. For sample usage see [6]. [1] https://github.com/openstack/neutron/blob/master/neutron/api/v2/router.py#L83 [2] https://github.com/openstack/neutron/blob/master/neutron/api/extensions.py#L457 [3] https://github.com/openstack/neutron/blob/master/neutron/api/extensions.py#L397 [4] https://github.com/openstack/neutron-lib/blob/master/neutron_lib/api/extensions.py#L129 [5] http://logs.openstack.org/82/423382/4/check/gate-neutron-python27-ubuntu-xenial/7d04c46/testr_results.html.gz [6] If2e66e06b83e15ee2851ea2bc3b64ad366e675dd Change-Id: Iff1ea5ac381f7823a3745d3956ee6179fcd07b1e
13 lines
639 B
YAML
13 lines
639 B
YAML
---
|
|
features:
|
|
- A new fixture for testing with neutron-lib API definitions has
|
|
been added as ``neutron_lib.fixtures.APIDefinitionFixture``. This
|
|
fixture can be used anytime extension plugins are being tested
|
|
that modify resource attribute maps and ensures the single global
|
|
API definition attribute map is copied and restored.
|
|
- The ``neutron_lib.api.extensions.APIExtensionDescriptor`` class now
|
|
defines update_attributes_map that uses the API definitions attribute
|
|
map if none is given. This is the default behavior in most all
|
|
extensions today and thus is collapsed into the base class for convenience.
|
|
|