Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use return instead of twisted.defer.returnValue #2955

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2955.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace twisted.internet.defer.returnValue with return due to deprecation in newest twisted version
8 changes: 4 additions & 4 deletions doc/hacking/adding-environment-probe-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Let's hardcode an example result for a single temperature sensor, based on the
'mib': 'SPAGENT-MIB',
}
]
defer.returnValue(result)
return result

This returns a list of a single item: A dictionary describing the first
temperature sensor from the snmpwalk from above. The dictionary should contain
Expand Down Expand Up @@ -284,8 +284,8 @@ Let's rewrite ``SPAgentMib`` to collect actual temperature sensors:
:emphasize-lines: 9, 20

from nav.models.manage import Sensor


class SPAgentMib(MibRetriever):
mib = get_mib('SPAGENT-MIB')

Expand All @@ -300,7 +300,7 @@ Let's rewrite ``SPAgentMib`` to collect actual temperature sensors:
sensors = (self._temp_row_to_sensor(index, row)
for index, row in result.iteritems())

defer.returnValue([s for s in sensors if s])
return [s for s in sensors if s]

def _temp_row_to_sensor(self, index, row):
online = row.get('sensorProbeTempOnline', 'offline')
Expand Down
4 changes: 2 additions & 2 deletions python/nav/bin/naventity.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def collect_entities(netbox, portnumber):
"""Collects the entPhysicalTable"""
agent = _create_agentproxy(netbox, portnumber)
if not agent:
defer.returnValue(None)
return None

mib = EntityMib(agent)
result = yield mib.get_entity_physical_table()
defer.returnValue(result)
return result


def make_graph(entities, netbox):
Expand Down
6 changes: 3 additions & 3 deletions python/nav/bin/navoidverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def verify(netbox, oid):
"""Verifies a GETNEXT response from below the oid subtree"""
agent = _create_agentproxy(netbox)
if not agent:
defer.returnValue(False)
return False

result = yield agent.walk(str(oid))
agent.close()
Expand All @@ -83,8 +83,8 @@ def verify(netbox, oid):
for key, _value in result:
if oid.is_a_prefix_of(key):
print(netbox.sysname)
defer.returnValue(True)
defer.returnValue(False)
return True
return False


def endit(_result):
Expand Down
10 changes: 5 additions & 5 deletions python/nav/ipdevpoll/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def _find_plugins(self):
]

if not plugins:
defer.returnValue(None)
return None

defer.returnValue(plugins)
return plugins

def _get_valid_plugins(self):
valid_plugins, invalid_plugins = splitby(
Expand Down Expand Up @@ -201,7 +201,7 @@ def _get_willing_plugins(self, plugin_classes):
else:
self._logger.debug("no %s plugins", willingness)

defer.returnValue(willing_plugins)
return willing_plugins

def _iterate_plugins(self, plugins):
"""Iterates plugins."""
Expand Down Expand Up @@ -278,7 +278,7 @@ def run(self):
self._reset_timers()
if not plugins:
self._destroy_agentproxy()
defer.returnValue(False)
return False

self._logger.debug("Starting job %r for %s", self.name, self.netbox.sysname)

Expand Down Expand Up @@ -353,7 +353,7 @@ def log_externally_failure(result):
df.addBoth(cleanup)
df.addCallbacks(log_externally_success, log_externally_failure)
yield df
defer.returnValue(True)
return True

def cancel(self):
"""Cancels a running job.
Expand Down
6 changes: 3 additions & 3 deletions python/nav/ipdevpoll/plugins/arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def handle(self):
@defer.inlineCallbacks
def _get_ip_mib(self):
if not self.is_arista():
defer.returnValue(IpMib(self.agent)) # regular IpMib for regular folks
return IpMib(self.agent) # regular IpMib for regular folks
else:
instances = yield get_arista_vrf_instances(self.agent)
defer.returnValue(MultiIpMib(self.agent, instances=instances))
return MultiIpMib(self.agent, instances=instances)

def is_arista(self):
"""Returns True if this is an Arista device"""
Expand Down Expand Up @@ -171,7 +171,7 @@ def _load_existing_mappings(self):
open_mappings = dict(
((IP(arp['ip']), arp['mac']), arp['id']) for arp in open_arp_records
)
defer.returnValue(open_mappings)
return open_mappings

@classmethod
def _update_prefix_cache(cls):
Expand Down
6 changes: 3 additions & 3 deletions python/nav/ipdevpoll/plugins/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""BGP peer state monitor plugin for ipdevpoll"""
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks

from nav.ipdevpoll import Plugin
from nav.ipdevpoll.shadows import GatewayPeerSession, Netbox
Expand All @@ -40,7 +40,7 @@ def handle(self):

if not mib:
self._logger.debug("No BGP MIBs are supported")
returnValue(None)
return None

self._logger.debug("Collect BGP peers from %s", mib.mib['moduleName'])
data = yield mib.get_bgp_peer_states()
Expand Down Expand Up @@ -73,4 +73,4 @@ def _get_supported_mib(self):
mib = mibclass(self.agent)
support = yield mib.is_supported()
if support:
returnValue(mib)
return mib
2 changes: 1 addition & 1 deletion python/nav/ipdevpoll/plugins/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle(self):
if bridge_address:
self._save_bridge_address(bridge_address)
baseports = yield bridge.get_baseport_ifindex_map()
defer.returnValue(self._set_port_numbers(baseports))
return self._set_port_numbers(baseports)

def _save_bridge_address(self, bridge_address):
info = self.containers.factory(
Expand Down
14 changes: 7 additions & 7 deletions python/nav/ipdevpoll/plugins/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Cam(Plugin):
def can_handle(cls, netbox):
daddy_says_ok = super(Cam, cls).can_handle(netbox)
has_ifcs = yield db.run_in_thread(cls._has_interfaces, netbox)
defer.returnValue(has_ifcs and daddy_says_ok)
return has_ifcs and daddy_says_ok

@classmethod
def _has_interfaces(cls, netbox):
Expand Down Expand Up @@ -102,7 +102,7 @@ def _get_dot1d_mac_port_mapping(self):
ifindex = baseports[port]
mapping[ifindex].add(mac)

defer.returnValue(dict(mapping))
return dict(mapping)

@defer.inlineCallbacks
def _get_dot1q_mac_port_mapping(self):
Expand All @@ -116,27 +116,27 @@ def _get_dot1q_mac_port_mapping(self):
ifindex = baseports[port]
mapping[ifindex].add(mac)

defer.returnValue(dict(mapping))
return dict(mapping)

@defer.inlineCallbacks
def _get_baseports(self):
if not self.baseports:
bridge = yield self._get_bridge()
self.baseports = yield bridge.get_baseport_ifindex_map()
defer.returnValue(self.baseports)
return self.baseports

@defer.inlineCallbacks
def _get_bridge(self):
if not self.bridge:
instances = yield self._get_dot1d_instances()
self.bridge = MultiBridgeMib(self.agent, instances)
defer.returnValue(self.bridge)
return self.bridge

@defer.inlineCallbacks
def _get_dot1d_instances(self):
if not self.dot1d_instances:
self.dot1d_instances = yield utils.get_dot1d_instances(self.agent)
defer.returnValue(self.dot1d_instances)
return self.dot1d_instances

def _log_fdb_stats(self, prefix, fdb):
mac_count = sum(len(v) for v in fdb.values())
Expand Down Expand Up @@ -230,7 +230,7 @@ def _get_dot1d_stp_blocking(self):
if translated:
self._log_blocking_ports(translated)
self._store_blocking_ports(translated)
defer.returnValue(translated)
return translated

def _log_blocking_ports(self, blocking):
ifc_count = len(set(ifc for ifc, vlan in blocking))
Expand Down
6 changes: 3 additions & 3 deletions python/nav/ipdevpoll/plugins/cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CDP(Plugin):
def can_handle(cls, netbox):
daddy_says_ok = super(CDP, cls).can_handle(netbox)
has_ifcs = yield run_in_thread(cls._has_interfaces, netbox)
defer.returnValue(has_ifcs and daddy_says_ok)
return has_ifcs and daddy_says_ok

@classmethod
def _has_interfaces(cls, netbox):
Expand Down Expand Up @@ -97,7 +97,7 @@ def _get_stampcheck(self, mib):
yield stampcheck.load()
yield stampcheck.collect([mib.get_neighbors_last_change()])

defer.returnValue(stampcheck)
return stampcheck

@defer.inlineCallbacks
def _get_cached_neighbors(self):
Expand All @@ -108,7 +108,7 @@ def _get_cached_neighbors(self):
INFO_KEY_NAME,
INFO_VAR_NEIGHBORS_CACHE,
)
defer.returnValue(value)
return value

@defer.inlineCallbacks
def _save_cached_neighbors(self, neighbors):
Expand Down
2 changes: 1 addition & 1 deletion python/nav/ipdevpoll/plugins/ciscovlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def handle(self):
def _get_ifindexes(self):
ifmib = IfMib(self.agent)
indexes = yield ifmib.get_ifindexes()
defer.returnValue(set(indexes))
return set(indexes)

def _store_access_ports(self, vlan_membership):
"""Store vlan memberships for all ports."""
Expand Down
4 changes: 2 additions & 2 deletions python/nav/ipdevpoll/plugins/dot1q.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from collections import defaultdict

from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks

from nav.util import mergedicts
from nav.mibs.bridge_mib import BridgeMib
Expand Down Expand Up @@ -122,7 +122,7 @@ def _retrieve_vlan_ports(self):
egress = yield query.get_vlan_static_egress_ports()
untagged = yield query.get_vlan_static_untagged_ports()

returnValue((egress, untagged))
return (egress, untagged)

def _find_trunkports(self, egress, untagged):
trunkports = defaultdict(list)
Expand Down
2 changes: 1 addition & 1 deletion python/nav/ipdevpoll/plugins/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _need_to_collect(self):
yield self.stampcheck.collect([self.entitymib.get_last_change_time()])

result = yield self.stampcheck.is_changed()
defer.returnValue(result)
return result

def _process_entities(self, result):
"""Process the list of collected entities."""
Expand Down
4 changes: 2 additions & 2 deletions python/nav/ipdevpoll/plugins/extremevlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"""

from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks

from nav.enterprise.ids import VENDOR_ID_EXTREME_NETWORKS
from nav.mibs.extreme_vlan_mib import ExtremeVlanMib
Expand Down Expand Up @@ -60,7 +60,7 @@ def _get_vlan_data(self):
vlan_ports = yield self.extremevlan.get_vlan_ports()
if not vlan_ports:
# Doesn't appear to have VLAN data in EXTREME MIBs, get out now.
returnValue(None)
return None
ifindex_vlan = yield self.extremevlan.get_ifindex_vlan_map()
self.baseport_ifindex = yield self.bridge.get_baseport_ifindex_map()

Expand Down
2 changes: 1 addition & 1 deletion python/nav/ipdevpoll/plugins/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _stackify(stackstatus):
stack = yield self.ifmib.get_stack_status().addCallback(_stackify)
self._get_ifalias_from_lower_layers(stack)
self._create_stack_containers(stack)
defer.returnValue(interfaces)
return interfaces

def _get_ifalias_from_lower_layers(self, stack):
"""For each interface without an ifAlias value, attempts to find
Expand Down
8 changes: 4 additions & 4 deletions python/nav/ipdevpoll/plugins/juniperdot1q.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

"""

from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks
from nav.enterprise.ids import VENDOR_ID_JUNIPER_NETWORKS_INC
from nav.oids import OID
from . import dot1q
Expand Down Expand Up @@ -84,12 +84,12 @@ def _retrieve_vlan_ports(self):
"""
(egress, untagged) = yield super(JuniperDot1q, self)._retrieve_vlan_ports()
if not self.jnx_vlan_map:
returnValue((egress, untagged))
return (egress, untagged)

new_egress = {self._remap_vlan(key): value for key, value in egress.items()}
new_untagged = {self._remap_vlan(key): value for key, value in untagged.items()}

returnValue((new_egress, new_untagged))
return (new_egress, new_untagged)

def __is_a_moronic_juniper_device(self):
if self.netbox.type:
Expand All @@ -103,4 +103,4 @@ def __get_jnx_ex_vlan_tag(self):
mappings = result.get(_jnxExVlanTag, {})
mappings = {OID(key)[-1]: value for key, value in mappings.items()}
self._logger.debug("got jnxExVlanTag map: %r", mappings)
returnValue(mappings)
return mappings
6 changes: 3 additions & 3 deletions python/nav/ipdevpoll/plugins/linkaggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
import logging
from collections import defaultdict
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks

from nav.ipdevpoll import Plugin
from nav.ipdevpoll import shadows
Expand Down Expand Up @@ -47,7 +47,7 @@ def _convert_to_interfaces(self, aggregatedict):
for if_idx in aggregates:
interface = yield self._get_interface(if_idx)
result.append((interface, aggregator))
returnValue(result)
return result

@inlineCallbacks
def _get_interface(self, ifindex):
Expand All @@ -56,7 +56,7 @@ def _get_interface(self, ifindex):
# In case no other plugins ran before us to collect this:
self._logger.debug("retrieving ifName.%s", ifindex)
ifc.ifname = yield self.ifmib.retrieve_column_by_index('ifName', (ifindex,))
returnValue(ifc)
return ifc

def _log_aggregates(self, aggregates):
if not self._logger.isEnabledFor(logging.DEBUG):
Expand Down
4 changes: 2 additions & 2 deletions python/nav/ipdevpoll/plugins/linkstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# License along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""Collects interface link states and dispatches NAV events on changes"""
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import inlineCallbacks

from nav.mibs import reduce_index
from nav.mibs.if_mib import IfMib
Expand All @@ -32,7 +32,7 @@ def handle(self):
self._logger.debug(
"this is a virtual instance of %s, not polling", self.netbox.master
)
returnValue(None)
return None

ifmib = IfMib(self.agent)
result = yield ifmib.retrieve_columns(
Expand Down
Loading
Loading