Ejemplo n.º 1
0
    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"})
Ejemplo n.º 2
0
    def test_serve_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'],
                    'file_buffer_size': 262144
                }):
            fnd = {'rel': 'testfile', 'path': 'testfile'}

            tmp_load = LOAD.copy()
            tmp_load['loc'] = 0
            tmp_load['path'] = 'testfile'

            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':
                    'testfile'
                }, ret)
Ejemplo n.º 3
0
    def test_serve_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'],
                                         'file_buffer_size': 262144}):
            fnd = {'rel': 'testfile',
                   'path': 'testfile'}

            tmp_load = load
            tmp_load['loc'] = 0

            ret = gitfs.serve_file(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': 'testfile'}, ret)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)