1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
|
#
# Copyright (c) 2014, Arista Networks, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# Neither the name of Arista Networks nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
import os
import unittest
from pyeapi.utils import CliVariants
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))
from testlib import random_string, random_int
from systestlib import DutSystemTest, random_interface
from time import sleep
class TestResourceInterfaces(DutSystemTest):
def test_get(self):
for dut in self.duts:
intf = random_interface(dut)
dut.config(['default interface %s' % intf,
'interface %s' % intf,
'description this is a test',
'flowcontrol send off',
'flowcontrol receive on',
'no sflow enable'])
result = dut.api('interfaces').get(intf)
self.assertIsInstance(result, dict)
self.assertEqual(result['description'], 'this is a test')
self.assertFalse(result['shutdown'])
self.assertEqual(result['flowcontrol_send'], 'off')
self.assertEqual(result['flowcontrol_receive'], 'on')
self.assertFalse(result['sflow'])
def test_getall(self):
for dut in self.duts:
rintf = random_interface(dut)
dut.config(['default interface %s' % rintf])
result = dut.api('interfaces').getall()
self.assertIsInstance(result, dict)
for intf in [rintf, 'Management1']:
self.assertIn(intf, result)
def test_create_and_return_true(self):
for dut in self.duts:
dut.config('no interface Loopback0')
result = dut.api('interfaces').create('Loopback0')
self.assertTrue(result)
config = dut.run_commands('show interfaces')
self.assertIn('Loopback0', config[0]['interfaces'])
def test_create_ethernet_raises_not_implemented_error(self):
for dut in self.duts:
with self.assertRaises(NotImplementedError):
dut.api('interfaces').create(random_interface(dut))
def test_delete_and_return_true(self):
for dut in self.duts:
dut.config('interface Loopback0')
result = dut.api('interfaces').delete('Loopback0')
self.assertTrue(result)
config = dut.run_commands('show interfaces')
self.assertNotIn('Loopback0', config[0]['interfaces'])
def test_delete_ethernet_raises_not_implemented_error(self):
for dut in self.duts:
with self.assertRaises(NotImplementedError):
dut.api('interfaces').delete(random_interface(dut))
def test_create_and_delete_ethernet_sub_interface(self):
for dut in self.duts:
# Default Ethernet1
dut.api('interfaces').default('Ethernet1')
# Create subint Ethernet1.1
res = dut.api('interfaces').create('Ethernet1.1')
self.assertTrue(res)
command = 'show running-config interfaces Ethernet1.1'
output = dut.run_commands(command, encoding='text')
self.assertIn('Ethernet1.1', output[0]['output'])
# Delete subint Ethernet1.1
res = dut.api('interfaces').delete('Ethernet1.1')
self.assertTrue(res)
output = dut.run_commands(command, encoding='text')
self.assertEqual(output[0]['output'], '')
def test_ethernet_set_and_unset_encapsulation(self):
for dut in self.duts:
# Default Ethernet1
dut.api('interfaces').default('Ethernet1')
# Create subint Ethernet1.1
res = dut.api('interfaces').create('Ethernet1.1')
self.assertTrue(res)
# Set encapsulation
res = dut.api('interfaces').set_encapsulation('Ethernet1.1', 4)
self.assertTrue(res)
command = 'show running-config interfaces Ethernet1.1'
output = dut.run_commands(command, encoding='text')
encap = 'encapsulation dot1q vlan 4'
self.assertIn(encap, output[0]['output'])
# Remove encapsulation
res = dut.api('interfaces').set_encapsulation('Ethernet1.1', 4,
disable=True)
self.assertTrue(res)
output = dut.run_commands(command, encoding='text')
self.assertNotIn(encap, output[0]['output'])
# Delete subint Ethernet1.1
res = dut.api('interfaces').delete('Ethernet1.1')
self.assertTrue(res)
def test_set_encapsulation_non_subintf_exception(self):
for dut in self.duts:
with self.assertRaises(NotImplementedError):
dut.api('interfaces').set_encapsulation(random_interface(dut),
1)
def test_set_encapsulation_non_supported_intf_exception(self):
for dut in self.duts:
with self.assertRaises(NotImplementedError):
dut.api('interfaces').set_encapsulation('Vlan1234',
1)
def test_default(self):
for dut in self.duts:
intf = random_interface(dut)
intf_status = dut.run_commands('show interfaces %s' % intf)
intf_status = intf_status[0]['interfaces'][intf]['interfaceStatus']
dut.config(['interface %s' % intf, 'shutdown'])
result = dut.api('interfaces').default(intf)
sleep( 10 ) # if intf was 'connected', give it a time to come up
self.assertTrue(result)
config = dut.run_commands('show interfaces %s' % intf)
config = config[0]['interfaces'][intf]
self.assertEqual(config['interfaceStatus'], intf_status)
def test_set_description(self):
for dut in self.duts:
text = random_string()
intf = random_interface(dut)
result = dut.api('interfaces').set_description(intf, text)
self.assertTrue(result)
config = dut.run_commands('show interfaces %s' % intf)
config = config[0]['interfaces'][intf]
self.assertEqual(config['description'], text)
def test_set_description_negate(self):
for dut in self.duts:
text = random_string()
intf = random_interface(dut)
dut.config(['interface %s' % intf, 'description %s' % text])
result = dut.api('interfaces').set_description(intf, disable=True)
self.assertTrue(result)
config = dut.run_commands('show interfaces %s' % intf)
config = config[0]['interfaces'][intf]
self.assertEqual(config['description'], '')
def test_set_description_default(self):
for dut in self.duts:
text = random_string()
intf = random_interface(dut)
dut.config(['interface %s' % intf, 'description %s' % text])
result = dut.api('interfaces').set_description(intf, default=True)
self.assertTrue(result)
config = dut.run_commands('show interfaces %s' % intf)
config = config[0]['interfaces'][intf]
self.assertEqual(config['description'], '')
def test_set_sflow_enable(self):
for dut in self.duts:
intf = random_interface(dut)
dut.config(['interface %s' % intf, 'no sflow enable'])
result = dut.api('interfaces').set_sflow(intf, True)
self.assertTrue(result)
config = dut.run_commands('show running-config interfaces %s' %
intf, 'text')
self.assertNotIn('no sflow enable', config[0]['output'])
def test_set_sflow_disable(self):
for dut in self.duts:
intf = random_interface(dut)
dut.config('default interface %s' % intf)
result = dut.api('interfaces').set_sflow(intf, disable=True)
self.assertTrue(result)
config = dut.run_commands('show running-config interfaces %s' %
intf, 'text')
self.assertIn('no sflow enable', config[0]['output'])
def test_set_sflow_default(self):
for dut in self.duts:
intf = random_interface(dut)
dut.config('default interface %s' % intf)
result = dut.api('interfaces').set_sflow(intf, default=True)
self.assertTrue(result)
config = dut.run_commands('show running-config interfaces %s' %
intf, 'text')
self.assertNotIn('no sflow enable', config[0]['output'])
def test_set_vrf(self):
for dut in self.duts:
intf = random_interface(dut)
dut.config('default interface %s' % intf)
# Verify set_vrf returns False if no vrf by name is configured
result = dut.api('interfaces').set_vrf(intf, 'test')
self.assertFalse(result)
dut.config( CliVariants('vrf instance test', 'vrf definition test') )
# Verify interface has vrf applied
result = dut.api('interfaces').set_vrf(intf, 'test')
self.assertTrue(result)
config = dut.run_commands(
f'show running-config interfaces {intf}', 'text' )
self.assertIn('vrf test' if dut.version_number >= '4.23'
else 'vrf forwarding test', config[0]['output'])
# Verify interface has vrf removed
result = dut.api('interfaces').set_vrf(intf, 'test', disable=True)
self.assertTrue(result)
config = dut.run_commands(
f'show running-config interfaces {intf}', 'text' )
self.assertNotIn('vrf test' if dut.version_number >= '4.23'
else 'vrf forwarding test', config[0]['output'])
dut.config( CliVariants(
'no vrf instance test', 'no vrf definition test') )
class TestPortchannelInterface(DutSystemTest):
def test_get(self):
for dut in self.duts:
dut.config(['no interface Port-Channel1',
'interface Port-Channel1'])
result = dut.api('interfaces').get('Port-Channel1')
self.assertIsInstance(result, dict)
self.assertEqual(result['type'], 'portchannel')
self.assertEqual(result['name'], 'Port-Channel1')
def test_set_members(self):
for dut in self.duts:
et1 = random_interface(dut)
et2 = random_interface(dut, exclude=[et1])
et3 = random_interface(dut, exclude=[et1, et2])
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'interface %s' % et1,
'channel-group 1 mode on',
'default interface %s' % et2,
'interface %s' % et2,
'channel-group 1 mode on',
'default interface %s' % et3])
api = dut.api('interfaces')
result = api.set_members('Port-Channel1', [et1, et3])
self.assertTrue(result, 'dut=%s' % dut)
cmd = 'show running-config interfaces %s'
# check to make sure et1 is still in the lag and et3 was
# added to the lag
for interface in [et1, et3]:
config = dut.run_commands(cmd % interface, 'text')
self.assertIn('channel-group 1 mode on',
config[0]['output'], 'dut=%s' % dut)
# checks to make sure et2 was remvoved form the lag
config = dut.run_commands(cmd % et2, 'text')
self.assertNotIn('channel-group 1 mode on',
config[0]['output'], 'dut=%s' % dut)
def test_set_members_with_mode(self):
for dut in self.duts:
et1 = random_interface(dut)
et2 = random_interface(dut, exclude=[et1])
et3 = random_interface(dut, exclude=[et1, et2])
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'interface %s' % et1,
'channel-group 1 mode on',
'default interface %s' % et2,
'interface %s' % et2,
'channel-group 1 mode on',
'default interface %s' % et3])
api = dut.api('interfaces')
result = api.set_members('Port-Channel1', [et1, et3], mode='active')
self.assertTrue(result, 'dut=%s' % dut)
cmd = 'show running-config interfaces %s'
# check to make sure et1 is still in the lag and et3 was
# added to the lag
for interface in [et1, et3]:
config = dut.run_commands(cmd % interface, 'text')
self.assertIn('channel-group 1 mode active',
config[0]['output'], 'dut=%s' % dut)
# checks to make sure et2 was remvoved form the lag
config = dut.run_commands(cmd % et2, 'text')
self.assertNotIn('channel-group 1 mode on',
config[0]['output'], 'dut=%s' % dut)
def test_get_members_default(self):
for dut in self.duts:
dut.config(['no interface Port-Channel1',
'interface Port-Channel1'])
instance = dut.api('interfaces').get_instance('Port-Channel1')
result = instance.get_members('Port-Channel1')
self.assertEqual(result, list(), 'dut=%s' % dut)
def test_get_members_one_member(self):
for dut in self.duts:
dut.config(['no interface Port-Channel1',
'interface Port-Channel1',
'default interface Ethernet1',
'interface Ethernet1',
'channel-group 1 mode active'])
instance = dut.api('interfaces').get_instance('Port-Channel1')
result = instance.get_members('Port-Channel1')
self.assertEqual(result, ['Ethernet1'], 'dut=%s' % dut)
def test_get_members_two_members(self):
for dut in self.duts:
dut.config(['no interface Port-Channel1',
'interface Port-Channel1',
'default interface Ethernet1-2',
'interface Ethernet1-2',
'channel-group 1 mode active'])
instance = dut.api('interfaces').get_instance('Port-Channel1')
result = instance.get_members('Port-Channel1')
self.assertEqual(result, ['Ethernet1', 'Ethernet2'], 'dut=%s' % dut)
def test_set_lacp_mode(self):
for dut in self.duts:
for mode in ['on', 'active', 'passive']:
cfgmode = 'on' if mode != 'on' else 'active'
dut.config(['no interface Port-Channel1',
'default interface Ethernet1',
'interface Ethernet1',
'channel-group 1 mode %s' % cfgmode])
result = dut.api('interfaces').set_lacp_mode('Port-Channel1',
mode)
self.assertTrue(result, 'dut=%s' % dut)
commands = 'show running-config interfaces Ethernet1'
config = dut.run_commands(commands, 'text')
self.assertIn('channel-group 1 mode %s' % mode,
config[0]['output'], 'dut=%s' % dut)
def test_set_lacp_mode_invalid_value(self):
for dut in self.duts:
mode = random_string()
result = dut.api('interfaces').set_lacp_mode('Port-Channel1', mode)
self.assertFalse(result)
def test_get_lacp_mode_with_default(self):
for dut in self.duts:
dut.config(['no interface Port-Channel1',
'interface Port-Channel1'])
instance = dut.api('interfaces').get_instance('Port-Channel1')
result = instance.get_lacp_mode('Port-Channel1')
self.assertEqual(result, 'on', 'dut=%s' % dut)
def test_minimum_links_valid(self):
for dut in self.duts:
minlinks = random_int(1, 16)
dut.config(['no interface Port-Channel1',
'interface Port-Channel1'])
result = dut.api('interfaces').set_minimum_links('Port-Channel1',
minlinks)
self.assertTrue(result, 'dut=%s' % dut)
commands = 'show running-config interfaces Port-Channel1'
config = dut.run_commands(commands, 'text')
self.assertIn('port-channel min-links %s' % minlinks,
config[0]['output'], 'dut=%s' % dut)
def test_minimum_links_invalid_value(self):
for dut in self.duts:
minlinks = random_int(129, 256) # some duts may support up to 128
result = dut.api(
'interfaces').set_minimum_links('Port-Channel1', minlinks)
self.assertFalse(result)
def test_create_and_delete_portchannel_sub_interface(self):
for dut in self.duts:
et1 = random_interface(dut)
et2 = random_interface(dut, exclude=[et1])
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'interface %s' % et1,
'channel-group 1 mode on',
'default interface %s' % et2,
'interface %s' % et2,
'channel-group 1 mode on'])
# Create subint Port-Channel1.1
api = dut.api('interfaces')
result = api.create('Port-Channel1.1')
self.assertTrue(result, 'dut=%s' % dut)
command = 'show running-config interfaces Port-Channel1.1'
output = dut.run_commands(command, encoding='text')
self.assertIn('Port-Channel1.1', output[0]['output'])
# Delete subint Port-Channel1.1
result = dut.api('interfaces').delete('Port-Channel1.1')
self.assertTrue(result)
output = dut.run_commands(command, encoding='text')
self.assertEqual(output[0]['output'], '')
# Remove port-channel and default interfaces
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'default interface %s' % et2])
def test_set_and_unset_portchannel_sub_intf_encapsulation(self):
for dut in self.duts:
et1 = random_interface(dut)
et2 = random_interface(dut, exclude=[et1])
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'interface %s' % et1,
'channel-group 1 mode on',
'default interface %s' % et2,
'interface %s' % et2,
'channel-group 1 mode on'])
# Create subint Port-Channel1.1
api = dut.api('interfaces')
result = api.create('Port-Channel1.1')
self.assertTrue(result)
# Set encapsulation
result = api.set_encapsulation('Port-Channel1.1', 4)
self.assertTrue(result)
command = 'show running-config interfaces Port-Channel1.1'
output = dut.run_commands(command, encoding='text')
encap = 'encapsulation dot1q vlan 4'
self.assertIn(encap, output[0]['output'])
# Unset encapsulation
result = api.set_encapsulation('Port-Channel1.1', 4, default=True)
self.assertTrue(result)
output = dut.run_commands(command, encoding='text')
self.assertNotIn(encap, output[0]['output'])
# Delete subint Port-Channel1.1
result = dut.api('interfaces').delete('Port-Channel1.1')
self.assertTrue(result)
output = dut.run_commands(command, encoding='text')
self.assertEqual(output[0]['output'], '')
# Remove port-channel and default interfaces
dut.config(['no interface Port-Channel1',
'default interface %s' % et1,
'default interface %s' % et2])
class TestApiVxlanInterface(DutSystemTest):
def test_get(self):
for dut in self.duts:
dut.config(['no interface Vxlan1',
'interface Vxlan1'])
result = dut.api('interfaces').get('Vxlan1')
self.assertIsInstance(result, dict)
self.assertEqual(result['type'], 'vxlan')
self.assertEqual(result['name'], 'Vxlan1')
self.assertFalse(result['shutdown'])
self.assertEqual(result['description'], None)
self.assertEqual(result['source_interface'], '')
self.assertEqual(result['multicast_group'], '')
self.assertEqual(result['multicast_decap'], False)
def get_config(self, dut):
cmd = 'show running-config all interfaces Vxlan1'
config = dut.run_commands(cmd, 'text')
return config[0]['output']
def contains(self, text, dut):
self.assertIn(text, self.get_config(dut), 'dut=%s' % dut)
def notcontains(self, text, dut):
self.assertNotIn(text, self.get_config(dut), 'dut=%s' % dut)
def may_contain( self, text, dut, first=False, last=False ):
"""handles multiple variants of cli, typically to handle deprecated
variants of the cli. The first and last calls in the variant sequence
must be initialized respectively. At least one call in the sequence
should result in a positive assertion
"""
if first:
self.skip_rest = False
if self.skip_rest:
return
if last:
self.assertIn(text, self.get_config(dut), 'dut=%s' % dut)
return
try:
self.assertIn(text, self.get_config(dut), 'dut=%s' % dut)
self.skip_rest = True
except AssertionError:
pass
def test_set_source_interface(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.set_source_interface('Vxlan1', 'Loopback0')
self.assertTrue(instance)
self.contains('vxlan source-interface Loopback0', dut)
def test_set_source_interface_default(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1',
'vxlan source-interface Loopback0'])
api = dut.api('interfaces')
instance = api.set_source_interface('Vxlan1', default=True)
self.assertTrue(instance)
self.contains('no vxlan source-interface', dut)
def test_set_source_interface_negate(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1',
'vxlan source-interface Loopback0'])
api = dut.api('interfaces')
instance = api.set_source_interface('Vxlan1', disable=True)
self.assertTrue(instance)
self.contains('no vxlan source-interface', dut)
def test_set_multicast_group(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.set_multicast_group('Vxlan1', '239.10.10.10')
self.assertTrue(instance)
self.contains('vxlan multicast-group', dut)
self.contains('239.10.10.10', dut)
def test_set_multicast_group_default(self):
for dut in self.duts:
dut.config( ['no interface Vxlan1', 'interface Vxlan1',
CliVariants( 'vxlan multicast-group decap 239.10.10.10',
'vxlan multicast-group 239.10.10.10') ])
api = dut.api('interfaces')
instance = api.set_multicast_group('Vxlan1', default=True)
self.assertTrue(instance)
self.contains('no vxlan multicast-group', dut)
def test_set_multicast_group_negate(self):
for dut in self.duts:
dut.config( ['no interface Vxlan1', 'interface Vxlan1',
CliVariants( 'vxlan multicast-group decap 239.10.10.10',
'vxlan multicast-group 239.10.10.10') ])
api = dut.api('interfaces')
instance = api.set_multicast_group('Vxlan1', disable=True)
self.assertTrue(instance)
self.contains('no vxlan multicast-group', dut)
'''commenting this one out as it will only parse on a trident based DUT
def test_set_multicast_decap(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.set_multicast_decap('Vxlan1')
self.assertTrue(instance)
self.contains('vxlan multicast-group decap', dut)
'''
def test_set_udp_port(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1',
'vxlan udp-port 1024'])
api = dut.api('interfaces')
instance = api.set_udp_port('Vxlan1', '1024')
self.assertTrue(instance)
self.contains('vxlan udp-port 1024', dut)
def test_set_udp_port_default(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1',
'vxlan udp-port 1024'])
api = dut.api('interfaces')
instance = api.set_udp_port('Vxlan1', default=True)
self.assertTrue(instance)
self.contains('vxlan udp-port 4789', dut)
def test_set_udp_port_negate(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1',
'vxlan udp-port 1024'])
api = dut.api('interfaces')
instance = api.set_udp_port('Vxlan1', disable=True)
self.assertTrue(instance)
self.contains('vxlan udp-port 4789', dut)
def test_add_vtep(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.add_vtep('Vxlan1', '1.1.1.1')
self.assertTrue(instance)
self.contains('vxlan flood vtep 1.1.1.1', dut)
def test_add_vtep_to_vlan(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.add_vtep('Vxlan1', '1.1.1.1', vlan='10')
self.assertTrue(instance)
self.contains('vxlan vlan 10 flood vtep 1.1.1.1', dut)
def test_remove_vtep(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.remove_vtep('Vxlan1', '1.1.1.1')
self.assertTrue(instance)
self.contains('no vxlan flood vtep', dut)
def test_remove_vtep_from_vlan(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.remove_vtep('Vxlan1', '1.1.1.1', vlan='10')
self.assertTrue(instance)
self.notcontains('vxlan vlan 10 flood vtep remove 1.1.1.1', dut)
def test_update_vlan(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.update_vlan('Vxlan1', '10', '10')
self.assertTrue(instance)
self.may_contain('vxlan vlan 10 vni 10', dut, first=True)
self.may_contain('vxlan vlan add 10 vni 10', dut, last=True)
def test_remove_vlan(self):
for dut in self.duts:
dut.config(['no interface Vxlan1', 'interface Vxlan1'])
api = dut.api('interfaces')
instance = api.remove_vlan('Vxlan1', '10')
self.assertTrue(instance)
self.notcontains('vxlan vlan remove 10 vni 10 $', dut)
if __name__ == '__main__':
unittest.main()
|