]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
python-common, orch: Move ServiceSpec to python-common: Fix imports
authorSebastian Wagner <sebastian.wagner@suse.com>
Mon, 9 Mar 2020 11:58:52 +0000 (12:58 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 10 Mar 2020 12:28:22 +0000 (13:28 +0100)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py
src/pybind/mgr/cephadm/tests/test_scheduling.py
src/pybind/mgr/orchestrator/__init__.py
src/pybind/mgr/orchestrator/module.py
src/python-common/ceph/deployment/drive_group.py
src/python-common/ceph/deployment/service_spec.py

index 8272bee58c317702411187ab1a41cf090a40a995..20f046cad8f66fda2a4e3bcdcfd39c8de1b71652 100644 (file)
@@ -30,11 +30,12 @@ import uuid
 from ceph.deployment import inventory, translate
 from ceph.deployment.drive_group import DriveGroupSpec
 from ceph.deployment.drive_selection import selector
+from ceph.deployment.service_spec import HostPlacementSpec, ServiceSpec
 
 from mgr_module import MgrModule
 import orchestrator
-from orchestrator import OrchestratorError, HostPlacementSpec, OrchestratorValidationError, HostSpec, \
-    CLICommandMeta, ServiceSpec
+from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpec, \
+    CLICommandMeta
 
 from . import remotes
 from .osd import RemoveUtil, OSDRemoval
@@ -121,7 +122,7 @@ class SpecStore():
     def __init__(self, mgr):
         # type: (CephadmOrchestrator) -> None
         self.mgr = mgr
-        self.specs = {} # type: Dict[str, orchestrator.ServiceSpec]
+        self.specs = {} # type: Dict[str, ServiceSpec]
         self.spec_created = {} # type: Dict[str, datetime.datetime]
 
     def load(self):
@@ -142,7 +143,7 @@ class SpecStore():
                 pass
 
     def save(self, spec):
-        # type: (orchestrator.ServiceSpec) -> None
+        # type: (ServiceSpec) -> None
         self.specs[spec.service_name()] = spec
         self.spec_created[spec.service_name()] = datetime.datetime.utcnow()
         self.mgr.set_store(
@@ -161,7 +162,7 @@ class SpecStore():
             self.mgr.set_store(SPEC_STORE_PREFIX + service_name, None)
 
     def find(self, service_name):
-        # type: (str) -> List[orchestrator.ServiceSpec]
+        # type: (str) -> List[ServiceSpec]
         specs = []
         for sn, spec in self.specs.items():
             if sn == service_name or sn.startswith(service_name + '.'):
@@ -2253,7 +2254,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
 
     def _apply_all_services(self):
         r = False
-        specs = [] # type: List[orchestrator.ServiceSpec]
+        specs = [] # type: List[ServiceSpec]
         for sn, spec in self.spec_store.specs.items():
             specs.append(spec)
         for spec in specs:
@@ -2397,7 +2398,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                                    extra_config=extra_config)
 
     def add_mon(self, spec):
-        # type: (orchestrator.ServiceSpec) -> orchestrator.Completion
+        # type: (ServiceSpec) -> orchestrator.Completion
         return self._add_daemon('mon', spec, self._create_mon)
 
     def _create_mgr(self, mgr_id, host):
@@ -2416,7 +2417,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
         return self._create_daemon('mgr', mgr_id, host, keyring=keyring)
 
     def add_mgr(self, spec):
-        # type: (orchestrator.ServiceSpec) -> orchestrator.Completion
+        # type: (ServiceSpec) -> orchestrator.Completion
         return self._add_daemon('mgr', spec, self._create_mgr)
 
     def _apply(self, spec):
@@ -2445,10 +2446,10 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
         return self._apply(spec)
 
     def add_mds(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._add_daemon('mds', spec, self._create_mds, self._config_mds)
 
-    def apply_mds(self, spec: orchestrator.ServiceSpec) -> orchestrator.Completion:
+    def apply_mds(self, spec: ServiceSpec) -> orchestrator.Completion:
         return self._apply(spec)
 
     def _config_mds(self, spec):
@@ -2742,7 +2743,7 @@ receivers:
         return self._apply(spec)
 
     def add_node_exporter(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._add_daemon('node-exporter', spec,
                                 self._create_node_exporter)
 
@@ -2753,7 +2754,7 @@ receivers:
         return self._create_daemon('node-exporter', daemon_id, host)
 
     def add_crash(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._add_daemon('crash', spec,
                                 self._create_crash)
 
@@ -2770,11 +2771,11 @@ receivers:
         return self._create_daemon('crash', daemon_id, host, keyring=keyring)
 
     def add_grafana(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._add_daemon('grafana', spec, self._create_grafana)
 
     def apply_grafana(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._apply(spec)
 
     def _create_grafana(self, daemon_id, host):
@@ -2782,11 +2783,11 @@ receivers:
         return self._create_daemon('grafana', daemon_id, host)
 
     def add_alertmanager(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._add_daemon('alertmanager', spec, self._create_alertmanager)
 
     def apply_alertmanager(self, spec):
-        # type: (orchestrator.ServiceSpec) -> AsyncCompletion
+        # type: (ServiceSpec) -> AsyncCompletion
         return self._apply(spec)
 
     def _create_alertmanager(self, daemon_id, host):
@@ -3046,14 +3047,14 @@ class HostAssignment(object):
     """
 
     def __init__(self,
-                 spec,  # type: orchestrator.ServiceSpec
+                 spec,  # type: ServiceSpec
                  get_hosts_func,  # type: Callable[[Optional[str]],List[str]]
                  get_daemons_func, # type: Callable[[str],List[orchestrator.DaemonDescription]]
 
                  scheduler=None,  # type: Optional[BaseScheduler]
                  ):
         assert spec and get_hosts_func and get_daemons_func
-        self.spec = spec  # type: orchestrator.ServiceSpec
+        self.spec = spec  # type: ServiceSpec
         self.scheduler = scheduler if scheduler else SimpleScheduler(self.spec.placement)
         self.get_hosts_func = get_hosts_func
         self.get_daemons_func = get_daemons_func
index 6080ee5503b314908a624ad0dbc20858f0d0feeb..ea095a8b27f80aff0157534ede2aa717ab27fd1f 100644 (file)
@@ -12,8 +12,9 @@ try:
 except ImportError:
     pass
 
+from ceph.deployment.service_spec import ServiceSpec, PlacementSpec, RGWSpec
 from orchestrator import ServiceDescription, DaemonDescription, InventoryHost, \
-    ServiceSpec, PlacementSpec, RGWSpec, HostSpec, OrchestratorError
+    HostSpec, OrchestratorError
 from tests import mock
 from .fixtures import cephadm_module, wait, _run_cephadm, mon_command, match_glob
 from cephadm.module import CephadmOrchestrator
index abd3b3e4e2da3b864b96464a11a18028ca65b960..e2a6a0191f7fabbc25dfdb7c479ef642445d20f5 100644 (file)
@@ -1,8 +1,10 @@
 from typing import NamedTuple, List
 import pytest
 
+from ceph.deployment.service_spec import ServiceSpec, PlacementSpec, ServiceSpecValidationError
+
 from cephadm.module import HostAssignment
-from orchestrator import ServiceSpec, PlacementSpec, DaemonDescription, OrchestratorValidationError
+from orchestrator import DaemonDescription, OrchestratorValidationError
 
 
 class NodeAssignmentTest(NamedTuple):
@@ -241,5 +243,5 @@ def test_bad_placements(placement):
     try:
         s = PlacementSpec.from_string(placement.split(' '))
         assert False
-    except OrchestratorValidationError as e:
+    except ServiceSpecValidationError as e:
         pass
index 05ac4601166d5ea718d455eb92ec214c93d1ce9b..5addd32cc2892250d6b7fbe9da88e3e57ef5f321 100644 (file)
@@ -8,9 +8,7 @@ from ._interface import \
     CLICommand, _cli_write_command, _cli_read_command, CLICommandMeta, \
     Orchestrator, OrchestratorClientMixin, \
     OrchestratorValidationError, OrchestratorError, NoOrchestrator, \
-    ServiceSpec, NFSServiceSpec, RGWSpec, HostPlacementSpec, \
-    servicespec_validate_add, \
-    ServiceDescription, InventoryFilter, PlacementSpec,  HostSpec, \
+    ServiceDescription, InventoryFilter, HostSpec, \
     DaemonDescription, \
     InventoryHost, DeviceLightLoc, \
     OutdatableData, OutdatablePersistentDict, \
index ded3f5839ccededb73e78c1793476e08a8639831..4ab1d93588bec2c14901544539d3331b9ae98fdb 100644 (file)
@@ -18,12 +18,13 @@ except ImportError:
 
 from ceph.deployment.drive_group import DriveGroupSpec, DeviceSelection, \
     DriveGroupSpecs
+from ceph.deployment.service_spec import PlacementSpec, ServiceSpec
 from mgr_module import MgrModule, HandleCommandResult
 
 from ._interface import OrchestratorClientMixin, DeviceLightLoc, _cli_read_command, \
     raise_if_exception, _cli_write_command, TrivialReadCompletion, OrchestratorError, \
-    NoOrchestrator, ServiceSpec, PlacementSpec, OrchestratorValidationError, NFSServiceSpec, \
-    RGWSpec, InventoryFilter, InventoryHost, HostPlacementSpec, HostSpec, CLICommandMeta
+    NoOrchestrator, OrchestratorValidationError, NFSServiceSpec, \
+    RGWSpec, InventoryFilter, InventoryHost, HostSpec, CLICommandMeta
 
 def nice_delta(now, t, suffix=''):
     if t:
index 8d4ab95b3d196cee67b4fbb380fe3a98383ebb00..78502e14ec70d3728d7aac825cb435fdb9e14611 100644 (file)
@@ -1,5 +1,7 @@
 import fnmatch
 from ceph.deployment.inventory import Device
+from ceph.deployment.service_spec import ServiceSpecValidationError
+
 try:
     from typing import Optional, List, Dict, Any
 except ImportError:
@@ -97,7 +99,7 @@ class DeviceSelection(object):
         return repr(self) == repr(other)
 
 
-class DriveGroupValidationError(Exception):
+class DriveGroupValidationError(ServiceSpecValidationError):
     """
     Defining an exception here is a bit problematic, cause you cannot properly catch it,
     if it was raised in a different mgr module.
index 5afe7c87ad0a8ad28ce7d143829085d5ff421d15..852078c2df5936714b07ac0859764dd0cfc2c705 100644 (file)
@@ -5,6 +5,16 @@ from typing import Optional, Dict, Any, List
 import six
 
 
+class ServiceSpecValidationError(Exception):
+    """
+    Defining an exception here is a bit problematic, cause you cannot properly catch it,
+    if it was raised in a different mgr module.
+    """
+
+    def __init__(self, msg):
+        super(ServiceSpecValidationError, self).__init__(msg)
+
+
 class HostPlacementSpec(namedtuple('HostPlacementSpec', ['hostname', 'network', 'name'])):
     def __str__(self):
         res = ''
@@ -100,7 +110,7 @@ class PlacementSpec(object):
     def __init__(self, label=None, hosts=None, count=None, all_hosts=False):
         # type: (Optional[str], Optional[List], Optional[int], bool) -> None
         if all_hosts and (count or hosts or label):
-            raise ValueError('cannot combine all:true and count|hosts|label')
+            raise ServiceSpecValidationError('cannot combine all:true and count|hosts|label')
         self.label = label
         self.hosts = []  # type: List[HostPlacementSpec]
         if hosts:
@@ -158,9 +168,9 @@ class PlacementSpec(object):
     def validate(self):
         if self.hosts and self.label:
             # TODO: a less generic Exception
-            raise ValueError('Host and label are mutually exclusive')
+            raise ServiceSpecValidationError('Host and label are mutually exclusive')
         if self.count is not None and self.count <= 0:
-            raise ValueError("num/count must be > 1")
+            raise ServiceSpecValidationError("num/count must be > 1")
 
     @classmethod
     def from_string(cls, arg):
@@ -200,7 +210,7 @@ class PlacementSpec(object):
             else:
                 strings = [arg]
         else:
-            raise ValueError('invalid placement %s' % arg)
+            raise ServiceSpecValidationError('invalid placement %s' % arg)
 
         count = None
         if strings:
@@ -229,7 +239,7 @@ class PlacementSpec(object):
         hosts = [x for x in strings if x != '*' and 'label:' not in x]
         labels = [x[6:] for x in strings if 'label:' in x]
         if len(labels) > 1:
-            raise ValueError('more than one label provided: {}'.format(labels))
+            raise ServiceSpecValidationError('more than one label provided: {}'.format(labels))
 
         ps = PlacementSpec(count=count,
                            hosts=hosts,
@@ -307,9 +317,9 @@ def servicespec_validate_add(self: ServiceSpec):
     # This must not be a method of ServiceSpec, otherwise you'll hunt
     # sub-interpreter affinity bugs.
     if not self.service_type:
-        raise ValueError('Cannot add Service: type required')
+        raise ServiceSpecValidationError('Cannot add Service: type required')
     if self.service_type in ['mds', 'rgw', 'nfs'] and not self.service_id:
-        raise ValueError('Cannot add Service: id required')
+        raise ServiceSpecValidationError('Cannot add Service: id required')
 
 
 class NFSServiceSpec(ServiceSpec):
@@ -328,7 +338,7 @@ class NFSServiceSpec(ServiceSpec):
         servicespec_validate_add(self)
 
         if not self.pool:
-            raise ValueError('Cannot add NFS: No Pool specified')
+            raise ServiceSpecValidationError('Cannot add NFS: No Pool specified')
 
 
 class RGWSpec(ServiceSpec):