From 5075f3f87579a5315b5908f6d155904f6b7f755d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 12 Apr 2024 16:23:13 -0500 Subject: [PATCH 1/5] Add deprecation warnings --- fabrictestbed_extensions/fablib/interface.py | 2 ++ fabrictestbed_extensions/fablib/node.py | 9 +++------ pyproject.toml | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fabrictestbed_extensions/fablib/interface.py b/fabrictestbed_extensions/fablib/interface.py index 2de0ec62..8dbfa5d3 100644 --- a/fabrictestbed_extensions/fablib/interface.py +++ b/fabrictestbed_extensions/fablib/interface.py @@ -36,6 +36,7 @@ from typing import TYPE_CHECKING, Any, Union import jinja2 +from deprecated.sphinx import deprecated from fabrictestbed.slice_editor import Flags from tabulate import tabulate @@ -336,6 +337,7 @@ def get_device_name(self) -> str: return os_iface + @deprecated(version="1.3.2", reason="Use get_device_name() instead.") def get_os_interface(self) -> str: """ Deprecated: see interface.get_device_name() diff --git a/fabrictestbed_extensions/fablib/node.py b/fabrictestbed_extensions/fablib/node.py index b06e4902..ff5f5618 100644 --- a/fabrictestbed_extensions/fablib/node.py +++ b/fabrictestbed_extensions/fablib/node.py @@ -60,6 +60,7 @@ import jinja2 import paramiko +from deprecated.sphinx import deprecated from fabric_cf.orchestrator.orchestrator_proxy import Status from IPython.core.display_functions import display from tabulate import tabulate @@ -2550,6 +2551,7 @@ def ip_link_down( logging.warning(f"Failed to down link: {e}") raise e + @deprecated(version="1.1.3") def set_ip_os_interface( self, os_iface: str = None, @@ -2558,9 +2560,6 @@ def set_ip_os_interface( cidr: str = None, mtu: str = None, ): - """ - .. deprecated:: 1.1.3. - """ # TODO: Add docstring after doc networking classes if cidr: cidr = str(cidr) @@ -2649,6 +2648,7 @@ def remove_vlan_os_interface(self, os_iface: str = None): command = f"sudo ip link del link {link} name {os_iface}" stdout, stderr = self.execute(command, quiet=True) + @deprecated(version="1.1.3") def add_vlan_os_interface( self, os_iface: str = None, @@ -2658,9 +2658,6 @@ def add_vlan_os_interface( mtu: str = None, interface: str = None, ): - """ - .. deprecated:: 1.1.3. - """ # TODO: Add docstring after doc networking classes if vlan: diff --git a/pyproject.toml b/pyproject.toml index 7cc44164..53a21448 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,8 @@ dependencies = [ "numpy", "ipython>=8.12.0", "fabric_fss_utils>=1.5.1", - "atomicwrites" + "atomicwrites", + "deprecated>=1.2.14", ] classifiers = [ From 75089f589f06f7a07efa04d9e178391b88e17fbb Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 12 Apr 2024 16:36:57 -0500 Subject: [PATCH 2/5] Add some unit tests to check DeprecationWarnings --- tests/unit/test_deprecations.py | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/unit/test_deprecations.py diff --git a/tests/unit/test_deprecations.py b/tests/unit/test_deprecations.py new file mode 100644 index 00000000..6dfaa8b4 --- /dev/null +++ b/tests/unit/test_deprecations.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# MIT License +# +# Copyright (c) 2024 FABRIC Testbed +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import unittest + +from fabrictestbed_extensions.fablib.interface import Interface +from fabrictestbed_extensions.fablib.node import Node + + +class FablibDeprecationTests(unittest.TestCase): + """ + Test that deprecation warnings are emitted. + """ + + def test_interface_deprecations(self): + """ + Test DeprecationWarnings from Interface module. + """ + with self.assertWarns(DeprecationWarning): + Interface().get_os_interface() + + def test_node_deprecations(self): + """ + Test DeprecationWarnings from Node module. + """ + with self.assertWarns(DeprecationWarning): + try: + Node(slice=None, node=None).set_ip_os_interface() + except Exception: + pass + + with self.assertWarns(DeprecationWarning): + try: + Node(slice=None, node=None).add_vlan_os_interface() + except Exception: + pass From 2d339fbe35c286da51fb9f6b0ab230f19f1b35f6 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 12 Apr 2024 16:44:30 -0500 Subject: [PATCH 3/5] Remove redundant deprecation warning --- fabrictestbed_extensions/fablib/interface.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/fabrictestbed_extensions/fablib/interface.py b/fabrictestbed_extensions/fablib/interface.py index 8dbfa5d3..3bf48b8b 100644 --- a/fabrictestbed_extensions/fablib/interface.py +++ b/fabrictestbed_extensions/fablib/interface.py @@ -340,8 +340,6 @@ def get_device_name(self) -> str: @deprecated(version="1.3.2", reason="Use get_device_name() instead.") def get_os_interface(self) -> str: """ - Deprecated: see interface.get_device_name() - Gets a name of the interface the operating system uses for this FABLib interface. From 37368a2e19564d3eac72f6dd1d1c29f17eafdd0d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 12 Apr 2024 16:49:51 -0500 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca4d579..ab832fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased ### Fixed +- Emit deprecation warnings from deprecated methods (Issue + [#239](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/239)) - Add Facility Port to allow adding multiple interfaces (Issue [#289](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/289)) - validate_config errors out when config directory does not exist (Issue [#299](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/299) - create_ssh_config adds extra indentation (Issue [#300](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/300) From 4965a78a2c120e2726fdcb13e180b2dc313e16f3 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Fri, 12 Apr 2024 17:02:40 -0500 Subject: [PATCH 5/5] On second thoughts, just use open bounds We're a library after all --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 53a21448..e6f95da5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "ipython>=8.12.0", "fabric_fss_utils>=1.5.1", "atomicwrites", - "deprecated>=1.2.14", + "deprecated", ] classifiers = [