class ContainerAttributeTest(Test): """ Tests DAOS container attribute get/set/list. """ def setUp(self): self.agent_sessions = None self.pool = None self.container = None self.hostlist = None self.large_data_set = {} with open('../../../.build_vars.json') as build_file: build_paths = json.load(build_file) basepath = os.path.normpath(build_paths['PREFIX'] + "/../") server_group = self.params.get("name", '/server_config/', 'daos_server') self.context = DaosContext(build_paths['PREFIX'] + '/lib/') self.hostlist = self.params.get("test_machines", '/run/hosts/*') self.hostfile = write_host_file.write_host_file(self.hostlist, self.workdir) self.agent_sessions = AgentUtils.run_agent(basepath, self.hostlist) server_utils.run_server(self.hostfile, server_group, basepath) self.pool = DaosPool(self.context) self.pool.create(self.params.get("mode", '/run/attrtests/createmode/*'), os.geteuid(), os.getegid(), self.params.get("size", '/run/attrtests/createsize/*'), self.params.get("setname", '/run/attrtests/createset/*'), None) self.pool.connect(1 << 1) poh = self.pool.handle self.container = DaosContainer(self.context) self.container.create(poh) self.container.open() def tearDown(self): try: if self.container: self.container.close() finally: if self.agent_sessions: AgentUtils.stop_agent(self.hostlist, self.agent_sessions) server_utils.stop_server(hosts=self.hostlist) def create_data_set(self): """ To create the large attribute dictionary """ allchar = string.ascii_letters + string.digits for i in range(1024): self.large_data_set[str(i)] = ( "".join(random.choice(allchar) for x in range(random.randint(1, 100)))) def test_container_attribute(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,sync_conattribute """ expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = {name[0]:value[0]} if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set attr_dict[name[0]] = value[0] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: self.container.set_attr(data=attr_dict) size, buf = self.container.list_attr() verify_list_attr(attr_dict, size, buf) # Request something that doesn't exist if name[0] is not None and "Negative" in name[0]: name[0] = "rubbish" results = {} results = self.container.get_attr([name[0]]) # for this test the dictionary has been altered, need to just # set it to what we are expecting to get back if name[0] is not None: if "largenumberofattr" in name[0]: attr_dict.clear() attr_dict[name[0]] = value[0] verify_get_attr(attr_dict, results) if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except (DaosApiError, DaosTestError) as excep: print(excep) print(traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n") def test_container_attribute_asyn(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,async_conattribute """ global GLOB_SIGNAL global GLOB_RC expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = {name[0]:value[0]} if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set attr_dict[name[0]] = value[0] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: GLOB_SIGNAL = threading.Event() self.container.set_attr(data=attr_dict, cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail("RC not as expected after set_attr First {0}" .format(GLOB_RC)) GLOB_SIGNAL = threading.Event() size, buf = self.container.list_attr(cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail("RC not as expected after list_attr First {0}" .format(GLOB_RC)) if expected_result in ['PASS']: verify_list_attr(attr_dict, size, buf, mode="async") # Request something that doesn't exist if name[0] is not None and "Negative" in name[0]: name[0] = "rubbish" GLOB_SIGNAL = threading.Event() self.container.get_attr([name[0]], cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail("RC not as expected after get_attr {0}" .format(GLOB_RC)) # not verifying the get_attr since its not available asynchronously if value[0] != None: if GLOB_RC == 0 and expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except DaosApiError as excep: print(excep) print(traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n")
class ContainerAttributeTest(TestWithServers): """ Tests DAOS container attribute get/set/list. :avocado: recursive """ def setUp(self): super(ContainerAttributeTest, self).setUp() self.large_data_set = {} self.pool = DaosPool(self.context) self.pool.create( self.params.get("mode", '/run/attrtests/createmode/*'), os.geteuid(), os.getegid(), self.params.get("size", '/run/attrtests/createsize/*'), self.params.get("setname", '/run/attrtests/createset/*'), None) self.pool.connect(1 << 1) poh = self.pool.handle self.container = DaosContainer(self.context) self.container.create(poh) self.container.open() def tearDown(self): try: if self.container: self.container.close() finally: super(ContainerAttributeTest, self).tearDown() def create_data_set(self): """ To create the large attribute dictionary """ allchar = string.ascii_letters + string.digits for i in range(1024): self.large_data_set[str(i)] = ("".join( random.choice(allchar) for x in range(random.randint(1, 100)))) def test_container_attribute(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,sync_conattribute """ expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = {name[0]: value[0]} if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set attr_dict[name[0]] = value[0] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: self.container.set_attr(data=attr_dict) size, buf = self.container.list_attr() verify_list_attr(attr_dict, size, buf) # Request something that doesn't exist if name[0] is not None and "Negative" in name[0]: name[0] = "rubbish" results = {} results = self.container.get_attr([name[0]]) # for this test the dictionary has been altered, need to just # set it to what we are expecting to get back if name[0] is not None: if "largenumberofattr" in name[0]: attr_dict.clear() attr_dict[name[0]] = value[0] verify_get_attr(attr_dict, results) if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except (DaosApiError, DaosTestError) as excep: print(excep) print(traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n") def test_container_attribute_asyn(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,async_conattribute """ global GLOB_SIGNAL global GLOB_RC expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = {name[0]: value[0]} if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set attr_dict[name[0]] = value[0] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: GLOB_SIGNAL = threading.Event() self.container.set_attr(data=attr_dict, cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail("RC not as expected after set_attr First {0}".format( GLOB_RC)) GLOB_SIGNAL = threading.Event() size, buf = self.container.list_attr(cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail( "RC not as expected after list_attr First {0}".format( GLOB_RC)) if expected_result in ['PASS']: verify_list_attr(attr_dict, size, buf, mode="async") # Request something that doesn't exist if name[0] is not None and "Negative" in name[0]: name[0] = "rubbish" GLOB_SIGNAL = threading.Event() self.container.get_attr([name[0]], cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0 and expected_result in ['PASS']: self.fail( "RC not as expected after get_attr {0}".format(GLOB_RC)) # not verifying the get_attr since its not available asynchronously if value[0] != None: if GLOB_RC == 0 and expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except DaosApiError as excep: print(excep) print(traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n")
class ContainerAttributeTest(Test): """ Tests DAOS container attribute get/set/list. """ def setUp(self): with open('../../../.build_vars.json') as f: build_paths = json.load(f) basepath = os.path.normpath(build_paths['PREFIX'] + "/../") tmp = build_paths['PREFIX'] + '/tmp' server_group = self.params.get("server_group", '/server/', 'daos_server') self.Context = DaosContext(build_paths['PREFIX'] + '/lib/') self.hostlist = self.params.get("test_machines", '/run/hosts/*') self.hostfile = WriteHostFile.WriteHostFile(self.hostlist, tmp) ServerUtils.runServer(self.hostfile, server_group, basepath) self.POOL = DaosPool(self.Context) self.POOL.create(self.params.get("mode", '/run/attrtests/createmode/*'), os.geteuid(), os.getegid(), self.params.get("size", '/run/attrtests/createsize/*'), self.params.get("setname", '/run/attrtests/createset/*'), None) self.POOL.connect(1 << 1) poh = self.POOL.handle self.CONTAINER = DaosContainer(self.Context) self.CONTAINER.create(poh) self.CONTAINER.open() self.large_data_set = {} def tearDown(self): try: if self.hostfile is not None: os.remove(self.hostfile) if self.CONTAINER: self.CONTAINER.close() finally: ServerUtils.stopServer(hosts=self.hostlist) def create_data_set(self): """ To create the large attribute dictionary """ allchar = string.ascii_letters + string.digits for i in range(1024): self.large_data_set[str(i)] = "".join(random.choice(allchar) for x in range(random.randint(1, 100))) def test_container_attribute(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,sync_conattribute """ expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = dict(zip(name, value)) if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set if 'PASS' in attr_dict: del attr_dict['PASS'] if 'FAIL' in attr_dict: del attr_dict['FAIL'] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: print ("===== Set Attr") self.CONTAINER.set_attr(data=attr_dict) size, buf = self.CONTAINER.list_attr() verify_list_attr(attr_dict, size, buf) ##This is for requesting the name which is not exist. if "Negative" in name[0]: attr_dict["Wrong_Value"] = attr_dict.pop(name[0]) val = self.CONTAINER.get_attr(data=attr_dict) verify_get_attr(attr_dict, val) if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except Exception as e: print (e) print (traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n") def test_container_attribute_asyn(self): """ Test basic container attribute tests. :avocado: tags=container,container_attr,attribute,async_conattribute """ global GLOB_SIGNAL global GLOB_RC expected_for_param = [] name = self.params.get("name", '/run/attrtests/name_handles/*/') expected_for_param.append(name[1]) value = self.params.get("value", '/run/attrtests/value_handles/*/') expected_for_param.append(value[1]) attr_dict = dict(zip(name, value)) if name[0] is not None: if "largenumberofattr" in name[0]: self.create_data_set() attr_dict = self.large_data_set if 'PASS' in attr_dict: del attr_dict['PASS'] if 'FAIL' in attr_dict: del attr_dict['FAIL'] expected_result = 'PASS' for result in expected_for_param: if result == 'FAIL': expected_result = 'FAIL' break try: print ("===== Set Attr") GLOB_SIGNAL = threading.Event() self.CONTAINER.set_attr(data=attr_dict, cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0: self.fail("RC not as expected after set_attr First {0}" .format(GLOB_RC)) GLOB_SIGNAL = threading.Event() size, buf = self.CONTAINER.list_attr(cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0: self.fail("RC not as expected after list_attr First {0}" .format(GLOB_RC)) verify_list_attr(attr_dict, size, buf, mode="async") #This is for requesting the name which is not exist. if "Negative" in name[0]: attr_dict["Wrong_Value"] = attr_dict.pop(name[0]) GLOB_SIGNAL = threading.Event() val = self.CONTAINER.get_attr(data=attr_dict, cb_func=cb_func) GLOB_SIGNAL.wait() if GLOB_RC != 0: self.fail("RC not as expected after get_attr {0}" .format(GLOB_RC)) verify_get_attr(attr_dict, val) if expected_result in ['FAIL']: self.fail("Test was expected to fail but it passed.\n") except DaosApiError as e: print(e) print(traceback.format_exc()) if expected_result == 'PASS': self.fail("Test was expected to pass but it failed.\n")