]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: add tests for service spec extra args handling
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 17 May 2023 18:30:18 +0000 (14:30 -0400)
committerAdam King <adking@redhat.com>
Thu, 31 Aug 2023 17:35:15 +0000 (13:35 -0400)
There were no existing tests for how the service spec(s) handled the
extra_container_args and extra_entrypoint_args values.  Add a short
parametrized test function to assert some basic properties of how the
arguments are currently handled. In particular, it asserts that the
values can appear at the top-level of the YAML and under spec.

This is in preparation for adding a more sophisticated argument
type in the future.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 4561fc37084faa766bd199f052bd2b2a1589269e)

src/python-common/ceph/tests/test_service_spec.py

index a0e0be2aa815be6c84cb67e5b7b588766469829f..8585e65d5bb0434d0d4b4fb8d6707852fa9a3cd3 100644 (file)
@@ -964,3 +964,146 @@ def test_service_spec_validation_error(y, error_match):
     with pytest.raises(SpecValidationError) as err:
         specObj = ServiceSpec.from_json(data)
     assert err.match(error_match)
+
+
+@pytest.mark.parametrize("y, ec_args, ee_args", [
+    pytest.param("""
+service_type: container
+service_id: hello-world
+service_name: container.hello-world
+spec:
+  args:
+  - --foo
+  bind_mounts:
+  - - type=bind
+    - source=lib/modules
+    - destination=/lib/modules
+    - ro=true
+  dirs:
+  - foo
+  - bar
+  entrypoint: /usr/bin/bash
+  envs:
+  - FOO=0815
+  files:
+    bar.conf:
+    - foo
+    - bar
+    foo.conf: 'foo
+
+      bar'
+  gid: 2000
+  image: docker.io/library/hello-world:latest
+  ports:
+  - 8080
+  - 8443
+  uid: 1000
+  volume_mounts:
+    foo: /foo
+""",
+    None,
+    None,
+    id="no_extra_args"),
+    pytest.param("""
+service_type: container
+service_id: hello-world
+service_name: container.hello-world
+spec:
+  args:
+  - --foo
+  extra_entrypoint_args:
+  - "--lasers=blue"
+  - "--enable-confetti"
+  bind_mounts:
+  - - type=bind
+    - source=lib/modules
+    - destination=/lib/modules
+    - ro=true
+  dirs:
+  - foo
+  - bar
+  entrypoint: /usr/bin/bash
+  envs:
+  - FOO=0815
+  files:
+    bar.conf:
+    - foo
+    - bar
+    foo.conf: 'foo
+
+      bar'
+  gid: 2000
+  image: docker.io/library/hello-world:latest
+  ports:
+  - 8080
+  - 8443
+  uid: 1000
+  volume_mounts:
+    foo: /foo
+""",
+    None,
+    ["--lasers=blue", "--enable-confetti"],
+    id="only_extra_entrypoint_args_spec"),
+    pytest.param("""
+service_type: container
+service_id: hello-world
+service_name: container.hello-world
+spec:
+  args:
+  - --foo
+  bind_mounts:
+  - - type=bind
+    - source=lib/modules
+    - destination=/lib/modules
+    - ro=true
+  dirs:
+  - foo
+  - bar
+  entrypoint: /usr/bin/bash
+  envs:
+  - FOO=0815
+  files:
+    bar.conf:
+    - foo
+    - bar
+    foo.conf: 'foo
+
+      bar'
+  gid: 2000
+  image: docker.io/library/hello-world:latest
+  ports:
+  - 8080
+  - 8443
+  uid: 1000
+  volume_mounts:
+    foo: /foo
+extra_entrypoint_args:
+- "--lasers=blue"
+- "--enable-confetti"
+""",
+    None,
+    ["--lasers=blue", "--enable-confetti"],
+    id="only_extra_entrypoint_args_toplevel"),
+    pytest.param("""
+service_type: nfs
+service_id: mynfs
+service_name: nfs.mynfs
+spec:
+  port: 1234
+  extra_entrypoint_args:
+  - "--lasers=blue"
+  - "--title=Custom NFS Options"
+  extra_container_args:
+  - "--cap-add=CAP_NET_BIND_SERVICE"
+  - "--oom-score-adj=12"
+""",
+    ["--cap-add=CAP_NET_BIND_SERVICE", "--oom-score-adj=12"],
+    ["--lasers=blue", "--title=Custom NFS Options"],
+    id="both_kinds_nfs"),
+])
+def test_extra_args_handling(y, ec_args, ee_args):
+    data = yaml.safe_load(y)
+    spec_obj = ServiceSpec.from_json(data)
+
+    assert spec_obj.extra_container_args == ec_args
+    assert spec_obj.extra_entrypoint_args == ee_args