Fix unit tests with oslo.config "enforce_type" setting

This oslo.config change enforces the type of an option by default:
https://github.com/openstack/oslo.config/commit/3a8ba0f8ea5
But that is not yet released.

This commit in oslo.config should make the transition to default
type enforcement easier, but it also not yet released:
https://github.com/openstack/oslo.config/commit/04a78cc1d0

We use Nova's "flags" method to override config options. That method
did already remove the "enforce_type=True" setting:
https://github.com/openstack/nova/commit/213f7120c

And that's why the Nova change did brake our unit tests.

This change uses the native "set_override" method of oslo.config
which allows us to set "enforce_Type=True" which then does a type
conversion which creates the types we expected.
This change is not the ultimate solution but a short term fix to
unwedge our gate checks.

Change-Id: I0445b22e87aa6434d057264d9b751eb0f2d57f06
This commit is contained in:
Markus Zoeller 2017-04-19 11:23:23 +02:00
parent cb545d92f5
commit 57221936dc
2 changed files with 6 additions and 3 deletions

View File

@ -67,7 +67,7 @@ class TestStorageAdapterMappingOpt(TestCase):
mapping = ["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:0"]
opt = MultiStorageAdapterMappingOpt("mapping")
cfg.CONF.register_opt(opt)
self.flags(mapping=mapping)
cfg.CONF.set_override("mapping", mapping, enforce_type=True)
self.assertEqual([("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "0")],
cfg.CONF.mapping)
@ -76,7 +76,7 @@ class TestStorageAdapterMappingOpt(TestCase):
"bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb:1"]
opt = MultiStorageAdapterMappingOpt("mapping")
cfg.CONF.register_opt(opt)
self.flags(mapping=mapping)
cfg.CONF.set_override("mapping", mapping, enforce_type=True)
expected_mapping = [
("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "0"),
("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", "1")]

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_config import cfg
from nova.compute import power_state
from nova.objects import flavor as flavor_obj
from nova.objects import instance as instance_obj
@ -121,7 +123,8 @@ class VmPartitionInstanceTestCase(TestCase):
self.port_element_id = adapter.ports.list()[0].get_property(
'element-id')
storage = self.adapter_object_id + ":" + self.port_element_id
self.flags(group="dpm", physical_storage_adapter_mappings=[storage])
cfg.CONF.set_override("physical_storage_adapter_mappings", [storage],
group="dpm", enforce_type=True)
dpm_hba_dict = {
"name": "OpenStack_Port_" + self.adapter_object_id +
"_" + str(self.port_element_id),