]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
node-proxy: rename attribute and class
authorGuillaume Abrioux <gabrioux@ibm.com>
Wed, 17 Jan 2024 08:47:36 +0000 (08:47 +0000)
committerGuillaume Abrioux <gabrioux@ibm.com>
Thu, 25 Jan 2024 16:01:04 +0000 (16:01 +0000)
This renames the mgr's NodeProxyCache attribute from
`self.node_proxy` to `self.node_proxy_cache` and the
class `NodeProxy` in agent.py from `NodeProxy` to
`NodeProxyEndpoint` to make it clearer and avoid confusion.

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
(cherry picked from commit c62d1c82cf6155aba5e75e88ff3390ed5288e758)

src/pybind/mgr/cephadm/agent.py
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/serve.py
src/pybind/mgr/cephadm/tests/test_node_proxy.py

index d2a155d5de0cacebc30f1987fe45989814991328..b589886e566c82c77b5a0a8031297f4bc8b42c28 100644 (file)
@@ -56,7 +56,7 @@ class AgentEndpoint:
         conf = {'/': {'tools.trailing_slash.on': False}}
 
         cherrypy.tree.mount(self.host_data, '/data', config=conf)
-        cherrypy.tree.mount(self.node_proxy, '/node-proxy', config=conf)
+        cherrypy.tree.mount(self.node_proxy_endpoint, '/node-proxy', config=conf)
 
     def configure_tls(self, server: Server) -> None:
         old_cert = self.mgr.get_store(self.KV_STORE_AGENT_ROOT_CERT)
@@ -87,12 +87,12 @@ class AgentEndpoint:
     def configure(self) -> None:
         self.host_data = HostData(self.mgr, self.server_port, self.server_addr)
         self.configure_tls(self.host_data)
-        self.node_proxy = NodeProxy(self.mgr)
+        self.node_proxy_endpoint = NodeProxyEndpoint(self.mgr)
         self.configure_routes()
         self.find_free_port()
 
 
-class NodeProxy:
+class NodeProxyEndpoint:
     def __init__(self, mgr: "CephadmOrchestrator"):
         self.mgr = mgr
         self.ssl_root_crt = self.mgr.http_server.agent.ssl_certs.get_root_cert()
@@ -106,7 +106,7 @@ class NodeProxy:
         self.redfish_token: str = ''
         self.redfish_session_location: str = ''
 
-    def _cp_dispatch(self, vpath: List[str]) -> "NodeProxy":
+    def _cp_dispatch(self, vpath: List[str]) -> "NodeProxyEndpoint":
         if len(vpath) > 1:  # /{hostname}/<endpoint>
             hostname = vpath.pop(0)  # /<endpoint>
             cherrypy.request.params['hostname'] = hostname
@@ -139,7 +139,7 @@ class NodeProxy:
         self.validate_node_proxy_data(data)
 
         host = data["cephx"]["name"]
-        results['result'] = self.mgr.node_proxy.oob.get(host)
+        results['result'] = self.mgr.node_proxy_cache.oob.get(host)
         if not results['result']:
             raise cherrypy.HTTPError(400, 'The provided host has no iDrac details.')
         return results
@@ -261,7 +261,7 @@ class NodeProxy:
         if 'patch' not in data.keys():
             raise cherrypy.HTTPError(400, 'Malformed data received.')
         host = data['cephx']['name']
-        self.mgr.node_proxy.save(host, data['patch'])
+        self.mgr.node_proxy_cache.save(host, data['patch'])
         self.raise_alert(data)
 
     @cherrypy.expose
@@ -311,7 +311,7 @@ class NodeProxy:
             self.mgr.log.debug(msg)
             raise cherrypy.HTTPError(400, msg)
 
-        if hostname not in self.mgr.node_proxy.data.keys():
+        if hostname not in self.mgr.node_proxy_cache.data.keys():
             # TODO(guits): update unit test for this
             msg = f"'{hostname}' not found."
             self.mgr.log.debug(msg)
@@ -323,7 +323,7 @@ class NodeProxy:
             data = json.dumps(cherrypy.request.json)
 
             if led_type == 'drive':
-                if id_drive not in self.mgr.node_proxy.data[hostname]['status']['storage'].keys():
+                if id_drive not in self.mgr.node_proxy_cache.data[hostname]['status']['storage'].keys():
                     # TODO(guits): update unit test for this
                     msg = f"'{id_drive}' not found."
                     self.mgr.log.debug(msg)
@@ -372,7 +372,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.fullreport(**kw)
+            results = self.mgr.node_proxy_cache.fullreport(**kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -396,7 +396,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.criticals(**kw)
+            results = self.mgr.node_proxy_cache.criticals(**kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -420,7 +420,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.summary(**kw)
+            results = self.mgr.node_proxy_cache.summary(**kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -445,7 +445,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('memory', **kw)
+            results = self.mgr.node_proxy_cache.common('memory', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -470,7 +470,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('network', **kw)
+            results = self.mgr.node_proxy_cache.common('network', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -495,7 +495,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('processors', **kw)
+            results = self.mgr.node_proxy_cache.common('processors', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -520,7 +520,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('storage', **kw)
+            results = self.mgr.node_proxy_cache.common('storage', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -545,7 +545,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('power', **kw)
+            results = self.mgr.node_proxy_cache.common('power', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -570,7 +570,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.common('fans', **kw)
+            results = self.mgr.node_proxy_cache.common('fans', **kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
@@ -594,7 +594,7 @@ class NodeProxy:
         :raises cherrypy.HTTPError 404: If the passed hostname is not found.
         """
         try:
-            results = self.mgr.node_proxy.firmwares(**kw)
+            results = self.mgr.node_proxy_cache.firmwares(**kw)
         except KeyError:
             raise cherrypy.HTTPError(404, f"{kw.get('hostname')} not found.")
         return results
index df5a846c5a3961dc3cd7069d7dfbea5016e90b88..f27f8ed7b323524b67f99659dd2bee30dd9d24cd 100644 (file)
@@ -584,8 +584,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
         self.cache = HostCache(self)
         self.cache.load()
 
-        self.node_proxy = NodeProxyCache(self)
-        self.node_proxy.load()
+        self.node_proxy_cache = NodeProxyCache(self)
+        self.node_proxy_cache.load()
 
         self.agent_cache = AgentCache(self)
         self.agent_cache.load()
@@ -1638,19 +1638,19 @@ Then run the following:
 
     @handle_orch_error
     def node_proxy_summary(self, hostname: Optional[str] = None) -> Dict[str, Any]:
-        return self.node_proxy.summary(hostname=hostname)
+        return self.node_proxy_cache.summary(hostname=hostname)
 
     @handle_orch_error
     def node_proxy_firmwares(self, hostname: Optional[str] = None) -> Dict[str, Any]:
-        return self.node_proxy.firmwares(hostname=hostname)
+        return self.node_proxy_cache.firmwares(hostname=hostname)
 
     @handle_orch_error
     def node_proxy_criticals(self, hostname: Optional[str] = None) -> Dict[str, Any]:
-        return self.node_proxy.criticals(hostname=hostname)
+        return self.node_proxy_cache.criticals(hostname=hostname)
 
     @handle_orch_error
     def node_proxy_common(self, category: str, hostname: Optional[str] = None) -> Dict[str, Any]:
-        return self.node_proxy.common(category, hostname=hostname)
+        return self.node_proxy_cache.common(category, hostname=hostname)
 
     @handle_orch_error
     def remove_host(self, host: str, force: bool = False, offline: bool = False) -> str:
index 2a95e5a9a1f38af7985d47173929837571289db3..f16e9f8c7b048db4884533e85d2e033789db3772 100644 (file)
@@ -117,7 +117,7 @@ class CephadmServe:
                         continue
 
                     # refresh node-proxy cache
-                    self.mgr.node_proxy.load()
+                    self.mgr.node_proxy_cache.load()
 
             except OrchestratorError as e:
                 if e.event_subject:
index 3b05a4f39a54450db920de6c312a7f55392bc4de..b713d04cd5975e5768452b3105cdfaf37f666c05 100644 (file)
@@ -2,7 +2,7 @@ import cherrypy
 import json
 from _pytest.monkeypatch import MonkeyPatch
 from cherrypy.test import helper
-from cephadm.agent import NodeProxy
+from cephadm.agent import NodeProxyEndpoint
 from unittest.mock import MagicMock, call, patch
 from cephadm.inventory import AgentCache, NodeProxyCache, Inventory
 from cephadm.ssl_cert_utils import SSLCerts
@@ -21,8 +21,8 @@ class FakeMgr:
         self.inventory = Inventory(self)
         self.agent_cache = AgentCache(self)
         self.agent_cache.agent_ports = {"host01": 1234}
-        self.node_proxy = NodeProxyCache(self)
-        self.node_proxy.save = MagicMock()
+        self.node_proxy_cache = NodeProxyCache(self)
+        self.node_proxy_cache.save = MagicMock()
         self.http_server = MagicMock()
         self.http_server.agent = MagicMock()
         self.http_server.agent.ssl_certs = SSLCerts()
@@ -32,9 +32,9 @@ class FakeMgr:
         return '0.0.0.0'
 
 
-class TestNodeProxy(helper.CPWebCase):
+class TestNodeProxyEndpoint(helper.CPWebCase):
     mgr = FakeMgr()
-    app = NodeProxy(mgr)
+    app = NodeProxyEndpoint(mgr)
     mgr.agent_cache.agent_keys = {"host01": "fake-secret01",
                                   "host02": "fake-secret02"}
     mgr.node_proxy.oob = {"host01": {"username": "oob-user01",
@@ -45,8 +45,8 @@ class TestNodeProxy(helper.CPWebCase):
 
     @classmethod
     def setup_server(cls):
-        # cherrypy.tree.mount(NodeProxy(TestNodeProxy.mgr))
-        cherrypy.tree.mount(TestNodeProxy.app)
+        # cherrypy.tree.mount(NodeProxyEndpoint(TestNodeProxyEndpoint.mgr))
+        cherrypy.tree.mount(TestNodeProxyEndpoint.app)
         cherrypy.config.update({'global': {
             'server.socket_host': '127.0.0.1',
             'server.socket_port': PORT}})
@@ -115,7 +115,7 @@ class TestNodeProxy(helper.CPWebCase):
                       detail=['dimm.socket.a1 is critical: Enabled'],
                       summary='1 memory member is not ok')]
 
-        assert TestNodeProxy.mgr.set_health_warning.mock_calls == calls
+        assert TestNodeProxyEndpoint.mgr.set_health_warning.mock_calls == calls
 
     # @pytest.mark.parametrize("method", ["GET", "PATCH"])
     # def test_led_no_hostname(self, method):
@@ -213,7 +213,7 @@ class TestNodeProxy(helper.CPWebCase):
             self.assertStatus('200 OK')
 
     # def test_led_endpoint_unreachable(self):
-    #     TestNodeProxy.app.query_endpoint = MagicMock(side_effect=URLError("fake-error"))
+    #     TestNodeProxyEndpoint.app.query_endpoint = MagicMock(side_effect=URLError("fake-error"))
     #     self.getPage("/host02/led", method="GET")
     #     calls = [call(addr='10.10.10.12',
     #                   data=None,
@@ -221,9 +221,9 @@ class TestNodeProxy(helper.CPWebCase):
     #                   headers={},
     #                   method='GET',
     #                   port=8080,
-    #                   ssl_ctx=TestNodeProxy.app.ssl_ctx)]
+    #                   ssl_ctx=TestNodeProxyEndpoint.app.ssl_ctx)]
     #     self.assertStatus('502 Bad Gateway')
-    #     assert TestNodeProxy.app.query_endpoint.mock_calls == calls
+    #     assert TestNodeProxyEndpoint.app.query_endpoint.mock_calls == calls
 
     def test_fullreport_with_valid_hostname(self):
         self.getPage("/host02/fullreport", method="GET")