1# 2# Copyright (c) 2014, Arista Networks, Inc. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# Redistributions of source code must retain the above copyright notice, 10# this list of conditions and the following disclaimer. 11# 12# Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# Neither the name of Arista Networks nor the names of its 17# contributors may be used to endorse or promote products derived from 18# this software without specific prior written permission. 19# 20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS 24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 29# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 30# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31# 32import os 33import unittest 34 35import sys 36sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) 37 38from systestlib import DutSystemTest 39 40 41class TestApiMlag(DutSystemTest): 42 43 def test_get(self): 44 for dut in self.duts: 45 dut.config(['no interface Port-Channel1-2000', 46 'default mlag configuration']) 47 response = dut.api('mlag').get() 48 config = dict(domain_id=None, local_interface=None, 49 peer_link=None, peer_address=None, shutdown=False) 50 values = dict(config=config, interfaces=dict()) 51 self.assertEqual(values, response) 52 53 def test_set_domain_id_with_value(self): 54 for dut in self.duts: 55 dut.config('default mlag configuration') 56 api = dut.api('mlag') 57 self.assertIn('no domain-id', api.get_block('mlag configuration')) 58 for domid in ['test_domain_id', 'test.dom-id', 'test domain id']: 59 result = dut.api('mlag').set_domain_id(domid) 60 self.assertTrue(result) 61 self.assertIn('domain-id %s' % domid, api.get_block('mlag configuration')) 62 63 def test_set_domain_id_with_no_value(self): 64 for dut in self.duts: 65 dut.config(['mlag configuration', 'domain-id test']) 66 api = dut.api('mlag') 67 self.assertIn('domain-id test', api.get_block('mlag configuration')) 68 result = dut.api('mlag').set_domain_id(disable=True) 69 self.assertTrue(result) 70 self.assertIn('no domain-id', api.get_block('mlag configuration')) 71 72 def test_set_domain_id_with_default(self): 73 for dut in self.duts: 74 dut.config(['mlag configuration', 'domain-id test']) 75 api = dut.api('mlag') 76 self.assertIn('domain-id test', api.get_block('mlag configuration')) 77 result = dut.api('mlag').set_domain_id(default=True) 78 self.assertTrue(result) 79 self.assertIn('no domain-id', api.get_block('mlag configuration')) 80 81 def test_set_local_interface_with_value(self): 82 for dut in self.duts: 83 dut.config('default mlag configuration') 84 api = dut.api('mlag') 85 self.assertIn('no local-interface', api.get_block('mlag configuration')) 86 result = dut.api('mlag').set_local_interface('Vlan1234') 87 self.assertTrue(result) 88 self.assertIn('local-interface Vlan1234', api.get_block('mlag configuration')) 89 90 def test_set_local_interface_with_no_value(self): 91 for dut in self.duts: 92 dut.config(['interface Vlan1234', 'mlag configuration', 'local-interface Vlan1234']) 93 api = dut.api('mlag') 94 self.assertIn('local-interface Vlan1234', api.get_block('mlag configuration')) 95 result = api.set_local_interface(disable=True) 96 self.assertTrue(result) 97 self.assertIn('no local-interface', api.get_block('mlag configuration')) 98 99 def test_set_local_interface_with_default(self): 100 for dut in self.duts: 101 dut.config(['interface Vlan1234', 'mlag configuration', 'local-interface Vlan1234']) 102 api = dut.api('mlag') 103 self.assertIn('local-interface Vlan1234', api.get_block('mlag configuration')) 104 result = api.set_local_interface(default=True) 105 self.assertTrue(result) 106 self.assertIn('no local-interface', api.get_block('mlag configuration')) 107 108 def test_set_peer_address_with_value(self): 109 for dut in self.duts: 110 dut.config('default mlag configuration') 111 api = dut.api('mlag') 112 self.assertIn('no peer-address', api.get_block('mlag configuration')) 113 result = dut.api('mlag').set_peer_address('1.2.3.4') 114 self.assertTrue(result) 115 self.assertIn('peer-address 1.2.3.4', api.get_block('mlag configuration')) 116 117 def test_set_peer_address_with_no_value(self): 118 for dut in self.duts: 119 dut.config(['interface Vlan1234', 'ip address 1.2.3.1/24', 120 'mlag configuration', 'peer-address 1.2.3.4']) 121 api = dut.api('mlag') 122 self.assertIn('peer-address 1.2.3.4', 123 api.get_block('mlag configuration')) 124 result = api.set_peer_address(disable=True) 125 self.assertTrue(result) 126 self.assertIn('no peer-address', 127 api.get_block('mlag configuration')) 128 129 def test_set_peer_address_with_default(self): 130 for dut in self.duts: 131 dut.config(['interface Vlan1234', 'ip address 1.2.3.1/24', 132 'mlag configuration', 'peer-address 1.2.3.4']) 133 api = dut.api('mlag') 134 self.assertIn('peer-address 1.2.3.4', 135 api.get_block('mlag configuration')) 136 result = api.set_peer_address(default=True) 137 self.assertTrue(result) 138 self.assertIn('no peer-address', 139 api.get_block('mlag configuration')) 140 141 def test_set_peer_link_with_value(self): 142 for dut in self.duts: 143 dut.config('default mlag configuration') 144 api = dut.api('mlag') 145 self.assertIn('no peer-link', api.get_block('mlag configuration')) 146 result = dut.api('mlag').set_peer_link('Ethernet1') 147 self.assertTrue(result) 148 self.assertIn('peer-link Ethernet1', 149 api.get_block('mlag configuration')) 150 151 def test_set_peer_link_with_value_portchannel(self): 152 for dut in self.duts: 153 dut.config(['default mlag configuration', 154 'interface Port-Channel5']) 155 api = dut.api('mlag') 156 self.assertIn('no peer-link', api.get_block('mlag configuration')) 157 result = dut.api('mlag').set_peer_link('Port-Channel5') 158 self.assertTrue(result) 159 self.assertIn('peer-link Port-Channel5', api.get_block('mlag configuration')) 160 161 def test_set_peer_link_with_no_value(self): 162 for dut in self.duts: 163 dut.config(['mlag configuration', 'peer-link Ethernet1']) 164 api = dut.api('mlag') 165 self.assertIn('peer-link Ethernet1', api.get_block('mlag configuration')) 166 result = api.set_peer_link(disable=True) 167 self.assertTrue(result) 168 self.assertIn('no peer-link', api.get_block('mlag configuration')) 169 170 def test_set_peer_link_with_default(self): 171 for dut in self.duts: 172 dut.config(['mlag configuration', 'peer-link Ethernet1']) 173 api = dut.api('mlag') 174 self.assertIn('peer-link Ethernet1', 175 api.get_block('mlag configuration')) 176 result = api.set_peer_link(default=True) 177 self.assertTrue(result) 178 self.assertIn('no peer-link', api.get_block('mlag configuration')) 179 180 def test_set_shutdown_with_true(self): 181 for dut in self.duts: 182 dut.config('default mlag configuration') 183 api = dut.api('mlag') 184 self.assertIn('no shutdown', api.get_block('mlag configuration')) 185 result = api.set_shutdown(True) 186 self.assertTrue(result) 187 self.assertIn('shutdown', api.get_block('mlag configuration')) 188 189 def test_set_shutdown_with_false(self): 190 for dut in self.duts: 191 dut.config(['mlag configuration', 'shutdown']) 192 api = dut.api('mlag') 193 self.assertIn('shutdown', api.get_block('mlag configuration')) 194 result = api.set_shutdown(False) 195 self.assertTrue(result) 196 self.assertIn('no shutdown', api.get_block('mlag configuration')) 197 198 def test_set_shutdown_with_no_value(self): 199 for dut in self.duts: 200 dut.config(['mlag configuration', 'shutdown']) 201 api = dut.api('mlag') 202 self.assertIn('shutdown', api.get_block('mlag configuration')) 203 result = api.set_shutdown(disable=True) 204 self.assertTrue(result) 205 self.assertIn('no shutdown', api.get_block('mlag configuration')) 206 207 def test_set_shutdown_with_default(self): 208 for dut in self.duts: 209 dut.config(['mlag configuration', 'shutdown']) 210 api = dut.api('mlag') 211 self.assertIn('shutdown', api.get_block('mlag configuration')) 212 result = api.set_shutdown(default=True) 213 self.assertTrue(result) 214 self.assertIn('no shutdown', api.get_block('mlag configuration')) 215 216 def test_set_mlag_id_with_value(self): 217 for dut in self.duts: 218 dut.config('no interface Port-Channel10') 219 api = dut.api('mlag') 220 self.assertIsNone(api.get_block('interface Port-Channel10')) 221 result = api.set_mlag_id('Port-Channel10', '100') 222 self.assertTrue(result) 223 self.assertIn('mlag 100', api.get_block('interface Port-Channel10')) 224 225 def test_set_mlag_id_with_no_value(self): 226 for dut in self.duts: 227 dut.config(['no interface Port-Channel10', 228 'interface Port-Channel10', 'mlag 100']) 229 api = dut.api('mlag') 230 self.assertIn('mlag 100', 231 api.get_block('interface Port-Channel10')) 232 result = api.set_mlag_id('Port-Channel10', disable=True) 233 self.assertTrue(result) 234 self.assertIn('no mlag', api.get_block('interface Port-Channel10')) 235 236 def test_set_mlag_id_with_default(self): 237 for dut in self.duts: 238 dut.config(['no interface Port-Channel10', 239 'interface Port-Channel10', 'mlag 100']) 240 api = dut.api('mlag') 241 self.assertIn('mlag 100', 242 api.get_block('interface Port-Channel10')) 243 result = api.set_mlag_id('Port-Channel10', default=True) 244 self.assertTrue(result) 245 self.assertIn('no mlag', api.get_block('interface Port-Channel10')) 246 247 248if __name__ == '__main__': 249 unittest.main() 250