chore: update volume access_mode to fit compose-spec

This commit is contained in:
Xyphuz 2022-05-24 17:06:31 +08:00
parent 2c692f3ab3
commit 81324f7f14
5 changed files with 11 additions and 22 deletions

View file

@ -6,7 +6,7 @@ from ruamel.yaml import YAML
from compose_viz.compose import Compose, Service
from compose_viz.extends import Extends
from compose_viz.port import Port, Protocol
from compose_viz.volume import AccessMode, Volume, VolumeType
from compose_viz.volume import Volume, VolumeType
class Parser:
@ -190,9 +190,7 @@ class Parser:
service_volumes.append(Volume(source=spilt_data[0], target=spilt_data[1]))
elif len(spilt_data) == 3:
service_volumes.append(
Volume(
source=spilt_data[0], target=spilt_data[1], access_mode=AccessMode[spilt_data[2]]
)
Volume(source=spilt_data[0], target=spilt_data[1], access_mode=spilt_data[2])
)
service_links: List[str] = []

View file

@ -8,17 +8,8 @@ class VolumeType(str, Enum):
npipe = "npipe"
class AccessMode(str, Enum):
rw = "rw"
ro = "ro"
z = "z"
Z = "Z"
class Volume:
def __init__(
self, source: str, target: str, type: VolumeType = VolumeType.volume, access_mode: AccessMode = AccessMode.rw
):
def __init__(self, source: str, target: str, type: VolumeType = VolumeType.volume, access_mode: str = "rw"):
self._source = source
self._target = target
self._type = type

View file

@ -5,7 +5,7 @@ from compose_viz.extends import Extends
from compose_viz.parser import Parser
from compose_viz.port import Port, Protocol
from compose_viz.service import Service
from compose_viz.volume import AccessMode, Volume, VolumeType
from compose_viz.volume import Volume, VolumeType
@pytest.mark.parametrize(
@ -219,7 +219,7 @@ from compose_viz.volume import AccessMode, Volume, VolumeType
Volume(
source="cli-volume",
target="/var/lib/backup/data",
access_mode=AccessMode.ro,
access_mode="ro,z",
),
],
),

View file

@ -1,4 +1,4 @@
from compose_viz.volume import AccessMode, Volume, VolumeType
from compose_viz.volume import Volume, VolumeType
def test_volume_init_normal() -> None:
@ -8,7 +8,7 @@ def test_volume_init_normal() -> None:
assert v.source == "./foo"
assert v.target == "./bar"
assert v.type == VolumeType.volume
assert v.access_mode == AccessMode.rw
assert v.access_mode == "rw"
except Exception as e:
assert False, e
@ -20,18 +20,18 @@ def test_volume_with_type() -> None:
assert v.source == "./foo"
assert v.target == "./bar"
assert v.type == VolumeType.bind
assert v.access_mode == AccessMode.rw
assert v.access_mode == "rw"
except Exception as e:
assert False, e
def test_volume_with_access_mode() -> None:
try:
v = Volume(source="./foo", target="./bar", access_mode=AccessMode.ro)
v = Volume(source="./foo", target="./bar", access_mode="ro,z")
assert v.source == "./foo"
assert v.target == "./bar"
assert v.type == VolumeType.volume
assert v.access_mode == AccessMode.ro
assert v.access_mode == "ro,z"
except Exception as e:
assert False, e

View file

@ -11,7 +11,7 @@ services:
common:
image: busybox
volumes:
- common-volume:/var/lib/backup/data:rw
- common-volume:/var/lib/backup/data:rw,z
cli:
extends:
service: common