feat: get_service_packages, which packages a systemd service is (NetOrk/netork#1236)
CI / test (3.10) (pull_request) Successful in 41s
CI / test (3.11) (pull_request) Successful in 40s
CI / test (3.12) (pull_request) Successful in 32s
CI / test (3.10) (push) Successful in 29s
CI / test (3.11) (push) Successful in 27s
CI / test (3.12) (push) Successful in 34s
CI / test (3.10) (pull_request) Successful in 41s
CI / test (3.11) (pull_request) Successful in 40s
CI / test (3.12) (pull_request) Successful in 32s
CI / test (3.10) (push) Successful in 29s
CI / test (3.11) (push) Successful in 27s
CI / test (3.12) (push) Successful in 34s
Mixes in napalm-device-types' ServicePackagesMixin. The transport runs the shared read-only command on an exec channel under sh, without sudo: it is about 1 kB, past what the PTY takes reliably, and written for sh whatever the login shell. Requires napalm-device-types 4.20.0; version 0.12.0.
This commit is contained in:
1 parent
c725f4882c
commit
a2bfa709f9
4 files changed
+50
-2
No files matched your search
@@ -1193,6 +1193,40 @@ def test_get_kernel_facts_raises_on_output_without_a_report(driver):
|
||||
driver.get_kernel_facts()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_service_packages -- the command and its parse live in napalm-device-types
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SVCPKG = (
|
||||
"SVCPKG_BEGIN\n[units]\nId=nginx.service\n"
|
||||
"FragmentPath=/lib/systemd/system/nginx.service\n"
|
||||
"ExecStart={ path=/usr/sbin/nginx ; argv[]=/usr/sbin/nginx }\n\n"
|
||||
"[dpkg]\nnginx-common: /lib/systemd/system/nginx.service\n"
|
||||
"nginx-core: /usr/sbin/nginx\nSVCPKG_END\n"
|
||||
)
|
||||
|
||||
|
||||
def test_get_service_packages_runs_the_shared_command_under_sh_on_an_exec_channel(driver):
|
||||
"""Read-only, so never through sudo; ``sh`` because the login shell may be another."""
|
||||
from shlex import quote
|
||||
|
||||
from napalm_device_types import CommandResult, ServicePackagesMixin
|
||||
from napalm_device_types.service_packages import SERVICE_PACKAGES_COMMAND
|
||||
|
||||
assert isinstance(driver, ServicePackagesMixin)
|
||||
calls = []
|
||||
|
||||
def run_command(command, *, privileged=False, timeout=60, stdin=None):
|
||||
calls.append((command, privileged))
|
||||
return CommandResult(_SVCPKG, "", 0)
|
||||
|
||||
driver.run_command = run_command
|
||||
|
||||
assert driver.get_service_packages() == {"nginx": ["nginx-common", "nginx-core"]}
|
||||
assert calls == [(f"sh -c {quote(SERVICE_PACKAGES_COMMAND)}", False)]
|
||||
driver._device.send_command.assert_not_called()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Services: listed in one round trip, controlled through systemctl (#7)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user