From: Sebastian Wagner Date: Fri, 13 Dec 2019 16:30:19 +0000 (+0100) Subject: mgr/ansible: Added missing type annotations X-Git-Tag: v15.1.0~450^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7222ba6f6ae1eb242f399dbaf0ed7f1d920c9045;p=ceph.git mgr/ansible: Added missing type annotations As requested by mypy Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/ansible/ansible_runner_svc.py b/src/pybind/mgr/ansible/ansible_runner_svc.py index 70355eab2bf12..347feafbadff5 100644 --- a/src/pybind/mgr/ansible/ansible_runner_svc.py +++ b/src/pybind/mgr/ansible/ansible_runner_svc.py @@ -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() diff --git a/src/pybind/mgr/ansible/module.py b/src/pybind/mgr/ansible/module.py index 89df99401d2c4..45cbfe00e37fa 100644 --- a/src/pybind/mgr/ansible/module.py +++ b/src/pybind/mgr/ansible/module.py @@ -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