def test_two(self): """ Verify Load Balancing - Have a known configuration of node count and chunk size - Load a sequence of files with specific sizes - Check the file count and distribution of load """ self.test_name = self.test_two.__doc__ try: app_config = json.load(open(config.TEST_DATA.milestone_3.app_config_location)) node_count = app_config['node_count'] size_per_slice = app_config['size_per_slice'] redunduncy_count = app_config['redundancy_count'] print("\nVerifying Pre-Requisites for the Test") assert(node_count==4) assert(size_per_slice==1024) assert(redunduncy_count==1) print("\nSuccessfully verified Pre-Requisites for the test") #Load 10KB file rs = txn.upload_a_file(config.TEST_DATA.milestone_3.file_1_path) assert(rs.status_code == 200) nodes = [] for items in os.listdir(config.TEST_DATA.milestone_3.location_of_nodes): if( os.path.isdir(config.TEST_DATA.milestone_3.location_of_nodes+'/'+items) and 'node_' in items): nodes.append(items) file_count_data = {} for node in nodes: file_count_in_that_node = 0 file_count_in_that_node =os.listdir( os.path.join(config.TEST_DATA.milestone_3.location_of_nodes , node) ).__len__() file_count_data[node]= file_count_in_that_node # there must not be more than 2 files per node for the given configuration for key in file_count_data.keys(): assert(file_count_data[key] <= config.TEST_DATA.milestone_3.test_2_count_1) #Load 2KB file Twice rs = txn.upload_a_file(config.TEST_DATA.milestone_3.file_2_path) assert(rs.status_code == 200) rs = txn.upload_a_file(config.TEST_DATA.milestone_3.file_3_path) assert(rs.status_code == 200) nodes = [] for items in os.listdir(config.TEST_DATA.milestone_3.location_of_nodes): if( os.path.isdir(config.TEST_DATA.milestone_3.location_of_nodes+'/'+items) and 'node_' in items): nodes.append(items) file_count_data = {} for node in nodes: file_count_in_that_node = 0 file_count_in_that_node =os.listdir( os.path.join(config.TEST_DATA.milestone_3.location_of_nodes , node) ).__len__() file_count_data[node]= file_count_in_that_node # there must not be more than 2 files per node for the given configuration for key in file_count_data.keys(): assert(file_count_data[key] <= config.TEST_DATA.milestone_3.test_2_count_2) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_six(self): """ Verify that a file uploaded to one server can be Deleted from another server """ self.test_name = self.test_six.__doc__ try: txn.test_configs.API_SERVER_URL = self.servers[0] response = txn.upload_a_file( config.TEST_DATA.milestone_1b.file_to_upload_2) assert (response.status_code == 200) id = response.text r = txn.retrive_a_file_by_id(id) assert (r.status_code == 200) txn.test_configs.API_SERVER_URL = self.servers[1] delete = txn.delete_a_file_by_id(id) assert (delete.status_code == 200) txn.test_configs.API_SERVER_URL = self.servers[0] r = txn.retrive_a_file_by_id(id) assert (r.status_code == 404) txn.test_configs.API_SERVER_URL = self.servers[2] list_of_files = txn.list_available_files().json() assert (str(id) not in str(list_of_files)) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_ten(self): """ Verify that an error is returned while trying to upload a duplicate file """ self.test_name = self.test_ten.__doc__ try: response = txn.upload_a_file( config.TEST_DATA.test_ten.file_to_upload) assert (response.status_code == 200) response = txn.upload_a_file( config.TEST_DATA.test_ten.file_to_upload) assert (response.status_code == 409) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_ten(self): """ Verify that an error is returned while trying to upload a duplicate file on different servers """ self.test_name = self.test_ten.__doc__ try: txn.test_configs.API_SERVER_URL = self.servers[0] response = txn.upload_a_file( config.TEST_DATA.milestone_1b.file__to_upload_3) assert (response.status_code == 200) txn.test_configs.API_SERVER_URL = self.servers[1] response = txn.upload_a_file( config.TEST_DATA.milestone_1b.file__to_upload_3) assert (response.status_code == 409) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_four(self): """ Verify redundancy - Have a known configuration of node count , chunk size and redunduncy level - Load a sequence of files with specific sizes - Delete number of nodes as redunduncy specification - Check if the files can be retrived """ self.test_name = self.test_four.__doc__ try: app_config = json.load( open(config.TEST_DATA.milestone_3.app_config_location)) node_count = app_config['node_count'] size_per_slice = app_config['size_per_slice'] redunduncy_count = app_config['redundancy_count'] print("\nVerifying Pre-Requisites for the Test") assert (node_count == 10) assert (size_per_slice == 1024) assert (redunduncy_count == 1) print("\nSuccessfully verified Pre-Requisites for the test") #Load 10KB file md5 = FileHash('sha1') input_checksum = md5.hash_file( config.TEST_DATA.milestone_3.file_1_path) rs = txn.upload_a_file(config.TEST_DATA.milestone_3.file_1_path) assert (rs.status_code == 200) file_id = str(rs.text) nodes = [] for items in os.listdir( config.TEST_DATA.milestone_3.location_of_nodes): if (os.path.isdir( config.TEST_DATA.milestone_3.location_of_nodes + '/' + items) and 'node_' in items): nodes.append(items) # delete a node #shutil.rmtree( os.path.join( config.TEST_DATA.milestone_3.location_of_nodes , nodes[0]) ) #rename a file os.rename( os.path.join(config.TEST_DATA.milestone_3.location_of_nodes, nodes[0]), os.path.join(config.TEST_DATA.milestone_3.location_of_nodes, 'XYZQBC')) # try getting the file back rs = txn.retrive_a_file_by_id(file_id) assert (rs.status_code == 200) open('Output.file', 'wb+').write(rs.content) output_checksum = md5.hash_file('Output.file') assert input_checksum, output_checksum self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_three(self): """ Verify that the a file can be uploaded successfully """ self.test_name = self.test_three.__doc__ try: response = txn.upload_a_file( config.TEST_DATA.test_three.file_to_upload) assert (response.status_code == 200) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_Upload(self): """ Verify that Upload of a file works fine """ self.test_name = self.test_Upload.__doc__ try: upload_response = txn.upload_a_file( config.TEST_DATA.sanity_test.file_to_upload) # , "status code 200 was expected , recieved {0}".format(upload_response.status_code)) assert (upload_response.status_code in [200, 201]) os.environ['sanity_file_name'] = upload_response.text self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_twelve(self): """ Verify that 404 is returned while trying to delete a file that does not exist """ self.test_name = self.test_twelve.__doc__ try: response = txn.upload_a_file( config.TEST_DATA.test_twelve.file_to_upload) assert (response.status_code == 200) id = response.text response = txn.delete_a_file_by_id(id) assert (response.status_code == 200) response = txn.delete_a_file_by_id(id) assert (response.status_code == 404) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_twelve(self): """ Verify that 404 is returned when deleting a file that was already deleted on another server """ self.test_name = self.test_twelve.__doc__ try: txn.test_configs.API_SERVER_URL = self.servers[1] response = txn.upload_a_file( config.TEST_DATA.milestone_1b.file_to_upload_4) assert (response.status_code == 200) id = response.text response = txn.delete_a_file_by_id(id) assert (response.status_code == 200) txn.test_configs.API_SERVER_URL = self.servers[0] response = txn.delete_a_file_by_id(id) assert (response.status_code == 404) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_four(self): """ Verify that the uploaded file can be reterived sucessfully - Verify check sum before upload and after reterive """ self.test_name = self.test_four.__doc__ try: md5 = FileHash('sha1') hash = md5.hash_file(config.TEST_DATA.test_four.file_to_upload) response = txn.upload_a_file( config.TEST_DATA.test_four.file_to_upload) assert (response.status_code == 200) id = response.text r = txn.retrive_a_file_by_id(id) open(config.TEST_DATA.test_four.file_name, 'wb+').write(r.content) hash_2 = md5.hash_file(config.TEST_DATA.test_four.file_name) assert (hash == hash_2) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_eleven(self): """ Verify that files of various names are accepted during upload """ self.test_name = self.test_eleven.__doc__ try: file_names = list(config.TEST_DATA.test_eleven.file_names) for items in file_names: open("Test/TestData/" + items, 'w+') upload_stat = txn.upload_a_file("Test/TestData/" + items) assert (upload_stat.status_code == 200) list_of_files = txn.list_available_files().json() file_names_Actual = [] for files in list_of_files: file_names_Actual.append(files['file_name']) assert (txn.is_slice_in_list(file_names, file_names_Actual), True) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_six(self): """ Verify that a delete operation happens successfully """ self.test_name = self.test_six.__doc__ try: response = txn.upload_a_file( config.TEST_DATA.test_five.file_to_upload) assert (response.status_code == 200) id = response.text r = txn.retrive_a_file_by_id(id) assert (r.status_code == 200) delete = txn.delete_a_file_by_id(id) assert (delete.status_code == 200) r = txn.retrive_a_file_by_id(id) assert (r.status_code == 404) list_of_files = txn.list_available_files().json() assert (str(id) not in str(list_of_files)) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e
def test_four(self): """ Verify that a file uploaded to a server can be retrieved from another server with integrity """ self.test_name = self.test_four.__doc__ try: txn.test_configs.API_SERVER_URL = self.servers[1] md5 = FileHash('sha1') hash = md5.hash_file( config.TEST_DATA.milestone_1b.file_to_upload_1) response = txn.upload_a_file( config.TEST_DATA.milestone_1b.file_to_upload_1) assert (response.status_code == 200) id = response.text txn.test_configs.API_SERVER_URL = self.servers[0] r = txn.retrive_a_file_by_id(id) open(config.TEST_DATA.milestone_1b.file_name_1, 'wb+').write(r.content) hash_2 = md5.hash_file(config.TEST_DATA.milestone_1b.file_name_1) assert (hash == hash_2) self.status = 'Pass' except Exception as e: self.status = 'Fail' raise e