Voltha test framework and tests to enable olt device
Change-Id: Iecdd6465c107b8d8726826a85cbb71139ff509f4
diff --git a/src/test/utils/VolthaCtrl.py b/src/test/utils/VolthaCtrl.py
new file mode 100644
index 0000000..505f92a
--- /dev/null
+++ b/src/test/utils/VolthaCtrl.py
@@ -0,0 +1,46 @@
+import requests
+import json
+import time
+from CordTestUtils import log_test as log
+
+class VolthaCtrl(object):
+
+ def __init__(self, host, rest_port = 8881):
+ self.host = host
+ self.rest_port = rest_port
+ self.rest_url = 'http://{}:{}/api/v1'.format(host, rest_port)
+
+ def get_devices(self):
+ url = '{}/local/devices'.format(self.rest_url)
+ resp = requests.get(url)
+ if resp.ok is not True or resp.status_code != 200:
+ return None
+ return resp.json()
+
+ def enable_device(self, olt_type, olt_mac):
+ url = '{}/local/devices'.format(self.rest_url)
+ device_config = { 'type' : olt_type, 'mac_address' : olt_mac }
+ #pre-provision
+ log.info('Pre-provisioning %s with mac %s' %(olt_type, olt_mac))
+ resp = requests.post(url, data = json.dumps(device_config))
+ if resp.ok is not True or resp.status_code != 200:
+ return False
+ device_id = resp.json()['id']
+ log.info('Enabling device %s' %(device_id))
+ enable_url = '{}/{}/enable'.format(url, device_id)
+ resp = requests.post(enable_url)
+ if resp.ok is not True or resp.status_code != 200:
+ return False
+ #get operational status
+ time.sleep(5)
+ log.info('Checking operational status for device %s' %(device_id))
+ resp = requests.get('{}/{}'.format(url, device_id))
+ if resp.ok is not True or resp.status_code != 200:
+ return False
+ device_info = resp.json()
+ if device_info['oper_status'] != 'ACTIVE' or \
+ device_info['admin_state'] != 'ENABLED' or \
+ device_info['connect_status'] != 'REACHABLE':
+ return False
+
+ return True
diff --git a/src/test/voltha/__init__.py b/src/test/voltha/__init__.py
new file mode 100644
index 0000000..db4ad9c
--- /dev/null
+++ b/src/test/voltha/__init__.py
@@ -0,0 +1,26 @@
+#
+# Copyright 2016-present Ciena Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import os,sys
+##add the python path to lookup the utils
+working_dir = os.path.dirname(os.path.realpath(sys.argv[-1]))
+utils_dir = os.path.join(working_dir, '../utils')
+fsm_dir = os.path.join(working_dir, '../fsm')
+subscriber_dir = os.path.join(working_dir, '../subscriber')
+__path__.append(utils_dir)
+__path__.append(fsm_dir)
+__path__.append(subscriber_dir)
+cli_dir = os.path.join(working_dir, '../cli')
+__path__.append(cli_dir)
diff --git a/src/test/voltha/volthaTest.json b/src/test/voltha/volthaTest.json
new file mode 100644
index 0000000..8ad1319
--- /dev/null
+++ b/src/test/voltha/volthaTest.json
@@ -0,0 +1,6 @@
+{
+ "OLT_TYPE" : "tibit_olt",
+ "OLT_MAC" : "00:0c:e2:31:12:00",
+ "VOLTHA_HOST" : "172.17.0.1",
+ "VOLTHA_REST_PORT" : 8881
+}
diff --git a/src/test/voltha/volthaTest.py b/src/test/voltha/volthaTest.py
new file mode 100644
index 0000000..d7a6892
--- /dev/null
+++ b/src/test/voltha/volthaTest.py
@@ -0,0 +1,24 @@
+import os
+import sys
+import unittest
+from nose.tools import *
+from CordTestConfig import setup_module
+from CordTestUtils import log_test
+from VolthaCtrl import VolthaCtrl
+
+class voltha_exchange(unittest.TestCase):
+
+ OLT_TYPE = 'tibit_olt'
+ OLT_MAC = '00:0c:e2:31:12:00'
+ VOLTHA_HOST = 'localhost'
+ VOLTHA_REST_PORT = 8881
+ voltha = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.voltha = VolthaCtrl(cls.VOLTHA_HOST, rest_port = cls.VOLTHA_REST_PORT)
+
+ def test_olt_enable(self):
+ log_test.info('Enabling OLT type %s, MAC %s' %(self.OLT_TYPE, self.OLT_MAC))
+ status = self.voltha.enable_device(self.OLT_TYPE, self.OLT_MAC)
+ assert_equal(status, True)