def test_bad_handle(self): """ Test ID: DAOS-1376 Test Description: Pass a bogus object handle, should return bad handle. :avocado: tags=all,object,full_regression,small,objbadhand """ self.prepare_pool() try: # create a container container = DaosContainer(self.context) container.create(self.pool.pool.handle) self.plog.info("Container %s created.", container.get_uuid_str()) # now open it container.open() # create an object and write some data into it thedata = "a string that I want to stuff into an object" thedatasize = len(thedata) + 1 dkey = "this is the dkey" akey = "this is the akey" obj = container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) saved_oh = obj.obj_handle obj.obj_handle = 99999 obj = container.write_an_obj(thedata, thedatasize, dkey, akey, obj, None, 2) container.oh = saved_oh container.close() container.destroy() self.fail("Test was expected to return a -1002 but it has not.\n") except DaosApiError as excep: container.oh = saved_oh container.close() container.destroy() self.plog.info("Test Complete") if '-1002' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1002 but it has not.\n")
class Snapshot(TestWithServers): """ Epic: DAOS-2249 Create system level tests that cover basic snapshot functionality. Testcase: DAOS-1370 Basic snapshot test DAOS-1386 Test container SnapShot information DAOS-1371 Test list snapshots DAOS-1395 Test snapshot destroy DAOS-1402 Test creating multiple snapshots Test Class Description: Start DAOS servers, set up the pool and container for the above snapshot Epic and Testcases, including snapshot basic, container information, list, creation and destroy. :avocado: recursive """ def setUp(self): """ set up method """ super(Snapshot, self).setUp() self.log.info("==In setUp, self.context= %s", self.context) # initialize a python pool object then create the underlying # daos storage and connect to it self.prepare_pool() try: # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) except DaosApiError as error: self.log.info("Error detected in DAOS pool container setup: %s", str(error)) self.log.info(traceback.format_exc()) self.fail("##Test failed on setUp, before snapshot taken") # now open it self.container.open() # do a query and compare the UUID returned from create with # that returned by query self.container.query() if self.container.get_uuid_str() != c_uuid_to_str( self.container.info.ci_uuid): self.fail("##Container UUID did not match the one in info.") def display_snapshot(self, snapshot): """ To display the snapshot information. Args: snapshot: snapshot handle to be displayed. Return: none. """ self.log.info("==display_snapshot================") self.log.info("snapshot= %s", snapshot) self.log.info("snapshot.context= %s", snapshot.context) self.log.info("snapshot.context.libdaos= %s", snapshot.context.libdaos) self.log.info("snapshot.context.libtest= %s", snapshot.context.libtest) self.log.info("snapshot.context.ftable= %s", snapshot.context.ftable) self.log.info("snapshot.context.ftable[list-attr]= %s", snapshot.context.ftable["list-attr"]) self.log.info("snapshot.context.ftable[test-event]=%s", snapshot.context.ftable["test-event"]) self.log.info("snapshot.name= %s", snapshot.name) self.log.info("snapshot.epoch= %s", snapshot.epoch) self.log.info("==================================") def take_snapshot(self, container): """ To take a snapshot on the container on current epoch. Args: container: container for the snapshot Return: An object representing the snapshot """ self.log.info("==Taking snapshot for:") self.log.info(" coh= %s", container.coh) snapshot = DaosSnapshot(self.context) snapshot.create(container.coh) self.display_snapshot(snapshot) return snapshot def invalid_snapshot_test(self, coh): """ Negative snapshot test with invalid container handle. Args: container: container for the snapshot Return: 0: Failed 1: Passed (expected failure detected) """ status = 0 try: snapshot = DaosSnapshot(self.context) snapshot.create(coh) except Exception as error: self.log.info("==>Negative test, expected error: %s", str(error)) status = 1 return status def test_snapshot_negativecases(self): # pylint: disable=no-member """ Test ID: DAOS-1390 Verify snap_create bad parameter behavior. DAOS-1322 Create a new container, verify snapshot state. as expected for a brand new container. DAOS-1392 Verify snap_destroy bad parameter behavior. DAOS-1388 Verify snap_list bad parameter behavior. Test Description: (0)Take a snapshot of the newly created container. (1)Create an object, write random data into it, and take a snapshot. (2)Verify the snapshot is working properly. (3)Test snapshot with an invalid container handle. (4)Test snapshot with a NULL container handle. (5)Verify snap_destroy with a bad parameter. (6)Verify snap_list bad parameter behavior. Use Cases: Combinations with minimum 1 client and 1 server. :avocado: tags=all,small,smoke,daily_regression,snap,snapshot_negative, :avocado: tags=snapshotcreate_negative """ #DAOS-1322 Create a new container, verify snapshot state as expected # for a brand new container. try: self.log.info( "==(0)Take a snapshot of the newly created container.") snapshot = DaosSnapshot(self.context) snapshot.create(self.container.coh) self.display_snapshot(snapshot) except Exception as error: self.fail("##(0)Error on a snapshot on a new container %s", str(error)) #(1)Create an object, write some data into it, and take a snapshot obj_cls = self.params.get("obj_class", '/run/object_class/*') akey = self.params.get("akey", '/run/snapshot/*', default="akey") dkey = self.params.get("dkey", '/run/snapshot/*', default="dkey") data_size = self.params.get("test_datasize", '/run/snapshot/*', default=150) rand_str = lambda n: ''.join( [random.choice(string.lowercase) for i in range(n)]) thedata = "--->>>Happy Daos Snapshot-Create Negative Testing " + \ "<<<---" + rand_str(random.randint(1, data_size)) try: obj = self.container.write_an_obj(thedata, len(thedata) + 1, dkey, akey, obj_cls=obj_cls) except DaosApiError as error: self.fail("##(1)Test failed during the initial object write: %s", str(error)) obj.close() ##Take a snapshot of the container snapshot = self.take_snapshot(self.container) self.log.info("==(1)snapshot.epoch= %s", snapshot.epoch) #(2)Verify the snapshot is working properly. try: obj.open() snap_handle = snapshot.open(self.container.coh, snapshot.epoch) thedata2 = self.container.read_an_obj(len(thedata) + 1, dkey, akey, obj, txn=snap_handle.value) except Exception as error: self.fail("##(2)Error when retrieving the snapshot data: %s", str(error)) self.log.info("==(2)snapshot_list[ind]=%s", snapshot) self.log.info("==snapshot.epoch= %s", snapshot.epoch) self.log.info("==written thedata=%s", thedata) self.log.info("==thedata2.value= %s", thedata2.value) if thedata2.value != thedata: raise Exception("##(2)The data in the snapshot is not the " "same as the original data") self.log.info("==Snapshot data matches the data originally " "written.") #(3)Test snapshot with an invalid container handle self.log.info("==(3)Snapshot with an invalid container handle.") if self.invalid_snapshot_test(self.container): self.log.info( "==>Negative test 1, expecting failed on taking " "snapshot with an invalid container.coh: %s", self.container) else: self.fail( "##(3)Negative test 1 passing, expecting failed on" " taking snapshot with an invalid container.coh: %s", self.container) #(4)Test snapshot with a NULL container handle self.log.info("==(4)Snapshot with a NULL container handle.") if self.invalid_snapshot_test(None): self.log.info("==>Negative test 2, expecting failed on taking " "snapshot on a NULL container.coh.") else: self.fail("##(4)Negative test 2 passing, expecting failed on " "taking snapshot with a NULL container.coh.") #(5)DAOS-1392 destroy snapshot with an invalid handle self.log.info( "==(6)DAOS-1392 destroy snapshot with an invalid handle.") try: snapshot.destroy(None, snapshot.epoch) self.fail("##(6)Negative test destroy snapshot with an " "invalid coh handle, expected fail, shown Passing##") except Exception as error: self.log.info( "==>Negative test, destroy snapshot with an invalid handle.") self.log.info(" Expected Error: %s", str(error)) expected_error = "RC: -1002" if expected_error not in str(error): self.fail("##(6.1)Expecting error RC: -1002 did not show.") #(6)DAOS-1388 Verify snap_list bad parameter behavior self.log.info( "==(7)DAOS-1388 Verify snap_list bad parameter behavior.") try: snapshot.list(None, 0) self.fail("##(7)Negative test snapshot list with an " "invalid coh and epoch, expected fail, shown Passing##") except Exception as error: self.log.info( "==>Negative test, snapshot list with an invalid coh.") self.log.info(" Expected Error: %s", str(error)) expected_error = "RC: -1002" if expected_error not in str(error): self.fail("##(7.1)Expecting error RC: -1002 did not show.") def display_snapshot_test_data(self, test_data, ss_index): """Display the snapshot test data. Args: test_data: list of snapshot testdata dictionary keys: coh: container handle snapshot: snapshot handle tst_obj: test object tst_data: test data ss_index: snapshot-list index to be displayed. """ if len(test_data) < ss_index - 1: self.log.info("##Under to display test_data info, " "index out of range.") else: ind = ss_index - 1 self.log.info(" =Snapshot number : %s", ss_index) self.log.info(" ==container_coh =%s", test_data[ind]["coh"]) self.log.info(" ==snapshot =%s", test_data[ind]["snapshot"]) self.log.info(" ==snapshot.epoch =%s", test_data[ind]["snapshot"].epoch) self.log.info(" ==data obj =%s", test_data[ind]["tst_obj"]) self.log.info(" ==snapshot tst_data_size= %s", len(test_data[ind]["tst_data"]) + 1) self.log.info(" ==original tst_data =%s", test_data[ind]["tst_data"]) return def test_snapshots(self): # pylint: disable=no-member,too-many-locals """ Test ID: DAOS-1386 Test container SnapShot information DAOS-1371 Test list snapshots DAOS-1395 Test snapshot destroy DAOS-1402 Test creating multiple snapshots Test Description: (1)Create an object, write random data into it, and take a snapshot. (2)Make changes to the data object. The write_an_obj function does a commit when the update is complete. (3)Verify the data in the snapshot is the original data. Get a handle for the snapshot and read the object at dkey, akey. Compare it to the originally written data. (4)List the snapshot and make sure it reflects the original epoch. ==>Repeat step(1) to step(4) for multiple snapshot tests. (5)Verify the snapshots data. (6)Destroy the snapshot individually. (7)Check if still able to Open the destroyed snapshot and Verify the snapshot removed from the snapshot list. (8)Destroy the container snapshot. Use Cases: Require 1 client and 1 server to run snapshot test. 1 pool and 1 container is used, num_of_snapshot defined in the snapshot.yaml will be performed and verified. :avocado: tags=all,small,smoke,snap,snapshots,full_regression """ test_data = [] ss_number = 0 obj_cls = self.params.get("obj_class", '/run/object_class/*') akey = self.params.get("akey", '/run/snapshot/*', default="akey") dkey = self.params.get("dkey", '/run/snapshot/*', default="dkey") data_size = self.params.get("test_datasize", '/run/snapshot/*', default=150) snapshot_loop = self.params.get("num_of_snapshot", '/run/snapshot/*', default=3) rand_str = lambda n: ''.join( [random.choice(string.lowercase) for i in range(n)]) # #Test loop for creat, modify and snapshot object in the DAOS container. # while ss_number < snapshot_loop: #(1)Create an object, write some data into it, and take a snapshot ss_number += 1 thedata = "--->>>Happy Daos Snapshot Testing " + \ str(ss_number) + \ "<<<---" + rand_str(random.randint(1, data_size)) datasize = len(thedata) + 1 try: obj = self.container.write_an_obj(thedata, datasize, dkey, akey, obj_cls=obj_cls) obj.close() except DaosApiError as error: self.fail("##(1)Test failed during the initial object " "write: {}".format(str(error))) #Take a snapshot of the container snapshot = DaosSnapshot(self.context) snapshot.create(self.container.coh) self.log.info("==Wrote an object and created a snapshot") #Display snapshot self.log.info("=(1.%s)snapshot test loop: %s", ss_number, ss_number) self.log.info(" ==snapshot.epoch= %s", snapshot.epoch) self.display_snapshot(snapshot) #Save snapshot test data test_data.append({ "coh": self.container.coh, "tst_obj": obj, "snapshot": snapshot, "tst_data": thedata }) #(2)Make changes to the data object. The write_an_obj function does # a commit when the update is complete num_transactions = more_transactions = 200 self.log.info( "=(2.%s)Committing %d additional transactions to " "the same KV.", ss_number, more_transactions) while more_transactions: size = random.randint(1, 250) + 1 new_data = rand_str(size) try: new_obj = self.container.write_an_obj(new_data, size, dkey, akey, obj_cls=obj_cls) new_obj.close() except Exception as error: self.fail("##(2)Test failed during the write of " "multi-objects: {}".format(str(error))) more_transactions -= 1 #(3)Verify the data in the snapshot is the original data. # Get a handle for the snapshot and read the object at dkey, akey # Compare it to the originally written data. self.log.info("=(3.%s)snapshot test loop: %s", ss_number, ss_number) try: obj.open() snap_handle = snapshot.open(self.container.coh, snapshot.epoch) thedata3 = self.container.read_an_obj(datasize, dkey, akey, obj, txn=snap_handle.value) obj.close() except Exception as error: self.fail("##(3.1)Error when retrieving the snapshot data: {}". format(str(error))) self.display_snapshot_test_data(test_data, ss_number) self.log.info(" ==thedata3.value= %s", thedata3.value) if thedata3.value != thedata: raise Exception("##(3.2)The data in the snapshot is not the " "same as the original data") self.log.info(" ==The snapshot data matches the data originally" " written.") #(4)List the snapshot and make sure it reflects the original epoch try: ss_list = snapshot.list(self.container.coh, snapshot.epoch) self.log.info("=(4.%s)snapshot.list(self.container.coh)= %s", ss_number, ss_list) self.log.info(" ==snapshot.epoch= %s", snapshot.epoch) except Exception as error: self.fail( "##(4)Test was unable to list the snapshot: {}".format( str(error))) self.log.info( " ==After %s additional commits the snapshot is " "still available", num_transactions) #(5)Verify the snapshots data for ind, _ in enumerate(test_data): ss_number = ind + 1 self.log.info("=(5.%s)Verify the snapshot number %s:", ss_number, ss_number) self.display_snapshot_test_data(test_data, ss_number) coh = test_data[ind]["coh"] current_ss = test_data[ind]["snapshot"] obj = test_data[ind]["tst_obj"] tst_data = test_data[ind]["tst_data"] datasize = len(tst_data) + 1 try: obj.open() snap_handle5 = snapshot.open(coh, current_ss.epoch) thedata5 = self.container.read_an_obj(datasize, dkey, akey, obj, txn=snap_handle5.value) obj.close() except Exception as error: self.fail("##(5.1)Error when retrieving the snapshot data: {}". format(str(error))) self.log.info(" ==snapshot tst_data =%s", thedata5.value) if thedata5.value != tst_data: raise Exception( "##(5.2)Snapshot #%s, test data Mis-matches" "the original data written.", ss_number) self.log.info( " snapshot test number %s, test data matches" " the original data written.", ss_number) #(6)Destroy the individual snapshot self.log.info("=(6.%s)Destroy the snapshot epoch: %s", ss_number, snapshot.epoch) try: snapshot.destroy(coh, snapshot.epoch) self.log.info(" ==snapshot.epoch %s successfully destroyed", snapshot.epoch) except Exception as error: self.fail("##(6)Error on snapshot.destroy: {}".format( str(error))) #(7)Check if still able to Open the destroyed snapshot and # Verify the snapshot removed from the snapshot list try: obj.open() snap_handle7 = snapshot.open(coh, snapshot.epoch) thedata7 = self.container.read_an_obj(datasize, dkey, akey, obj, txn=snap_handle7.value) obj.close() except Exception as error: self.fail( "##(7)Error when retrieving the snapshot data: {}".format( str(error))) self.log.info("=(7)=>thedata_after_snapshot.destroyed.value= %s", thedata7.value) self.log.info(" ==>snapshot.epoch= %s", snapshot.epoch) #Still able to open the snapshot and read data after destroyed. try: ss_list = snapshot.list(coh, snapshot.epoch) self.log.info(" -->snapshot.list(coh, snapshot.epoch)= %s", ss_list) except Exception as error: self.fail("##(7)Error when calling the snapshot list: {}".format( str(error))) #(8)Destroy the snapshot on the container try: snapshot.destroy(coh) self.log.info("=(8)Container snapshot destroyed successfully.") except Exception as error: self.fail("##(8)Error on snapshot.destroy. {}".format(str(error))) self.log.info("===DAOS container Multiple snapshots test passed.")
class SameKeyDifferentValue(TestWithServers): """ Test Description: Test to verify different type of values passed to same akey and dkey. :avocado: recursive """ def setUp(self): super(SameKeyDifferentValue, self).setUp() self.prepare_pool() try: # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) # now open it self.container.open() except DaosApiError as excpn: print(excpn) print(traceback.format_exc()) self.fail("Test failed during setup.\n") def test_single_to_array_value(self): """ Jira ID: DAOS-2218 Test Description: Test to verify different type of values passed (i.e. single to array value) to the same akey and dkey. Case1: Insert akey,dkey with single value Insert same akey,dkey with array value Result: should return -1001 ERR. Case2: Insert akey,dkey with single value Punch the keys Insert same akey,dkey under same object with array value Result: should either pass or return -1001 ERR Case3: Insert akey,dkey with single value Punch the keys Trigger aggregation Insert same akey,dkey under same object with array value Result: should either pass or return -1001 ERR :avocado: tags=object,samekeydifferentvalue,singletoarray,vm,small """ # define akey,dkey, single value data and array value data single_value_data = "a string that I want to stuff into an object" array_value_data = [] array_value_data.append("data string one") array_value_data.append("data string two") array_value_data.append("data string tre") dkey = "this is the dkey" akey = "this is the akey" aggregation = False for i in range(3): try: # create an object and write single value data into it obj = self.container.write_an_obj(single_value_data, len(single_value_data) + 1, dkey, akey, obj_cls=1) # read the data back and make sure its correct read_back_data = self.container.read_an_obj( len(single_value_data) + 1, dkey, akey, obj) if single_value_data != read_back_data.value: print("data I wrote:" + single_value_data) print("data I read back" + read_back_data.value) self.fail("Write data, read it back, didn't match\n") # test case 1 if i == 0: try: # write array value data to same keys, expected to fail self.container.write_an_array_value(array_value_data, dkey, akey, obj, obj_cls=1) # above line is expected to return an error, # if not fail the test self.fail( "Array value write to existing single value" + " key should have failed\n") # should fail with -1001 ERR except DaosApiError as excp: if "-1001" not in str(excp): print(excp) self.fail("Should have failed with -1001 error" + " message, but it did not\n") # test case 2 and 3 elif i == 1 or 2: try: # punch the keys obj.punch_akeys(0, dkey, [akey]) obj.punch_dkeys(0, [dkey]) if aggregation is True: # trigger aggregation self.container.aggregate(self.container.coh, 0) # write to the same set of keys under same object # with array value type self.container.write_an_array_value(array_value_data, dkey, akey, obj, obj_cls=1) # above write of array value should either succeed # or fail with -1001 ERR except DaosApiError as excp: if "-1001" not in str(excp): print(excp) self.fail("Should have failed with -1001 error" + " message or the write should have" + " been successful, but it did not\n") # change the value of aggregation to test Test Case 3 aggregation = True # punch the entire object after each iteration obj.close() # catch the exception if test fails to write to an object # or fails to punch the written object except DaosApiError as excp: self.fail("Failed to write to akey/dkey or punch the object") def test_array_to_single_value(self): """ Jira ID: DAOS-2218 Test Description: Test to verify different type of values passed (i.e array to single value) to the same akey and dkey. Case1: Insert akey,dkey with array value Insert same akey,dkey with single value Result: should return -1001 ERR. Case2: Insert akey,dkey with array value Punch the keys Insert same akey,dkey under same object with single value Result: should either pass or return -1001 ERR Case3: Insert akey,dkey with array value Punch the keys Trigger aggregation Insert same akey,dkey under same object with single value Result: should either pass or return -1001 ERR :avocado: tags=object,samekeydifferentvalue,arraytosingle,vm,small """ # define akey,dkey, single value data and array value data single_value_data = "a string that I want to stuff into an object" array_value_data = [] array_value_data.append("data string one") array_value_data.append("data string two") array_value_data.append("data string tre") dkey = "this is the dkey" akey = "this is the akey" aggregation = False for i in range(3): try: # create an object and write array value data into it obj = self.container.write_an_array_value(array_value_data, dkey, akey, obj_cls=1) # read the data back and make sure its correct length = len(array_value_data[0]) read_back_data = self.container.read_an_array( len(array_value_data), length + 1, dkey, akey, obj) for j in range(3): if (array_value_data[j][0:length - 1] != read_back_data[j][0:length - 1]): print("Written Data: {}".format(array_value_data[j])) print("Read Data: {}".format(read_back_data[j])) self.fail("Data mismatch\n") # test case 1 if i == 0: try: # write single value data to same keys, expected to fail self.container.write_an_obj(single_value_data, len(single_value_data) + 1, dkey, akey, obj, obj_cls=1) # above line is expected to return an error, # if not fail the test self.fail( "Single value write to existing array value" + " key should have failed\n") # should fail with -1001 ERR except DaosApiError as excp: if "-1001" not in str(excp): print(excp) self.fail("Should have failed with -1001 error" + " message, but it did not\n") # test case 2 and 3 elif i == 1 or 2: try: # punch the keys obj.punch_akeys(0, dkey, [akey]) obj.punch_dkeys(0, [dkey]) if aggregation is True: # trigger aggregation self.container.aggregate(self.container.coh, 0) # write to the same set of keys under same object # with single value type self.container.write_an_obj(single_value_data, len(single_value_data) + 1, dkey, akey, obj, obj_cls=1) # above write of array value should either succeed # or fail with -1001 ERR except DaosApiError as excp: if "-1001" not in str(excp): print(excp) self.fail("Should have failed with -1001 error" + " message or the write should have" + " been successful, but it did not\n") # change the value of aggregation to test Test Case 3 aggregation = True # punch the entire object after each iteration obj.close() # catch the exception if test fails to write to an object # or fails to punch the written object except DaosApiError as excp: self.fail("Failed to write to akey/dkey or punch the object")
class PunchTest(TestWithServers): """ Simple test to verify the 3 different punch calls. :avocado: recursive """ def setUp(self): try: super(PunchTest, self).setUp() # parameters used in pool create createmode = self.params.get("mode", '/run/pool/createmode/') createsetid = self.params.get("setname", '/run/pool/createset/') createsize = self.params.get("size", '/run/pool/createsize/') createuid = os.geteuid() creategid = os.getegid() # initialize a python pool object then create the underlying # daos storage self.pool = DaosPool(self.context) self.pool.create(createmode, createuid, creategid, createsize, createsetid, None) self.pool.connect(1 << 1) # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.handle) # now open it self.container.open() except DaosApiError as excpn: print(excpn) print(traceback.format_exc()) self.fail("Test failed during setup.\n") def test_dkey_punch(self): """ The most basic test of the dkey punch function. :avocado: tags=all,object,pr,small,dkeypunch """ try: # create an object and write some data into it thedata = "a string that I want to stuff into an object" dkey = "this is the dkey" akey = "this is the akey" obj, txn = self.container.write_an_obj(thedata, len(thedata) + 1, dkey, akey, obj_cls=1) # read the data back and make sure its correct thedata2 = self.container.read_an_obj( len(thedata) + 1, dkey, akey, obj, txn) if thedata != thedata2.value: print("data I wrote:" + thedata) print("data I read back" + thedata2.value) self.fail("Wrote data, read it back, didn't match\n") # now punch this data, should fail, can't punch committed data obj.punch_dkeys(txn, [dkey]) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as dummy_e: pass try: # now punch this data obj.punch_dkeys(0, [dkey]) # this one should work so error if exception occurs except DaosApiError as dummy_e: self.fail("Punch should have worked.\n") # there are a bunch of other cases to test here, # --test punching the same updating and punching the same data in # the same tx, should fail # --test non updated data in an open tx, should work def test_akey_punch(self): """ The most basic test of the akey punch function. :avocado: tags=all,object,pr,small,akeypunch """ try: # create an object and write some data into it dkey = "this is the dkey" data1 = [("this is akey 1", "this is data value 1"), ("this is akey 2", "this is data value 2"), ("this is akey 3", "this is data value 3")] obj, txn = self.container.write_multi_akeys(dkey, data1, obj_cls=1) # read back the 1st epoch's data and check 1 value just to make sure # everything is on the up and up readbuf = [(data1[0][0], len(data1[0][1]) + 1), (data1[1][0], len(data1[1][1]) + 1), (data1[2][0], len(data1[2][1]) + 1)] retrieved_data = self.container.read_multi_akeys( dkey, readbuf, obj, txn) if retrieved_data[data1[1][0]] != data1[1][1]: print("middle akey: {}".format(retrieved_data[data1[1][0]])) self.fail("data retrieval failure") # now punch one akey from this data obj.punch_akeys(txn, dkey, [data1[1][0]]) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as excep: print(excep) try: # now punch the object without a tx obj.punch_akeys(0, dkey, [data1[1][0]]) # expecting it to work this time so error except DaosApiError as excep: self.fail("Punch should have worked: {}\n".format(excep)) def test_obj_punch(self): """ The most basic test of the object punch function. Really similar to above except the whole object is deleted. :avocado: tags=all,object,pr,small,objpunch """ try: # create an object and write some data into it thedata = "a string that I want to stuff into an object" dkey = "this is the dkey" akey = "this is the akey" obj, txn = self.container.write_an_obj(thedata, len(thedata) + 1, dkey, akey, obj_cls=1) # read the data back and make sure its correct thedata2 = self.container.read_an_obj( len(thedata) + 1, dkey, akey, obj, txn) if thedata != thedata2.value: print("data I wrote:" + thedata) print("data I read back" + thedata2.value) self.fail("Wrote data, read it back, didn't match\n") # now punch the object, commited so not expecting it to work obj.punch(txn) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as excep: print(excep) try: obj.punch(0) # expecting it to work without a tx except DaosApiError as excep: print(excep) self.fail("Punch should have worked.\n")
def test_null_values(self): """ Test ID: DAOS-1376 Test Description: Pass a dkey and an akey that is null. :avocado: tags=all,object,full_regression,small,objupdatenull """ self.prepare_pool() try: # create a container container = DaosContainer(self.context) container.create(self.pool.pool.handle) self.plog.info("Container %s created.", container.get_uuid_str()) # now open it container.open() # data used in the test thedata = "a string that I want to stuff into an object" thedatasize = len(thedata) + 1 except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test failed during setup .\n") try: # try using a null dkey dkey = None akey = "this is the akey" container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) container.close() container.destroy() self.plog.error("Didn't get expected return code.") self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): container.close() container.destroy() self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # try using a null akey/io descriptor dkey = "this is the dkey" akey = None container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # lastly try passing no data thedata = None thedatasize = 0 dkey = "this is the dkey" akey = "this is the akey" container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.plog.info("Update with no data worked") except DaosApiError as excep: container.close() container.destroy() print(excep) print(traceback.format_exc()) self.plog.error("Update with no data failed") self.fail("Update with no data failed.\n") container.close() container.destroy() self.plog.info("Test Complete")
class Permission(TestWithServers): """Test pool permissions. Test Class Description: Tests DAOS pool permissions while connect, whether modifying file with specific permissions work as expected. :avocado: recursive """ def test_file_modification(self): """Test ID: DAOS-???. Test Description: Test whether file modification happens as expected under different permission levels. :avocado: tags=all,daily_regression :avocado: tags=pool,permission,file_modification """ # parameter used for pool connect permissions = self.params.get("perm", '/run/createtests/permissions/*') expected_result = self.params.get("exp_result", '/run/createtests/permissions/*') # initialize a python pool object then create the underlying # daos storage self.add_pool(create=False) self.test_log.debug("Pool initialization successful") self.pool.create() self.test_log.debug("Pool Creation successful") try: self.pool.connect(1 << permissions) self.test_log.debug("Pool Connect successful") except TestFail as excep: self.log.error(str(excep)) if expected_result == RESULT_PASS: self.fail( "#Test was expected to pass but it failed at pool.connect.\n") try: self.container = DaosContainer(self.context) self.test_log.debug("Container initialization successful") self.container.create(self.pool.pool.handle) self.test_log.debug("Container create successful") # now open it self.container.open() self.test_log.debug("Container open successful") thedata = b"a string that I want to stuff into an object" size = 45 dkey = b"this is the dkey" akey = b"this is the akey" self.container.write_an_obj(thedata, size, dkey, akey) self.test_log.debug("Container write successful") if expected_result == RESULT_FAIL: self.fail( "Test was expected to fail at container operations " + "but it passed.\n") else: self.test_log.debug("Test Passed.") except DaosApiError as excep: self.log.error(str(excep)) if expected_result == RESULT_PASS: self.fail( "#Test was expected to pass but it failed at container operations.\n") else: self.test_log.debug("Test expected failed in container create, r/w. Test Passed.")
class ObjFetchBadParam(TestWithServers): """ Test Class Description: Pass an assortment of bad parameters to the daos_obj_fetch function. :avocado: recursive """ def setUp(self): super(ObjFetchBadParam, self).setUp() time.sleep(5) self.prepare_pool() try: # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) # now open it self.container.open() # create an object and write some data into it thedata = "a string that I want to stuff into an object" self.datasize = len(thedata) + 1 self.dkey = "this is the dkey" self.akey = "this is the akey" self.obj = self.container.write_an_obj(thedata, self.datasize, self.dkey, self.akey, None, None, 2) thedata2 = self.container.read_an_obj(self.datasize, self.dkey, self.akey, self.obj) if thedata not in thedata2.value: print(thedata) print(thedata2.value) self.fail("Error reading back data, test failed during"\ " the initial setup.\n") except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test failed during the initial setup.\n") def test_bad_handle(self): """ Test ID: DAOS-1377 Test Description: Pass a bogus object handle, should return bad handle. :avocado: tags=all,object,full_regression,small,objbadhandle """ try: # trash the handle and read again saved_oh = self.obj.obj_handle self.obj.obj_handle = 99999 # expecting this to fail with -1002 dummy_thedata2 = self.container.read_an_obj( self.datasize, self.dkey, self.akey, self.obj) self.container.oh = saved_oh self.fail("Test was expected to return a -1002 but it has not.\n") except DaosApiError as excep: self.container.oh = saved_oh if '-1002' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1002 but it has not.\n") def test_null_ptrs(self): """ Test ID: DAOS-1377 Test Description: Pass null pointers for various fetch parameters. :avocado: tags=all,object,full_regression,small,objfetchnull """ try: # now try it with a bad dkey, expecting this to fail with -1003 dummy_thedata2 = self.container.read_an_obj( self.datasize, None, self.akey, self.obj) self.container.close() self.container.destroy() self.pool.destroy(1) self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # now try it with a null sgl (iod_size is not set) # expecting this to fail with -2013 test_hints = ['sglnull'] dummy_thedata2 = self.container.read_an_obj( self.datasize, self.dkey, self.akey, self.obj, test_hints) # behavior not as expect so commented out for now # when DAOS-1448 is complete, uncomment and retest self.fail("Test was expected to return a -2013 but it has not.\n") except DaosApiError as excep: if '-2013' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -2013 but it has not.\n") try: # when DAOS-1449 is complete, uncomment and retest # now try it with a null iod, expecting this to fail with -1003 #test_hints = ['iodnull'] #thedata2 = self.container.read_an_obj(self.datasize, dkey, akey, # self.obj, test_hints) pass #self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n")
def test_bad_handle(self): """ Test ID: DAOS-1376 Test Description: Pass a bogus object handle, should return bad handle. :avocado: tags=all,object,full_regression,small,objbadhand """ try: # parameters used in pool create createmode = self.params.get("mode", '/run/conttests/createmode/') createsetid = self.params.get("setname", '/run/conttests/createset/') createsize = self.params.get("size", '/run/conttests/createsize/') createuid = os.geteuid() creategid = os.getegid() # initialize a python pool object then create the underlying # daos storage pool = DaosPool(self.context) pool.create(createmode, createuid, creategid, createsize, createsetid, None) self.plog.info("Pool %s created.", pool.get_uuid_str()) # need a connection to create container pool.connect(1 << 1) # create a container container = DaosContainer(self.context) container.create(pool.handle) self.plog.info("Container %s created.", container.get_uuid_str()) # now open it container.open() # create an object and write some data into it thedata = "a string that I want to stuff into an object" thedatasize = len(thedata) + 1 dkey = "this is the dkey" akey = "this is the akey" obj, dummy_tx = container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) saved_oh = obj.obj_handle obj.obj_handle = 99999 obj, dummy_tx = container.write_an_obj(thedata, thedatasize, dkey, akey, obj, None, 2) container.oh = saved_oh container.close() container.destroy() pool.disconnect() pool.destroy(1) self.fail("Test was expected to return a -1002 but it has not.\n") except DaosApiError as excep: container.oh = saved_oh container.close() container.destroy() pool.disconnect() pool.destroy(1) self.plog.info("Test Complete") if '-1002' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1002 but it has not.\n")
class ObjOpenBadParam(TestWithServers): """ Test Class Description: Pass an assortment of bad parameters to the daos_obj_open function. :avocado: recursive """ def setUp(self): super(ObjOpenBadParam, self).setUp() self.prepare_pool() try: # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) # now open it self.container.open() # create an object and write some data into it thedata = "a string that I want to stuff into an object" self.datasize = len(thedata) + 1 self.dkey = "this is the dkey" self.akey = "this is the akey" self.obj = self.container.write_an_obj(thedata, self.datasize, self.dkey, self.akey, obj_cls=1) thedata2 = self.container.read_an_obj(self.datasize, self.dkey, self.akey, self.obj) if thedata not in thedata2.value: print(thedata) print(thedata2.value) err_str = "Error reading back data, test failed during the " \ "initial setup." self.d_log.error(err_str) self.fail(err_str) # setup leaves object in open state, so closing to start clean self.obj.close() except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test failed during the initial setup.") def test_bad_obj_handle(self): """ Test ID: DAOS-1320 Test Description: Attempt to open a garbage object handle. :avocado: tags=all,object,full_regression,tiny,objopenbadhandle """ saved_handle = self.obj.obj_handle self.obj.obj_handle = 8675309 try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1002' not in str(excep): self.d_log.error("test expected a -1002 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1002 but did not get it") finally: self.obj.obj_handle = saved_handle def test_invalid_container_handle(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object with a garbage container handle. :avocado: tags=all,object,full_regression,tiny,objopenbadcont """ saved_coh = self.container.coh self.container.coh = 8675309 try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1002' not in str(excep): self.d_log.error("test expected a -1002 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1002 but did not get it") finally: self.container.coh = saved_coh def test_closed_container_handle(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object in a container with a closed handle. :avocado: tags=all,object,full_regression,tiny,objopenclosedcont """ self.container.close() try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1002' not in str(excep): self.d_log.error("test expected a -1002 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1002 but did not get it") finally: self.container.open() def test_pool_handle_as_obj_handle(self): """ Test ID: DAOS-1320 Test Description: Adding this test by request, this test attempts to open an object that's had its handle set to be the same as a valid pool handle. :avocado: tags=all,object,full_regression,tiny,objopenbadpool """ saved_oh = self.obj.obj_handle self.obj.obj_handle = self.pool.pool.handle try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1002' not in str(excep): self.d_log.error("test expected a -1002 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1002 but did not get it") finally: self.obj.obj_handle = saved_oh def test_null_ranklist(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object in a container with an empty ranklist. :avocado: tags=all,object,full_regression,tiny,objopennullrl """ # null rl saved_rl = self.obj.tgt_rank_list self.obj.tgt_rank_list = None try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1003' not in str(excep): self.d_log.error("test expected a -1003 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1003 but did not get it") finally: self.obj.tgt_rank_list = saved_rl def test_null_oid(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object in a container with null object id. :avocado: tags=all,object,full_regression,tiny,objopennulloid """ # null oid saved_oid = self.obj.c_oid self.obj.c_oid = DaosObjId(0, 0) try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1003' not in str(excep): self.d_log.error("Test expected a -1003 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1003 but did not get it") finally: self.obj.c_oid = saved_oid def test_null_tgts(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object in a container with null tgt. :avocado: tags=all,object,full_regression,tiny,objopennulltgts """ # null tgts saved_ctgts = self.obj.c_tgts self.obj.c_tgts = 0 try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1003' not in str(excep): self.d_log.error("Test expected a -1003 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1003 but did not get it") finally: self.obj.c_tgts = saved_ctgts def test_null_attrs(self): """ Test ID: DAOS-1320 Test Description: Attempt to open an object in a container with null object attributes. :avocado: tags=all,object,full_regression,tiny,objopennullattr """ # null attr saved_attr = self.obj.attr self.obj.attr = 0 try: dummy_obj = self.obj.open() except DaosApiError as excep: if '-1003' not in str(excep): self.d_log.error("test expected a -1003 but did not get it") self.d_log.error(traceback.format_exc()) self.fail("test expected a -1003 but did not get it") finally: self.obj.attr = saved_attr
class Permission(TestWithServers): """Test pool permissions. Test Class Description: Tests DAOS pool permissions while connect, whether modifying file with specific permissions work as expected. :avocado: recursive """ def test_connectpermission(self): """Test ID: DAOS-???. Test Description: Test pool connections with specific permissions. :avocado: tags=pool,permission,connectpermission """ # parameters used in pool create createmode = self.params.get("mode", '/run/createtests/createmode/*/') createuid = os.geteuid() creategid = os.getegid() createsetid = self.params.get("setname", '/run/createtests/createset/') createsize = self.params.get("size", '/run/createtests/createsize/') # parameters used for pool connect permissions = self.params.get("perm", '/run/createtests/permissions/*') if createmode == 73 or \ (createmode == 146 and permissions != 1) or \ (createmode == 292 and permissions != 3): self.cancelForTicket("DAOS-3442") if createmode == 73: expected_result = 'FAIL' if createmode == 511 and permissions == 0: expected_result = 'PASS' elif createmode in [146, 511] and permissions == 1: expected_result = 'PASS' elif createmode in [292, 511] and permissions == 2: expected_result = 'PASS' else: expected_result = 'FAIL' try: # initialize a python pool object then create the underlying # daos storage self.pool = DaosPool(self.context) self.multi_log("Pool initialisation successful", "debug") self.pool.create(createmode, createuid, creategid, createsize, createsetid, None) self.multi_log("Pool Creation successful", "debug") self.pool.connect(1 << permissions) self.multi_log("Pool Connect successful", "debug") if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except DaosApiError as excep: self.log.error(str(excep)) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n") def test_filemodification(self): """Test ID: DAOS-???. Test Description: Test whether file modification happens as expected under different permission levels. :avocado: tags=pool,permission,filemodification """ # parameters used in pool create createmode = self.params.get("mode", '/run/createtests/createmode/*/') createuid = self.params.get("uid", '/run/createtests/createuid/') creategid = self.params.get("gid", '/run/createtests/creategid/') createsetid = self.params.get("setname", '/run/createtests/createset/') createsize = self.params.get("size", '/run/createtests/createsize/') if createmode == 73: expected_result = 'FAIL' elif createmode in [146, 511]: permissions = 1 expected_result = 'PASS' elif createmode == 292: permissions = 2 expected_result = 'PASS' try: # initialize a python pool object then create the underlying # daos storage self.pool = DaosPool(self.context) self.multi_log("Pool initialisation successful", "debug") self.pool.create(createmode, createuid, creategid, createsize, createsetid, None) self.multi_log("Pool Creation successful", "debug") self.pool.connect(1 << permissions) self.multi_log("Pool Connect successful", "debug") self.container = DaosContainer(self.context) self.multi_log("Contianer initialisation successful", "debug") self.container.create(self.pool.handle) self.multi_log("Container create successful", "debug") # now open it self.container.open() self.multi_log("Container open successful", "debug") thedata = "a string that I want to stuff into an object" size = 45 dkey = "this is the dkey" akey = "this is the akey" self.container.write_an_obj(thedata, size, dkey, akey) self.multi_log("Container write successful", "debug") if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except DaosApiError as excep: self.log.error(str(excep)) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n")
def test_null_values(self): """ Test ID: DAOS-1376 Test Description: Pass a dkey and an akey that is null. :avocado: tags=all,object,full_regression,small,objupdatenull """ try: # parameters used in pool create createmode = self.params.get("mode", '/run/conttests/createmode/') createsetid = self.params.get("setname", '/run/conttests/createset/') createsize = self.params.get("size", '/run/conttests/createsize/') createuid = os.geteuid() creategid = os.getegid() # initialize a python pool object then create the underlying # daos storage pool = DaosPool(self.context) pool.create(createmode, createuid, creategid, createsize, createsetid, None) self.plog.info("Pool %s created.", pool.get_uuid_str()) # need a connection to create container pool.connect(1 << 1) # create a container container = DaosContainer(self.context) container.create(pool.handle) self.plog.info("Container %s created.", container.get_uuid_str()) # now open it container.open() # data used in the test thedata = "a string that I want to stuff into an object" thedatasize = len(thedata) + 1 except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test failed during setup .\n") try: # try using a null dkey dkey = None akey = "this is the akey" container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) container.close() container.destroy() pool.disconnect() pool.destroy(1) self.plog.error("Didn't get expected return code.") self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): container.close() container.destroy() pool.disconnect() pool.destroy(1) self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # try using a null akey/io descriptor dkey = "this is the dkey" akey = None container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # lastly try passing no data thedata = None thedatasize = 0 dkey = "this is the dkey" akey = "this is the akey" container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.plog.info("Update with no data worked") except DaosApiError as excep: container.close() container.destroy() pool.disconnect() pool.destroy(1) print(excep) print(traceback.format_exc()) self.plog.error("Update with no data failed") self.fail("Update with no data failed.\n") container.close() container.destroy() pool.disconnect() pool.destroy(1) self.plog.info("Test Complete")
class FullPoolContainerCreate(TestWithServers): """ Class for test to create a container in a pool with no remaining free space. :avocado: recursive """ def __init__(self, *args, **kwargs): super(FullPoolContainerCreate, self).__init__(*args, **kwargs) self.cont = None self.cont2 = None @skipForTicket("DAOS-3142") def test_no_space_cont_create(self): """ :avocado: tags=all,container,tiny,full_regression,fullpoolcontcreate """ # full storage rc err = "-1007" # probably should be -1007, revisit later err2 = "-1009" # create pool self.pool = DaosPool(self.context) mode = self.params.get("mode", '/conttests/createmode/') self.d_log.debug("mode is {0}".format(mode)) uid = os.geteuid() gid = os.getegid() # 16 mb pool, minimum size currently possible size = 16777216 self.d_log.debug("creating pool") self.pool.create(mode, uid, gid, size, self.server_group, None) self.d_log.debug("created pool") # connect to the pool self.d_log.debug("connecting to pool") self.pool.connect(1 << 1) self.d_log.debug("connected to pool") # query the pool self.d_log.debug("querying pool info") dummy_pool_info = self.pool.pool_query() self.d_log.debug("queried pool info") # create a container try: self.d_log.debug("creating container") self.cont = DaosContainer(self.context) self.cont.create(self.pool.handle) self.d_log.debug("created container") except DaosApiError as excep: self.d_log.error("caught exception creating container: " "{0}".format(excep)) self.fail("caught exception creating container: {0}".format(excep)) self.d_log.debug("opening container") self.cont.open() self.d_log.debug("opened container") # generate random dkey, akey each time # write 1mb until no space, then 1kb, etc. to fill pool quickly for obj_sz in [1048576, 10240, 10, 1]: write_count = 0 while True: self.d_log.debug("writing obj {0}, sz {1} to " "container".format(write_count, obj_sz)) my_str = "a" * obj_sz my_str_sz = obj_sz dkey = (''.join( random.choice(string.lowercase) for i in range(5))) akey = (''.join( random.choice(string.lowercase) for i in range(5))) try: dummy_oid = self.cont.write_an_obj(my_str, my_str_sz, dkey, akey, obj_cls="OC_SX") self.d_log.debug("wrote obj {0}, sz {1}".format( write_count, obj_sz)) write_count += 1 except DaosApiError as excep: if not (err in repr(excep) or err2 in repr(excep)): self.d_log.error("caught exception while writing " "object: {0}".format(repr(excep))) self.fail("caught exception while writing object: {0}". format(repr(excep))) else: self.d_log.debug("pool is too full for {0} byte " "objects".format(obj_sz)) break self.d_log.debug("closing container") self.cont.close() self.d_log.debug("closed container") # create a 2nd container now that pool is full try: self.d_log.debug("creating 2nd container") self.cont2 = DaosContainer(self.context) self.cont2.create(self.pool.handle) self.d_log.debug("created 2nd container") self.d_log.debug("opening container 2") self.cont2.open() self.d_log.debug("opened container 2") self.d_log.debug("writing one more object, write expected to fail") self.cont2.write_an_obj(my_str, my_str_sz, dkey, akey, obj_cls="OC_SX") self.fail("wrote one more object after pool was completely filled," " this should never print") except DaosApiError as excep: if not (err in repr(excep) or err2 in repr(excep)): self.d_log.error("caught unexpected exception while " "writing object: {0}".format(repr(excep))) self.fail("caught unexpected exception while writing " "object: {0}".format(repr(excep))) else: self.d_log.debug("correctly caught -1007 while attempting " "to write object in full pool")
class ObjUpdateBadParam(TestWithServers): """ Test Class Description: Pass an assortment of bad parameters to the daos_obj_update function. :avocado: recursive """ def setUp(self): super().setUp() self.plog = logging.getLogger("progress") try: self.prepare_pool() # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) self.plog.info("Container %s created.", self.container.get_uuid_str()) # now open it self.container.open() except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test failed during setup .\n") def test_bad_handle(self): """ Test ID: DAOS-1376 Test Description: Pass a bogus object handle, should return bad handle. :avocado: tags=all,full_regression,small :avocado: tags=object,objupdatebadparam :avocado: tags=objbadhand """ try: # create an object and write some data into it thedata = b"a string that I want to stuff into an object" thedatasize = len(thedata) + 1 dkey = b"this is the dkey" akey = b"this is the akey" obj = self.container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) saved_oh = obj.obj_handle obj.obj_handle = 99999 obj = self.container.write_an_obj(thedata, thedatasize, dkey, akey, obj, None, 2) self.container.oh = saved_oh self.fail("Test was expected to return a -1002 but it has not.\n") except DaosApiError as excep: self.container.oh = saved_oh self.plog.info("Test Complete") if '-1002' not in str(excep): print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1002 but it has not.\n") def test_null_values(self): """ Test ID: DAOS-1376 Test Description: Pass a dkey and an akey that is null. :avocado: tags=all,full_regression,small :avocado: tags=object,objupdatebadparam :avocado: tags=objupdatenull """ # data used in the test thedata = b"a string that I want to stuff into an object" thedatasize = len(thedata) + 1 try: # try using a null dkey dkey = None akey = b"this is the akey" self.container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.plog.error("Didn't get expected return code.") self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # try using a null akey/io descriptor dkey = b"this is the dkey" akey = None self.container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.fail("Test was expected to return a -1003 but it has not.\n") except DaosApiError as excep: if '-1003' not in str(excep): self.plog.error("Didn't get expected return code.") print(excep) print(traceback.format_exc()) self.fail("Test was expected to get -1003 but it has not.\n") try: # lastly try passing no data thedata = None thedatasize = 0 dkey = b"this is the dkey" akey = b"this is the akey" self.container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) self.plog.info("Update with no data worked") except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.plog.error("Update with no data failed") self.fail("Update with no data failed.\n") self.plog.info("Test Complete")
class PunchTest(TestWithServers): """ Simple test to verify the 3 different punch calls. :avocado: recursive """ def setUp(self): super(PunchTest, self).setUp() self.prepare_pool() try: # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) # now open it self.container.open() except DaosApiError as excpn: print(excpn) print(traceback.format_exc()) self.fail("Test failed during setup.\n") def test_dkey_punch(self): """ The most basic test of the dkey punch function. :avocado: tags=all,object,daily_regression,small,dkeypunch """ try: # create an object and write some data into it thedata = "a string that I want to stuff into an object" dkey = "this is the dkey" akey = "this is the akey" tx_handle = self.container.get_new_tx() print("Created a new TX for punch dkey test") obj = self.container.write_an_obj(thedata, len(thedata) + 1, dkey, akey, obj_cls=1, txn=tx_handle) print("Committing the TX for punch dkey test") self.container.commit_tx(tx_handle) print("Committed the TX for punch dkey test") # read the data back and make sure its correct thedata2 = self.container.read_an_obj(len(thedata) + 1, dkey, akey, obj, txn=tx_handle) if thedata != thedata2.value: print("data I wrote:" + thedata) print("data I read back" + thedata2.value) self.fail("Wrote data, read it back, didn't match\n") # now punch this data, should fail, can't punch committed data obj.punch_dkeys(tx_handle, [dkey]) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as dummy_e: pass try: self.container.close_tx(tx_handle) print("Closed TX for punch dkey test") # now punch this data obj.punch_dkeys(0, [dkey]) # this one should work so error if exception occurs except DaosApiError as dummy_e: self.fail("Punch should have worked.\n") # there are a bunch of other cases to test here, # --test punching the same updating and punching the same data in # the same tx, should fail # --test non updated data in an open tx, should work def test_akey_punch(self): """ The most basic test of the akey punch function. :avocado: tags=all,object,daily_regression,small,akeypunch """ try: # create an object and write some data into it dkey = "this is the dkey" data1 = [("this is akey 1", "this is data value 1"), ("this is akey 2", "this is data value 2"), ("this is akey 3", "this is data value 3")] tx_handle = self.container.get_new_tx() print("Created a new TX for punch akey test") obj = self.container.write_multi_akeys(dkey, data1, obj_cls=1, txn=tx_handle) print("Committing the TX for punch akey test") self.container.commit_tx(tx_handle) print("Committed the TX for punch dkey test") # read back the 1st epoch's data and check 1 value just to make sure # everything is on the up and up readbuf = [(data1[0][0], len(data1[0][1]) + 1), (data1[1][0], len(data1[1][1]) + 1), (data1[2][0], len(data1[2][1]) + 1)] retrieved_data = self.container.read_multi_akeys(dkey, readbuf, obj, txn=tx_handle) if retrieved_data[data1[1][0]] != data1[1][1]: print("middle akey: {}".format(retrieved_data[data1[1][0]])) self.fail("data retrieval failure") # now punch one akey from this data obj.punch_akeys(tx_handle, dkey, [data1[1][0]]) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as excep: print(excep) try: self.container.close_tx(tx_handle) print("Closed TX for punch akey test") # now punch the object without a tx obj.punch_akeys(0, dkey, [data1[1][0]]) # expecting it to work this time so error except DaosApiError as excep: self.fail("Punch should have worked: {}\n".format(excep)) def test_obj_punch(self): """ The most basic test of the object punch function. Really similar to above except the whole object is deleted. :avocado: tags=all,object,daily_regression,small,objpunch """ try: # create an object and write some data into it thedata = "a string that I want to stuff into an object" dkey = "this is the dkey" akey = "this is the akey" tx_handle = self.container.get_new_tx() print("Created a new TX for punch obj test") obj = self.container.write_an_obj(thedata, len(thedata) + 1, dkey, akey, obj_cls=1, txn=tx_handle) print("Committing the TX for punch obj test") self.container.commit_tx(tx_handle) print("Committed the TX for punch obj test") # read the data back and make sure its correct thedata2 = self.container.read_an_obj(len(thedata) + 1, dkey, akey, obj, txn=tx_handle) if thedata != thedata2.value: print("data I wrote:" + thedata) print("data I read back" + thedata2.value) self.fail("Wrote data, read it back, didn't match\n") # now punch the object, committed so not expecting it to work obj.punch(tx_handle) # expecting punch of commit data above to fail self.fail("Punch should have failed but it didn't.\n") # expecting an exception so do nothing except DaosApiError as excep: print(excep) try: self.container.close_tx(tx_handle) print("Closed TX for punch obj test") obj.punch(0) # expecting it to work without a tx except DaosApiError as excep: print(excep) self.fail("Punch should have worked.\n")
class Permission(TestWithServers): """Test pool permissions. Test Class Description: Tests DAOS pool permissions while connect, whether modifying file with specific permissions work as expected. :avocado: recursive """ # Cancel any tests with tickets already assigned CANCEL_FOR_TICKET = [ ["DAOS-3442", "mode", 73], ["DAOS-3442", "mode", 146, "perm", 0], ["DAOS-3442", "mode", 146, "perm", 2], ["DAOS-3442", "mode", 292], ] def test_connectpermission(self): """Test ID: DAOS-???. Test Description: Test pool connections with specific permissions. :avocado: tags=pool,permission,connectpermission """ # parameter used in pool create createmode = self.params.get("mode", '/run/createtests/createmode/*/') # parameter used for pool connect permissions = self.params.get("perm", '/run/createtests/permissions/*') if createmode == 73: expected_result = RESULT_FAIL if createmode == 511 and permissions == 0: expected_result = RESULT_PASS elif createmode in [146, 511] and permissions == 1: expected_result = RESULT_PASS elif createmode in [292, 511] and permissions == 2: expected_result = RESULT_PASS else: expected_result = RESULT_FAIL # initialize a python pool object then create the underlying # daos storage self.pool = TestPool(self.context, self.get_dmg_command()) self.test_log.debug("Pool initialization successful") self.pool.get_params(self) self.pool.mode.value = createmode self.pool.create() self.test_log.debug("Pool Creation successful") try: self.pool.connect(1 << permissions) self.test_log.debug("Pool Connect successful") if expected_result == RESULT_FAIL: self.fail( "Test was expected to fail at pool.connect, but it " + "passed.\n") except TestFail as excep: self.log.error(str(excep)) if expected_result == RESULT_PASS: self.fail("Test was expected to pass but it failed at " + "pool.connect.\n") def test_filemodification(self): """Test ID: DAOS-???. Test Description: Test whether file modification happens as expected under different permission levels. :avocado: tags=pool,permission,filemodification """ # parameters used in pool create createmode = self.params.get("mode", '/run/createtests/createmode/*/') if createmode == 73: expected_result = RESULT_FAIL elif createmode in [146, 511]: permissions = 1 expected_result = RESULT_PASS elif createmode == 292: permissions = 2 expected_result = RESULT_PASS # initialize a python pool object then create the underlying # daos storage self.pool = TestPool(self.context, self.get_dmg_command()) self.test_log.debug("Pool initialization successful") self.pool.get_params(self) self.pool.mode.value = createmode self.test_log.debug("Pool Creation successful") try: self.pool.connect(1 << permissions) self.test_log.debug("Pool Connect successful") if expected_result == RESULT_FAIL: self.fail("Test was expected to fail at pool.connect but it " + "passed.\n") except TestFail as excep: self.log.error(str(excep)) if expected_result == RESULT_PASS: self.fail("Test was expected to pass but it failed at " + "pool.connect.\n") try: self.container = DaosContainer(self.context) self.test_log.debug("Container initialization successful") self.container.create(self.pool.pool.handle) self.test_log.debug("Container create successful") # now open it self.container.open() self.test_log.debug("Container open successful") thedata = "a string that I want to stuff into an object" size = 45 dkey = "this is the dkey" akey = "this is the akey" self.container.write_an_obj(thedata, size, dkey, akey) self.test_log.debug("Container write successful") if expected_result == RESULT_FAIL: self.fail( "Test was expected to fail at container operations " + "but it passed.\n") except DaosApiError as excep: self.log.error(str(excep)) if expected_result == RESULT_PASS: self.fail( "Test was expected to pass but it failed at container " + "operations.\n")
class BasicSnapshot(TestWithServers): """DAOS-1370 Basic snapshot test. Test Class Description: Test that a snapshot taken of a container remains unchaged even after an object in the container has been updated 500 times. Create the container. Write an object to the container. Take a snapshot. Write 500 changes to the KV pair of the object. Check that the snapshot is still there. Confirm that the data in the snapshot is unchanged. Destroy the snapshot :avocado: recursive """ def __init__(self, *args, **kwargs): """Initialize a BasicSnapshot object.""" super(BasicSnapshot, self).__init__(*args, **kwargs) self.snapshot = None def test_basic_snapshot(self): """Test ID: DAOS-1370. Test Description: Create a pool, container in the pool, object in the container, add one key:value to the object. Commit the transaction. Perform a snapshot create on the container. Create 500 additional transactions with a small change to the object in each and commit each after the object update is done. Verify the snapshot is still available and the contents remain in their original state. :avocado: tags=snap,basicsnap """ # Set up the pool and container. try: # initialize a pool object then create the underlying # daos storage, and connect self.prepare_pool() # create a container self.container = DaosContainer(self.context) self.container.create(self.pool.pool.handle) # now open it self.container.open() except DaosApiError as error: self.log.error(str(error)) self.fail("Test failed before snapshot taken") try: # create an object and write some data into it obj_cls = self.params.get("obj_class", '/run/object_class/*') thedata = "Now is the winter of our discontent made glorious" datasize = len(thedata) + 1 dkey = "dkey" akey = "akey" tx_handle = self.container.get_new_tx() obj = self.container.write_an_obj(thedata, datasize, dkey, akey, obj_cls=obj_cls, txn=tx_handle) self.container.commit_tx(tx_handle) obj.close() # Take a snapshot of the container self.snapshot = DaosSnapshot(self.context) self.snapshot.create(self.container.coh, tx_handle) self.log.info("Wrote an object and created a snapshot") except DaosApiError as error: self.fail("Test failed during the initial object write.\n{0}" .format(error)) # Make 500 changes to the data object. The write_an_obj function does a # commit when the update is complete try: self.log.info( "Committing 500 additional transactions to the same KV") more_transactions = 500 while more_transactions: size = random.randint(1, 250) + 1 new_data = get_random_string(size) new_obj = self.container.write_an_obj( new_data, size, dkey, akey, obj_cls=obj_cls) new_obj.close() more_transactions -= 1 except DaosApiError as error: self.fail( "Test failed during the write of 500 objects.\n{0}".format( error)) # List the snapshot try: reported_epoch = self.snapshot.list(self.container.coh) except DaosApiError as error: self.fail( "Test was unable to list the snapshot\n{0}".format(error)) # Make sure the snapshot reflects the original epoch if self.snapshot.epoch != reported_epoch: self.fail( "The snapshot epoch returned from snapshot list is not the " "same as the original epoch snapshotted.") self.log.info( "After 500 additional commits the snapshot is still available") # Make sure the data in the snapshot is the original data. # Get a handle for the snapshot and read the object at dkey, akey. try: obj.open() snap_handle = self.snapshot.open(self.container.coh) thedata2 = self.container.read_an_obj( datasize, dkey, akey, obj, txn=snap_handle.value) except DaosApiError as error: self.fail( "Error when retrieving the snapshot data.\n{0}".format(error)) # Compare the snapshot to the originally written data. if thedata2.value != thedata: self.fail( "The data in the snapshot is not the same as the original data") self.log.info( "The snapshot data matches the data originally written.") # Now destroy the snapshot try: self.snapshot.destroy(self.container.coh) self.log.info("Snapshot successfully destroyed") except DaosApiError as error: self.fail(str(error))
def test_tx_basics(self): """ Perform I/O to an object in a container in 2 different transactions, verifying basic I/O and transactions in particular. NOTE: this was an epoch test and all I did was get it working with tx Not a good test at this point, need to redesign when tx is fully working. :avocado: tags=all,container,tx,small,smoke,pr,basictx """ self.pool = None try: # parameters used in pool create createmode = self.params.get("mode", '/run/poolparams/createmode/') createuid = os.geteuid() creategid = os.getegid() createsetid = self.params.get("setname", '/run/poolparams/createset/') createsize = self.params.get("size", '/run/poolparams/createsize/') # initialize a python pool object then create the underlying # daos storage self.pool = DaosPool(self.context) self.pool.create(createmode, createuid, creategid, createsize, createsetid, None) # need a connection to create container self.pool.connect(1 << 1) # create a container container = DaosContainer(self.context) container.create(self.pool.handle) # now open it container.open() # do a query and compare the UUID returned from create with # that returned by query container.query() if container.get_uuid_str() != c_uuid_to_str( container.info.ci_uuid): self.fail("Container UUID did not match the one in info\n") # create an object and write some data into it thedata = "a string that I want to stuff into an object" thedatasize = 45 dkey = "this is the dkey" akey = "this is the akey" oid, txn = container.write_an_obj(thedata, thedatasize, dkey, akey, None, None, 2) # read the data back and make sure its correct thedata2 = container.read_an_obj(thedatasize, dkey, akey, oid, txn) if thedata != thedata2.value: print("thedata>" + thedata) print("thedata2>" + thedata2.value) self.fail("Write data 1, read it back, didn't match\n") # repeat above, but know that the write_an_obj call is advancing # the epoch so the original copy remains and the new copy is in # a new epoch. thedata3 = "a different string" thedatasize2 = 19 # note using the same keys so writing to the same spot dkey = "this is the dkey" akey = "this is the akey" oid, tx2 = container.write_an_obj(thedata3, thedatasize2, dkey, akey, oid, None, 2) # read the data back and make sure its correct thedata4 = container.read_an_obj(thedatasize2, dkey, akey, oid, tx2) if thedata3 != thedata4.value: self.fail("Write data 2, read it back, didn't match\n") # transactions generally don't work this way but need to explore # an alternative to below code once model is complete, maybe # read from a snapshot or read from TX_NONE etc. # the original data should still be there too #thedata5 = container.read_an_obj(thedatasize, dkey, akey, # oid, transaction) #if thedata != thedata5.value: # self.fail("Write data 3, read it back, didn't match\n") container.close() # wait a few seconds and then destroy time.sleep(5) container.destroy() except DaosApiError as excep: print(excep) print(traceback.format_exc()) self.fail("Test was expected to pass but it failed.\n")
def test_no_space_cont_create(self): """ :avocado: tags=all,container,tiny,full_regression,fullpoolcontcreate """ # full storage rc err = "-1007" # probably should be -1007, revisit later err2 = "-1009" # create pool and connect self.prepare_pool() # query the pool self.log.info("Pool Query before write") self.pool.set_query_data() self.log.info("Pool %s query data: %s\n", self.pool.uuid, self.pool.query_data) # create a container try: self.log.info("creating container 1") cont = DaosContainer(self.context) cont.create(self.pool.pool.handle) self.log.info("created container 1") except DaosApiError as excep: self.log.error("caught exception creating container: " "%s", excep) self.fail("caught exception creating container: {}".format(excep)) self.log.info("opening container 1") cont.open() # generate random dkey, akey each time # write 1mb until no space, then 1kb, etc. to fill pool quickly for obj_sz in [1048576, 10240, 10, 1]: write_count = 0 while True: self.d_log.debug("writing obj {0} sz {1} to " "container".format(write_count, obj_sz)) my_str = b"a" * obj_sz my_str_sz = obj_sz dkey = get_random_bytes(5) akey = get_random_bytes(5) try: dummy_oid = cont.write_an_obj(my_str, my_str_sz, dkey, akey, obj_cls="OC_SX") self.d_log.debug("wrote obj {0}, sz {1}".format( write_count, obj_sz)) write_count += 1 except DaosApiError as excep: if not (err in repr(excep) or err2 in repr(excep)): self.log.error( "caught exception while writing " "object: %s", repr(excep)) cont.close() self.fail("caught exception while writing " "object: {}".format(repr(excep))) else: self.log.info( "pool is too full for %s byte " "objects", obj_sz) break self.log.info("closing container") cont.close() # query the pool self.log.info("Pool Query after filling") self.pool.set_query_data() self.log.info("Pool %s query data: %s\n", self.pool.uuid, self.pool.query_data) # create a 2nd container now that pool is full try: self.log.info("creating 2nd container") cont2 = DaosContainer(self.context) cont2.create(self.pool.pool.handle) self.log.info("created 2nd container") self.log.info("opening container 2") cont2.open() self.log.info("writing one more object, write expected to fail") cont2.write_an_obj(my_str, my_str_sz, dkey, akey, obj_cls="OC_SX") self.log.info("closing container") cont2.close() self.fail("wrote one more object after pool was completely filled," " this should never print") except DaosApiError as excep: if not (err in repr(excep) or err2 in repr(excep)): self.log.error( "caught unexpected exception while " "writing object: %s", repr(excep)) self.log.info("closing container") cont2.close() self.fail("caught unexpected exception while writing " "object: {}".format(repr(excep))) else: self.log.info("correctly caught -1007 while attempting " "to write object in full pool") self.log.info("closing container") cont2.close()