Beispiel #1
0
 def test_account_details_cached_miss_mtime(self):
     mc = SimMemcache()
     the_path = "/tmp/bar"
     def mock_get_account_details_from_fs(acc_path, acc_stats):
         mt = 100
         cc = 2
         cl = ['a', 'b']
         return utils.AccountDetails(mt, cc, cl)
     def mock_do_stat(path):
         class MockStat(object):
             def __init__(self, mtime):
                 self.st_mtime = mtime
         return MockStat(100)
     ad = mock_get_account_details_from_fs(the_path, None)
     ad.container_list = ['x', 'y']
     ad.mtime = 200
     mc.set(utils.MEMCACHE_ACCOUNT_DETAILS_KEY_PREFIX + Glusterfs.strip_obj_storage_path(the_path), ad)
     orig_gcdff = utils._get_account_details_from_fs
     orig_ds = utils.do_stat
     utils._get_account_details_from_fs = mock_get_account_details_from_fs
     utils.do_stat = mock_do_stat
     try:
         retval = utils.get_account_details(the_path, memcache=mc)
         correct_ad = mock_get_account_details_from_fs(the_path, None)
         assert retval == (correct_ad.container_list, correct_ad.container_count)
         assert correct_ad != ad
     finally:
         utils._get_account_details_from_fs = orig_gcdff
         utils.do_stat = orig_ds
Beispiel #2
0
    def update_container_count(self):
        containers = []
        container_count = 0

        containers, container_count = get_account_details(self.datadir)

        if int(self.metadata[X_CONTAINER_COUNT]) != container_count:
            self.metadata[X_CONTAINER_COUNT] = container_count
            self.update_account(self.metadata)
Beispiel #3
0
    def update_container_count(self):
        containers = []
        container_count = 0

        containers, container_count = get_account_details(self.datadir)

        if int(self.metadata[X_CONTAINER_COUNT]) != container_count:
            self.metadata[X_CONTAINER_COUNT] = container_count
            self.update_account(self.metadata)
Beispiel #4
0
    def list_containers_iter(self, limit, marker, end_marker, prefix,
                             delimiter):
        """
        Return tuple of name, object_count, bytes_used, 0(is_subdir).
        Used by account server.
        """
        if delimiter and not prefix:
            prefix = ''
        containers = []
        container_count = 0
        account_list = []

        containers, container_count = get_account_details(self.datadir)

        if int(self.metadata[X_CONTAINER_COUNT]) != container_count:
            self.metadata[X_CONTAINER_COUNT] = container_count
            self.update_account(self.metadata)

        if containers:
            containers.sort()

        if containers and prefix:
            containers = self.filter_prefix(containers, prefix)

        if containers and delimiter:
            containers = self.filter_delimiter(containers, delimiter, prefix)

        if containers and marker:
            containers = self.filter_marker(containers, marker)

        if containers and end_marker:
            containers = self.filter_end_marker(containers, end_marker)

        if containers and limit:
            if len(containers) > limit:
                containers = self.filter_limit(containers, limit)

        if containers:
            for cont in containers:
                list_item = []
                metadata = None
                list_item.append(cont)
                metadata = read_metadata(self.datadir + '/' + cont)
                if not metadata or not validate_container(metadata):
                    metadata = create_container_metadata(self.datadir + '/' +
                                                         cont)

                if metadata:
                    list_item.append(metadata[X_OBJECTS_COUNT])
                    list_item.append(metadata[X_BYTES_USED])
                    list_item.append(0)
                account_list.append(list_item)

        return account_list
Beispiel #5
0
    def list_containers_iter(self, limit, marker, end_marker,
                             prefix, delimiter):
        """
        Return tuple of name, object_count, bytes_used, 0(is_subdir).
        Used by account server.
        """
        if delimiter and not prefix:
            prefix = ''
        containers = []
        container_count = 0
        account_list = []

        containers, container_count = get_account_details(self.datadir)

        if int(self.metadata[X_CONTAINER_COUNT][0]) != container_count:
            self.metadata[X_CONTAINER_COUNT] = (container_count, 0)
            self.update_account(self.metadata)

        if containers:
            containers.sort()

        if containers and prefix:
            containers = self.filter_prefix(containers, prefix)

        if containers and delimiter:
            containers = self.filter_delimiter(containers, delimiter, prefix)

        if containers and marker:
            containers = self.filter_marker(containers, marker)

        if containers and end_marker:
            containers = self.filter_end_marker(containers, end_marker)

        if containers and limit:
            if len(containers) > limit:
                containers = self.filter_limit(containers, limit)

        if containers:
            for cont in containers:
                list_item = []
                metadata = None
                list_item.append(cont)
                cont_path = os.path.join(self.datadir, cont)
                metadata = _read_metadata(cont_path)
                if not metadata or not validate_container(metadata):
                    metadata = create_container_metadata(cont_path)

                if metadata:
                    list_item.append(metadata[X_OBJECTS_COUNT][0])
                    list_item.append(metadata[X_BYTES_USED][0])
                    list_item.append(0)
                account_list.append(list_item)

        return account_list
Beispiel #6
0
 def test_account_details_uncached(self):
     the_path = "/tmp/bar"
     def mock_get_account_details_from_fs(acc_path, acc_stats):
         mt = 100
         cc = 2
         cl = ['a', 'b']
         return utils.AccountDetails(mt, cc, cl)
     orig_gcdff = utils._get_account_details_from_fs
     utils._get_account_details_from_fs = mock_get_account_details_from_fs
     try:
         retval = utils.get_account_details(the_path)
         ad = mock_get_account_details_from_fs(the_path, None)
         assert retval == (ad.container_list, ad.container_count)
     finally:
         utils._get_account_details_from_fs = orig_gcdff