Merge ~sw37th/cloud-init:opennebula_fix_null_gateway6 into cloud-init:master
- Git
- lp:~sw37th/cloud-init
- opennebula_fix_null_gateway6
- Merge into master
Status: | Merged |
---|---|
Approved by: | Scott Moser |
Approved revision: | 3f8f3249643056c751efe11ce27edfe56d9cec3d |
Merge reported by: | Server Team CI bot |
Merged at revision: | not available |
Proposed branch: | ~sw37th/cloud-init:opennebula_fix_null_gateway6 |
Merge into: | cloud-init:master |
Diff against target: |
446 lines (+407/-3) 2 files modified
cloudinit/sources/DataSourceOpenNebula.py (+1/-1) tests/unittests/test_datasource/test_opennebula.py (+406/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Server Team CI bot | continuous-integration | Approve | |
Scott Moser | Approve | ||
Review via email: mp+350428@code.launchpad.net |
Commit message
OpenNebula: Fix null gateway6
The OpenNebula data source generates an invalid netplan yaml file
if the IPv6 gateway is not defined in context.sh.
LP: #1768547
Description of the change
Akihiko Ota (sw37th) wrote : | # |
Scott Moser (smoser) wrote : | # |
Hi,
Thanks for the merge proposal. I'll have the c-i bot run tests on it and it will post result here shortly.
That said, I'd like to see a unit tests added that covers this path.
It looks l ike you should be able to add a test to
tests/
without too much effort.
Please feel free to ping me if you have any questions.
Thanks!
- 57941a4... by Akihiko Ota
-
OpenNebula: add tests for OpenNebulaNetwo
rk.gen_ conf() - 148dda5... by Akihiko Ota
-
OpenNebula: add tests for several get methods of OpenNebulaNetwork
Akihiko Ota (sw37th) wrote : | # |
Hi Scott,
Ok, I added some tests for TestOpenNebulaN
And also added several tests for get_* methods.
Scott Moser (smoser) wrote : | # |
Akihiko,
This looks great, thank you for the extended test coverage.
I have a few little things inline.
https:/
is running against your build here and will post its results.
- 3f8f324... by Akihiko Ota
-
OpenNebula: Fix up unittests
Added docstring, changed argument order of assertEqual, and splited some
tests.
Changed from assertIsNone() to assertEqual() to avoid RPM build error.
Akihiko Ota (sw37th) wrote : | # |
Hi Scott,
I have changed TestOpenNebulaN
- added docstrings to each new tests.
- changed argument order of assertEqual().
- splited some tests.
And changed from assertIsNone() to assertEqual() to avoid RPM build error.
Please confirm.
Scott Moser (smoser) wrote : | # |
Akihiko,
Thanks.
https:/
is running it will post here.
if it passes. i approve.
thanks.
Server Team CI bot (server-team-bot) : | # |
Preview Diff
1 | diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py | |||
2 | index 16c1078..77ccd12 100644 | |||
3 | --- a/cloudinit/sources/DataSourceOpenNebula.py | |||
4 | +++ b/cloudinit/sources/DataSourceOpenNebula.py | |||
5 | @@ -232,7 +232,7 @@ class OpenNebulaNetwork(object): | |||
6 | 232 | 232 | ||
7 | 233 | # Set IPv6 default gateway | 233 | # Set IPv6 default gateway |
8 | 234 | gateway6 = self.get_gateway6(c_dev) | 234 | gateway6 = self.get_gateway6(c_dev) |
10 | 235 | if gateway: | 235 | if gateway6: |
11 | 236 | devconf['gateway6'] = gateway6 | 236 | devconf['gateway6'] = gateway6 |
12 | 237 | 237 | ||
13 | 238 | # Set DNS servers and search domains | 238 | # Set DNS servers and search domains |
14 | diff --git a/tests/unittests/test_datasource/test_opennebula.py b/tests/unittests/test_datasource/test_opennebula.py | |||
15 | index ab42f34..36b4d77 100644 | |||
16 | --- a/tests/unittests/test_datasource/test_opennebula.py | |||
17 | +++ b/tests/unittests/test_datasource/test_opennebula.py | |||
18 | @@ -354,6 +354,412 @@ class TestOpenNebulaNetwork(unittest.TestCase): | |||
19 | 354 | 354 | ||
20 | 355 | system_nics = ('eth0', 'ens3') | 355 | system_nics = ('eth0', 'ens3') |
21 | 356 | 356 | ||
22 | 357 | def test_context_devname(self): | ||
23 | 358 | """Verify context_devname correctly returns mac and name.""" | ||
24 | 359 | context = { | ||
25 | 360 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
26 | 361 | 'ETH1_MAC': '02:00:0a:12:0f:0f', } | ||
27 | 362 | expected = { | ||
28 | 363 | '02:00:0a:12:01:01': 'ETH0', | ||
29 | 364 | '02:00:0a:12:0f:0f': 'ETH1', } | ||
30 | 365 | net = ds.OpenNebulaNetwork(context) | ||
31 | 366 | self.assertEqual(expected, net.context_devname) | ||
32 | 367 | |||
33 | 368 | def test_get_nameservers(self): | ||
34 | 369 | """ | ||
35 | 370 | Verify get_nameservers('device') correctly returns DNS server addresses | ||
36 | 371 | and search domains. | ||
37 | 372 | """ | ||
38 | 373 | context = { | ||
39 | 374 | 'DNS': '1.2.3.8', | ||
40 | 375 | 'ETH0_DNS': '1.2.3.6 1.2.3.7', | ||
41 | 376 | 'ETH0_SEARCH_DOMAIN': 'example.com example.org', } | ||
42 | 377 | expected = { | ||
43 | 378 | 'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8'], | ||
44 | 379 | 'search': ['example.com', 'example.org']} | ||
45 | 380 | net = ds.OpenNebulaNetwork(context) | ||
46 | 381 | val = net.get_nameservers('eth0') | ||
47 | 382 | self.assertEqual(expected, val) | ||
48 | 383 | |||
49 | 384 | def test_get_mtu(self): | ||
50 | 385 | """Verify get_mtu('device') correctly returns MTU size.""" | ||
51 | 386 | context = {'ETH0_MTU': '1280'} | ||
52 | 387 | net = ds.OpenNebulaNetwork(context) | ||
53 | 388 | val = net.get_mtu('eth0') | ||
54 | 389 | self.assertEqual('1280', val) | ||
55 | 390 | |||
56 | 391 | def test_get_ip(self): | ||
57 | 392 | """Verify get_ip('device') correctly returns IPv4 address.""" | ||
58 | 393 | context = {'ETH0_IP': PUBLIC_IP} | ||
59 | 394 | net = ds.OpenNebulaNetwork(context) | ||
60 | 395 | val = net.get_ip('eth0', MACADDR) | ||
61 | 396 | self.assertEqual(PUBLIC_IP, val) | ||
62 | 397 | |||
63 | 398 | def test_get_ip_emptystring(self): | ||
64 | 399 | """ | ||
65 | 400 | Verify get_ip('device') correctly returns IPv4 address. | ||
66 | 401 | It returns IP address created by MAC address if ETH0_IP has empty | ||
67 | 402 | string. | ||
68 | 403 | """ | ||
69 | 404 | context = {'ETH0_IP': ''} | ||
70 | 405 | net = ds.OpenNebulaNetwork(context) | ||
71 | 406 | val = net.get_ip('eth0', MACADDR) | ||
72 | 407 | self.assertEqual(IP_BY_MACADDR, val) | ||
73 | 408 | |||
74 | 409 | def test_get_ip6(self): | ||
75 | 410 | """ | ||
76 | 411 | Verify get_ip6('device') correctly returns IPv6 address. | ||
77 | 412 | In this case, IPv6 address is Given by ETH0_IP6. | ||
78 | 413 | """ | ||
79 | 414 | context = { | ||
80 | 415 | 'ETH0_IP6': IP6_GLOBAL, | ||
81 | 416 | 'ETH0_IP6_ULA': '', } | ||
82 | 417 | expected = [IP6_GLOBAL] | ||
83 | 418 | net = ds.OpenNebulaNetwork(context) | ||
84 | 419 | val = net.get_ip6('eth0') | ||
85 | 420 | self.assertEqual(expected, val) | ||
86 | 421 | |||
87 | 422 | def test_get_ip6_ula(self): | ||
88 | 423 | """ | ||
89 | 424 | Verify get_ip6('device') correctly returns IPv6 address. | ||
90 | 425 | In this case, IPv6 address is Given by ETH0_IP6_ULA. | ||
91 | 426 | """ | ||
92 | 427 | context = { | ||
93 | 428 | 'ETH0_IP6': '', | ||
94 | 429 | 'ETH0_IP6_ULA': IP6_ULA, } | ||
95 | 430 | expected = [IP6_ULA] | ||
96 | 431 | net = ds.OpenNebulaNetwork(context) | ||
97 | 432 | val = net.get_ip6('eth0') | ||
98 | 433 | self.assertEqual(expected, val) | ||
99 | 434 | |||
100 | 435 | def test_get_ip6_dual(self): | ||
101 | 436 | """ | ||
102 | 437 | Verify get_ip6('device') correctly returns IPv6 address. | ||
103 | 438 | In this case, IPv6 addresses are Given by ETH0_IP6 and ETH0_IP6_ULA. | ||
104 | 439 | """ | ||
105 | 440 | context = { | ||
106 | 441 | 'ETH0_IP6': IP6_GLOBAL, | ||
107 | 442 | 'ETH0_IP6_ULA': IP6_ULA, } | ||
108 | 443 | expected = [IP6_GLOBAL, IP6_ULA] | ||
109 | 444 | net = ds.OpenNebulaNetwork(context) | ||
110 | 445 | val = net.get_ip6('eth0') | ||
111 | 446 | self.assertEqual(expected, val) | ||
112 | 447 | |||
113 | 448 | def test_get_ip6_prefix(self): | ||
114 | 449 | """ | ||
115 | 450 | Verify get_ip6_prefix('device') correctly returns IPv6 prefix. | ||
116 | 451 | """ | ||
117 | 452 | context = {'ETH0_IP6_PREFIX_LENGTH': IP6_PREFIX} | ||
118 | 453 | net = ds.OpenNebulaNetwork(context) | ||
119 | 454 | val = net.get_ip6_prefix('eth0') | ||
120 | 455 | self.assertEqual(IP6_PREFIX, val) | ||
121 | 456 | |||
122 | 457 | def test_get_ip6_prefix_emptystring(self): | ||
123 | 458 | """ | ||
124 | 459 | Verify get_ip6_prefix('device') correctly returns IPv6 prefix. | ||
125 | 460 | It returns default value '64' if ETH0_IP6_PREFIX_LENGTH has empty | ||
126 | 461 | string. | ||
127 | 462 | """ | ||
128 | 463 | context = {'ETH0_IP6_PREFIX_LENGTH': ''} | ||
129 | 464 | net = ds.OpenNebulaNetwork(context) | ||
130 | 465 | val = net.get_ip6_prefix('eth0') | ||
131 | 466 | self.assertEqual('64', val) | ||
132 | 467 | |||
133 | 468 | def test_get_gateway(self): | ||
134 | 469 | """ | ||
135 | 470 | Verify get_gateway('device') correctly returns IPv4 default gateway | ||
136 | 471 | address. | ||
137 | 472 | """ | ||
138 | 473 | context = {'ETH0_GATEWAY': '1.2.3.5'} | ||
139 | 474 | net = ds.OpenNebulaNetwork(context) | ||
140 | 475 | val = net.get_gateway('eth0') | ||
141 | 476 | self.assertEqual('1.2.3.5', val) | ||
142 | 477 | |||
143 | 478 | def test_get_gateway6(self): | ||
144 | 479 | """ | ||
145 | 480 | Verify get_gateway6('device') correctly returns IPv6 default gateway | ||
146 | 481 | address. | ||
147 | 482 | """ | ||
148 | 483 | context = {'ETH0_GATEWAY6': IP6_GW} | ||
149 | 484 | net = ds.OpenNebulaNetwork(context) | ||
150 | 485 | val = net.get_gateway6('eth0') | ||
151 | 486 | self.assertEqual(IP6_GW, val) | ||
152 | 487 | |||
153 | 488 | def test_get_mask(self): | ||
154 | 489 | """ | ||
155 | 490 | Verify get_mask('device') correctly returns IPv4 subnet mask. | ||
156 | 491 | """ | ||
157 | 492 | context = {'ETH0_MASK': '255.255.0.0'} | ||
158 | 493 | net = ds.OpenNebulaNetwork(context) | ||
159 | 494 | val = net.get_mask('eth0') | ||
160 | 495 | self.assertEqual('255.255.0.0', val) | ||
161 | 496 | |||
162 | 497 | def test_get_mask_emptystring(self): | ||
163 | 498 | """ | ||
164 | 499 | Verify get_mask('device') correctly returns IPv4 subnet mask. | ||
165 | 500 | It returns default value '255.255.255.0' if ETH0_MASK has empty string. | ||
166 | 501 | """ | ||
167 | 502 | context = {'ETH0_MASK': ''} | ||
168 | 503 | net = ds.OpenNebulaNetwork(context) | ||
169 | 504 | val = net.get_mask('eth0') | ||
170 | 505 | self.assertEqual('255.255.255.0', val) | ||
171 | 506 | |||
172 | 507 | def test_get_network(self): | ||
173 | 508 | """ | ||
174 | 509 | Verify get_network('device') correctly returns IPv4 network address. | ||
175 | 510 | """ | ||
176 | 511 | context = {'ETH0_NETWORK': '1.2.3.0'} | ||
177 | 512 | net = ds.OpenNebulaNetwork(context) | ||
178 | 513 | val = net.get_network('eth0', MACADDR) | ||
179 | 514 | self.assertEqual('1.2.3.0', val) | ||
180 | 515 | |||
181 | 516 | def test_get_network_emptystring(self): | ||
182 | 517 | """ | ||
183 | 518 | Verify get_network('device') correctly returns IPv4 network address. | ||
184 | 519 | It returns network address created by MAC address if ETH0_NETWORK has | ||
185 | 520 | empty string. | ||
186 | 521 | """ | ||
187 | 522 | context = {'ETH0_NETWORK': ''} | ||
188 | 523 | net = ds.OpenNebulaNetwork(context) | ||
189 | 524 | val = net.get_network('eth0', MACADDR) | ||
190 | 525 | self.assertEqual('10.18.1.0', val) | ||
191 | 526 | |||
192 | 527 | def test_get_field(self): | ||
193 | 528 | """ | ||
194 | 529 | Verify get_field('device', 'name') returns *context* value. | ||
195 | 530 | """ | ||
196 | 531 | context = {'ETH9_DUMMY': 'DUMMY_VALUE'} | ||
197 | 532 | net = ds.OpenNebulaNetwork(context) | ||
198 | 533 | val = net.get_field('eth9', 'dummy') | ||
199 | 534 | self.assertEqual('DUMMY_VALUE', val) | ||
200 | 535 | |||
201 | 536 | def test_get_field_withdefaultvalue(self): | ||
202 | 537 | """ | ||
203 | 538 | Verify get_field('device', 'name', 'default value') returns *context* | ||
204 | 539 | value. | ||
205 | 540 | """ | ||
206 | 541 | context = {'ETH9_DUMMY': 'DUMMY_VALUE'} | ||
207 | 542 | net = ds.OpenNebulaNetwork(context) | ||
208 | 543 | val = net.get_field('eth9', 'dummy', 'DEFAULT_VALUE') | ||
209 | 544 | self.assertEqual('DUMMY_VALUE', val) | ||
210 | 545 | |||
211 | 546 | def test_get_field_withdefaultvalue_emptycontext(self): | ||
212 | 547 | """ | ||
213 | 548 | Verify get_field('device', 'name', 'default value') returns *default* | ||
214 | 549 | value if context value is empty string. | ||
215 | 550 | """ | ||
216 | 551 | context = {'ETH9_DUMMY': ''} | ||
217 | 552 | net = ds.OpenNebulaNetwork(context) | ||
218 | 553 | val = net.get_field('eth9', 'dummy', 'DEFAULT_VALUE') | ||
219 | 554 | self.assertEqual('DEFAULT_VALUE', val) | ||
220 | 555 | |||
221 | 556 | def test_get_field_emptycontext(self): | ||
222 | 557 | """ | ||
223 | 558 | Verify get_field('device', 'name') returns None if context value is | ||
224 | 559 | empty string. | ||
225 | 560 | """ | ||
226 | 561 | context = {'ETH9_DUMMY': ''} | ||
227 | 562 | net = ds.OpenNebulaNetwork(context) | ||
228 | 563 | val = net.get_field('eth9', 'dummy') | ||
229 | 564 | self.assertEqual(None, val) | ||
230 | 565 | |||
231 | 566 | def test_get_field_nonecontext(self): | ||
232 | 567 | """ | ||
233 | 568 | Verify get_field('device', 'name') returns None if context value is | ||
234 | 569 | None. | ||
235 | 570 | """ | ||
236 | 571 | context = {'ETH9_DUMMY': None} | ||
237 | 572 | net = ds.OpenNebulaNetwork(context) | ||
238 | 573 | val = net.get_field('eth9', 'dummy') | ||
239 | 574 | self.assertEqual(None, val) | ||
240 | 575 | |||
241 | 576 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | ||
242 | 577 | def test_gen_conf_gateway(self, m_get_phys_by_mac): | ||
243 | 578 | """Test rendering with/without IPv4 gateway""" | ||
244 | 579 | self.maxDiff = None | ||
245 | 580 | # empty ETH0_GATEWAY | ||
246 | 581 | context = { | ||
247 | 582 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
248 | 583 | 'ETH0_GATEWAY': '', } | ||
249 | 584 | for nic in self.system_nics: | ||
250 | 585 | expected = { | ||
251 | 586 | 'version': 2, | ||
252 | 587 | 'ethernets': { | ||
253 | 588 | nic: { | ||
254 | 589 | 'match': {'macaddress': MACADDR}, | ||
255 | 590 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
256 | 591 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
257 | 592 | net = ds.OpenNebulaNetwork(context) | ||
258 | 593 | self.assertEqual(net.gen_conf(), expected) | ||
259 | 594 | |||
260 | 595 | # set ETH0_GATEWAY | ||
261 | 596 | context = { | ||
262 | 597 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
263 | 598 | 'ETH0_GATEWAY': '1.2.3.5', } | ||
264 | 599 | for nic in self.system_nics: | ||
265 | 600 | expected = { | ||
266 | 601 | 'version': 2, | ||
267 | 602 | 'ethernets': { | ||
268 | 603 | nic: { | ||
269 | 604 | 'gateway4': '1.2.3.5', | ||
270 | 605 | 'match': {'macaddress': MACADDR}, | ||
271 | 606 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
272 | 607 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
273 | 608 | net = ds.OpenNebulaNetwork(context) | ||
274 | 609 | self.assertEqual(net.gen_conf(), expected) | ||
275 | 610 | |||
276 | 611 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | ||
277 | 612 | def test_gen_conf_gateway6(self, m_get_phys_by_mac): | ||
278 | 613 | """Test rendering with/without IPv6 gateway""" | ||
279 | 614 | self.maxDiff = None | ||
280 | 615 | # empty ETH0_GATEWAY6 | ||
281 | 616 | context = { | ||
282 | 617 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
283 | 618 | 'ETH0_GATEWAY6': '', } | ||
284 | 619 | for nic in self.system_nics: | ||
285 | 620 | expected = { | ||
286 | 621 | 'version': 2, | ||
287 | 622 | 'ethernets': { | ||
288 | 623 | nic: { | ||
289 | 624 | 'match': {'macaddress': MACADDR}, | ||
290 | 625 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
291 | 626 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
292 | 627 | net = ds.OpenNebulaNetwork(context) | ||
293 | 628 | self.assertEqual(net.gen_conf(), expected) | ||
294 | 629 | |||
295 | 630 | # set ETH0_GATEWAY6 | ||
296 | 631 | context = { | ||
297 | 632 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
298 | 633 | 'ETH0_GATEWAY6': IP6_GW, } | ||
299 | 634 | for nic in self.system_nics: | ||
300 | 635 | expected = { | ||
301 | 636 | 'version': 2, | ||
302 | 637 | 'ethernets': { | ||
303 | 638 | nic: { | ||
304 | 639 | 'gateway6': IP6_GW, | ||
305 | 640 | 'match': {'macaddress': MACADDR}, | ||
306 | 641 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
307 | 642 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
308 | 643 | net = ds.OpenNebulaNetwork(context) | ||
309 | 644 | self.assertEqual(net.gen_conf(), expected) | ||
310 | 645 | |||
311 | 646 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | ||
312 | 647 | def test_gen_conf_ipv6address(self, m_get_phys_by_mac): | ||
313 | 648 | """Test rendering with/without IPv6 address""" | ||
314 | 649 | self.maxDiff = None | ||
315 | 650 | # empty ETH0_IP6, ETH0_IP6_ULA, ETH0_IP6_PREFIX_LENGTH | ||
316 | 651 | context = { | ||
317 | 652 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
318 | 653 | 'ETH0_IP6': '', | ||
319 | 654 | 'ETH0_IP6_ULA': '', | ||
320 | 655 | 'ETH0_IP6_PREFIX_LENGTH': '', } | ||
321 | 656 | for nic in self.system_nics: | ||
322 | 657 | expected = { | ||
323 | 658 | 'version': 2, | ||
324 | 659 | 'ethernets': { | ||
325 | 660 | nic: { | ||
326 | 661 | 'match': {'macaddress': MACADDR}, | ||
327 | 662 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
328 | 663 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
329 | 664 | net = ds.OpenNebulaNetwork(context) | ||
330 | 665 | self.assertEqual(net.gen_conf(), expected) | ||
331 | 666 | |||
332 | 667 | # set ETH0_IP6, ETH0_IP6_ULA, ETH0_IP6_PREFIX_LENGTH | ||
333 | 668 | context = { | ||
334 | 669 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
335 | 670 | 'ETH0_IP6': IP6_GLOBAL, | ||
336 | 671 | 'ETH0_IP6_PREFIX_LENGTH': IP6_PREFIX, | ||
337 | 672 | 'ETH0_IP6_ULA': IP6_ULA, } | ||
338 | 673 | for nic in self.system_nics: | ||
339 | 674 | expected = { | ||
340 | 675 | 'version': 2, | ||
341 | 676 | 'ethernets': { | ||
342 | 677 | nic: { | ||
343 | 678 | 'match': {'macaddress': MACADDR}, | ||
344 | 679 | 'addresses': [ | ||
345 | 680 | IP_BY_MACADDR + '/' + IP4_PREFIX, | ||
346 | 681 | IP6_GLOBAL + '/' + IP6_PREFIX, | ||
347 | 682 | IP6_ULA + '/' + IP6_PREFIX]}}} | ||
348 | 683 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
349 | 684 | net = ds.OpenNebulaNetwork(context) | ||
350 | 685 | self.assertEqual(net.gen_conf(), expected) | ||
351 | 686 | |||
352 | 687 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | ||
353 | 688 | def test_gen_conf_dns(self, m_get_phys_by_mac): | ||
354 | 689 | """Test rendering with/without DNS server, search domain""" | ||
355 | 690 | self.maxDiff = None | ||
356 | 691 | # empty DNS, ETH0_DNS, ETH0_SEARCH_DOMAIN | ||
357 | 692 | context = { | ||
358 | 693 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
359 | 694 | 'DNS': '', | ||
360 | 695 | 'ETH0_DNS': '', | ||
361 | 696 | 'ETH0_SEARCH_DOMAIN': '', } | ||
362 | 697 | for nic in self.system_nics: | ||
363 | 698 | expected = { | ||
364 | 699 | 'version': 2, | ||
365 | 700 | 'ethernets': { | ||
366 | 701 | nic: { | ||
367 | 702 | 'match': {'macaddress': MACADDR}, | ||
368 | 703 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
369 | 704 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
370 | 705 | net = ds.OpenNebulaNetwork(context) | ||
371 | 706 | self.assertEqual(net.gen_conf(), expected) | ||
372 | 707 | |||
373 | 708 | # set DNS, ETH0_DNS, ETH0_SEARCH_DOMAIN | ||
374 | 709 | context = { | ||
375 | 710 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
376 | 711 | 'DNS': '1.2.3.8', | ||
377 | 712 | 'ETH0_DNS': '1.2.3.6 1.2.3.7', | ||
378 | 713 | 'ETH0_SEARCH_DOMAIN': 'example.com example.org', } | ||
379 | 714 | for nic in self.system_nics: | ||
380 | 715 | expected = { | ||
381 | 716 | 'version': 2, | ||
382 | 717 | 'ethernets': { | ||
383 | 718 | nic: { | ||
384 | 719 | 'nameservers': { | ||
385 | 720 | 'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8'], | ||
386 | 721 | 'search': ['example.com', 'example.org']}, | ||
387 | 722 | 'match': {'macaddress': MACADDR}, | ||
388 | 723 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
389 | 724 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
390 | 725 | net = ds.OpenNebulaNetwork(context) | ||
391 | 726 | self.assertEqual(net.gen_conf(), expected) | ||
392 | 727 | |||
393 | 728 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | ||
394 | 729 | def test_gen_conf_mtu(self, m_get_phys_by_mac): | ||
395 | 730 | """Test rendering with/without MTU""" | ||
396 | 731 | self.maxDiff = None | ||
397 | 732 | # empty ETH0_MTU | ||
398 | 733 | context = { | ||
399 | 734 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
400 | 735 | 'ETH0_MTU': '', } | ||
401 | 736 | for nic in self.system_nics: | ||
402 | 737 | expected = { | ||
403 | 738 | 'version': 2, | ||
404 | 739 | 'ethernets': { | ||
405 | 740 | nic: { | ||
406 | 741 | 'match': {'macaddress': MACADDR}, | ||
407 | 742 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
408 | 743 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
409 | 744 | net = ds.OpenNebulaNetwork(context) | ||
410 | 745 | self.assertEqual(net.gen_conf(), expected) | ||
411 | 746 | |||
412 | 747 | # set ETH0_MTU | ||
413 | 748 | context = { | ||
414 | 749 | 'ETH0_MAC': '02:00:0a:12:01:01', | ||
415 | 750 | 'ETH0_MTU': '1280', } | ||
416 | 751 | for nic in self.system_nics: | ||
417 | 752 | expected = { | ||
418 | 753 | 'version': 2, | ||
419 | 754 | 'ethernets': { | ||
420 | 755 | nic: { | ||
421 | 756 | 'mtu': '1280', | ||
422 | 757 | 'match': {'macaddress': MACADDR}, | ||
423 | 758 | 'addresses': [IP_BY_MACADDR + '/' + IP4_PREFIX]}}} | ||
424 | 759 | m_get_phys_by_mac.return_value = {MACADDR: nic} | ||
425 | 760 | net = ds.OpenNebulaNetwork(context) | ||
426 | 761 | self.assertEqual(net.gen_conf(), expected) | ||
427 | 762 | |||
428 | 357 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") | 763 | @mock.patch(DS_PATH + ".get_physical_nics_by_mac") |
429 | 358 | def test_eth0(self, m_get_phys_by_mac): | 764 | def test_eth0(self, m_get_phys_by_mac): |
430 | 359 | for nic in self.system_nics: | 765 | for nic in self.system_nics: |
431 | @@ -395,7 +801,6 @@ class TestOpenNebulaNetwork(unittest.TestCase): | |||
432 | 395 | 'match': {'macaddress': MACADDR}, | 801 | 'match': {'macaddress': MACADDR}, |
433 | 396 | 'addresses': [IP_BY_MACADDR + '/16'], | 802 | 'addresses': [IP_BY_MACADDR + '/16'], |
434 | 397 | 'gateway4': '1.2.3.5', | 803 | 'gateway4': '1.2.3.5', |
435 | 398 | 'gateway6': None, | ||
436 | 399 | 'nameservers': { | 804 | 'nameservers': { |
437 | 400 | 'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8']}}}} | 805 | 'addresses': ['1.2.3.6', '1.2.3.7', '1.2.3.8']}}}} |
438 | 401 | 806 | ||
439 | @@ -494,7 +899,6 @@ class TestOpenNebulaNetwork(unittest.TestCase): | |||
440 | 494 | 'match': {'macaddress': MAC_1}, | 899 | 'match': {'macaddress': MAC_1}, |
441 | 495 | 'addresses': ['10.3.1.3/16'], | 900 | 'addresses': ['10.3.1.3/16'], |
442 | 496 | 'gateway4': '10.3.0.1', | 901 | 'gateway4': '10.3.0.1', |
443 | 497 | 'gateway6': None, | ||
444 | 498 | 'nameservers': { | 902 | 'nameservers': { |
445 | 499 | 'addresses': ['10.3.1.2', '1.2.3.8'], | 903 | 'addresses': ['10.3.1.2', '1.2.3.8'], |
446 | 500 | 'search': [ | 904 | 'search': [ |
OpenNebula: Fix null gateway6
The OpenNebula data source generates an invalid netplan yaml file
if the IPv6 gateway is not defined in context.sh.
LP: #1768547