4주차 과제 (2) - 호세헌

필수 과제

이번 3주차 과제는 아직 미구현된 functional test를 구현하는게 과제입니다.

이미 많이 쓰이고 있는 CLI지만 아직 functional test가 없는게 많습니다!

[필수 과제]

  1. 아래 게시글 참고하여 functional test를 구현할 openstack cli 선택하기 ( 본문에 이름 없으신분들은 댓글로 어떤 CLI 할지 댓글 남겨주세요)

  2. CLI 사용법 정리 하기 ( 먼저 진행 )

  3. CLI에 대한 functional test 코드 구현하기 ( 추후에 공지 후 진행 )

Functional Test 작성 (volume host set)

대상

  • openstack volume host set [--enable | --disable] <host-name>

  • 테스트 파일: openstackclient/tests/functional/volume/v3/test_volume_host.py

openstack volume host set
    [--enable | --disable]
    <host-name>

1. Cinder 서비스 작동 확인

stack@hsh-devstack:~/devstack$ openstack volume service list --long | grep cinder-volume

| cinder-volume    | hsh-devstack@lvmdriver-1 | nova | enabled | up    | 2025-08-16T00:46:37.000000 | None            |

Statusenabled/up이면 정상입니다.

2. devstack 환경

# devstack 인스턴스
sudo su - stack
cd devstack
source /opt/stack/devstack/openrc admin admin

HOST="hsh-devstack@lvmdriver-1"

# 상태 확인
openstack volume service list --long

# 비활성화
openstack volume host set --disable "$HOST"

# 상태 확인
openstack volume service list --long

# 활성화
openstack volume host set --enable "$HOST"

openstack volume service list --long

테스트를 위해 로컬 clouds.yaml 설정

# 로컬 ./.config/clouds.yaml
clouds:
  devstack-admin:
    auth_type: password
    auth:
      auth_url: http://<IP>/identity
      username: admin
      password: <비밀번호>
      project_name: admin
      user_domain_id: default
      project_domain_id: default
    region_name: RegionOne
    interface: public
    identity_api_version: 3

3. Functional Test 코드

# python-openstackclient/openstackclient/tests/functional/volume/v3/test_volume.py
from openstackclient.tests.functional import base

class VolumeHostTests(base.TestCase):
    """Functional tests for volume host set."""
    
    def setUp(self):
        super().setUp()
        rows = self.openstack('volume service list --long', parse_output=True)
        try:
            self.host = next(r['Host'] for r in rows if r.get('Binary') == 'cinder-volume')
        except StopIteration:
            self.skipTest('No cinder-volume service found')

    def volume_host_status(self):
        rows = self.openstack('volume service list --long', parse_output=True)
        row = next(r for r in rows
                   if r.get('Binary') == 'cinder-volume' and r.get('Host') == self.host)
        return (row.get('Status') or '').strip().lower()
        
    # 비활성화 테스트
    def test_disable_sets_status_disabled(self):
        """Test disable volume host."""
        
        self.openstack(f'volume host set --disable {self.host}')
        status = self.volume_host_status()
        self.assertEqual('disabled', status)
    # 활성화 테스트
    def test_enable_sets_status_enabled(self):
        """Test enable volume host."""
        self.openstack(f'volume host set --enable {self.host}')
        status = self.volume_host_status()
        self.assertEqual('enabled', status)

4. Functional Test 실행

tox -e functional -- openstackclient.tests.functional.volume.v3.test_volume_host