bridge, bond: drop slave support from schema

In order to follow our efforts to support inclusive language in Nmstate,
we are dropping the support of the "slave" term.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
This commit is contained in:
Fernando Fernandez Mancera 2021-06-22 16:48:09 +02:00 committed by Gris Ge
parent 9408ae4309
commit ebc8082532
3 changed files with 2 additions and 112 deletions

View File

@ -17,8 +17,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import warnings
import pkgutil
import yaml
@ -155,48 +153,7 @@ class InterfaceIPv6(InterfaceIP):
AUTOCONF = "autoconf"
OVS_BRIDGE = "OVSBridge.Port.LinkAggregation"
DEPRECATED_CONSTANTS = {
"Bond.SLAVES": "Bond.PORT",
"LinkAggregation.SLAVES_SUBTREE": f"{OVS_BRIDGE}.PORT_SUBTREE",
"LinkAggregation.Slave": f"{OVS_BRIDGE}.Port",
}
class _DeprecatorType(type):
def __getattribute__(cls, attribute):
try:
return super().__getattribute__(attribute)
except AttributeError:
deprecated_class = cls
deprecated_classname = deprecated_class.__name__
deprecated_name = attribute
oldconstant = f"{deprecated_classname}.{deprecated_name}"
newconstant = DEPRECATED_CONSTANTS.get(oldconstant)
if newconstant:
warnings.warn(
f"Using '{oldconstant}' is deprecated, "
f"use '{newconstant}' instead.",
FutureWarning,
stacklevel=3,
)
attributes = newconstant.split(".")
new_classname = attributes.pop(0)
new_value = globals()[new_classname]
while attributes:
new_value = getattr(new_value, attributes.pop(0))
return new_value
raise
class Bond(metaclass=_DeprecatorType):
class Bond:
KEY = InterfaceType.BOND
CONFIG_SUBTREE = "link-aggregation"
@ -364,7 +321,7 @@ class OVSBridge(Bridge, OvsDB):
class Port(Bridge.Port):
LINK_AGGREGATION_SUBTREE = "link-aggregation"
class LinkAggregation(metaclass=_DeprecatorType):
class LinkAggregation:
MODE = "mode"
PORT_SUBTREE = "port"

View File

@ -276,10 +276,6 @@ definitions:
properties:
mode:
type: string
slaves:
type: array
items:
type: string
port:
type: array
items:
@ -435,13 +431,6 @@ definitions:
properties:
mode:
type: string
slaves:
type: array
items:
type: object
properties:
name:
type: string
port:
type: array
items:

View File

@ -1,56 +0,0 @@
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This file is part of nmstate
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
import pytest
from libnmstate.schema import Bond
from libnmstate.schema import OVSBridge
def test_bond_deprecated_constants():
with pytest.warns(FutureWarning) as record:
deprecated_value = getattr(Bond, "SLAVES")
assert len(record) == 1
assert "SLAVES" in record[0].message.args[0]
assert deprecated_value == "port"
def test_ovsbridge_slaves_subtree_deprecated_constants():
with pytest.warns(FutureWarning) as record:
deprecated_value = getattr(
OVSBridge.Port.LinkAggregation, "SLAVES_SUBTREE"
)
assert len(record) == 1
assert "SLAVES_SUBTREE" in record[0].message.args[0]
assert deprecated_value == "port"
def test_ovsbridge_port_subtree_deprecated_constants():
with pytest.warns(FutureWarning) as record:
# pylint: disable=E1101
deprecated_value = getattr(
OVSBridge.Port.LinkAggregation.Slave, "NAME"
)
# pylint: enable=E1101
assert len(record) == 1
assert "Port" in record[0].message.args[0]
assert deprecated_value == "name"