swift/test/unit/cli/test_recon_cron.py
kim woo seok bd5076ebe6 Fix repeated unnecessarily 'os.makedirs()' in test_recon_cron.py
Return value instead of sys.exit() if an exception occurs

RelatedChange: I4ca91e3b519a99f3096b95b286779a183e936eb7
Change-Id: I9ebbf5b9f4216c3eab5ab42a0014a750ca28980b
2023-09-23 23:32:09 +09:00

51 lines
1.6 KiB
Python

# Copyright (c) 2010-2022 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tempfile
import shutil
import os
from unittest import TestCase
from swift.cli.recon_cron import get_async_count
from swift.obj.diskfile import ASYNCDIR_BASE
class TestReconCron(TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_get_async_count(self):
device_dir = os.path.join(self.temp_dir, 'device')
device_index = os.path.join(device_dir, '1')
async_dir = os.path.join(device_index, ASYNCDIR_BASE)
entry1 = os.path.join(async_dir, 'entry1')
entry2 = os.path.join(async_dir, 'entry2')
os.makedirs(entry1)
os.makedirs(entry2)
pending_file1 = os.path.join(entry1, 'pending_file1')
pending_file2 = os.path.join(entry1, 'pending_file2')
pending_file3 = os.path.join(entry2, 'pending_file3')
open(pending_file1, 'w').close()
open(pending_file2, 'w').close()
open(pending_file3, 'w').close()
count = get_async_count(device_dir)
self.assertEqual(count, 3)