blob: ec17e4945357583f21dd0e20f57fcbb12c55ec15 [file] [log] [blame]
A R Karthick07608ef2016-08-23 16:51:19 -07001#
2# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import unittest
17from nose.tools import *
18from nose.twistedtools import reactor, deferred
19from twisted.internet import defer
20from TestManifest import TestManifest
21from Fabric import FabricMAAS, Fabric
22from scapy.all import *
23import os
24log.setLevel('INFO')
25
26class fabric_exchange(unittest.TestCase):
27
28 node_list = []
29 fabric = None
30 FABRIC_TEST_TIMEOUT = 30
31 key_file = os.getenv('SSH_KEY_FILE', None)
32 api_key = os.getenv('MAAS_API_KEY', 'UNKNOWN')
33
34 @classmethod
35 def setUpClass(cls):
36 if cls.api_key == 'UNKNOWN':
37 return
38 maas = FabricMAAS(api_key = cls.api_key)
39 cls.node_list = maas.get_node_list()
40 cls.fabric = Fabric(cls.node_list, key_file = cls.key_file, verbose = False)
41
42 @deferred(FABRIC_TEST_TIMEOUT)
43 def test_fabric(self):
44 """Test the connectivity between the compute nodes"""
45 df = defer.Deferred()
46 def verify_fabric(df):
47 assert_not_equal(self.fabric, None)
48 failed_nodes = []
49 failed_nodes = self.fabric.ping_neighbors()
50 if failed_nodes:
51 log.info('Failed nodes: %s' %failed_nodes)
52 for node, neighbor, _ in failed_nodes:
53 log.info('Ping from node %s to neighbor %s Failed' %(node, neighbor))
54 assert_equal(len(failed_nodes), 0)
55 df.callback(0)
56 reactor.callLater(0, verify_fabric, df)
57 return df