Skip to content

Commit 069796d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Introduce new option ngs_save_configuration"
2 parents c56ec05 + 76d8b31 commit 069796d

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

doc/source/configuration.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,16 @@ networking generic switch adding or removing any VLANs::
292292

293293
[genericswitch:device-hostname]
294294
ngs_manage_vlans = False
295+
296+
Saving configuration on devices
297+
===============================
298+
299+
By default, all configuration changes are saved on persistent storage of the
300+
devices, using model-specific commands. This occurs after each change.
301+
302+
This may be undesirable for performance reasons, or if you have external means
303+
of saving configuration on a regular basis. In this case, configuration saving
304+
can be disabled::
305+
306+
[genericswitch:device-hostname]
307+
ngs_save_configuration = False

networking_generic_switch/devices/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
{'name': 'ngs_network_name_format', 'default': '{network_id}'},
4343
# If false, ngs will not add and delete VLANs from switches
4444
{'name': 'ngs_manage_vlans', 'default': True},
45+
# If False, ngs will skip saving configuration on devices
46+
{'name': 'ngs_save_configuration', 'default': True},
4547
]
4648

4749

@@ -121,6 +123,11 @@ def _disable_inactive_ports(self):
121123
return strutils.bool_from_string(
122124
self.ngs_config['ngs_disable_inactive_ports'])
123125

126+
def _get_save_configuration(self):
127+
"""Return whether configuration should be saved on device."""
128+
return strutils.bool_from_string(
129+
self.ngs_config['ngs_save_configuration'])
130+
124131
def _get_network_name(self, network_id, segmentation_id):
125132
"""Return a network name to configure on switches.
126133

networking_generic_switch/devices/netmiko_devices/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ def send_commands_to_device(self, cmd_set):
192192
with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
193193
with self._get_connection() as net_connect:
194194
output = self.send_config_set(net_connect, cmd_set)
195-
# NOTE (vsaienko) always save configuration
196-
# when configuration is applied successfully.
197-
self.save_configuration(net_connect)
195+
if self._get_save_configuration():
196+
# Save configuration only if enabled in settings
197+
# and when configuration is applied successfully.
198+
self.save_configuration(net_connect)
198199
except exc.GenericSwitchException:
199200
# Reraise without modification exceptions originating from this
200201
# module.

networking_generic_switch/tests/unit/netmiko/test_netmiko_base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ def test_send_commands_to_device(self, save_mock, send_mock, gc_mock):
256256
self.assertEqual('fake output', result)
257257
save_mock.assert_called_once_with(connect_mock)
258258

259+
@mock.patch.object(netmiko_devices.NetmikoSwitch, '_get_connection')
260+
@mock.patch.object(netmiko_devices.NetmikoSwitch, 'send_config_set')
261+
@mock.patch.object(netmiko_devices.NetmikoSwitch, 'save_configuration')
262+
def test_send_commands_to_device_without_save_config(self, save_mock,
263+
send_mock, gc_mock):
264+
switch = self._make_switch_device(
265+
extra_cfg={'ngs_save_configuration': False})
266+
connect_mock = mock.MagicMock(netmiko.base_connection.BaseConnection)
267+
gc_mock.return_value.__enter__.return_value = connect_mock
268+
send_mock.return_value = 'fake output'
269+
result = switch.send_commands_to_device(['spam ham aaaa'])
270+
send_mock.assert_called_once_with(connect_mock, ['spam ham aaaa'])
271+
self.assertEqual('fake output', result)
272+
save_mock.assert_not_called()
273+
259274
def test_send_config_set(self):
260275
connect_mock = mock.MagicMock(netmiko.base_connection.BaseConnection)
261276
connect_mock.send_config_set.return_value = 'fake output'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add new device setting ``ngs_save_configuration``, allowing to disable
5+
saving configuration on the device after each change. This can speed up
6+
the overall process significantly, but changes will be lost if the device
7+
reboots.

0 commit comments

Comments
 (0)