def test_get_account_details_notadir(self): tf = tempfile.NamedTemporaryFile() try: utils.get_account_details(tf.name) except OSError as err: if err.errno != errno.ENOTDIR: self.fail("Expecting ENOTDIR") else: self.fail("Expecting ENOTDIR")
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 + 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
def _update_container_count(self): containers, container_count = get_account_details(self.datadir) if X_CONTAINER_COUNT not in self.metadata or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count: self.metadata[X_CONTAINER_COUNT] = (container_count, 0) write_metadata(self.datadir, self.metadata) return containers
def update_container_count(self): if not self.container_info: self.container_info = get_account_details(self.datadir) containers, container_count = self.container_info if X_CONTAINER_COUNT not in self.metadata or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count: self.metadata[X_CONTAINER_COUNT] = (container_count, 0) write_metadata(self.datadir, self.metadata)
def _update_container_count(self): containers, container_count = get_account_details(self.datadir) if X_CONTAINER_COUNT not in self.metadata \ or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count: self.metadata[X_CONTAINER_COUNT] = (container_count, 0) write_metadata(self.datadir, self.metadata) return containers
def update_container_count(self): if not self.container_info: self.container_info = get_account_details(self.datadir) containers, container_count = self.container_info if X_CONTAINER_COUNT not in self.metadata \ or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count: self.metadata[X_CONTAINER_COUNT] = (container_count, 0) write_metadata(self.datadir, self.metadata)
def test_get_account_details(self): orig_cwd = os.getcwd() td = tempfile.mkdtemp() try: tf = tarfile.open("common/data/account_tree.tar.bz2", "r:bz2") os.chdir(td) tf.extractall() container_list, container_count = utils.get_account_details(td) assert container_count == 3 assert set(container_list) == set(['c1', 'c2', 'c3']) finally: os.chdir(orig_cwd) shutil.rmtree(td)
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
def test_get_account_details_notadir(self): tf = tempfile.NamedTemporaryFile() container_list, container_count = utils.get_account_details(tf.name) assert container_count == 0 assert container_list == []