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

**URL:** <https://forum.openinfra-kr.org/t/4-2/226>\
**Category:** 컨트리뷰션\
**Tags:** 2025컨트리뷰션, 컨트리뷰션\
**Created:** [8월 16, 2025, 6:45오전 UTC](https://forum.openinfra-kr.org/t/4-2/226 "2025-08-16T06:45:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seheon](https://forum.openinfra-kr.org/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@seheon](https://forum.openinfra-kr.org/u/seheon)\
**Post date:** [8월 16, 2025, 6:45오전 UTC](https://forum.openinfra-kr.org/t/4-2/226/1 "2025-08-16T06:45:18Z")

</div>

# 필수 과제

> 이번 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`

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

```

### 1. **Cinder 서비스 작동 확인**

```auto
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 |

```

`Status`가 `enabled/up`이면 정상입니다.

### 2. devstack 환경

```bash
# 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

```

 ![1](https://forum.openinfra-kr.org/uploads/default/original/1X/dfe2a8907b84ecf41fcd09e7ae7ca460cfa9ea48.png)

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

```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

```

 ![2](https://forum.openinfra-kr.org/uploads/default/original/1X/d1cdbaa69c9b1846fd4c30dad46ac244307d9abd.png)

### 3. Functional Test 코드

```python
# 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 실행

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

```

 ![3](https://forum.openinfra-kr.org/uploads/default/original/1X/7e7cb0c97b39756d8612852d592999330bece408.png)
