Beispiel #1
0
    def test_update_mtime(self):
        self.mount()
        try:
            stat_a_src = os.stat('source/a/b/c')
            stat_a_dst = os.stat('mnt/b/c')

            stat_a_dst_dir = os.stat('mnt/b')

            self.assertEqual(stat_a_src.st_mtime, stat_a_dst.st_mtime)
            self.assertEqual(stat_a_src.st_mtime, stat_a_dst_dir.st_mtime)

            # Make sure enough time passes for timestamps to change.
            time.sleep(1)

            os.utime('source/a/b/c', None)

            # Wait for dest file mtime to change:
            sleep_until(lambda:
                        (os.stat('mnt/b/c').st_mtime != stat_a_dst.st_mtime))

            stat_b_src = os.stat('source/a/b/c')
            stat_b_dst = os.stat('mnt/b/c')

            stat_b_dst_dir = os.stat('mnt/b')

            self.assertEqual(stat_b_src.st_mtime, stat_b_dst.st_mtime)
            self.assertEqual(stat_b_src.st_mtime, stat_b_dst_dir.st_mtime)

            assert stat_a_src.st_mtime < stat_b_src.st_mtime
            assert stat_a_dst.st_mtime < stat_b_dst.st_mtime
        finally:
            self.umount()
        self.clean_up()
Beispiel #2
0
    def test_update_mode(self):
        self.mount()
        try:
            stat_a_src = os.stat('source/a/b/c')
            stat_a_dst = os.stat('mnt/b/c')

            mode_a_src = stat.S_IMODE(stat_a_src.st_mode)
            mode_a_dst = stat.S_IMODE(stat_a_dst.st_mode)

            self.assertEqual(mode_a_src, 0644)
            self.assertEqual(mode_a_dst, 0644)

            new_mode = (mode_a_src & 0000) | 0600

            os.chmod('source/a/b/c', new_mode)

            # Wait for dest file mode to change:
            sleep_until(lambda: (stat.S_IMODE(os.stat('mnt/b/c').st_mode) !=
                                 mode_a_dst))

            stat_b_src = os.stat('source/a/b/c')
            stat_b_dst = os.stat('mnt/b/c')

            mode_b_src = stat.S_IMODE(stat_b_src.st_mode)
            mode_b_dst = stat.S_IMODE(stat_b_dst.st_mode)

            self.assertEqual(mode_b_src, 0600)
            self.assertEqual(mode_b_dst, 0600)
        finally:
            self.umount()
        self.clean_up()
Beispiel #3
0
    def test_update_mode(self):
        self.mount()
        try:
            stat_a_src = os.stat('source/a/b/c')
            stat_a_dst = os.stat('mnt/b/c')

            mode_a_src = stat.S_IMODE(stat_a_src.st_mode)
            mode_a_dst = stat.S_IMODE(stat_a_dst.st_mode)

            self.assertEqual(mode_a_src, 0644)
            self.assertEqual(mode_a_dst, 0644)

            new_mode = (mode_a_src & 0000) | 0600

            os.chmod('source/a/b/c', new_mode)

            # Wait for dest file mode to change:
            sleep_until(lambda: (
              stat.S_IMODE(os.stat('mnt/b/c').st_mode) != mode_a_dst
            ))

            stat_b_src = os.stat('source/a/b/c')
            stat_b_dst = os.stat('mnt/b/c')

            mode_b_src = stat.S_IMODE(stat_b_src.st_mode)
            mode_b_dst = stat.S_IMODE(stat_b_dst.st_mode)

            self.assertEqual(mode_b_src, 0600)
            self.assertEqual(mode_b_dst, 0600)
        finally:
            self.umount()
        self.clean_up()
Beispiel #4
0
    def umount(self):
        # FIXME: If umount cannot be completed, we should probably send SIGKILL
        # to the filesystem process and make sure the umount succeeds after
        # that.  Otherwise, filesystem processes can persist uncleanly.

        try:
            # Filesystem process should still be running.
            self.assertTrue(self.filesystem_process.isRunning())

            # Check that mnt is accessible:
            os.stat('mnt')

            # Check for spurious tracebacks:
            self.assertFileDoesNotContain('logfile', 'Traceback')

        finally:
            try:
                self.sh.execute(UMOUNT_COMMAND % '"${PWD}/mnt"')
            except CommandFailed:
                for i in range(UMOUNT_RETRY_COUNT):
                    e = None
                    time.sleep(UMOUNT_RETRY_DELAY)
                    try:
                        self.sh.execute(UMOUNT_COMMAND % '"${PWD}/mnt"')
                    except CommandFailed, e:
                        pass
                    else:
                        break
                if e is not None:
                    raise

            sleep_until(lambda: (not self.filesystem_process.isRunning()))
            self.assertEqual(self.filesystem_process.getExitStatus(), 0)
            self.assertEqual(self.filesystem_process.getExitSignal(), None)
Beispiel #5
0
    def test_update_mtime(self):
        self.mount()
        try:
            stat_a_src = os.stat('source/a/b/c')
            stat_a_dst = os.stat('mnt/b/c')

            stat_a_dst_dir = os.stat('mnt/b')

            self.assertEqual(stat_a_src.st_mtime, stat_a_dst.st_mtime)
            self.assertEqual(stat_a_src.st_mtime, stat_a_dst_dir.st_mtime)

            # Make sure enough time passes for timestamps to change.
            time.sleep(1)

            os.utime('source/a/b/c', None)

            # Wait for dest file mtime to change:
            sleep_until(lambda: (
              os.stat('mnt/b/c').st_mtime != stat_a_dst.st_mtime
            ))

            stat_b_src = os.stat('source/a/b/c')
            stat_b_dst = os.stat('mnt/b/c')

            stat_b_dst_dir = os.stat('mnt/b')

            self.assertEqual(stat_b_src.st_mtime, stat_b_dst.st_mtime)
            self.assertEqual(stat_b_src.st_mtime, stat_b_dst_dir.st_mtime)

            assert stat_a_src.st_mtime < stat_b_src.st_mtime
            assert stat_a_dst.st_mtime < stat_b_dst.st_mtime
        finally:
            self.umount()
        self.clean_up()
Beispiel #6
0
    def test_add_empty_file(self):
        self.mount()
        try:
            self.sh.execute('touch source/a/b/d')

            sleep_until(lambda: (os.path.exists('mnt/d')))

            self.assertFileExists('mnt/d')
        finally:
            self.umount()
        self.clean_up()
Beispiel #7
0
    def test_remove_file(self):
        self.mount()
        try:
            os.unlink(self.p('source/foo.ext'))

            sleep_until(lambda:
                        (not os.path.exists(self.p('mnt/bar - baz.ext'))))

            self.assertEqual(os.listdir('mnt'), ['.log'])
        finally:
            self.umount()
        self.clean_up()
Beispiel #8
0
    def test_remove_file(self):
        self.mount()
        try:
            os.unlink(self.p('source/foo.ext'))

            sleep_until(lambda: (
              not os.path.exists(self.p('mnt/bar - baz.ext'))
            ))

            self.assertEqual(os.listdir('mnt'), ['.log'])
        finally:
            self.umount()
        self.clean_up()
Beispiel #9
0
    def test_add_empty_file(self):
        self.mount()
        try:
            self.sh.execute('touch source/a/b/d')

            sleep_until(lambda: (
              os.path.exists('mnt/d')
            ))

            self.assertFileExists('mnt/d')
        finally:
            self.umount()
        self.clean_up()
Beispiel #10
0
    def test_simple_rename(self):
        self.mount()
        try:
            os.makedirs('source/m/n')
            os.rename('source/a/b/c', 'source/m/n/o')

            sleep_until(lambda: (os.path.exists('mnt/n/o')))

            self.assertFileDoesNotExist('mnt/b/c')
            self.assertFileExists('mnt/n/o')
        finally:
            self.umount()
        self.clean_up()
Beispiel #11
0
    def test_simple_rename(self):
        self.mount()
        try:
            os.makedirs('source/m/n')
            os.rename('source/a/b/c', 'source/m/n/o')

            sleep_until(lambda: (
              os.path.exists('mnt/n/o')
            ))

            self.assertFileDoesNotExist('mnt/b/c')
            self.assertFileExists('mnt/n/o')
        finally:
            self.umount()
        self.clean_up()
Beispiel #12
0
    def test_tag_change_causing_path_change(self):
        self.mount()
        try:
            self.set_tag(self.p('source/foo.ext'), 'artist', self.p('qux'))

            sleep_until(lambda: (os.path.exists(self.p('mnt/qux - baz.ext'))))

            self.assertEqual(
                self.get_tag(self.p('mnt/qux - baz.ext'), 'artist'),
                [self.p('qux')],
            )
            self.assertFilesHaveSameAudioContent(self.data_file,
                                                 self.p('mnt/qux - baz.ext'))
        finally:
            self.umount()
        self.clean_up()
Beispiel #13
0
    def test_tag_change_causing_path_change(self):
        self.mount()
        try:
            self.set_tag(self.p('source/foo.ext'), 'artist', self.p('qux'))

            sleep_until(lambda: (
              os.path.exists(self.p('mnt/qux - baz.ext'))
            ))

            self.assertEqual(
              self.get_tag(self.p('mnt/qux - baz.ext'), 'artist'),
              [self.p('qux')],
            )
            self.assertFilesHaveSameAudioContent(
              self.data_file, self.p('mnt/qux - baz.ext'))
        finally:
            self.umount()
        self.clean_up()
Beispiel #14
0
    def test_update_file_contents(self):
        self.mount()
        try:
            content = 'foo\n'

            orig_mtime = os.stat('mnt/b/c').st_mtime

            f = open('source/a/b/c', 'w')
            try:
                f.write(content)
            finally:
                f.close()

            sleep_until(lambda: (os.stat('mnt/b/c').st_mtime != orig_mtime))

            self.assertFileContent('mnt/b/c', content)
        finally:
            self.umount()
        self.clean_up()
Beispiel #15
0
    def test_update_file_contents(self):
        self.mount()
        try:
            content = 'foo\n'

            orig_mtime = os.stat('mnt/b/c').st_mtime

            f = open('source/a/b/c', 'w')
            try:
                f.write(content)
            finally:
                f.close()

            sleep_until(lambda: (
              os.stat('mnt/b/c').st_mtime != orig_mtime
            ))

            self.assertFileContent('mnt/b/c', content)
        finally:
            self.umount()
        self.clean_up()
Beispiel #16
0
    def mount(self):
        args = [PYTHON_EXECUTABLE, PYTAGSFS_EXECUTABLE]
        args.extend(self.get_options())

        mount_cmd = shinterp.interpolate(' '.join(len(args) * '?'), *args)
        self.sh.execute('mount_cmd=?', mount_cmd)
        self.sh.execute('echo "${mount_cmd}" >mount_cmd')

        self.filesystem_process = BackgroundCommand(
            PYTHON_EXECUTABLE,
            args,
            stderr='logfile',
            stdout='logfile',
        )
        self.filesystem_process.run()

        sleep_until(lambda: (os.path.exists('mnt/.log')))

        self.assertTrue(self.filesystem_process.isRunning())

        # Check that mnt is accessible:
        os.stat('mnt')
Beispiel #17
0
    def mount(self):
        args = [PYTHON_EXECUTABLE, PYTAGSFS_EXECUTABLE]
        args.extend(self.get_options())

        mount_cmd = shinterp.interpolate(' '.join(len(args) * '?'), *args)
        self.sh.execute('mount_cmd=?', mount_cmd)
        self.sh.execute('echo "${mount_cmd}" >mount_cmd')

        self.filesystem_process = BackgroundCommand(
          PYTHON_EXECUTABLE,
          args,
          stderr = 'logfile',
          stdout = 'logfile',
        )
        self.filesystem_process.run()

        sleep_until(lambda: (
          os.path.exists('mnt/.log')
        ))

        self.assertTrue(self.filesystem_process.isRunning())

        # Check that mnt is accessible:
        os.stat('mnt')
Beispiel #18
0
    def umount(self):
        # FIXME: If umount cannot be completed, we should probably send SIGKILL
        # to the filesystem process and make sure the umount succeeds after
        # that.  Otherwise, filesystem processes can persist uncleanly.

        try:
            # Filesystem process should still be running.
            self.assertTrue(self.filesystem_process.isRunning())

            # Check that mnt is accessible:
            os.stat('mnt')

            # Check for spurious tracebacks:
            self.assertFileDoesNotContain('logfile', 'Traceback')

        finally:
            try:
                self.sh.execute(UMOUNT_COMMAND % '"${PWD}/mnt"')
            except CommandFailed:
                for i in range(UMOUNT_RETRY_COUNT):
                    e = None
                    time.sleep(UMOUNT_RETRY_DELAY)
                    try:
                        self.sh.execute(UMOUNT_COMMAND % '"${PWD}/mnt"')
                    except CommandFailed, e:
                        pass
                    else:
                        break
                if e is not None:
                    raise

            sleep_until(lambda: (
              not self.filesystem_process.isRunning()
            ))
            self.assertEqual(self.filesystem_process.getExitStatus(), 0)
            self.assertEqual(self.filesystem_process.getExitSignal(), None)