[CORD-2957]New tests for VOLTDevice and PONPORT with framework edits

Change-Id: I130875a34372220b3ce25b89c999c264eefc8f24
diff --git a/src/test/cord-api/Framework/restApi.py b/src/test/cord-api/Framework/restApi.py
index ba2de91..cbd157c 100644
--- a/src/test/cord-api/Framework/restApi.py
+++ b/src/test/cord-api/Framework/restApi.py
@@ -118,6 +118,16 @@
         passed = self.checkResult(resp, requests.codes.created) or self.checkResult(resp, requests.codes.ok)
         return passed
 
+    def ApiPostReturnJson(self, key, jsonData):
+        url = self.getURL(key)
+        data = json.dumps(jsonData)
+        print "url, data..", url, data
+        resp = requests.post(url, data=data, headers=self.jsonHeader, auth=(self.user, self.password))
+        print "requests.codes.....",requests.codes.created
+        print "posted data...", resp.json()
+        passed = self.checkResult(resp, requests.codes.created) or self.checkResult(resp, requests.codes.ok)
+        return passed, resp.json()
+
     def ApiGet(self, key, urlSuffix=""):
         url = self.getURL(key) + str(urlSuffix)
         print "get url...",url
@@ -171,8 +181,22 @@
         return passed
 
 #test
-'''
+#'''
 test = restApi("MCORD_RestApiProperties.py")
 print test.getURL("CORE_INSTANCES")
 
-'''
+test = restApi()
+voltdevice = {
+   "name" : "volt-10",
+   "device_type" : "asf_olt",
+   "host" : "172.17.0.1",
+   "port" : 50060,
+   "switch_port" : "5",
+   "outer_tpid" : "0x8100",
+   "volt_service_id" : 7
+  }
+#result = test.ApiPost("VOLT_DEVICE",voltdevice) 
+dele = test.ApiChameleonDelete("VOLT_DEVICE",13)
+dele = test.ApiChameleonDelete("VOLT_DEVICE",14)
+dele = test.ApiChameleonDelete("VOLT_DEVICE",15)
+#'''
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index c34a378..d3d4606 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -16,12 +16,15 @@
 
 #!/usr/bin/env python
 
-SERVER_IP = 'localhost'
-SERVER_PORT = '9101'
+SERVER_IP = 'ms1343.utah.cloudlab.us'
+SERVER_PORT = '8080'
 XOS_USER = 'xosadmin@opencord.org'
-XOS_PASSWD = ''
+XOS_PASSWD = 'TbVle45watOPMeB1q93N'
 VOLT_SUBSCRIBER = '/xosapi/v1/rcord/cordsubscriberroots'
 VOLT_TENANT = '/xosapi/v1/volt/voltserviceinstances'
+VOLT_DEVICE = '/xosapi/v1/volt/oltdevices'
+VOLT_SERVICE = '/xosapi/v1/volt/voltservices'
+PON_PORT = '/xosapi/v1/volt/ponports'
 CH_CORE_SERVICELINK = '/xosapi/v1/core/serviceinstancelinks'
 TENANT_SUBSCRIBER = '/api/tenant/cord/subscriber/'
 TENANT_VOLT = '/api/tenant/cord/volt/'
diff --git a/src/test/cord-api/Tests/Sanity_PONPort.txt b/src/test/cord-api/Tests/Sanity_PONPort.txt
new file mode 100644
index 0000000..ba7237a
--- /dev/null
+++ b/src/test/cord-api/Tests/Sanity_PONPort.txt
@@ -0,0 +1,73 @@
+*** Settings ***
+Documentation     Test suite for PONPort
+Suite Setup       Read InputFile
+Test Template     Verify PONPort functionality
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           XML
+Library           RequestsLibrary
+Library           ../Framework/utils/utils.py
+Library           ../Framework/restApi.py
+
+*** Variables ***
+# Update the input file for olt_device_id before running the tests
+${PATHFILE}       ${CURDIR}/data/PONPort.json
+
+*** Test Cases ***    TYPE                         LISTINDEX
+Test Create PONPort-1
+                      CREATE                       0
+
+Test Get PONPort-1
+                      RETRIEVE                     0
+Test Delete PONPort-1
+                      DELETE       0
+Test Create PONPort-2
+                      CREATE       1
+Test Get PONPort-2
+                      RETRIEVE     1
+Test Delete PONPort-2
+                      DELETE       1
+Test Create PONPort-3
+                      CREATE       2
+Test Get PONPort-3
+                      RETRIEVE     2
+Test Delete PONPort-3
+                      DELETE       2
+
+*** Keywords ***
+Read InputFile
+    ${PONPortList}=    utils.jsonToList    ${PATHFILE}    PONPortInfo
+    Set Suite Variable    ${plist}    ${PONPortList}
+    Set Suite Variable    ${PONPort_Id}    ${EMPTY}
+
+Verify PONPort functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post PONPort API    ${listIndex}
+    Run Keyword If    "${type}" == "RETRIEVE"    Test Get PONPort API    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete PONPort API    ${listIndex}
+
+Test Post PONPort API
+    [Arguments]    ${listIndex}
+    ${PONPortList} =    Get Variable Value    ${plist}
+    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
+    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    PON_PORT    ${PONPortDict}
+    Should Be True    ${api_result_status}
+    ${PONPort_Id}=    Get From Dictionary    ${api_result_json}    id
+    Set Global Variable    ${PONPort_Id}
+
+Test Get PONPort API
+    [Arguments]    ${listIndex}
+    Log    ${PONPort_Id}
+    ${json_result}=    restApi.ApiChameleonGet    PON_PORT    ${PONPort_Id}
+    Log    ${json_result}
+    ${PONPortList} =    Get Variable Value    ${plist}
+    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
+    Log    ${PONPortDict}
+    ${test_result}=    utils.compare_dict    ${PONPortDict}    ${json_result}
+    Should Be True    ${test_result}
+
+Test Delete PONPort API
+    [Arguments]    ${listIndex}
+    ${test_result}=    restApi.ApiChameleonDelete    PON_PORT    ${PONPort_Id}
+    Should Be True    ${test_result}
diff --git a/src/test/cord-api/Tests/VOLTDevice_Test.txt b/src/test/cord-api/Tests/VOLTDevice_Test.txt
new file mode 100644
index 0000000..d3b1f1c
--- /dev/null
+++ b/src/test/cord-api/Tests/VOLTDevice_Test.txt
@@ -0,0 +1,118 @@
+*** Settings ***
+Documentation     Test suite for VOLTDevice
+Suite Setup       Read InputFile
+Test Template     Verify VOLTDevice functionality
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           XML
+Library           RequestsLibrary
+Library           ../Framework/utils/utils.py
+Library           ../Framework/restApi.py
+
+*** Variables ***
+${PATHFILE}       ${CURDIR}/data/VOLTDevice.json
+${PATHFILE1}      ${CURDIR}/data/PONPort.json
+
+*** Test Cases ***    TYPE                         LISTINDEX
+Test Create VOLTDevice-1
+                      CREATE                       0
+Test Get VOLTDevice-1
+                      RETRIEVE                     0
+Test Create PONPort-1
+                      PONCREATE                       0
+
+Test Get PONPort-1
+                      PONRETRIEVE                     0
+#Test Delete VOLTDevice-1
+#                      DELETE       0
+Test Create VOLTDevice-2
+                      CREATE       1
+Test Get VOLTDevice-2
+                      RETRIEVE     1
+Test Create PONPort-2
+                      PONCREATE       1
+Test Get PONPort-2
+                      PONRETRIEVE     1
+#Test Delete VOLTDevice-2
+#                      DELETE       1
+Test Create VOLTDevice-3
+                      CREATE       2
+Test Get VOLTDevice-3
+                      RETRIEVE     2
+Test Create PONPort-3
+                      CREATE       2
+Test Get PONPort-3
+                      RETRIEVE     2
+#Test Delete VOLTDevice-3
+#                      DELETE       2
+
+
+*** Keywords ***
+Read InputFile
+    ${voltDeviceList}=    utils.jsonToList    ${PATHFILE}    VOLTDeviceInfo
+    Set Suite Variable    ${dlist}    ${voltDeviceList}
+    Set Global Variable    ${VOLTDevice_Id}    ${EMPTY}
+    ${PONPortList}=    utils.jsonToList    ${PATHFILE1}    PONPortInfo
+    Set Suite Variable    ${plist}    ${PONPortList}
+    Set Suite Variable    ${PONPort_Id}    ${EMPTY}
+
+Verify VOLTDevice functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post VOLT Device API    ${listIndex}
+    Run Keyword If    "${type}" == "RETRIEVE"    Test Get VOLT Device API    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete VOLT Device API    ${listIndex}
+    Run Keyword If    "${type}" == "PONCREATE"    Test Post PONPort API    ${listIndex}
+    Run Keyword If    "${type}" == "PONRETRIEVE"    Test Get PONPort API    ${listIndex}
+
+Test Post VOLT Device API
+    [Arguments]    ${listIndex}
+    ${voltDeviceList} =    Get Variable Value    ${dlist}
+    ${voltDeviceDict}=    utils.listToDict    ${voltDeviceList}    ${listIndex}
+    ${api_getResult}=    restApi.ApiGet    VOLT_SERVICE
+    ${voltServiceList}=    Get From Dictionary    ${api_getResult}    items
+    ${voltServiceDict}=    utils.getDictFromListOfDict    ${voltServiceList}    leaf_model_name    VOLTService
+    ${VOLTService_Id}=    Get From Dictionary    ${voltServiceDict}    id
+    ${voltDeviceDict}=    utils.setFieldValueInDict    ${voltDeviceDict}    volt_service_id    ${VOLTService_Id}
+    Log    ${voltDeviceDict}
+    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    VOLT_DEVICE    ${voltDeviceDict}
+    Should Be True    ${api_result_status}
+    ${VOLTDevice_Id}=    Get From Dictionary    ${api_result_json}    id
+    Set Global Variable    ${VOLTDevice_Id}
+
+Test Get VOLT Device API
+    [Arguments]    ${listIndex}
+    Log    ${VOLTDevice_Id}
+    ${json_result}=    restApi.ApiChameleonGet    VOLT_DEVICE    ${VOLTDevice_Id}
+    Log    ${json_result}
+    ${voltDeviceList} =    Get Variable Value    ${dlist}
+    ${voltDeviceDict}=    utils.listToDict    ${voltDeviceList}    ${listIndex}
+    Log    ${voltDeviceDict}
+    ${test_result}=    utils.compare_dict    ${voltDeviceDict}    ${json_result}
+    Should Be True    ${test_result}
+
+Test Post PONPort API
+    [Arguments]    ${listIndex}
+    ${PONPortList} =    Get Variable Value    ${plist}
+    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
+    ${PONPortDict}=    utils.setFieldValueInDict    ${PONPortDict}    olt_device_id    ${VOLTDevice_Id}
+    ${api_result_status}    ${api_result_json}=    restApi.ApiPostReturnJson    PON_PORT    ${PONPortDict}
+    Should Be True    ${api_result_status}
+    ${PONPort_Id}=    Get From Dictionary    ${api_result_json}    id
+    Set Global Variable    ${PONPort_Id}
+
+Test Get PONPort API
+    [Arguments]    ${listIndex}
+    Log    ${PONPort_Id}
+    ${json_result}=    restApi.ApiChameleonGet    PON_PORT    ${PONPort_Id}
+    Log    ${json_result}
+    ${PONPortList} =    Get Variable Value    ${plist}
+    ${PONPortDict}=    utils.listToDict    ${PONPortList}    ${listIndex}
+    Log    ${PONPortDict}
+    ${test_result}=    utils.compare_dict    ${PONPortDict}    ${json_result}
+    Should Be True    ${test_result}
+
+Test Delete VOLT Device API
+    [Arguments]    ${listIndex}
+    ${test_result}=    restApi.ApiChameleonDelete    VOLT_DEVICE    ${VOLTDevice_Id}
+    Should Be True    ${test_result}
diff --git a/src/test/cord-api/Tests/data/Ch_Subscriber.json b/src/test/cord-api/Tests/data/Ch_Subscriber.json
index e194a2e..44bf456 100644
--- a/src/test/cord-api/Tests/data/Ch_Subscriber.json
+++ b/src/test/cord-api/Tests/data/Ch_Subscriber.json
@@ -8,8 +8,9 @@
             "status": "enabled",
             "service_specific_id": "304",
             "name": "My House-304",
-            "s_tag": 333,
-            "c_tag": 888
+            "c_tag": 888,
+            "olt_device": "volt-1",
+            "olt_port": "volt-port-1"
     },
     {
             "cdn_enable": false,
@@ -19,16 +20,18 @@
             "status": "enabled",
             "service_specific_id": "305",
             "name": "My House-305",
-            "s_tag": 555,
-            "c_tag": 999
+            "c_tag": 999,
+            "olt_device": "volt-2",
+            "olt_port": "volt-port-2"
     },
     {
             "cdn_enable": true,
             "uplink_speed": 500000000,
             "service_specific_id": "306",
             "name": "My House-306",
-            "s_tag": 666,
-            "c_tag": 661
+            "c_tag": 661,
+            "olt_device": "volt-3",
+            "olt_port": "volt-port-3"
     }
   ]
 }
diff --git a/src/test/cord-api/Tests/data/PONPort.json b/src/test/cord-api/Tests/data/PONPort.json
new file mode 100644
index 0000000..da28e42
--- /dev/null
+++ b/src/test/cord-api/Tests/data/PONPort.json
@@ -0,0 +1,19 @@
+{
+    "PONPortInfo" : [
+    {
+            "name": "volt-port-1",
+            "s_tag": 222,
+            "olt_device_id": 1
+    },
+    {
+            "name": "volt-port-2",
+            "s_tag": 444,
+            "olt_device_id": 1
+    },
+    {
+            "name": "volt-port-3",
+            "s_tag": 333,
+            "olt_device_id": 1
+    }
+  ]
+}
diff --git a/src/test/cord-api/Tests/data/VOLTDevice.json b/src/test/cord-api/Tests/data/VOLTDevice.json
new file mode 100644
index 0000000..03b8eb1
--- /dev/null
+++ b/src/test/cord-api/Tests/data/VOLTDevice.json
@@ -0,0 +1,34 @@
+{
+    "VOLTDeviceInfo" : [
+    {
+            "device_type": "simulate_olt",
+            "host": "172.17.0.1",
+            "port": 50060,
+            "switch_datapath_id": "of:0000000ce2314000",
+            "switch_port": "5",
+            "outer_tpid": "0x8100",
+            "name": "volt-1",
+            "volt_service_id": 1
+    },
+    {
+            "device_type": "asf_olt",
+            "host": "172.17.0.2",
+            "port": 50060,
+            "switch_datapath_id": "of:0000000ce2315000",
+            "switch_port": "5",
+            "outer_tpid": "0x8100",
+            "name": "volt-2",
+            "volt_service_id": 1
+    },
+    {
+            "device_type": "ponsim_olt",
+            "host": "172.17.0.3",
+            "port": 50060,
+            "switch_datapath_id": "of:0000000ce2316000",
+            "switch_port": "5",
+            "outer_tpid": "0x8100",
+            "name": "volt-3",
+            "volt_service_id": 1
+    }
+  ]
+}