Petr Horáček has uploaded a new change for review. Change subject: network: allow custom bondOption ......................................................................
network: allow custom bondOption Allow 'custom' in bond options. This value will be accepted by Bond.validateOptions method but it will not be passed to configurator. Thanks to this patch, users will be allowed to pass custom properties to setupNetworks hooks. This path was reverted in past because of malfunction, now it should work, there is a new test for sure. Change-Id: I9ace532d959bc3195a8a92b4536bdc0062bc7d1d Signed-off-by: Petr Horáček <[email protected]> --- M lib/vdsm/netinfo.py M tests/functional/networkTests.py M vdsm/network/models.py 3 files changed, 44 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/82/40882/1 diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index e7563d6..3a2aa8e 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -70,8 +70,9 @@ _BONDING_FAILOVER_MODES = frozenset(('1', '3')) _BONDING_LOADBALANCE_MODES = frozenset(('0', '2', '4', '5', '6')) _EXCLUDED_BONDING_ENTRIES = frozenset(( - 'slaves', 'active_slave', 'mii_status', 'queue_id', 'ad_aggregator', - 'ad_num_ports', 'ad_actor_key', 'ad_partner_key', 'ad_partner_mac' + 'slaves', 'active_slave', 'mii_status', 'queue_id', 'ad_aggregator', + 'ad_num_ports', 'ad_actor_key', 'ad_partner_key', 'ad_partner_mac', + 'custom' )) _IFCFG_ZERO_SUFFIXED = frozenset( ('IPADDR0', 'GATEWAY0', 'PREFIX0', 'NETMASK0')) diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py index 0bfda68..1328783 100644 --- a/tests/functional/networkTests.py +++ b/tests/functional/networkTests.py @@ -1848,7 +1848,7 @@ else: network_params.update( {'ipaddr': IP_ADDRESS_IN_NETWORK, 'netmask': IP_MASK, - 'gateway': IP_GATEWAY}) + 'gateway': IP_GATEWAY}) status, msg = self.vdsm_net.setupNetworks( {NETWORK_NAME: network_params}, {}, NOCHK) @@ -2387,3 +2387,25 @@ self.assertNetworkDoesntExist(NETWORK_NAME) self.assertBondDoesntExist(BONDING_NAME, [nic]) self.vdsm_net.save_config() + + @cleanupNet + @ValidateRunningAsRoot + def test_setupNetworks_bond_with_custom_option(self): + with dummyIf(1) as nics: + status, msg = self.vdsm_net.setupNetworks( + {}, + {BONDING_NAME: {'nics': nics, + 'options': 'custom=foo mode=balance-rr'}}, + NOCHK) + self.assertEqual(status, SUCCESS, msg) + self.assertBondExists(BONDING_NAME, nics) + with open(NET_CONF_PREF + BONDING_NAME) as f: + for l in f: + if 'BONDING_OPTS' in l: + self.assertNotIn('custom=foo', l) + self.assertIn('mode=balance-rr', l) + + status, msg = self.vdsm_net.setupNetworks( + {}, {BONDING_NAME: {'remove': True}}, NOCHK) + self.assertEqual(status, SUCCESS, msg) + self.assertBondDoesntExist(BONDING_NAME, nics) diff --git a/vdsm/network/models.py b/vdsm/network/models.py index 708bad8..9526b99 100644 --- a/vdsm/network/models.py +++ b/vdsm/network/models.py @@ -276,9 +276,25 @@ _netinfo=_netinfo)) return slaves + @staticmethod + def remove_custom_option(options): + """ 'custom' property should not be exposed to configurator, it is + only for purpose of hooks """ + d_opts = dict(opt.split('=', 1) for opt in options.split()) + try: + d_opts.pop('custom') + d_opts = ['%s=%s' % (key, value) for key, value in d_opts.items()] + return ' '.join(d_opts) + except KeyError: + return options + @classmethod def objectivize(cls, name, configurator, options, nics, mtu, _netinfo, destroyOnMasterRemoval=None): + + if options: + options = cls.remove_custom_option(options) + if nics: # New bonding or edit bonding. slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics), mtu, _netinfo) @@ -318,8 +334,8 @@ try: for option in bondingOptions.split(): key, _ = option.split('=') - if not os.path.exists('/sys/class/net/%s/bonding/%s' % - (bond, key)): + if key != 'custom' and not os.path.exists( + '/sys/class/net/%s/bonding/%s' % (bond, key)): raise ConfigNetworkError(ne.ERR_BAD_BONDING, '%r is ' 'not a valid bonding option' % key) -- To view, visit https://gerrit.ovirt.org/40882 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9ace532d959bc3195a8a92b4536bdc0062bc7d1d Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Petr Horáček <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
