]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: make annotations for inventory.py mandatory
authorSebastian Wagner <sebastian.wagner@suse.com>
Fri, 20 Nov 2020 11:04:53 +0000 (12:04 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Jan 2021 12:02:21 +0000 (13:02 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
(cherry picked from commit 77791a21db6597bc17a33411e02b12c03bd857a8)

Conflicts:
src/mypy.ini

src/mypy.ini
src/pybind/mgr/cephadm/inventory.py

index bb1f5fbf35a5c9a3bae28b3304fb084135ef5947..94f852f5e51541b03d3f3439688afc7bb03c62a1 100755 (executable)
@@ -15,3 +15,6 @@ disallow_untyped_defs = True
 [mypy-cephadm.serve.*]
 disallow_untyped_defs = True
 
+[mypy-cephadm.inventory]
+disallow_untyped_defs = True
+
index f17a7bd257c9c66df37305d13e63d103f9a80679..188cd0082a68faef342fe0f565ae447cb9a5a72f 100644 (file)
@@ -43,25 +43,25 @@ class Inventory:
     def __contains__(self, host: str) -> bool:
         return host in self._inventory
 
-    def assert_host(self, host):
+    def assert_host(self, host: str) -> None:
         if host not in self._inventory:
             raise OrchestratorError('host %s does not exist' % host)
 
-    def add_host(self, spec: HostSpec):
+    def add_host(self, spec: HostSpec) -> None:
         self._inventory[spec.hostname] = spec.to_json()
         self.save()
 
-    def rm_host(self, host: str):
+    def rm_host(self, host: str) -> None:
         self.assert_host(host)
         del self._inventory[host]
         self.save()
 
-    def set_addr(self, host, addr):
+    def set_addr(self, host: str, addr: str) -> None:
         self.assert_host(host)
         self._inventory[host]['addr'] = addr
         self.save()
 
-    def add_label(self, host, label):
+    def add_label(self, host: str, label: str) -> None:
         self.assert_host(host)
 
         if 'labels' not in self._inventory[host]:
@@ -70,7 +70,7 @@ class Inventory:
             self._inventory[host]['labels'].append(label)
         self.save()
 
-    def rm_label(self, host, label):
+    def rm_label(self, host: str, label: str) -> None:
         self.assert_host(host)
 
         if 'labels' not in self._inventory[host]:
@@ -79,7 +79,7 @@ class Inventory:
             self._inventory[host]['labels'].remove(label)
         self.save()
 
-    def get_addr(self, host) -> str:
+    def get_addr(self, host: str) -> str:
         self.assert_host(host)
         return self._inventory[host].get('addr', host)
 
@@ -91,7 +91,7 @@ class Inventory:
                 else:
                     yield h
 
-    def spec_from_dict(self, info) -> HostSpec:
+    def spec_from_dict(self, info: dict) -> HostSpec:
         hostname = info['hostname']
         return HostSpec(
             hostname,
@@ -103,7 +103,7 @@ class Inventory:
     def all_specs(self) -> List[HostSpec]:
         return list(map(self.spec_from_dict, self._inventory.values()))
 
-    def save(self):
+    def save(self) -> None:
         self.mgr.set_store('inventory', json.dumps(self._inventory))
 
 
@@ -293,7 +293,7 @@ class HostCache():
         self.networks[host] = nets
         self.last_device_update[host] = datetime.datetime.utcnow()
 
-    def update_daemon_config_deps(self, host, name, deps, stamp):
+    def update_daemon_config_deps(self, host: str, name: str, deps: List[str], stamp: datetime.datetime) -> None:
         self.daemon_config_deps[host][name] = {
             'deps': deps,
             'last_config': stamp,
@@ -332,7 +332,7 @@ class HostCache():
             del self.last_device_update[host]
         self.mgr.event.set()
 
-    def distribute_new_registry_login_info(self):
+    def distribute_new_registry_login_info(self) -> None:
         self.registry_login_queue = set(self.mgr.inventory.keys())
 
     def save_host(self, host: str) -> None:
@@ -422,7 +422,7 @@ class HostCache():
         raise orchestrator.OrchestratorError(f'Unable to find {daemon_name} daemon(s)')
 
     def get_daemons_with_volatile_status(self) -> Iterator[Tuple[str, Dict[str, orchestrator.DaemonDescription]]]:
-        def alter(host, dd_orig: orchestrator.DaemonDescription) -> orchestrator.DaemonDescription:
+        def alter(host: str, dd_orig: orchestrator.DaemonDescription) -> orchestrator.DaemonDescription:
             dd = copy(dd_orig)
             if host in self.mgr.offline_hosts:
                 dd.status = -1
@@ -459,7 +459,7 @@ class HostCache():
                 r.append(name)
         return r
 
-    def get_daemon_last_config_deps(self, host, name) -> Tuple[Optional[List[str]], Optional[datetime.datetime]]:
+    def get_daemon_last_config_deps(self, host: str, name: str) -> Tuple[Optional[List[str]], Optional[datetime.datetime]]:
         if host in self.daemon_config_deps:
             if name in self.daemon_config_deps[host]:
                 return self.daemon_config_deps[host][name].get('deps', []), \
@@ -515,7 +515,7 @@ class HostCache():
             return True
         return False
 
-    def host_needs_osdspec_preview_refresh(self, host):
+    def host_needs_osdspec_preview_refresh(self, host: str) -> bool:
         if host in self.mgr.offline_hosts:
             logger.debug(f'Host "{host}" marked as offline. Skipping osdspec preview refresh')
             return False
@@ -532,7 +532,7 @@ class HostCache():
             seconds=self.mgr.host_check_interval)
         return host not in self.last_host_check or self.last_host_check[host] < cutoff
 
-    def host_needs_new_etc_ceph_ceph_conf(self, host: str):
+    def host_needs_new_etc_ceph_ceph_conf(self, host: str) -> bool:
         if not self.mgr.manage_etc_ceph_ceph_conf:
             return False
         if self.mgr.paused:
@@ -550,7 +550,7 @@ class HostCache():
         # already up to date:
         return False
 
-    def update_last_etc_ceph_ceph_conf(self, host: str):
+    def update_last_etc_ceph_ceph_conf(self, host: str) -> None:
         if not self.mgr.last_monmap:
             return
         self.last_etc_ceph_ceph_conf[host] = datetime.datetime.utcnow()
@@ -568,12 +568,12 @@ class HostCache():
         assert host in self.daemons
         self.daemons[host][dd.name()] = dd
 
-    def rm_daemon(self, host, name):
+    def rm_daemon(self, host: str, name: str) -> None:
         if host in self.daemons:
             if name in self.daemons[host]:
                 del self.daemons[host][name]
 
-    def daemon_cache_filled(self):
+    def daemon_cache_filled(self) -> bool:
         """
         i.e. we have checked the daemons for each hosts at least once.
         excluding offline hosts.
@@ -584,7 +584,7 @@ class HostCache():
         return all((self.host_had_daemon_refresh(h) or h in self.mgr.offline_hosts)
                    for h in self.get_hosts())
 
-    def schedule_daemon_action(self, host: str, daemon_name: str, action: str):
+    def schedule_daemon_action(self, host: str, daemon_name: str, action: str) -> None:
         priorities = {
             'start': 1,
             'restart': 2,
@@ -602,14 +602,14 @@ class HostCache():
             self.scheduled_daemon_actions[host] = {}
         self.scheduled_daemon_actions[host][daemon_name] = action
 
-    def rm_scheduled_daemon_action(self, host: str, daemon_name: str):
+    def rm_scheduled_daemon_action(self, host: str, daemon_name: str) -> None:
         if host in self.scheduled_daemon_actions:
             if daemon_name in self.scheduled_daemon_actions[host]:
                 del self.scheduled_daemon_actions[host][daemon_name]
             if not self.scheduled_daemon_actions[host]:
                 del self.scheduled_daemon_actions[host]
 
-    def get_scheduled_daemon_action(self, host, daemon) -> Optional[str]:
+    def get_scheduled_daemon_action(self, host: str, daemon: str) -> Optional[str]:
         return self.scheduled_daemon_actions.get(host, {}).get(daemon)
 
 
@@ -633,12 +633,12 @@ class EventStore():
         # limit to five events for now.
         self.events[event.kind_subject()] = self.events[event.kind_subject()][-5:]
 
-    def for_service(self, spec: ServiceSpec, level, message) -> None:
+    def for_service(self, spec: ServiceSpec, level: str, message: str) -> None:
         e = OrchestratorEvent(datetime.datetime.utcnow(), 'service',
                               spec.service_name(), level, message)
         self.add(e)
 
-    def from_orch_error(self, e: OrchestratorError):
+    def from_orch_error(self, e: OrchestratorError) -> None:
         if e.event_subject is not None:
             self.add(OrchestratorEvent(
                 datetime.datetime.utcnow(),
@@ -648,11 +648,11 @@ class EventStore():
                 str(e)
             ))
 
-    def for_daemon(self, daemon_name, level, message):
+    def for_daemon(self, daemon_name: str, level: str, message: str) -> None:
         e = OrchestratorEvent(datetime.datetime.utcnow(), 'daemon', daemon_name, level, message)
         self.add(e)
 
-    def for_daemon_from_exception(self, daemon_name, e: Exception):
+    def for_daemon_from_exception(self, daemon_name: str, e: Exception) -> None:
         self.for_daemon(
             daemon_name,
             "ERROR",
@@ -677,8 +677,8 @@ class EventStore():
         for k_s in unknowns:
             del self.events[k_s]
 
-    def get_for_service(self, name) -> List[OrchestratorEvent]:
+    def get_for_service(self, name: str) -> List[OrchestratorEvent]:
         return self.events.get('service:' + name, [])
 
-    def get_for_daemon(self, name) -> List[OrchestratorEvent]:
+    def get_for_daemon(self, name: str) -> List[OrchestratorEvent]:
         return self.events.get('daemon:' + name, [])