summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-07 10:21:08 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-07 10:21:11 +0200
commit733ebc67ca80c13efa4fa809f6ba763a38c3d0f7 (patch)
treea85ed7027d5e46995caa40616605516ad693ecfb /src
parent2afd1163361ea2ad3e94f51eac882007d8f9b7cf (diff)
downloadvyos-1x-733ebc67ca80c13efa4fa809f6ba763a38c3d0f7.tar.gz
vyos-1x-733ebc67ca80c13efa4fa809f6ba763a38c3d0f7.zip
[bridge] T1156: add missing if statement in config-migration
Fixes: Traceback (most recent call last): File "/opt/vyatta/etc/config-migrate/migrate/interfaces/0-to-1", line 27, in <module> for br in config.list_nodes(base): File "/usr/lib/python3/dist-packages/vyos/configtree.py", line 255, in list_nodes raise ConfigTreeError("Path [{}] doesn't exist".format(path_str)) vyos.configtree.ConfigTreeError: Path [b'interfaces bridge'] doesn't exist
Diffstat (limited to 'src')
-rwxr-xr-xsrc/migration-scripts/interfaces/0-to-1120
1 files changed, 62 insertions, 58 deletions
diff --git a/src/migration-scripts/interfaces/0-to-1 b/src/migration-scripts/interfaces/0-to-1
index b8e190f2c..38f2bd8f5 100755
--- a/src/migration-scripts/interfaces/0-to-1
+++ b/src/migration-scripts/interfaces/0-to-1
@@ -21,61 +21,65 @@ with open(file_name, 'r') as f:
config = ConfigTree(config_file)
base = ['interfaces', 'bridge']
-#
-# make stp and igmp-snooping nodes valueless
-#
-for br in config.list_nodes(base):
- # STP: check if enabled
- stp_val = config.return_value(base + [br, 'stp'])
- # STP: delete node with old syntax
- config.delete(base + [br, 'stp'])
- # STP: set new node - if enabled
- if stp_val == "true":
- config.set(base + [br, 'stp'], value=None)
-
- # igmp-snooping: check if enabled
- igmp_val = config.return_value(base + [br, 'igmp-snooping', 'querier'])
- # igmp-snooping: delete node with old syntax
- config.delete(base + [br, 'igmp-snooping', 'querier'])
- # igmp-snooping: set new node - if enabled
- if igmp_val == "enable":
- config.set(base + [br, 'igmp', 'querier'], value=None)
-
-#
-# move interface based bridge-group to actual bridge (de-nest)
-#
-bridge_types = ['bonding', 'ethernet', 'l2tpv3', 'openvpn', 'vxlan', 'wireless']
-for type in bridge_types:
- if not config.exists(['interfaces', type]):
- continue
-
- for intf in config.list_nodes(['interfaces', type]):
- # check if bridge-group exists
- if config.exists(['interfaces', type, intf, 'bridge-group']):
- bridge = config.return_value(['interfaces', type, intf, 'bridge-group', 'bridge'])
-
- # create new bridge member interface
- config.set(base + [bridge, 'member', 'interface', intf])
- # format as tag node to avoid loading problems
- config.set_tag(base + [bridge, 'member', 'interface'])
-
- # cost: migrate if configured
- if config.exists(['interfaces', type, intf, 'bridge-group', 'cost']):
- cost = config.return_value(['interfaces', type, intf, 'bridge-group', 'cost'])
- # set new node
- config.set(base + [bridge, 'member', 'interface', intf, 'cost'], value=cost)
-
- if config.exists(['interfaces', type, intf, 'bridge-group', 'priority']):
- priority = config.return_value(['interfaces', type, intf, 'bridge-group', 'priority'])
- # set new node
- config.set(base + [bridge, 'member', 'interface', intf, 'priority'], value=priority)
-
- # Delete the old bridge-group assigned to an interface
- config.delete(['interfaces', type, intf, 'bridge-group'])
-
- try:
- with open(file_name, 'w') as f:
- f.write(config.to_string())
- except OSError as e:
- print("Failed to save the modified config: {}".format(e))
- sys.exit(1)
+if not config.exists(base):
+ # Nothing to do
+ sys.exit(0)
+else:
+ #
+ # make stp and igmp-snooping nodes valueless
+ #
+ for br in config.list_nodes(base):
+ # STP: check if enabled
+ stp_val = config.return_value(base + [br, 'stp'])
+ # STP: delete node with old syntax
+ config.delete(base + [br, 'stp'])
+ # STP: set new node - if enabled
+ if stp_val == "true":
+ config.set(base + [br, 'stp'], value=None)
+
+ # igmp-snooping: check if enabled
+ igmp_val = config.return_value(base + [br, 'igmp-snooping', 'querier'])
+ # igmp-snooping: delete node with old syntax
+ config.delete(base + [br, 'igmp-snooping', 'querier'])
+ # igmp-snooping: set new node - if enabled
+ if igmp_val == "enable":
+ config.set(base + [br, 'igmp', 'querier'], value=None)
+
+ #
+ # move interface based bridge-group to actual bridge (de-nest)
+ #
+ bridge_types = ['bonding', 'ethernet', 'l2tpv3', 'openvpn', 'vxlan', 'wireless']
+ for type in bridge_types:
+ if not config.exists(['interfaces', type]):
+ continue
+
+ for intf in config.list_nodes(['interfaces', type]):
+ # check if bridge-group exists
+ if config.exists(['interfaces', type, intf, 'bridge-group']):
+ bridge = config.return_value(['interfaces', type, intf, 'bridge-group', 'bridge'])
+
+ # create new bridge member interface
+ config.set(base + [bridge, 'member', 'interface', intf])
+ # format as tag node to avoid loading problems
+ config.set_tag(base + [bridge, 'member', 'interface'])
+
+ # cost: migrate if configured
+ if config.exists(['interfaces', type, intf, 'bridge-group', 'cost']):
+ cost = config.return_value(['interfaces', type, intf, 'bridge-group', 'cost'])
+ # set new node
+ config.set(base + [bridge, 'member', 'interface', intf, 'cost'], value=cost)
+
+ if config.exists(['interfaces', type, intf, 'bridge-group', 'priority']):
+ priority = config.return_value(['interfaces', type, intf, 'bridge-group', 'priority'])
+ # set new node
+ config.set(base + [bridge, 'member', 'interface', intf, 'priority'], value=priority)
+
+ # Delete the old bridge-group assigned to an interface
+ config.delete(['interfaces', type, intf, 'bridge-group'])
+
+ try:
+ with open(file_name, 'w') as f:
+ f.write(config.to_string())
+ except OSError as e:
+ print("Failed to save the modified config: {}".format(e))
+ sys.exit(1)