2021-01-08 13:41:50 +01:00
|
|
|
From 140c237f7ffefe61258e9ab3c26d04bd1e8df78a Mon Sep 17 00:00:00 2001
|
2020-07-09 13:56:13 +02:00
|
|
|
From: Jochen Breuer <jbreuer@suse.de>
|
|
|
|
Date: Fri, 3 Jul 2020 14:08:03 +0200
|
|
|
|
Subject: [PATCH] openSUSE-3000.3 spacewalk runner parse command (#250)
|
|
|
|
|
|
|
|
* Accept nested namespaces in spacewalk.api
|
|
|
|
|
|
|
|
salt-run $server spacewalk.api allows users to run arbitrary Spacewalk
|
|
|
|
API functions through Salt. These are passed in a namespace.method
|
|
|
|
notation and may use nested namespaces. Previously only methods in a
|
|
|
|
top-level namespace were supported.
|
|
|
|
|
|
|
|
Fixes https://github.com/saltstack/salt/issues/57442
|
|
|
|
|
|
|
|
Co-authored-by: Wayne Werner <wwerner@saltstack.com>
|
|
|
|
|
|
|
|
* Add spacewalk runner command parsing tests
|
|
|
|
|
|
|
|
Co-authored-by: Alexander Graul <agraul@suse.com>
|
|
|
|
Co-authored-by: Wayne Werner <wwerner@saltstack.com>
|
|
|
|
---
|
|
|
|
changelog/57442.fixed | 1 +
|
|
|
|
tests/unit/runners/test_spacewalk.py | 50 ++++++++++++++++++++++++++++
|
2021-01-08 13:41:50 +01:00
|
|
|
2 files changed, 51 insertions(+)
|
2020-07-09 13:56:13 +02:00
|
|
|
create mode 100644 changelog/57442.fixed
|
|
|
|
create mode 100644 tests/unit/runners/test_spacewalk.py
|
|
|
|
|
|
|
|
diff --git a/changelog/57442.fixed b/changelog/57442.fixed
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000..81f394880f
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/changelog/57442.fixed
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+Accept nested namespaces in spacewalk.api runner function.
|
|
|
|
diff --git a/tests/unit/runners/test_spacewalk.py b/tests/unit/runners/test_spacewalk.py
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000..5b64069cc9
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/tests/unit/runners/test_spacewalk.py
|
|
|
|
@@ -0,0 +1,50 @@
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+"""
|
|
|
|
+Unit tests for Spacewalk runner
|
|
|
|
+"""
|
|
|
|
+import salt.runners.spacewalk as spacewalk
|
|
|
|
+from tests.support.mock import Mock, call, patch
|
|
|
|
+from tests.support.unit import TestCase
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class SpacewalkTest(TestCase):
|
|
|
|
+ """Test the Spacewalk runner"""
|
|
|
|
+
|
|
|
|
+ def test_api_command_must_have_namespace(self):
|
|
|
|
+ _get_session_mock = Mock(return_value=(None, None))
|
|
|
|
+
|
|
|
|
+ with patch.object(spacewalk, "_get_session", _get_session_mock):
|
|
|
|
+ result = spacewalk.api("mocked.server", "badMethod")
|
|
|
|
+ assert result == {
|
|
|
|
+ "badMethod ()": "Error: command must use the following format: 'namespace.method'"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ def test_api_command_accepts_single_namespace(self):
|
|
|
|
+ client_mock = Mock()
|
|
|
|
+ _get_session_mock = Mock(return_value=(client_mock, "key"))
|
|
|
|
+ getattr_mock = Mock(return_value="mocked_getattr_return")
|
|
|
|
+
|
|
|
|
+ with patch.object(spacewalk, "_get_session", _get_session_mock):
|
|
|
|
+ with patch.object(spacewalk, "getattr", getattr_mock):
|
|
|
|
+ spacewalk.api("mocked.server", "system.listSystems")
|
|
|
|
+ getattr_mock.assert_has_calls(
|
|
|
|
+ [
|
|
|
|
+ call(client_mock, "system"),
|
|
|
|
+ call("mocked_getattr_return", "listSystems"),
|
|
|
|
+ ]
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ def test_api_command_accepts_nested_namespace(self):
|
|
|
|
+ client_mock = Mock()
|
|
|
|
+ _get_session_mock = Mock(return_value=(client_mock, "key"))
|
|
|
|
+ getattr_mock = Mock(return_value="mocked_getattr_return")
|
|
|
|
+
|
|
|
|
+ with patch.object(spacewalk, "_get_session", _get_session_mock):
|
|
|
|
+ with patch.object(spacewalk, "getattr", getattr_mock):
|
|
|
|
+ spacewalk.api("mocked.server", "channel.software.listChildren")
|
|
|
|
+ getattr_mock.assert_has_calls(
|
|
|
|
+ [
|
|
|
|
+ call(client_mock, "channel.software"),
|
|
|
|
+ call("mocked_getattr_return", "listChildren"),
|
|
|
|
+ ]
|
|
|
|
+ )
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-07-09 13:56:13 +02:00
|
|
|
|
|
|
|
|