openstack cached image [ list | queue | delete | clear ] functional test 진행
링크: https://review.opendev.org/c/openstack/python-openstackclient/+/958937
- 커밋메시지
image: add functional tests for cache commands
Add functional tests for the following commands:
- cached image list
- cached image queue
- cached image delete
- cached image clear
Change-Id: I29aa18bee18117f6ae926af8c26a05a37b77e2ec
Signed-off-by: jja6312 <jja6312@naver.com>
-
코드
-
멘토님께서 말씀하신 신경 쓸 부분
-
setup 함수 하나로 묶음 + 전체테스트를 하나의 함수로 구성.
-
함수명을 CRUD제외한 test_{기여항목}으로 작성. (주석으로 각 기능 명시)
-
기존 CRUD 테스트 함수가 있다면 refactoring 한 패치셋을 올려야하나, cached_image 테스트 파일 자체가 없었음.
-
disable/enable 가능한
service,agent와 같은 객체는 Get, List, Show의 테스트만 작성해야함을 인지. -
참고 레퍼런스
-
-
# 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 time
import uuid
import fixtures
from openstackclient.tests.functional.image import base
class TestCachedImage(base.BaseImageTests):
"""Functional tests for Image cache commands"""
def setUp(self):
super().setUp()
ver_fixture = fixtures.EnvironmentVariable('OS_IMAGE_API_VERSION', '2')
self.useFixture(ver_fixture)
# create test images
self.image_name1 = f"test-cache-{uuid.uuid4().hex}"
self.image_name2 = f"test-cache-{uuid.uuid4().hex}"
output1 = self.openstack(
f'image create {self.image_name1}',
parse_output=True,
)
self.image_id1 = output1["id"]
self.assertEqual(self.image_name1, output1["name"])
self.addCleanup(self.openstack, f'image delete {self.image_name1}')
output2 = self.openstack(
f'image create {self.image_name2}',
parse_output=True,
)
self.image_id2 = output2["id"]
self.assertEqual(self.image_name2, output2["name"])
self.addCleanup(self.openstack, f'image delete {self.image_name2}')
def test_cached_image(self):
"""Test all image cache operations in a single test method"""
# list cache
cache_output = self.openstack('cached image list', parse_output=True)
self.assertIsInstance(cache_output, list)
# queue images for caching
self.openstack(f'cached image queue {self.image_id1}')
self.openstack(f'cached image queue {self.image_id2}')
# list cache
cache_output = self.openstack('cached image list', parse_output=True)
self.assertIsInstance(cache_output, list)
# delete image from cache
self.openstack(f'cached image delete {self.image_id1}')
# clear cache
self.openstack('cached image clear --queue')
self.openstack('cached image clear --cache')
self.openstack('cached image clear')
# list cache
final_cache = self.openstack('cached image list', parse_output=True)
self.assertIsInstance(final_cache, list)