Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
| 16 | |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 17 | # |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 18 | # Copyright 2016-present Ciena Corporation |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | # you may not use this file except in compliance with the License. |
| 22 | # You may obtain a copy of the License at |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 23 | # |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 25 | # |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 28 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | # See the License for the specific language governing permissions and |
| 30 | # limitations under the License. |
| 31 | # |
| 32 | import unittest |
| 33 | from nose.tools import * |
| 34 | from nose.twistedtools import reactor, deferred |
| 35 | from twisted.internet import defer |
| 36 | from TestManifest import TestManifest |
| 37 | from Fabric import FabricMAAS, Fabric |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 38 | from CordTestUtils import log_test as log |
A R Karthick | 07608ef | 2016-08-23 16:51:19 -0700 | [diff] [blame] | 39 | import os |
| 40 | log.setLevel('INFO') |
| 41 | |
| 42 | class fabric_exchange(unittest.TestCase): |
| 43 | |
| 44 | node_list = [] |
| 45 | fabric = None |
| 46 | FABRIC_TEST_TIMEOUT = 30 |
| 47 | key_file = os.getenv('SSH_KEY_FILE', None) |
| 48 | api_key = os.getenv('MAAS_API_KEY', 'UNKNOWN') |
| 49 | |
| 50 | @classmethod |
| 51 | def setUpClass(cls): |
| 52 | if cls.api_key == 'UNKNOWN': |
| 53 | return |
| 54 | maas = FabricMAAS(api_key = cls.api_key) |
| 55 | cls.node_list = maas.get_node_list() |
| 56 | cls.fabric = Fabric(cls.node_list, key_file = cls.key_file, verbose = False) |
| 57 | |
| 58 | @deferred(FABRIC_TEST_TIMEOUT) |
| 59 | def test_fabric(self): |
| 60 | """Test the connectivity between the compute nodes""" |
| 61 | df = defer.Deferred() |
| 62 | def verify_fabric(df): |
| 63 | assert_not_equal(self.fabric, None) |
| 64 | failed_nodes = [] |
| 65 | failed_nodes = self.fabric.ping_neighbors() |
| 66 | if failed_nodes: |
| 67 | log.info('Failed nodes: %s' %failed_nodes) |
| 68 | for node, neighbor, _ in failed_nodes: |
| 69 | log.info('Ping from node %s to neighbor %s Failed' %(node, neighbor)) |
| 70 | assert_equal(len(failed_nodes), 0) |
| 71 | df.callback(0) |
| 72 | reactor.callLater(0, verify_fabric, df) |
| 73 | return df |