Skip to content

Commit 4f8ba92

Browse files
committed
Turns off debug. Adds an option to enable it.
Issues: Fixes #1394 Problem: Debugging could overwhelm memory on long-running sdk usage. Analysis: this is a problem, so by default we disable debugging and provide and option to enable it. Tests:
1 parent 9cff7a6 commit 4f8ba92

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

docs/userguide/debugging_api_calls.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Consider the following SDK usage
3131
.. code-block:: python
3232
3333
from f5.bigip import ManagementRoot
34-
mgmt = ManagementRoot('localhost', 'admin', 'admin', port=10443, token=True)
34+
mgmt = ManagementRoot('localhost', 'admin', 'admin', port=10443, token=True, debug=True)
3535
resource = mgmt.tm.ltm.pools.pool.create(name='foobar')
3636
3737
This SDK call communicates with a BIG-IP to create an LTM pool. What if you needed to recreate
@@ -47,7 +47,7 @@ let's print each of them.
4747

4848
.. code-block:: python
4949
50-
for x in mgmt._debug:
50+
for x in mgmt.debug_output:
5151
print(x)
5252
5353
When this is done, we will be presented with output that resembles the following (printed for readability).
@@ -92,3 +92,15 @@ handy is in the process of debugging errors, or, in implementing new functionali
9292

9393
You can copy and paste the commands as they are printed and use them to issue the same API calls the the
9494
equivalent SDK code does.
95+
96+
Enabling and disabling
97+
----------------------
98+
99+
The debug logging can also be enabled and disabled as desired. To do this, you can set the ``debug`` property
100+
of the ``ManagementRoot`` object to either a truth-like or false-like value. These include,
101+
102+
**Truth**
103+
'y', 'yes', 'on', '1', 'true', 't', 1, 1.0, True
104+
105+
**False**
106+
'n', 'no', 'off', '0', 'false', 'f', 0, 0.0, False

f5/bigip/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def parse_arguments(self, *args, **kwargs):
6565
icontrol_version=kwargs.pop('icontrol_version', ''),
6666
token=kwargs.pop('token', False),
6767
verify=kwargs.pop('verify', False),
68-
auth_provider=kwargs.pop('auth_provider', None)
68+
auth_provider=kwargs.pop('auth_provider', None),
69+
debug=kwargs.pop('debug', False)
6970
)
7071
if kwargs:
7172
raise TypeError('Unexpected **kwargs: %r' % kwargs)
@@ -89,6 +90,7 @@ def _get_icr_session(self, *args, **kwargs):
8990
params['token'] = kwargs['token']
9091

9192
result = iControlRESTSession(**params)
93+
result.debug = kwargs['debug']
9294
return result
9395

9496
def configure_meta_data(self, *args, **kwargs):
@@ -141,10 +143,18 @@ def tmos_version(self):
141143
return self._meta_data['tmos_version']
142144

143145
@property
144-
def _debug(self):
146+
def debug(self):
147+
return self.icrs.debug
148+
149+
@debug.setter
150+
def debug(self, value):
151+
self.icrs.debug = value
152+
153+
@property
154+
def debug_output(self):
145155
result = []
146-
if self.icrs._debug:
147-
result += self.icrs._debug
156+
if self.icrs.debug_output:
157+
result += self.icrs.debug_output
148158
return result
149159

150160

f5/bigip/test/functional/test__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@ def test_hard_timeout():
4545

4646

4747
def test_icontrol_debug_tracing(opt_bigip, opt_username, opt_password, opt_port):
48-
m = ManagementRoot(opt_bigip, opt_username, opt_password, port=opt_port)
49-
m._debug
50-
assert len(m._debug) > 0
48+
m = ManagementRoot(opt_bigip, opt_username, opt_password, port=opt_port, debug=True)
49+
assert len(m.debug_output) > 0

0 commit comments

Comments
 (0)