Browse Source

Numvfs setting during update/upgrade

Earlier numvfs is set by puppet-tripleo. Now during update/upgrade,
the numvfs setting and persistence across reboot shall be managed
by os-net-config with the corresponding setting of numvfs via
nic-configs. However the numvfs value can't be changed during
the update/upgrade.

Change-Id: I717d822eb64f95c129bcfd66b553784643333f0e
(cherry picked from commit d9ea668972)
tags/8.5.1
Karthik S 1 month ago
parent
commit
5541c98ceb

+ 18
- 2
os_net_config/sriov_config.py View File

@@ -102,6 +102,17 @@ def _get_sriov_map():
102 102
     return sriov_map
103 103
 
104 104
 
105
+def get_numvfs(ifname):
106
+    try:
107
+        sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, ifname,
108
+                                         "device/sriov_numvfs")
109
+        with open(sriov_numvfs_path, 'r') as f:
110
+            return int(f.read())
111
+    except IOError:
112
+        msg = ("Unable to read numvfs for %s" % ifname)
113
+        raise SRIOVNumvfsException(msg)
114
+
115
+
105 116
 def configure_sriov_pf():
106 117
     # Create a context for pyudev and observe udev events for network
107 118
     context = pyudev.Context()
@@ -118,8 +129,13 @@ def configure_sriov_pf():
118 129
         if item['device_type'] == 'pf':
119 130
             _pf_interface_up(item)
120 131
             try:
121
-                sriov_numvfs_path = ("/sys/class/net/%s/device/sriov_numvfs"
122
-                                     % item['name'])
132
+                sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, item['name'],
133
+                                                 "device/sriov_numvfs")
134
+                curr_numvfs = get_numvfs(item['name'])
135
+                if curr_numvfs == item['numvfs']:
136
+                    logger.info("Numvfs already configured for %s"
137
+                                % item['name'])
138
+                    continue
123 139
                 with open(sriov_numvfs_path, 'w') as f:
124 140
                     f.write("%d" % item['numvfs'])
125 141
             except IOError as exc:

+ 4
- 0
os_net_config/tests/test_impl_ifcfg.py View File

@@ -1934,6 +1934,10 @@ class TestIfcfgNetConfigApply(base.TestCase):
1934 1934
         self.assertEqual(_ROUTES, route_data)
1935 1935
 
1936 1936
     def test_sriov_pf_network_apply(self):
1937
+        def get_numvfs_stub(pf_name):
1938
+            return 0
1939
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
1940
+                      get_numvfs_stub)
1937 1941
         route1 = objects.Route('192.168.1.1', default=True,
1938 1942
                                route_options="metric 10")
1939 1943
         route2 = objects.Route('192.168.1.1', '172.19.0.0/24')

+ 41
- 11
os_net_config/tests/test_utils.py View File

@@ -119,6 +119,10 @@ class TestUtils(base.TestCase):
119 119
         shutil.rmtree(tmpdir)
120 120
 
121 121
     def test_update_sriov_pf_map_new(self):
122
+        def get_numvfs_stub(pf_name):
123
+            return 0
124
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
125
+                      get_numvfs_stub)
122 126
         utils.update_sriov_pf_map('eth1', 10, False)
123 127
         contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
124 128
         sriov_pf_map = yaml.safe_load(contents) if contents else []
@@ -127,7 +131,32 @@ class TestUtils(base.TestCase):
127 131
                               'name': 'eth1', 'numvfs': 10}]
128 132
         self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
129 133
 
134
+    def test_update_sriov_pf_map_with_same_numvfs(self):
135
+        def get_numvfs_stub(pf_name):
136
+            return 10
137
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
138
+                      get_numvfs_stub)
139
+        utils.update_sriov_pf_map('eth1', 10, False)
140
+        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
141
+        sriov_pf_map = yaml.safe_load(contents) if contents else []
142
+        self.assertEqual(1, len(sriov_pf_map))
143
+        test_sriov_pf_map = [{'device_type': 'pf', 'link_mode': 'legacy',
144
+                              'name': 'eth1', 'numvfs': 10}]
145
+        self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
146
+
147
+    def test_update_sriov_pf_map_with_diff_numvfs(self):
148
+        def get_numvfs_stub(pf_name):
149
+            return 12
150
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
151
+                      get_numvfs_stub)
152
+        self.assertRaises(sriov_config.SRIOVNumvfsException,
153
+                          utils.update_sriov_pf_map, 'eth1', 10, False)
154
+
130 155
     def test_update_sriov_pf_map_new_with_promisc(self):
156
+        def get_numvfs_stub(pf_name):
157
+            return 0
158
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
159
+                      get_numvfs_stub)
131 160
         utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
132 161
         contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
133 162
         sriov_pf_map = yaml.safe_load(contents) if contents else []
@@ -137,27 +166,28 @@ class TestUtils(base.TestCase):
137 166
         self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
138 167
 
139 168
     def test_update_sriov_pf_map_exist(self):
169
+        def get_numvfs_stub(pf_name):
170
+            return 10
171
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
172
+                      get_numvfs_stub)
140 173
         pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
141 174
                        'name': 'eth1', 'numvfs': 10}]
142 175
         utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)
143
-
144
-        utils.update_sriov_pf_map('eth1', 20, False)
145
-        pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
146
-                     'name': 'eth1', 'numvfs': 20}]
147
-        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
148
-
149
-        pf_map = yaml.safe_load(contents) if contents else []
150
-        self.assertEqual(1, len(pf_map))
151
-        self.assertListEqual(pf_final, pf_map)
176
+        self.assertRaises(sriov_config.SRIOVNumvfsException,
177
+                          utils.update_sriov_pf_map, 'eth1', 20, False)
152 178
 
153 179
     def test_update_sriov_pf_map_exist_with_promisc(self):
180
+        def get_numvfs_stub(pf_name):
181
+            return 10
182
+        self.stub_out('os_net_config.sriov_config.get_numvfs',
183
+                      get_numvfs_stub)
154 184
         pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
155 185
                        'name': 'eth1', 'numvfs': 10, 'promisc': 'on'}]
156 186
         utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)
157 187
 
158
-        utils.update_sriov_pf_map('eth1', 20, False)
188
+        utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
159 189
         pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
160
-                     'name': 'eth1', 'numvfs': 20, 'promisc': 'on'}]
190
+                     'name': 'eth1', 'numvfs': 10, 'promisc': 'off'}]
161 191
         contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
162 192
 
163 193
         pf_map = yaml.safe_load(contents) if contents else []

+ 4
- 0
os_net_config/utils.py View File

@@ -417,6 +417,10 @@ def _get_dpdk_mac_address(name):
417 417
 def update_sriov_pf_map(ifname, numvfs, noop, promisc=None,
418 418
                         link_mode='legacy'):
419 419
     if not noop:
420
+        cur_numvfs = sriov_config.get_numvfs(ifname)
421
+        if cur_numvfs > 0 and cur_numvfs != numvfs:
422
+            msg = ("Can't change the numvfs for %s" % ifname)
423
+            raise sriov_config.SRIOVNumvfsException(msg)
420 424
         sriov_map = _get_sriov_map()
421 425
         for item in sriov_map:
422 426
             if item['device_type'] == 'pf' and item['name'] == ifname:

Loading…
Cancel
Save