From ee124d2e98c2660ced7d71c1bd10525bf095a939 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 13 Mar 2019 17:56:18 +0000 Subject: [PATCH] Remove IP proxy methods Remove IP proxy methods in os_vif.internal.command.ip.__init__.py. Both Windows and Linux IP implementations have the same interface, IpCommand. Method calls (set, add, delete, exists) must be the same for both IP classes, making those proxy calls unnecessary. Removed a nesting level for internal IP commands. Now those commands are located in os_vif.internal.ip. Change-Id: Id8b71172fb06b435cf169a7e55c11233f22fa65b Closes-Bug: #1817940 --- os_vif/internal/command/ip/__init__.py | 37 ------------------- os_vif/internal/{command => ip}/__init__.py | 0 os_vif/internal/{command => }/ip/api.py | 4 +- .../internal/{command => }/ip/ip_command.py | 0 .../{command => }/ip/linux/__init__.py | 0 .../{command => }/ip/linux/impl_pyroute2.py | 2 +- .../{command => }/ip/windows/__init__.py | 0 .../ip/windows/impl_netifaces.py | 2 +- .../internal/command/ip/test_impl_pyroute2.py | 2 +- .../internal/command/ip/windows/__init__.py | 0 .../unit/internal/{command => ip}/__init__.py | 0 .../{command/ip => ip/linux}/__init__.py | 0 .../ip/linux/test_impl_pyroute2.py | 2 +- .../internal/{command => }/ip/test_api.py | 6 +-- .../ip/linux => ip/windows}/__init__.py | 0 .../ip/windows/test_impl_netifaces.py | 2 +- vif_plug_linux_bridge/linux_net.py | 2 +- .../tests/unit/test_linux_net.py | 2 +- vif_plug_ovs/linux_net.py | 2 +- vif_plug_ovs/ovs.py | 2 +- vif_plug_ovs/tests/unit/test_linux_net.py | 2 +- vif_plug_ovs/tests/unit/test_plugin.py | 2 +- 22 files changed, 16 insertions(+), 53 deletions(-) delete mode 100644 os_vif/internal/command/ip/__init__.py rename os_vif/internal/{command => ip}/__init__.py (100%) rename os_vif/internal/{command => }/ip/api.py (85%) rename os_vif/internal/{command => }/ip/ip_command.py (100%) rename os_vif/internal/{command => }/ip/linux/__init__.py (100%) rename os_vif/internal/{command => }/ip/linux/impl_pyroute2.py (98%) rename os_vif/internal/{command => }/ip/windows/__init__.py (100%) rename os_vif/internal/{command => }/ip/windows/impl_netifaces.py (97%) delete mode 100644 os_vif/tests/unit/internal/command/ip/windows/__init__.py rename os_vif/tests/unit/internal/{command => ip}/__init__.py (100%) rename os_vif/tests/unit/internal/{command/ip => ip/linux}/__init__.py (100%) rename os_vif/tests/unit/internal/{command => }/ip/linux/test_impl_pyroute2.py (99%) rename os_vif/tests/unit/internal/{command => }/ip/test_api.py (86%) rename os_vif/tests/unit/internal/{command/ip/linux => ip/windows}/__init__.py (100%) rename os_vif/tests/unit/internal/{command => }/ip/windows/test_impl_netifaces.py (96%) diff --git a/os_vif/internal/command/ip/__init__.py b/os_vif/internal/command/ip/__init__.py deleted file mode 100644 index 6667b7a4..00000000 --- a/os_vif/internal/command/ip/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from os_vif.internal.command.ip import api - - -def set(device, check_exit_code=None, state=None, mtu=None, address=None, - promisc=None, master=None): - """Method to set a parameter in an interface.""" - return api.ip.set(device, check_exit_code=check_exit_code, state=state, - mtu=mtu, address=address, promisc=promisc, master=master) - - -def add(device, dev_type, check_exit_code=None, peer=None, link=None, - vlan_id=None): - """Method to add an interface.""" - return api.ip.add(device, dev_type, check_exit_code=check_exit_code, - peer=peer, link=link, vlan_id=vlan_id) - - -def delete(device, check_exit_code=None): - """Method to delete an interface.""" - return api.ip.delete(device, check_exit_code=check_exit_code) - - -def exists(device): - """Method to check if an interface exists.""" - return api.ip.exists(device) diff --git a/os_vif/internal/command/__init__.py b/os_vif/internal/ip/__init__.py similarity index 100% rename from os_vif/internal/command/__init__.py rename to os_vif/internal/ip/__init__.py diff --git a/os_vif/internal/command/ip/api.py b/os_vif/internal/ip/api.py similarity index 85% rename from os_vif/internal/command/ip/api.py rename to os_vif/internal/ip/api.py index cfb42c0d..a2901a5a 100644 --- a/os_vif/internal/command/ip/api.py +++ b/os_vif/internal/ip/api.py @@ -15,10 +15,10 @@ import os from oslo_log import log as logging if os.name == 'nt': - from os_vif.internal.command.ip.windows.impl_netifaces import \ + from os_vif.internal.ip.windows.impl_netifaces import \ Netifaces as ip_lib_class else: - from os_vif.internal.command.ip.linux.impl_pyroute2 import \ + from os_vif.internal.ip.linux.impl_pyroute2 import \ PyRoute2 as ip_lib_class diff --git a/os_vif/internal/command/ip/ip_command.py b/os_vif/internal/ip/ip_command.py similarity index 100% rename from os_vif/internal/command/ip/ip_command.py rename to os_vif/internal/ip/ip_command.py diff --git a/os_vif/internal/command/ip/linux/__init__.py b/os_vif/internal/ip/linux/__init__.py similarity index 100% rename from os_vif/internal/command/ip/linux/__init__.py rename to os_vif/internal/ip/linux/__init__.py diff --git a/os_vif/internal/command/ip/linux/impl_pyroute2.py b/os_vif/internal/ip/linux/impl_pyroute2.py similarity index 98% rename from os_vif/internal/command/ip/linux/impl_pyroute2.py rename to os_vif/internal/ip/linux/impl_pyroute2.py index 44372c6c..2745223c 100644 --- a/os_vif/internal/command/ip/linux/impl_pyroute2.py +++ b/os_vif/internal/ip/linux/impl_pyroute2.py @@ -17,7 +17,7 @@ from pyroute2.netlink import exceptions as ipexc from pyroute2.netlink.rtnl import ifinfmsg from os_vif import exception -from os_vif.internal.command.ip import ip_command +from os_vif.internal.ip import ip_command from os_vif import utils LOG = logging.getLogger(__name__) diff --git a/os_vif/internal/command/ip/windows/__init__.py b/os_vif/internal/ip/windows/__init__.py similarity index 100% rename from os_vif/internal/command/ip/windows/__init__.py rename to os_vif/internal/ip/windows/__init__.py diff --git a/os_vif/internal/command/ip/windows/impl_netifaces.py b/os_vif/internal/ip/windows/impl_netifaces.py similarity index 97% rename from os_vif/internal/command/ip/windows/impl_netifaces.py rename to os_vif/internal/ip/windows/impl_netifaces.py index 9b67114b..e0212603 100644 --- a/os_vif/internal/command/ip/windows/impl_netifaces.py +++ b/os_vif/internal/ip/windows/impl_netifaces.py @@ -17,7 +17,7 @@ import netifaces from oslo_log import log as logging from os_vif import exception -from os_vif.internal.command.ip import ip_command +from os_vif.internal.ip import ip_command LOG = logging.getLogger(__name__) diff --git a/os_vif/tests/functional/internal/command/ip/test_impl_pyroute2.py b/os_vif/tests/functional/internal/command/ip/test_impl_pyroute2.py index 5cbab8d7..5cf6e3fb 100644 --- a/os_vif/tests/functional/internal/command/ip/test_impl_pyroute2.py +++ b/os_vif/tests/functional/internal/command/ip/test_impl_pyroute2.py @@ -16,7 +16,7 @@ import re from oslo_concurrency import processutils from oslo_utils import excutils -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from os_vif.tests.functional import base from os_vif.tests.functional import privsep diff --git a/os_vif/tests/unit/internal/command/ip/windows/__init__.py b/os_vif/tests/unit/internal/command/ip/windows/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/os_vif/tests/unit/internal/command/__init__.py b/os_vif/tests/unit/internal/ip/__init__.py similarity index 100% rename from os_vif/tests/unit/internal/command/__init__.py rename to os_vif/tests/unit/internal/ip/__init__.py diff --git a/os_vif/tests/unit/internal/command/ip/__init__.py b/os_vif/tests/unit/internal/ip/linux/__init__.py similarity index 100% rename from os_vif/tests/unit/internal/command/ip/__init__.py rename to os_vif/tests/unit/internal/ip/linux/__init__.py diff --git a/os_vif/tests/unit/internal/command/ip/linux/test_impl_pyroute2.py b/os_vif/tests/unit/internal/ip/linux/test_impl_pyroute2.py similarity index 99% rename from os_vif/tests/unit/internal/command/ip/linux/test_impl_pyroute2.py rename to os_vif/tests/unit/internal/ip/linux/test_impl_pyroute2.py index 50a70b86..9066c36e 100644 --- a/os_vif/tests/unit/internal/command/ip/linux/test_impl_pyroute2.py +++ b/os_vif/tests/unit/internal/ip/linux/test_impl_pyroute2.py @@ -16,7 +16,7 @@ from pyroute2.netlink import exceptions as ipexc from pyroute2.netlink.rtnl import ifinfmsg from os_vif import exception -from os_vif.internal.command.ip.linux import impl_pyroute2 +from os_vif.internal.ip.linux import impl_pyroute2 from os_vif.tests.unit import base diff --git a/os_vif/tests/unit/internal/command/ip/test_api.py b/os_vif/tests/unit/internal/ip/test_api.py similarity index 86% rename from os_vif/tests/unit/internal/command/ip/test_api.py rename to os_vif/tests/unit/internal/ip/test_api.py index 434e58e1..801dd3a4 100644 --- a/os_vif/tests/unit/internal/command/ip/test_api.py +++ b/os_vif/tests/unit/internal/ip/test_api.py @@ -13,7 +13,7 @@ import mock from six import moves -from os_vif.internal.command.ip import api +from os_vif.internal.ip import api from os_vif.tests.unit import base @@ -27,12 +27,12 @@ class TestIpApi(base.TestCase): self.addCleanup(self._reload_original_os_module) with mock.patch('os.name', 'nt'): moves.reload_module(api) - from os_vif.internal.command.ip.windows import impl_netifaces + from os_vif.internal.ip.windows import impl_netifaces self.assertIsInstance(api.ip, impl_netifaces.Netifaces) def test_get_impl_linux(self): self.addCleanup(self._reload_original_os_module) with mock.patch('os.name', 'posix'): moves.reload_module(api) - from os_vif.internal.command.ip.linux import impl_pyroute2 + from os_vif.internal.ip.linux import impl_pyroute2 self.assertIsInstance(api.ip, impl_pyroute2.PyRoute2) diff --git a/os_vif/tests/unit/internal/command/ip/linux/__init__.py b/os_vif/tests/unit/internal/ip/windows/__init__.py similarity index 100% rename from os_vif/tests/unit/internal/command/ip/linux/__init__.py rename to os_vif/tests/unit/internal/ip/windows/__init__.py diff --git a/os_vif/tests/unit/internal/command/ip/windows/test_impl_netifaces.py b/os_vif/tests/unit/internal/ip/windows/test_impl_netifaces.py similarity index 96% rename from os_vif/tests/unit/internal/command/ip/windows/test_impl_netifaces.py rename to os_vif/tests/unit/internal/ip/windows/test_impl_netifaces.py index f2c094e1..cb115c84 100644 --- a/os_vif/tests/unit/internal/command/ip/windows/test_impl_netifaces.py +++ b/os_vif/tests/unit/internal/ip/windows/test_impl_netifaces.py @@ -13,7 +13,7 @@ import mock import netifaces -from os_vif.internal.command.ip.windows import impl_netifaces as ip_lib +from os_vif.internal.ip.windows import impl_netifaces as ip_lib from os_vif.tests.unit import base diff --git a/vif_plug_linux_bridge/linux_net.py b/vif_plug_linux_bridge/linux_net.py index dee421e1..a338a97d 100644 --- a/vif_plug_linux_bridge/linux_net.py +++ b/vif_plug_linux_bridge/linux_net.py @@ -21,7 +21,7 @@ import os -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from oslo_concurrency import lockutils from oslo_concurrency import processutils from oslo_log import log as logging diff --git a/vif_plug_linux_bridge/tests/unit/test_linux_net.py b/vif_plug_linux_bridge/tests/unit/test_linux_net.py index a5b68b7b..3fc8b90e 100644 --- a/vif_plug_linux_bridge/tests/unit/test_linux_net.py +++ b/vif_plug_linux_bridge/tests/unit/test_linux_net.py @@ -14,7 +14,7 @@ import mock import testtools import fixtures -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from oslo_concurrency import lockutils from oslo_concurrency import processutils from oslo_config import cfg diff --git a/vif_plug_ovs/linux_net.py b/vif_plug_ovs/linux_net.py index 1b1556d0..b36bcd22 100644 --- a/vif_plug_ovs/linux_net.py +++ b/vif_plug_ovs/linux_net.py @@ -24,7 +24,7 @@ import os import re import sys -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from oslo_concurrency import processutils from oslo_log import log as logging from oslo_utils import excutils diff --git a/vif_plug_ovs/ovs.py b/vif_plug_ovs/ovs.py index 8f90510c..f9abe3fa 100644 --- a/vif_plug_ovs/ovs.py +++ b/vif_plug_ovs/ovs.py @@ -19,7 +19,7 @@ import sys -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from os_vif import objects from os_vif import plugin from oslo_config import cfg diff --git a/vif_plug_ovs/tests/unit/test_linux_net.py b/vif_plug_ovs/tests/unit/test_linux_net.py index b4fa4925..2f413f18 100644 --- a/vif_plug_ovs/tests/unit/test_linux_net.py +++ b/vif_plug_ovs/tests/unit/test_linux_net.py @@ -15,7 +15,7 @@ import mock import os.path import testtools -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from vif_plug_ovs import exception from vif_plug_ovs import linux_net diff --git a/vif_plug_ovs/tests/unit/test_plugin.py b/vif_plug_ovs/tests/unit/test_plugin.py index 2da53355..4921b31e 100644 --- a/vif_plug_ovs/tests/unit/test_plugin.py +++ b/vif_plug_ovs/tests/unit/test_plugin.py @@ -13,7 +13,7 @@ import mock import testtools -from os_vif.internal.command import ip as ip_lib +from os_vif.internal.ip.api import ip as ip_lib from os_vif import objects from os_vif.objects import fields