def test_file_hash_sha1(self): ''' NOTE: This test requires that gitfs.find_file is executed to ensure that the file exists in the gitfs cache. ''' target = 'testfile' with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir']}): # This needs to be in its own patch because we are using a # different hash_type for this test (sha1) from the one the master # is using (md5), which will cause the find_file to fail when the # repo URI is hashed to determine the cachedir. gitfs.find_file(target) with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'], 'hash_type': 'sha1'}): tmp_load = copy.deepcopy(LOAD) tmp_load['loc'] = 0 tmp_load['path'] = target fnd = {'rel': target, 'path': os.path.join(gitfs.__opts__['cachedir'], 'gitfs/refs', tmp_load['saltenv'], tmp_load['path'])} ret = gitfs.file_hash(tmp_load, fnd) self.assertDictEqual( {'hash_type': 'sha1', 'hsum': '6b18d04b61238ba13b5e4626b13ac5fb7432b5e2'}, ret)
def test_find_and_serve_file_fallback(self): with patch.dict( gitfs.__opts__, {"file_buffer_size": 262144, "gitfs_fallback": "master"} ): gitfs.update() # find_file ret = gitfs.find_file("testfile", tgt_env="notexisting") self.assertEqual("testfile", ret["rel"]) full_path_to_file = salt.utils.path.join( gitfs.__opts__["cachedir"], "gitfs", "refs", "notexisting", "testfile" ) self.assertEqual(full_path_to_file, ret["path"]) # serve_file load = {"saltenv": "notexisting", "path": full_path_to_file, "loc": 0} fnd = {"path": full_path_to_file, "rel": "testfile"} ret = gitfs.serve_file(load, fnd) with salt.utils.files.fopen( os.path.join(RUNTIME_VARS.BASE_FILES, "testfile"), "r" ) as fp_: # NB: Why not 'rb'? data = fp_.read() self.assertDictEqual(ret, {"data": data, "dest": "testfile"})
def test_serve_file(self): ''' NOTE: This test requires that gitfs.find_file is executed to ensure that the file exists in the gitfs cache. ''' target = 'testfile' with patch.dict( gitfs.__opts__, { 'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'], 'file_buffer_size': 262144 }): tmp_load = copy.deepcopy(LOAD) tmp_load['loc'] = 0 tmp_load['path'] = target fnd = { 'rel': target, 'path': os.path.join(gitfs.__opts__['cachedir'], 'gitfs/refs', tmp_load['saltenv'], tmp_load['path']) } gitfs.find_file(tmp_load['path']) ret = gitfs.serve_file(tmp_load, fnd) self.assertDictEqual( { 'data': 'Scene 24\n\n \n OLD MAN: Ah, hee he he ha!\n ' 'ARTHUR: And this enchanter of whom you speak, he ' 'has seen the grail?\n OLD MAN: Ha ha he he he ' 'he!\n ARTHUR: Where does he live? Old man, where ' 'does he live?\n OLD MAN: He knows of a cave, a ' 'cave which no man has entered.\n ARTHUR: And the ' 'Grail... The Grail is there?\n OLD MAN: Very much ' 'danger, for beyond the cave lies the Gorge\n of ' 'Eternal Peril, which no man has ever crossed.\n ' 'ARTHUR: But the Grail! Where is the Grail!?\n OLD ' 'MAN: Seek you the Bridge of Death.\n ARTHUR: The ' 'Bridge of Death, which leads to the Grail?\n OLD ' 'MAN: Hee hee ha ha!\n\n', 'dest': target }, ret)
def test_find_file(self): with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_git], 'sock_dir': self.master_opts['sock_dir']}): ret = gitfs.find_file('testfile') expected_ret = {'path': '/tmp/salttest/cache/gitfs/refs/master/testfile', 'rel': 'testfile'} self.assertDictEqual(ret, expected_ret)
def test_file_hash_sha1(self): ''' NOTE: This test requires that gitfs.find_file is executed to ensure that the file exists in the gitfs cache. ''' target = 'testfile' with patch.dict( gitfs.__opts__, { 'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'] }): # This needs to be in its own patch because we are using a # different hash_type for this test (sha1) from the one the master # is using (md5), which will cause the find_file to fail when the # repo URI is hashed to determine the cachedir. gitfs.find_file(target) with patch.dict( gitfs.__opts__, { 'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'], 'hash_type': 'sha1' }): tmp_load = copy.deepcopy(LOAD) tmp_load['loc'] = 0 tmp_load['path'] = target fnd = { 'rel': target, 'path': os.path.join(gitfs.__opts__['cachedir'], 'gitfs/refs', tmp_load['saltenv'], tmp_load['path']) } ret = gitfs.file_hash(tmp_load, fnd) self.assertDictEqual( { 'hash_type': 'sha1', 'hsum': '6b18d04b61238ba13b5e4626b13ac5fb7432b5e2' }, ret)
def test_find_file(self): with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir']}): path = os.path.join(self.master_opts['cachedir'], 'gitfs/refs', LOAD['saltenv'], 'testfile') ret = gitfs.find_file('testfile') expected_ret = {'path': path, 'rel': 'testfile'} self.assertDictEqual(ret, expected_ret)
def test_find_file(self): with patch.dict( gitfs.__opts__, { 'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'] }): path = os.path.join(self.master_opts['cachedir'], 'gitfs/refs', LOAD['saltenv'], 'testfile') ret = gitfs.find_file('testfile') expected_ret = {'path': path, 'rel': 'testfile'} self.assertDictEqual(ret, expected_ret)
def test_serve_file(self): ''' NOTE: This test requires that gitfs.find_file is executed to ensure that the file exists in the gitfs cache. ''' target = 'testfile' with patch.dict(gitfs.__opts__, {'cachedir': self.master_opts['cachedir'], 'gitfs_remotes': ['file://' + self.tmp_repo_dir], 'sock_dir': self.master_opts['sock_dir'], 'file_buffer_size': 262144}): tmp_load = copy.deepcopy(LOAD) tmp_load['loc'] = 0 tmp_load['path'] = target fnd = {'rel': target, 'path': os.path.join(gitfs.__opts__['cachedir'], 'gitfs/refs', tmp_load['saltenv'], tmp_load['path'])} gitfs.find_file(tmp_load['path']) ret = gitfs.serve_file(tmp_load, fnd) self.assertDictEqual({ 'data': 'Scene 24\n\n \n OLD MAN: Ah, hee he he ha!\n ' 'ARTHUR: And this enchanter of whom you speak, he ' 'has seen the grail?\n OLD MAN: Ha ha he he he ' 'he!\n ARTHUR: Where does he live? Old man, where ' 'does he live?\n OLD MAN: He knows of a cave, a ' 'cave which no man has entered.\n ARTHUR: And the ' 'Grail... The Grail is there?\n OLD MAN: Very much ' 'danger, for beyond the cave lies the Gorge\n of ' 'Eternal Peril, which no man has ever crossed.\n ' 'ARTHUR: But the Grail! Where is the Grail!?\n OLD ' 'MAN: Seek you the Bridge of Death.\n ARTHUR: The ' 'Bridge of Death, which leads to the Grail?\n OLD ' 'MAN: Hee hee ha ha!\n\n', 'dest': target}, ret)