frontendConfigXOS: Slice tests, WIP instance test

Change-Id: I60d16a043399d93a6cee165552b7c7d812fb27ef
diff --git a/src/test/cord-api/Framework/restApi.py b/src/test/cord-api/Framework/restApi.py
index 1889f21..c40c930 100644
--- a/src/test/cord-api/Framework/restApi.py
+++ b/src/test/cord-api/Framework/restApi.py
@@ -148,14 +148,24 @@
 #jsonResponse = test.ApiPost(key2,{"username":"padmin@vicci.org","password":"letmein"})
 #jsonResponse = test.ApiPut(key,{"username":"testuser","password":"TestUser001"},"9")
 #key = "UTILS_SYNCHRONIZER"
-key = "TENANT_VOLT"
+key = "CORE_SANITY_INSTANCES"
+key1 = "CORE_SANITY_SLICES"
+key2 = "CORE_SLICES"
 #input_dict = { "s_tag" : "111", "c_tag" : "222", "subscriber" : 23}
-#jsonResponse = test.ApiPost(key,input_dict)
+input_dict = {
+           "name": "test-instance",
+           "image": 1,
+           "slice": 1,
+           "deployment": 1,
+           "node": 1
+           }
+input_dict1 = { "name" : "mysite_Test1", "site" : 1 , "creator" : 1}
+jsonResponse = test.ApiPost(key1,input_dict1)
 #jsonGetData = test.ApiGet(key)
 print "========="
 #print jsonGetData
-jsonEdit = test.ApiPut(key,{"c_tag" : "666","s_tag" : "123"},"30")
-#jsonO = test.ApiDelete(key,"36")
+#jsonEdit = test.ApiPut(key,{"c_tag" : "666","s_tag" : "123"},"30")
+#jsonO = test.ApiDelete(key2,"1")
 #jsonResponse = test.ApiPut(key,{"identity":{"name":"My House 22"}},"71")
 #jsonResponse = test.ApiPost(key,{"name":"test-2"})
 #jsonResponse = test.ApiPut(key,{"name":"test1-changed"},"9")
diff --git a/src/test/cord-api/Framework/utils/readProperties.py b/src/test/cord-api/Framework/utils/readProperties.py
index 6bd8c6f..902e161 100644
--- a/src/test/cord-api/Framework/utils/readProperties.py
+++ b/src/test/cord-api/Framework/utils/readProperties.py
@@ -6,7 +6,7 @@
 
     @staticmethod
     def parse_line(input):
-        key, value = input.split('=')
+        key, value = input.split('=',1)
         key = key.strip()
         value = value.strip()
         return key, value
@@ -29,5 +29,8 @@
     def getValueProperties(self, key):
         datas = readProperties.getProperties(self)
         value = datas[key]
-
         return value
+
+#test
+#test = readProperties("testProperties.py")
+#test.getValueProperties("CORE_INSTANCES")
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index 2dfb02b..29a7563 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
-SERVER_IP = '10.128.100.9'
-SERVER_PORT = '8080'
+SERVER_IP = '10.128.15.254'
+SERVER_PORT = '9999'
 USER = 'padmin@vicci.org'
 PASSWD = 'letmein'
 TENANT_SUBSCRIBER = '/api/tenant/cord/subscriber/'
@@ -11,3 +11,6 @@
 CORE_SERVICES = '/api/core/services/'
 CORE_INSTANCES = '/api/core/instances/'
 CORE_DEPLOYMENTS = '/api/core/deployments/'
+CORE_SANITY_INSTANCES = '/api/core/instances/?no_hyperlinks=1'
+CORE_SANITY_SLICES = '/api/core/slices/?no_hyperlinks=1'
+CORE_SLICES = '/api/core/slices/'
diff --git a/src/test/cord-api/Tests/SanityInstance.txt b/src/test/cord-api/Tests/SanityInstance.txt
new file mode 100644
index 0000000..b149b57
--- /dev/null
+++ b/src/test/cord-api/Tests/SanityInstance.txt
@@ -0,0 +1,78 @@
+*** Settings ***
+Documentation     Test suite for Sanity Test of Instance API
+Suite Setup       Read InputFile
+Test Template     Verify Instance API functionality
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           XML
+Library           RequestsLibrary
+Library           ../Framework/utils/utils.py
+Library           ../Framework/restApi.py
+
+*** Variables ***
+${USER}           admin
+${PASSWORD}       admin
+${PATHFILE}       ${CURDIR}/data/Sanity_Instance.json
+
+*** Test Cases ***    TYPE        LISTINDEX
+Test Add Instance-1
+                      CREATE      0
+
+Test Get Instance-1
+                      RETRIEVE    0
+
+Test Delete Instance-1
+                      DELETE      0
+
+Test Add Instance-2
+                      CREATE      1
+
+Test Get Instance-2
+                      RETRIEVE    1
+
+Test Delete Instance-2
+                      DELETE      1
+
+*** Keywords ***
+Read InputFile
+    ${userList} =    utils.jsonToList    ${PATHFILE}    InstanceInfo
+    Set Suite Variable    ${uList}    ${userList}
+
+Verify Instance API functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post Instances    ${listIndex}
+    Run Keyword If    "${type}" == "RETRIEVE"    Test Get Instances    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete Instances    ${listIndex}
+
+Test Post Instances
+    [Arguments]    ${listIndex}
+    ${userList} =    Get Variable Value    ${uList}
+    ${userDict}=    utils.listToDict    ${userList}    ${listIndex}
+    ${api_result}=    restApi.ApiPost    CORE_SANITY_INSTANCES    ${userDict}
+    Should Be True    ${api_result}
+
+Test Get Instances
+    [Arguments]    ${listIndex}
+    ${json_result}=    restApi.ApiGet    CORE_SANITY_INSTANCES
+    Log    ${json_result}
+    ${userList}=    Get Variable Value    ${uList}
+    ${inputDict}=    utils.listToDict    ${userList}    ${listIndex}
+    ${ID}=    utils.getFieldValueFromDict    ${inputDict}    id
+    ${getJsonDict}=    utils.getDictFromListOfDict    ${json_result}    id    ${ID}
+    ${test_result}=    utils.compare_dict    ${inputDict}    ${getJsonDict}
+    Should Be True    ${json_result}
+
+Test Delete Instances
+    [Arguments]    ${listIndex}
+    ${json_getresult}=    restApi.ApiGet    CORE_INSTANCES
+    ${instanceList}=    Get Variable Value    ${iList}
+    ${instanceDict}=    utils.listToDict    ${iList}    ${listIndex}
+    ${ID}=    utils.getFieldValueFromDict    ${instanceDict}    id
+    Log    ${ID}
+    ${getInstanceDict}=    utils.getDictFromListofDict    ${json_getresult}    id    ${ID}
+    Log    ${geInstanceDict}
+    ${instanceID}=    utils.getFieldValueFromDict    ${getInstanceDict}    id
+    Log    ${instanceID}
+    ${test_result}=    restApi.ApiDelete    CORE_INSTANCES    ${instanceID}
+    Should be True    ${test_result}
diff --git a/src/test/cord-api/Tests/SanitySlice.txt b/src/test/cord-api/Tests/SanitySlice.txt
new file mode 100644
index 0000000..6e1a74b
--- /dev/null
+++ b/src/test/cord-api/Tests/SanitySlice.txt
@@ -0,0 +1,74 @@
+*** Settings ***
+Documentation     Test suite for Sanity Test of Slice API
+Suite Setup       Read InputFile
+Test Template     Verify Slice API functionality
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           XML
+Library           RequestsLibrary
+Library           ../Framework/utils/utils.py
+Library           ../Framework/restApi.py
+
+*** Variables ***
+${USER}           admin
+${PASSWORD}       admin
+${PATHFILE}       ${CURDIR}/data/Sanity_slice.json
+
+*** Test Cases ***    TYPE        LISTINDEX
+Test Add Slice-1      CREATE      0
+
+Test Get Slice-1      RETRIEVE    0
+
+Test Delete Slice-1
+                      DELETE      0
+
+Test Add Slice-2      CREATE      1
+
+Test Get Slice-2      RETRIEVE    1
+
+Test Delete Slice-2
+                      DELETE      1
+
+*** Keywords ***
+Read InputFile
+    ${sliceList} =    utils.jsonToList    ${PATHFILE}    sliceInfo
+    Set Suite Variable    ${sList}    ${sliceList}
+
+Verify Slice API functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post Instances    ${listIndex}
+    Run Keyword If    "${type}" == "RETRIEVE"    Test Get Instances    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete Instances    ${listIndex}
+
+Test Post Instances
+    [Arguments]    ${listIndex}
+    ${sliceList} =    Get Variable Value    ${sList}
+    ${sliceDict}=    utils.listToDict    ${sliceList}    ${listIndex}
+    ${api_result}=    restApi.ApiPost    CORE_SANITY_SLICES    ${sliceDict}
+    Should Be True    ${api_result}
+
+Test Get Instances
+    [Arguments]    ${listIndex}
+    ${json_result}=    restApi.ApiGet    CORE_SLICES
+    Log    ${json_result}
+    ${sliceList}=    Get Variable Value    ${sList}
+    ${inputDict}=    utils.listToDict    ${sliceList}    ${listIndex}
+    ${ID}=    utils.getFieldValueFromDict    ${inputDict}    id
+    ${getJsonDict}=    utils.getDictFromListOfDict    ${json_result}    id    ${ID}
+    ${test_result}=    utils.compare_dict    ${inputDict}    ${getJsonDict}
+    Should Be True    ${json_result}
+
+Test Delete Instances
+    [Arguments]    ${listIndex}
+    ${json_getresult}=    restApi.ApiGet    CORE_SLICES
+    ${sliceList}=    Get Variable Value    ${sList}
+    ${sliceDict}=    utils.listToDict    ${sList}    ${listIndex}
+    ${sliceName}=    utils.getFieldValueFromDict    ${sliceDict}    name
+    Log    ${sliceName}
+    ${getSliceDict}=    utils.getDictFromListofDict    ${json_getresult}    name    ${sliceName}
+    Log    ${getSliceDict}
+    ${sliceID}=    utils.getFieldValueFromDict    ${getSliceDict}    id
+    Log    ${sliceID}
+    ${test_result}=    restApi.ApiDelete    CORE_SLICES    ${sliceID}
+    Should be True    ${test_result}
diff --git a/src/test/cord-api/Tests/data/Sanity_Instance.json b/src/test/cord-api/Tests/data/Sanity_Instance.json
new file mode 100644
index 0000000..329a5cf
--- /dev/null
+++ b/src/test/cord-api/Tests/data/Sanity_Instance.json
@@ -0,0 +1,18 @@
+{
+     "InstanceInfo": [
+            {
+            "name": "test-instance1",
+            "image": 1,
+            "slice": 1,
+            "deployment": 1,
+            "node": 1
+            },
+            {
+            "name": "test-instance",
+            "image": 1,
+            "slice": 1,
+            "deployment": 1,
+            "node": 1
+             }
+    ]
+}
diff --git a/src/test/cord-api/Tests/data/Sanity_slice.json b/src/test/cord-api/Tests/data/Sanity_slice.json
new file mode 100644
index 0000000..5bff343
--- /dev/null
+++ b/src/test/cord-api/Tests/data/Sanity_slice.json
@@ -0,0 +1,14 @@
+{
+     "sliceInfo": [
+            {
+            "name": "mysite_Test21",
+            "site": 1,
+            "creator": 1
+            },
+            {
+            "name": "mysite_Test22",
+            "site": 2,
+            "creator": 1
+             }
+    ]
+}