From: Bin Yang Date: Mon, 15 Nov 2021 02:23:33 +0000 (+0800) Subject: Refactor watchers X-Git-Tag: 1.0.0~34 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=e60b74de2ecaccc5f2fef8e75a44649d0e90d362;p=pti%2Fo2.git Refactor watchers add watcher tree to organize watchers Signed-off-by: Bin Yang Change-Id: I14485ae39128591a80dc8ffba86e5fdde96ddd1a --- diff --git a/o2ims/adapter/clients/ocloud_sa_client.py b/o2ims/adapter/clients/ocloud_sa_client.py index e8c48a3..8ae4968 100644 --- a/o2ims/adapter/clients/ocloud_sa_client.py +++ b/o2ims/adapter/clients/ocloud_sa_client.py @@ -33,16 +33,10 @@ class StxSaOcloudClient(BaseClient): super().__init__() self.driver = driver if driver else StxSaClientImp() - # def list(self) -> List[ocloudModel.StxGenericModel]: - # return self._list() - - # def get(self, id) -> ocloudModel.StxGenericModel: - # return self._get(id) - def _get(self, id) -> ocloudModel.StxGenericModel: return self.driver.getInstanceInfo() - def _list(self): + def _list(self, **filters): return [self.driver.getInstanceInfo()] @@ -54,7 +48,7 @@ class StxSaResourcePoolClient(BaseClient): def _get(self, id) -> ocloudModel.StxGenericModel: return self.driver.getInstanceInfo() - def _list(self): + def _list(self, **filters): return [self.driver.getInstanceInfo()] @@ -66,8 +60,8 @@ class StxSaDmsClient(BaseClient): def _get(self, name) -> ocloudModel.StxGenericModel: return self.driver.getK8sDetail(name) - def _list(self): - return self.driver.getK8sList() + def _list(self, **filters): + return self.driver.getK8sList(filters) class StxPserverClient(BaseClient): @@ -78,21 +72,21 @@ class StxPserverClient(BaseClient): def _get(self, id) -> ocloudModel.StxGenericModel: return self.driver.getPserver(id) - def _list(self) -> List[ocloudModel.StxGenericModel]: - return self.driver.getPserverList() + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getPserverList(filters) class StxCpuClient(BaseClient): - def __init__(self, pserver_id): + def __init__(self): super().__init__() - self._pserver_id = pserver_id + # self._pserver_id = pserver_id self.driver = StxSaClientImp() def _get(self, id) -> ocloudModel.StxGenericModel: return self.driver.getCpu(id) - def _list(self) -> List[ocloudModel.StxGenericModel]: - return self.driver.getCpuList(self._pserver_id) + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getCpuList(filters) # internal driver which implement client call to Stx Standalone instance @@ -113,7 +107,8 @@ class StxSaClientImp(object): return ocloudModel.StxGenericModel( ResourceTypeEnum.OCLOUD, systems[0]) if systems else None - def getPserverList(self) -> List[ocloudModel.StxGenericModel]: + def getPserverList(self, **filters) -> List[ocloudModel.StxGenericModel]: + # resourcepoolid = filters.get("resourcepoolid", None) hosts = self.stxclient.ihost.list() logger.debug("host 1:" + str(hosts[0].to_dict())) return [ocloudModel.StxGenericModel( @@ -126,7 +121,7 @@ class StxSaClientImp(object): return ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER, self._hostconverter(host)) - def getK8sList(self) -> List[ocloudModel.StxGenericModel]: + def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]: k8sclusters = self.stxclient.kube_cluster.list() logger.debug("k8sresources[0]:" + str(k8sclusters[0].to_dict())) return [ocloudModel.StxGenericModel( @@ -149,7 +144,8 @@ class StxSaClientImp(object): ResourceTypeEnum.DMS, self._k8sconverter(k8scluster), self._k8shasher(k8scluster)) - def getCpuList(self, hostid) -> List[ocloudModel.StxGenericModel]: + def getCpuList(self, **filters) -> List[ocloudModel.StxGenericModel]: + hostid = filters.get("hostid", None) cpulist = self.stxclient.icpu.list(hostid) return [ocloudModel.StxGenericModel( ResourceTypeEnum.OCLOUD, diff --git a/o2ims/entrypoints/resource_watcher.py b/o2ims/entrypoints/resource_watcher.py index a3292df..b559959 100644 --- a/o2ims/entrypoints/resource_watcher.py +++ b/o2ims/entrypoints/resource_watcher.py @@ -15,11 +15,20 @@ import cotyledon from o2ims.service.watcher.worker import PollWorker -from o2ims.service.watcher.base import OcloudWatcher -from o2ims.service.watcher.base import DmsWatcher -# from o2ims.service.client.base_client import BaseClient +from o2ims.service.watcher.ocloud_watcher import OcloudWatcher +from o2ims.service.watcher.ocloud_watcher import DmsWatcher +from o2ims.service.watcher.resourcepool_watcher import ResourcePoolWatcher from o2ims.adapter.clients.ocloud_sa_client import StxSaDmsClient from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient +from o2ims.adapter.clients.ocloud_sa_client import StxSaResourcePoolClient + +from o2ims.service.watcher.pserver_watcher import PServerWatcher +from o2ims.adapter.clients.ocloud_sa_client import StxPserverClient + +from o2ims.service.watcher.pserver_cpu_watcher import PServerCpuWatcher +from o2ims.adapter.clients.ocloud_sa_client import StxCpuClient + +from o2ims.service.watcher.base import WatcherTree from o2ims import bootstrap # from o2ims import config @@ -37,16 +46,24 @@ class WatcherService(cotyledon.Service): self.args = args self.bus = bootstrap.bootstrap() self.worker = PollWorker() - # self.stxrepo = self.bus.uow.stxobjects - # tbd: 1 client per resource pool - # self.client = StxSaOcloudClient() def run(self): try: - self.worker.add_watcher(OcloudWatcher(StxSaOcloudClient(), - self.bus.uow)) - self.worker.add_watcher(DmsWatcher(StxSaDmsClient(), + root = WatcherTree(OcloudWatcher( + StxSaOcloudClient(), self.bus.uow)) + root.addchild( + DmsWatcher(StxSaDmsClient(), self.bus.uow)) + + child_respool = root.addchild( + ResourcePoolWatcher(StxSaResourcePoolClient(), self.bus.uow)) + child_pserver = child_respool.addchild( + PServerWatcher(StxPserverClient(), self.bus.uow)) + child_pserver.addchild( + PServerCpuWatcher(StxCpuClient(), self.bus.uow)) + + self.worker.add_watcher(root) + self.worker.start() except Exception as ex: logger.warning("WorkerService Exception:" + str(ex)) diff --git a/o2ims/service/client/base_client.py b/o2ims/service/client/base_client.py index 6057ab3..48047af 100644 --- a/o2ims/service/client/base_client.py +++ b/o2ims/service/client/base_client.py @@ -22,8 +22,8 @@ class BaseClient(abc.ABC): def __init__(self): pass - def list(self) -> List[ocloudModel.StxGenericModel]: - return self._list() + def list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self._list(filters) def get(self, id) -> ocloudModel.StxGenericModel: return self._get(id) @@ -33,5 +33,5 @@ class BaseClient(abc.ABC): raise NotImplementedError @abc.abstractmethod - def _list(self): + def _list(self, **filters): raise NotImplementedError diff --git a/o2ims/service/watcher/base.py b/o2ims/service/watcher/base.py index c3ff3d4..45967de 100644 --- a/o2ims/service/watcher/base.py +++ b/o2ims/service/watcher/base.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from o2ims.domain.resource_type import ResourceTypeEnum from o2ims.service.client.base_client import BaseClient from o2ims.domain.stx_object import StxGenericModel from o2ims.service.unit_of_work import AbstractUnitOfWork @@ -21,142 +20,66 @@ import logging logger = logging.getLogger(__name__) -class InvalidOcloudState(Exception): - pass - - class BaseWatcher(object): - def __init__(self, client: BaseClient) -> None: + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: super().__init__() self._client = client + self._uow = uow def targetname(self) -> str: return self._targetname() - def probe(self): - self._probe() + def probe(self, parent: object = None): + return self._probe(parent) - def _probe(self): + def _probe(self, parent: object = None): raise NotImplementedError def _targetname(self): raise NotImplementedError - -class OcloudWatcher(BaseWatcher): - def __init__(self, ocloud_client: BaseClient, - uow: AbstractUnitOfWork) -> None: - super().__init__(ocloud_client) - self._uow = uow - - def _targetname(self): - return "ocloud" - - def _probe(self): - ocloudmodel = self._client.get(None) - if ocloudmodel: - self._compare_and_update(ocloudmodel) - - def _compare_and_update(self, ocloudmodel: StxGenericModel) -> bool: - with self._uow: - # localmodel = self._uow.stxobjects.get(str(ocloudmodel.id)) - oclouds = self._uow.stxobjects.list(ResourceTypeEnum.OCLOUD) - if len(oclouds) > 1: - raise InvalidOcloudState("More than 1 ocloud is found") - if len(oclouds) == 0: - logger.info("add ocloud:" + ocloudmodel.name - + " update_at: " + str(ocloudmodel.updatetime) - + " id: " + str(ocloudmodel.id) - + " hash: " + str(ocloudmodel.hash)) - self._uow.stxobjects.add(ocloudmodel) - else: - localmodel = oclouds.pop() - if localmodel.is_outdated(ocloudmodel): - logger.info("update ocloud:" + ocloudmodel.name - + " update_at: " + str(ocloudmodel.updatetime) - + " id: " + str(ocloudmodel.id) - + " hash: " + str(ocloudmodel.hash)) - localmodel.update_by(ocloudmodel) - self._uow.stxobjects.update(localmodel) - self._uow.commit() - - -class DmsWatcher(BaseWatcher): - def __init__(self, client: BaseClient, - uow: AbstractUnitOfWork) -> None: - super().__init__(client) - self._uow = uow - - def _targetname(self): - return "dms" - - def _probe(self): - ocloudmodel = self._client.get(None) - if ocloudmodel: - self._compare_and_update(ocloudmodel) - def _compare_and_update(self, newmodel: StxGenericModel) -> bool: with self._uow: # localmodel = self._uow.stxobjects.get(ocloudmodel.id) localmodel = self._uow.stxobjects.get(str(newmodel.id)) if not localmodel: - logger.info("add dms:" + newmodel.name) + logger.info("add entry:" + newmodel.name) self._uow.stxobjects.add(newmodel) elif localmodel.is_outdated(newmodel): - logger.info("update dms:" + newmodel.name) + logger.info("update entry:" + newmodel.name) localmodel.update_by(newmodel) - self._uow.stxobjects.update(newmodel) + self._uow.stxobjects.update(localmodel) self._uow.commit() -class ResourcePoolWatcher(BaseWatcher): - def __init__(self, client: BaseClient, - uow: AbstractUnitOfWork) -> None: +# node to organize watchers in tree hierachy +class WatcherTree(object): + def __init__(self, watcher: BaseWatcher) -> None: super().__init__() - self._uow = uow - - def _targetname(self): - return "resourcepool" - - def _probe(self): - ocloudmodel = self._client.get(None) - if ocloudmodel: - logger.info("detect ocloudmodel:" + ocloudmodel.name) - self._compare_and_update(ocloudmodel) - - def _compare_and_update(self, newmodel: StxGenericModel) -> bool: - with self._uow: - # localmodel = self._uow.stxobjects.get(ocloudmodel.id) - localmodel = self._uow.stxobjects.get(str(newmodel.id)) - if not localmodel: - self._uow.stxobjects.add(newmodel) - elif localmodel.is_outdated(newmodel): - localmodel.update_by(newmodel) - self._uow.stxobjects.update(newmodel) - self._uow.commit() - - -class ResourceWatcher(BaseWatcher): - def __init__(self, client: BaseClient, - uow: AbstractUnitOfWork) -> None: - super().__init__() - self._uow = uow - - def _targetname(self): - return "resource" - - def _probe(self): - ocloudmodel = self._client.get(None) - if ocloudmodel: - self._compare_and_update(ocloudmodel) - - def _compare_and_update(self, newmodel: StxGenericModel) -> bool: - with self._uow: - # localmodel = self._repo.get(ocloudmodel.id) - localmodel = self._uow.stxobjects.get(str(newmodel.id)) - if not localmodel: - self._uow.stxobjects.add(newmodel) - elif localmodel.is_outdated(newmodel): - localmodel.update_by(newmodel) - self._uow.stxobjects.update(newmodel) - self._uow.commit() + self.watcher = watcher + self.children = {} + + def addchild(self, watcher: BaseWatcher) -> object: + child = WatcherTree(watcher) + self.children[watcher.targetname()] = child + return child + + def removechild(self, targetname: str) -> object: + return self.children.pop(targetname) + + # probe all resources by parent, depth = 0 for indefinite recursive + def probe(self, parentresource=None, depth: int = 0): + logger.debug("probe resources with watcher: " + + self.watcher.targetname()) + childdepth = depth - 1 if depth > 0 else 0 + resources = self.watcher.probe(parentresource) + logger.debug("probe returns " + str(len(resources)) + "resources") + + if depth == 1: + # stop recursive + return + + for res in resources: + for node in self.children: + node.probe(res, childdepth) diff --git a/o2ims/service/watcher/ocloud_watcher.py b/o2ims/service/watcher/ocloud_watcher.py new file mode 100644 index 0000000..acdc655 --- /dev/null +++ b/o2ims/service/watcher/ocloud_watcher.py @@ -0,0 +1,80 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from o2ims.domain.resource_type import ResourceTypeEnum +from o2ims.service.client.base_client import BaseClient +from o2ims.domain.stx_object import StxGenericModel +from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.base import BaseWatcher + +import logging +logger = logging.getLogger(__name__) + + +class InvalidOcloudState(Exception): + pass + + +class OcloudWatcher(BaseWatcher): + def __init__(self, ocloud_client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(ocloud_client, uow) + + def _targetname(self): + return "ocloud" + + def _probe(self, parent: object = None): + ocloudmodel = self._client.get(None) + if ocloudmodel: + self._compare_and_update(ocloudmodel) + return [ocloudmodel] + + def _compare_and_update(self, ocloudmodel: StxGenericModel) -> bool: + with self._uow: + # localmodel = self._uow.stxobjects.get(str(ocloudmodel.id)) + oclouds = self._uow.stxobjects.list(ResourceTypeEnum.OCLOUD) + if len(oclouds) > 1: + raise InvalidOcloudState("More than 1 ocloud is found") + if len(oclouds) == 0: + logger.info("add ocloud:" + ocloudmodel.name + + " update_at: " + str(ocloudmodel.updatetime) + + " id: " + str(ocloudmodel.id) + + " hash: " + str(ocloudmodel.hash)) + self._uow.stxobjects.add(ocloudmodel) + else: + localmodel = oclouds.pop() + if localmodel.is_outdated(ocloudmodel): + logger.info("update ocloud:" + ocloudmodel.name + + " update_at: " + str(ocloudmodel.updatetime) + + " id: " + str(ocloudmodel.id) + + " hash: " + str(ocloudmodel.hash)) + localmodel.update_by(ocloudmodel) + self._uow.stxobjects.update(localmodel) + self._uow.commit() + + +class DmsWatcher(BaseWatcher): + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(client, uow) + + def _targetname(self): + return "dms" + + def _probe(self, parent: object = None): + ocloudid = parent.id if parent else None + newmodels = self._client.list(ocloudid=ocloudid) + for newmodel in newmodels: + super()._compare_and_update(newmodel) + return newmodels diff --git a/o2ims/service/watcher/pserver_cpu_watcher.py b/o2ims/service/watcher/pserver_cpu_watcher.py new file mode 100644 index 0000000..e99cdc0 --- /dev/null +++ b/o2ims/service/watcher/pserver_cpu_watcher.py @@ -0,0 +1,36 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from o2ims.service.client.base_client import BaseClient +from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.resource_watcher import ResourceWatcher + +import logging +logger = logging.getLogger(__name__) + + +class PServerCpuWatcher(ResourceWatcher): + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(client, uow) + + def _targetname(self): + return "pserver_cpu" + + def _probe(self, parent: object = None): + hostid = parent.id if parent else None + newmodels = self._client.list(hostid=hostid) + for newmodel in newmodels: + super()._compare_and_update(newmodel) + return newmodels diff --git a/o2ims/service/watcher/pserver_watcher.py b/o2ims/service/watcher/pserver_watcher.py new file mode 100644 index 0000000..ec21564 --- /dev/null +++ b/o2ims/service/watcher/pserver_watcher.py @@ -0,0 +1,36 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from o2ims.service.client.base_client import BaseClient +from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.resource_watcher import ResourceWatcher + +import logging +logger = logging.getLogger(__name__) + + +class PServerWatcher(ResourceWatcher): + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(client, uow) + + def _targetname(self): + return "pserver" + + def _probe(self, parent: object = None): + resourcepoolid = parent.id if parent else None + newmodels = self._client.list(resourcepoolid=resourcepoolid) + for newmodel in newmodels: + super()._compare_and_update(newmodel) + return newmodels diff --git a/o2ims/service/watcher/resource_watcher.py b/o2ims/service/watcher/resource_watcher.py new file mode 100644 index 0000000..c54318a --- /dev/null +++ b/o2ims/service/watcher/resource_watcher.py @@ -0,0 +1,36 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from o2ims.service.client.base_client import BaseClient +from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.base import BaseWatcher + +import logging +logger = logging.getLogger(__name__) + + +class ResourceWatcher(BaseWatcher): + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(client, uow) + + def _targetname(self): + return "resource" + + def _probe(self, parent: object = None): + parentid = parent.id if parent else None + newmodels = self._client.get(parentid=parentid) + for newmodel in newmodels: + super()._compare_and_update(newmodel) + return newmodels diff --git a/o2ims/service/watcher/resourcepool_watcher.py b/o2ims/service/watcher/resourcepool_watcher.py new file mode 100644 index 0000000..6caf5fd --- /dev/null +++ b/o2ims/service/watcher/resourcepool_watcher.py @@ -0,0 +1,37 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from o2ims.service.client.base_client import BaseClient +from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.base import BaseWatcher + +import logging +logger = logging.getLogger(__name__) + + +class ResourcePoolWatcher(BaseWatcher): + def __init__(self, client: BaseClient, + uow: AbstractUnitOfWork) -> None: + super().__init__(client, uow) + + def _targetname(self): + return "resourcepool" + + def _probe(self, parent: object = None): + ocloudid = parent.id if parent else None + newmodels = self._client.list(ocloudid=ocloudid) + for newmodel in newmodels: + logger.info("detect ocloudmodel:" + newmodel.name) + super()._compare_and_update(newmodel) + return newmodels diff --git a/o2ims/service/watcher/worker.py b/o2ims/service/watcher/worker.py index 11bdfdc..9b87ebe 100644 --- a/o2ims/service/watcher/worker.py +++ b/o2ims/service/watcher/worker.py @@ -14,7 +14,7 @@ import time import sched -from o2ims.service.watcher.base import BaseWatcher +from o2ims.service.watcher.base import WatcherTree import logging logger = logging.getLogger(__name__) @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) class PollWorker(object): def __init__(self, interval=10) -> None: super().__init__() - self.watchers = {} + self.watchers = [] self.schedinstance = sched.scheduler(time.time, time.sleep) self.schedinterval = interval self._stopped = True @@ -34,19 +34,19 @@ class PollWorker(object): else: raise Exception("Invalid interval:" + interval) - def add_watcher(self, watcher: BaseWatcher): - self.watchers[watcher.targetname()] = watcher + def add_watcher(self, watcher: WatcherTree): + self.watchers.append(watcher) def _repeat(self): logger.debug("_repeat started") if self._stopped: return - for w in self.watchers.keys(): + for w in self.watchers: try: - logger.debug("about to probe:"+w) - self.watchers[w].probe() + # logger.debug("about to probe:"+w) + w.probe(None) except Exception as ex: - logger.warning("Worker:" + w + " raises exception:" + str(ex)) + logger.warning("Worker raises exception:" + str(ex)) continue self.schedinstance.enter(self.schedinterval, 1, self._repeat) diff --git a/tests/integration-ocloud/test_clientdriver_stx_sa.py b/tests/integration-ocloud/test_clientdriver_stx_sa.py index 4e45070..4cf4c64 100644 --- a/tests/integration-ocloud/test_clientdriver_stx_sa.py +++ b/tests/integration-ocloud/test_clientdriver_stx_sa.py @@ -81,7 +81,7 @@ def test_get_cpu_list(real_stx_aio_client): hostlist = stxSaClientImp.getPserverList() assert len(hostlist) > 0 - cpulist = stxSaClientImp.getCpuList(hostlist[0].id) + cpulist = stxSaClientImp.getCpuList(hostid=hostlist[0].id) assert len(cpulist) > 0 cpu1 = cpulist[0] cpu2 = stxSaClientImp.getCpu(cpu1.id) diff --git a/tests/unit/test_watcher.py b/tests/unit/test_watcher.py index 76f5d78..b0aded4 100644 --- a/tests/unit/test_watcher.py +++ b/tests/unit/test_watcher.py @@ -21,12 +21,13 @@ from o2ims.service.client.base_client import BaseClient from o2ims.domain import ocloud from o2ims import config import uuid -from o2ims.service.watcher.base import BaseWatcher, OcloudWatcher +from o2ims.service.watcher.base import BaseWatcher, WatcherTree from o2ims.domain import stx_object as ocloudModel from o2ims.adapter.ocloud_repository import OcloudRepository from o2ims.domain.stx_repo import StxObjectRepository from o2ims.service.watcher import worker from o2ims.service.unit_of_work import AbstractUnitOfWork +from o2ims.service.watcher.ocloud_watcher import OcloudWatcher class FakeOcloudClient(BaseClient): @@ -132,7 +133,7 @@ def test_watchers_worker(): class FakeOCloudWatcher(BaseWatcher): def __init__(self, client: BaseClient, repo: OcloudRepository) -> None: - super().__init__(client) + super().__init__(client, None) self.fakeOcloudWatcherCounter = 0 self._client = client self._repo = repo @@ -140,11 +141,13 @@ def test_watchers_worker(): def _targetname(self): return "fakeocloudwatcher" - def _probe(self): + def _probe(self, parent: object=None): + # import pdb; pdb.set_trace() self.fakeOcloudWatcherCounter += 1 # hacking to stop the blocking sched task if self.fakeOcloudWatcherCounter > 2: testedworker.stop() + return [] # fakeRepo = FakeOcloudRepo() @@ -153,8 +156,10 @@ def test_watchers_worker(): fakeClient = FakeOcloudClient() fakewatcher = FakeOCloudWatcher(fakeClient, fakeuow) + root = WatcherTree(fakewatcher) + testedworker.set_interval(1) - testedworker.add_watcher(fakewatcher) + testedworker.add_watcher(root) assert fakewatcher.fakeOcloudWatcherCounter == 0 count1 = fakewatcher.fakeOcloudWatcherCounter