]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/ansible: Added missing type annotations
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 13 Dec 2019 16:30:19 +0000 (17:30 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 13 Dec 2019 16:30:19 +0000 (17:30 +0100)
As requested by mypy

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/ansible/ansible_runner_svc.py
src/pybind/mgr/ansible/module.py

index 70355eab2bf120eaf40cfa612c2760367cfcc7b0..347feafbadff5bdfff9a08985646955de0e5a93e 100644 (file)
@@ -8,7 +8,7 @@ from functools import wraps
 import collections
 import logging
 try:
-    from typing import Optional
+    from typing import Optional, Dict, Any, List, Set
 except ImportError:
     pass # just for type checking
 
@@ -159,7 +159,7 @@ class PlayBookExecution(object):
             logger.exception("Error getting playbook <%s> result", self.playbook)
 
         if not response:
-            result_events = {}
+            result_events = {}  # type: Dict[str, Any]
         else:
             events = json.loads(response.text)["data"]["events"]
 
@@ -346,7 +346,7 @@ class Client(object):
             if response.status_code != 200:
                 raise AnsibleRunnerServiceError("Error when trying to "\
                                                 "create group:{}".format(group))
-            hosts_in_group = []
+            hosts_in_group = []  # type: List[str]
         else:
             hosts_in_group = json.loads(response.text)["data"]["members"]
 
@@ -419,7 +419,7 @@ class InventoryGroup(collections.MutableSet):
         : returns    : Nothing
         """
 
-        self.elements = set()
+        self.elements = set()  # type: Set[Any]
 
         self.group_name = group_name
         self.url_group = URL_MANAGE_GROUP.format(group_name=self.group_name)
@@ -521,4 +521,4 @@ class InventoryGroup(collections.MutableSet):
                                             "create group:{}".format(
                                                 self.group_name))
         self.created = True
-        self.elements = {}
+        self.elements = set()
index 89df99401d2c477f656e87602aeefebb2f2079b8..45cbfe00e37fad9ed3d2dfa6b239ad407dedef27 100644 (file)
@@ -12,7 +12,7 @@ import errno
 import tempfile
 
 try:
-    from typing import List, Optional, Callable
+    from typing import List, Optional, Callable, Any
 except ImportError:
     pass # just for type checking
 
@@ -144,6 +144,7 @@ def playbook_operation(client,  # type: Client
 
             # Clean hosts if operation is succesful
             if status == ExecutionStatusCode.SUCCESS:
+                assert clean_hosts_on_success is not None
                 clean_inventory(client, clean_hosts_on_success)
 
             return processed_result
@@ -208,7 +209,7 @@ def ars_change(client, operations, output_wizard=None):
 
 
 def ars_read(client, url, get_operation=True, payload=None, output_wizard=None):
-    # type: (Client, str, bool, Optional[str], Optional[OutputWizard]) -> orchestrator.Completion[str]
+    # type: (Client, str, bool, Optional[str], Optional[OutputWizard]) -> orchestrator.Completion
     """
     Execute the Ansible Runner Service operation
 
@@ -241,7 +242,7 @@ class Module(MgrModule, orchestrator.Orchestrator):
 
         self.all_completions = []
 
-        self.ar_client = None  # type: Client
+        self._ar_client = None  # type: Optional[Client]
 
         # TLS certificate and key file names used to connect with the external
         # Ansible Runner Service
@@ -253,6 +254,11 @@ class Module(MgrModule, orchestrator.Orchestrator):
 
         self.all_progress_references = list()  # type: List[orchestrator.ProgressReference]
 
+    @property
+    def ar_client(self):
+        # type: () -> Client
+        assert self._ar_client is not None
+        return self._ar_client
 
     def available(self):
         """ Check if Ansible Runner service is working
@@ -261,7 +267,7 @@ class Module(MgrModule, orchestrator.Orchestrator):
         msg = ""
         try:
 
-            if self.ar_client:
+            if self._ar_client:
                 available = self.ar_client.is_operative()
                 if not available:
                     msg = "No response from Ansible Runner Service"
@@ -300,7 +306,7 @@ class Module(MgrModule, orchestrator.Orchestrator):
             self.verify_config()
 
             # Ansible runner service client
-            self.ar_client = Client(
+            self._ar_client = Client(
                 server_url=self.get_module_option('server_location', ''),
                 verify_server=self.get_module_option('verify_server', True),
                 ca_bundle=self.get_module_option('ca_bundle', ''),
@@ -440,7 +446,7 @@ class Module(MgrModule, orchestrator.Orchestrator):
         :returns : orchestrator.Completion
         """
 
-        host_groups = []
+        host_groups = []  # type: List[Any]
 
         try:
             # Get the list of groups where the host is included