Upgraded WCBench to v2.0
[integration/test.git] / test / csit / libraries / CrudLibrary.py
index 8e371e20243ddee1280d2e42f887bfcd1cd8a497..f1a23d6fa0ee3cd65b063c24599f0ea60d730a56 100644 (file)
@@ -5,6 +5,7 @@ __email__ = "syedbahm@cisco.com"
 import sys
 import UtilLibrary
 import SettingsLibrary
+import time
 
 #
 #Creates the specified number of cars based on Cars yang model
@@ -205,6 +206,66 @@ def deleteAllCarsPersons(hostname,port,ignore):
     resp = getPersons(hostname,port,ignore)
     print("Persons in store after deletion:"+ str(resp))
 
+#
+# Write longevity
+#
+def testlongevity(inputtime,port,*ips):
+    max_time = int(inputtime)
+    start_time = time.time()  # remember when we started
+    while (time.time() - start_time) < max_time:
+        for ip in ips:
+            deleteAllCars(ip,port,0)
+            resp = getCars(ip,port,0)
+            if resp.status_code == 404:
+                print("Pass: no cars found after deletion")
+            else:
+                print("Fail: Cars are present after deletion")
+            deleteAllPersons(ip,port,0)
+            resp = getPersons(ip,port,0)
+            if resp.status_code == 404:
+                print("Pass: no person found after deletion")
+            else:
+                print("Fail: people are present after deletion")
+
+            addCar(ip,port,100)
+            time.sleep(20)
+            resp = getCars(ip,port,0)
+            if resp.status_code == 200:
+                print("Pass: car data available after addition")
+                if resp.content.find("manufacturer100") == -1:
+                    print("Fail: last car is not there")
+                else:
+                    print("Pass: car data matches")
+            else:
+                print("Fail: car addition failed")
+            addPerson(ip,port,0)
+            addPerson(ip,port,100)
+            time.sleep(20)
+            resp = getPersons(ip,port,0)
+            if resp.status_code == 200:
+                print("Pass: people data available after addition")
+                if resp.content.find("user100") == -1:
+                    print("Fail: last person is not there")
+                else:
+                    print("Pass: person data matches")
+            else:
+                print("Fail: person addition failed")
+
+            addCarPerson(ip,port,0)
+            buyCar(ip,port,100)
+            time.sleep(20)
+            resp = getCarPersonMappings(ip,port,0)
+            if resp.status_code == 200:
+                print("Pass: car person data available after addition")
+                if resp.content.find("user100") == -1:
+                    print("Fail: last car person is not there")
+                else:
+                    print("Pass: car person data matches")
+            else:
+                print("Fail: car person addition failed")
+            time.sleep(60)    # sleep before next host starts working
+
+
 #
 # Usage message shown to user
 #