nispor: Use nispor information for VLAN querying
Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
parent
666880850e
commit
c219bc043b
@ -18,6 +18,7 @@
|
||||
#
|
||||
|
||||
from libnmstate.schema import InterfaceType
|
||||
from libnmstate.schema import VLAN
|
||||
|
||||
from .base_iface import NisporPluginBaseIface
|
||||
|
||||
@ -26,3 +27,11 @@ class NisporPluginVlanIface(NisporPluginBaseIface):
|
||||
@property
|
||||
def type(self):
|
||||
return InterfaceType.VLAN
|
||||
|
||||
def to_dict(self):
|
||||
info = super().to_dict()
|
||||
info[VLAN.CONFIG_SUBTREE] = {
|
||||
VLAN.ID: self._np_iface.vlan_id,
|
||||
VLAN.BASE_IFACE: self._np_iface.base_iface,
|
||||
}
|
||||
return info
|
||||
|
@ -39,7 +39,6 @@ from . import ovs as nm_ovs
|
||||
from . import translator as nm_translator
|
||||
from . import wired as nm_wired
|
||||
from . import user as nm_user
|
||||
from . import vlan as nm_vlan
|
||||
from . import team as nm_team
|
||||
from . import dns as nm_dns
|
||||
from . import applier as nm_applier
|
||||
@ -136,7 +135,6 @@ class NetworkManagerPlugin(NmstatePlugin):
|
||||
iface_info.update(nm_wired.get_info(dev))
|
||||
iface_info.update(nm_user.get_info(self.context, dev))
|
||||
iface_info.update(nm_lldp.get_info(self.client, dev))
|
||||
iface_info.update(nm_vlan.get_info(dev))
|
||||
iface_info.update(nm_bridge.get_info(self.context, dev))
|
||||
iface_info.update(nm_team.get_info(dev))
|
||||
|
||||
|
@ -42,16 +42,3 @@ def create_setting(iface_state, base_con_profile):
|
||||
vlan_setting.props.parent = vlan_base_iface
|
||||
|
||||
return vlan_setting
|
||||
|
||||
|
||||
def get_info(device):
|
||||
"""
|
||||
Provides the current active values for a device
|
||||
"""
|
||||
info = {}
|
||||
if device.get_device_type() == NM.DeviceType.VLAN:
|
||||
info[VLAN.CONFIG_SUBTREE] = {
|
||||
VLAN.ID: device.props.vlan_id,
|
||||
VLAN.BASE_IFACE: device.props.parent.get_iface(),
|
||||
}
|
||||
return info
|
||||
|
@ -21,9 +21,11 @@ from contextlib import contextmanager
|
||||
|
||||
from libnmstate import nm
|
||||
from libnmstate.nm.common import NM
|
||||
from libnmstate.schema import Interface
|
||||
from libnmstate.schema import VLAN
|
||||
|
||||
from ..testlib.retry import retry_till_true_or_timeout
|
||||
from ..testlib import statelib
|
||||
from .testlib import main_context
|
||||
|
||||
|
||||
@ -38,18 +40,14 @@ def test_create_and_remove_vlan(nm_plugin, eth1_up):
|
||||
}
|
||||
|
||||
with _vlan_interface(nm_plugin.context, vlan_desired_state):
|
||||
vlan_current_state = _get_vlan_current_state(
|
||||
nm_plugin, vlan_desired_state
|
||||
)
|
||||
vlan_current_state = _get_vlan_current_state(vlan_desired_state)
|
||||
assert vlan_desired_state == vlan_current_state
|
||||
|
||||
assert retry_till_true_or_timeout(
|
||||
5, _vlan_is_absent, nm_plugin, vlan_desired_state
|
||||
)
|
||||
assert retry_till_true_or_timeout(5, _vlan_is_absent, vlan_desired_state)
|
||||
|
||||
|
||||
def _vlan_is_absent(nm_plugin, vlan_desired_state):
|
||||
return not _get_vlan_current_state(nm_plugin, vlan_desired_state)
|
||||
def _vlan_is_absent(vlan_desired_state):
|
||||
return not _get_vlan_current_state(vlan_desired_state)
|
||||
|
||||
|
||||
@contextmanager
|
||||
@ -61,11 +59,15 @@ def _vlan_interface(ctx, state):
|
||||
_delete_vlan(ctx, _get_vlan_ifname(state))
|
||||
|
||||
|
||||
def _get_vlan_current_state(nm_plugin, vlan_desired_state):
|
||||
nm_plugin.refresh_content()
|
||||
def _get_vlan_current_state(vlan_desired_state):
|
||||
ifname = _get_vlan_ifname(vlan_desired_state)
|
||||
nmdev = nm_plugin.context.get_nm_dev(ifname)
|
||||
return nm.vlan.get_info(nmdev) if nmdev else {}
|
||||
state = statelib.show_only((ifname,))
|
||||
vlan_state = {}
|
||||
if state[Interface.KEY]:
|
||||
iface_state = state[Interface.KEY][0]
|
||||
vlan_state = {VLAN.CONFIG_SUBTREE: iface_state[VLAN.CONFIG_SUBTREE]}
|
||||
|
||||
return vlan_state
|
||||
|
||||
|
||||
def _create_vlan(ctx, vlan_desired_state):
|
||||
|
Loading…
x
Reference in New Issue
Block a user