Exemplo n.º 1
0
    def test_callback(self):
        called = {'check': False}

        def call(tree):
            LOG.info('In callback: tree has %i files', tree.get_num_files())
            called['check'] = True

        create.create_dirinfo('', 'mc', my_ls, callback=call)
        self.assertTrue(called['check'])
Exemplo n.º 2
0
    def test_olddir(self):
        empty_dir = 'mc/new/empty/0002'
        path = os.path.join(TMP_DIR, empty_dir)
        os.makedirs(path)
        os.utime(path, (1000000000, 1000000000))

        listing = datatypes.DirectoryInfo('/store',
                                          directories=[
                                              create.create_dirinfo(
                                                  '', subdir, my_ls)
                                              for subdir in ['mc', 'data']
                                          ])

        LOG.info('=' * 40)
        LOG.info('Doing the hash')
        LOG.info('=' * 40)

        listing.setup_hash()

        LOG.info('=' * 40)
        LOG.info('Doing the comparison')
        LOG.info('=' * 40)

        LOG.info(listing.displays())
        LOG.info('=' * 40)
        LOG.info(self.listing.displays())

        file_list, dir_list, _ = listing.compare(self.listing)

        self.assertEqual(len(dir_list), 1)
        self.assertTrue(
            os.path.join('/store', empty_dir).startswith(dir_list[0]))

        for file_name, _ in self.file_list:
            self.assertFalse(file_name.startswith(dir_list[0]))
Exemplo n.º 3
0
    def do_more_setup(self):
        for name, size in self.file_list + self.orphan:
            path = os.path.join(TMP_DIR, name[7:])
            if not os.path.isdir(os.path.dirname(path)):
                os.makedirs(os.path.dirname(path))
            out = open(path, 'w')
            out.write('\0' * size)
            out.close()

            os.utime(path, (1000000000, 1000000000))

        self.tree.add_file_list(self.missing)

        for name, size in self.new_file:
            path = os.path.join(TMP_DIR, name[7:])
            if not os.path.isdir(os.path.dirname(path)):
                os.makedirs(os.path.dirname(path))
            out = open(path, 'w')
            out.write('\0' * size)
            out.close()

        self.listing = datatypes.DirectoryInfo(
            '/store',
            directories=[
                create.create_dirinfo('', subdir, my_ls)
                for subdir in ['mc', 'data']
            ])

        self.tree.setup_hash()
        self.listing.setup_hash()
Exemplo n.º 4
0
    def test_ls_vs_list(self):

        dirinfos = [create.create_dirinfo('', subdir, my_ls) \
                        for subdir in ['mc', 'data']]

        master_dirinfo = datatypes.DirectoryInfo('/store',
                                                 directories=dirinfos)

        self.check_equal(self.tree, master_dirinfo)
        self.assertEqual(self.tree.count_nodes(), master_dirinfo.count_nodes())
Exemplo n.º 5
0
    def test_newdir(self):
        empty_dir = 'mc/new/empty/0002'

        os.makedirs(os.path.join(TMP_DIR, empty_dir))

        dirinfos = [create.create_dirinfo('', subdir, my_ls) \
                        for subdir in ['mc', 'data']]

        master_dirinfo = datatypes.DirectoryInfo('/store',
                                                 directories=dirinfos)

        self.check_equal(self.tree, master_dirinfo)
        self.assertFalse(
            master_dirinfo.get_node(os.path.join(empty_dir, 'not_there'),
                                    False))
        self.assertTrue(master_dirinfo.get_node(empty_dir, False))
        self.assertFalse(master_dirinfo.get_node(empty_dir, False).can_compare)