1. Add auditor for resource pool, pserver and cpu/memory/port/interface of pserver
2. CUpdate resource type column, auto create resource type before create cpu/memory/port/interface resource
3. Give the git clone parameters to make download size lesser
Issue-ID: INF-236
Issue-ID: INF-235
Issue-ID: INF-234
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
Change-Id: I7ddc7d8c18b7f3c17b22cdd35bdf68864f32f780
# in case git repo is not accessable\r
# RUN mkdir -p /cgtsclient\r
# COPY temp/config /cgtsclient/\r
-RUN git clone https://opendev.org/starlingx/config.git /cgtsclient\r
+RUN git clone --depth 1 --branch master https://opendev.org/starlingx/config.git /cgtsclient\r
RUN pip install -e /cgtsclient/sysinv/cgts-client/cgts-client/\r
\r
# RUN mkdir -p /distcloud-client\r
# COPY temp/distcloud-client /distcloud-client/\r
-RUN git clone https://opendev.org/starlingx/distcloud-client.git /distcloud-client/\r
+RUN git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git /distcloud-client/\r
RUN pip install -e /distcloud-client/distributedcloud-client\r
# in case git repo is not accessable\r
\r
\r
mkdir -p temp\r
cd temp\r
-git clone https://opendev.org/starlingx/config.git\r
-git clone https://opendev.org/starlingx/distcloud-client.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/config.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git\r
cd -\r
\r
docker-compose build\r
```sh\r
mkdir -p temp\r
cd temp\r
-git clone https://opendev.org/starlingx/config.git\r
-git clone https://opendev.org/starlingx/distcloud-client.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/config.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git\r
cd -\r
```\r
\r
from o2ims.service.watcher.pserver_cpu_watcher import PServerCpuWatcher\r
from o2ims.adapter.clients.ocloud_sa_client import StxCpuClient\r
\r
+from o2ims.service.watcher.pserver_mem_watcher import PServerMemWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxMemClient\r
+\r
+from o2ims.service.watcher.pserver_if_watcher import PServerIfWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxIfClient\r
+\r
+from o2ims.service.watcher.pserver_port_watcher import PServerPortWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxPortClient\r
+\r
from o2common.helper import o2logging\r
logger = o2logging.get_logger(__name__)\r
\r
PServerWatcher(StxPserverClient(), self.bus))\r
child_pserver.addchild(\r
PServerCpuWatcher(StxCpuClient(), self.bus))\r
+ child_pserver.addchild(\r
+ PServerMemWatcher(StxMemClient(), self.bus))\r
+ child_pserver.addchild(\r
+ PServerIfWatcher(StxIfClient(), self.bus))\r
+ child_pserver.addchild(\r
+ PServerPortWatcher(StxPortClient(), self.bus))\r
\r
self.worker.add_watcher(root)\r
\r
from __future__ import annotations
# from dataclasses import asdict
from typing import List, Dict, Callable, Type
-from o2ims.service.auditor import dms_handler
# TYPE_CHECKING
from o2ims.domain import commands, events
-from o2ims.service.auditor import ocloud_handler
+from o2ims.service.auditor import ocloud_handler, dms_handler, \
+ resourcepool_handler, pserver_handler, pserver_cpu_handler, \
+ pserver_mem_handler, pserver_port_handler, pserver_if_handler
# if TYPE_CHECKING:
# from . import unit_of_work
COMMAND_HANDLERS = {
commands.UpdateOCloud: ocloud_handler.update_ocloud,
- commands.UpdateDms: dms_handler.update_dms
+ commands.UpdateDms: dms_handler.update_dms,
+ commands.UpdateResourcePool: resourcepool_handler.update_resourcepool,
+ commands.UpdatePserver: pserver_handler.update_pserver,
+ commands.UpdatePserverCpu: pserver_cpu_handler.update_pserver_cpu,
+ commands.UpdatePserverMem: pserver_mem_handler.update_pserver_mem,
+ commands.UpdatePserverIf: pserver_if_handler.update_pserver_if,
+ commands.UpdatePserverPort: pserver_port_handler.update_pserver_port,
} # type: Dict[Type[commands.Command], Callable]
class AgRoot:\r
def __init__(self) -> None:\r
self.hash = ""\r
- # self.id = ""\r
self.updatetime = datetime.now()\r
self.createtime = datetime.now()\r
self.events = [] # type: List[Event]\r
+ # self.id = ""\r
def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
return self.driver.getCpuList(**filters)\r
\r
-# internal driver which implement client call to Stx Standalone instance\r
+\r
+class StxMemClient(BaseClient):\r
+ def __init__(self):\r
+ super().__init__()\r
+ # self._pserver_id = pserver_id\r
+ self.driver = StxSaClientImp()\r
+\r
+ def _get(self, id) -> ocloudModel.StxGenericModel:\r
+ return self.driver.getMem(id)\r
+\r
+ def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ return self.driver.getMemList(**filters)\r
+\r
+\r
+class StxPortClient(BaseClient):\r
+ def __init__(self):\r
+ super().__init__()\r
+ # self._pserver_id = pserver_id\r
+ self.driver = StxSaClientImp()\r
+\r
+ def _get(self, id) -> ocloudModel.StxGenericModel:\r
+ return self.driver.getPort(id)\r
+\r
+ def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ return self.driver.getPortList(**filters)\r
+\r
+\r
+class StxIfClient(BaseClient):\r
+ def __init__(self):\r
+ super().__init__()\r
+ # self._pserver_id = pserver_id\r
+ self.driver = StxSaClientImp()\r
+\r
+ def _get(self, id) -> ocloudModel.StxGenericModel:\r
+ return self.driver.getIf(id)\r
+\r
+ def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ return self.driver.getIfList(**filters)\r
\r
\r
+# internal driver which implement client call to Stx Standalone instance\r
class StxSaClientImp(object):\r
def __init__(self, stx_client=None):\r
super().__init__()\r
logger.debug("host 1:" + str(hosts[0].to_dict()))\r
return [ocloudModel.StxGenericModel(\r
ResourceTypeEnum.PSERVER, self._hostconverter(host))\r
- for host in hosts if host]\r
+ for host in hosts if host]\r
\r
def getPserver(self, id) -> ocloudModel.StxGenericModel:\r
host = self.stxclient.ihost.get(id)\r
return ocloudModel.StxGenericModel(\r
ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo))\r
\r
+ def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query imem list"\r
+ memlist = self.stxclient.imemory.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_RAM,\r
+ self._memconverter(memories)) for memories in memlist if memories]\r
+\r
+ def getMem(self, id) -> ocloudModel.StxGenericModel:\r
+ meminfo = self.stxclient.imemory.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo))\r
+\r
+ def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query port list"\r
+ portlist = self.stxclient.port.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_PORT,\r
+ port) for port in portlist if port]\r
+\r
+ def getPort(self, id) -> ocloudModel.StxGenericModel:\r
+ portinfo = self.stxclient.port.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_PORT, portinfo)\r
+\r
+ def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query iinterface list"\r
+ iflist = self.stxclient.iinterface.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_IF,\r
+ self._ifconverter(ifs)) for ifs in iflist if ifs]\r
+\r
+ def getIf(self, id) -> ocloudModel.StxGenericModel:\r
+ ifinfo = self.stxclient.iinterface.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo))\r
+\r
def _getIsystems(self):\r
return self.stxclient.isystem.list()\r
\r
'more than one system exists in the account.')\r
return isystems[0]\r
\r
- @staticmethod\r
+ @ staticmethod\r
def _hostconverter(host):\r
setattr(host, "name", host.hostname)\r
return host\r
\r
- @staticmethod\r
+ @ staticmethod\r
def _cpuconverter(cpu):\r
- setattr(cpu, "name", "core-"+str(cpu.core))\r
+ setattr(cpu, "name", "cpu-"+str(cpu.cpu))\r
return cpu\r
\r
- @staticmethod\r
+ @ staticmethod\r
+ def _memconverter(mem):\r
+ setattr(mem, "name", "mem-node-"+str(mem.numa_node))\r
+ return mem\r
+\r
+ @ staticmethod\r
+ def _ifconverter(ifs):\r
+ setattr(ifs, "name", ifs.ifname)\r
+ setattr(ifs, 'updated_at', None)\r
+ setattr(ifs, 'created_at', None)\r
+ return ifs\r
+\r
+ @ staticmethod\r
def _k8sconverter(cluster):\r
setattr(cluster, "name", cluster.cluster_name)\r
setattr(cluster, "uuid",\r
uuid.uuid3(uuid.NAMESPACE_URL, cluster.cluster_name))\r
setattr(cluster, 'updated_at', None)\r
setattr(cluster, 'created_at', None)\r
+ setattr(cluster, 'events', [])\r
logger.debug("k8s cluster name/uuid:" +\r
cluster.name + "/" + str(cluster.uuid))\r
return cluster\r
\r
- @staticmethod\r
+ @ staticmethod\r
def _k8shasher(cluster):\r
return str(hash((cluster.cluster_name,\r
cluster.cluster_api_endpoint, cluster.admin_user)))\r
from o2ims.domain.ocloud_repo import OcloudRepository, ResourceTypeRepository,\
ResourcePoolRepository, ResourceRepository, DeploymentManagerRepository,\
SubscriptionRepository
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
class OcloudSqlAlchemyRepository(OcloudRepository):
# See the License for the specific language governing permissions and\r
# limitations under the License.\r
\r
+# from typing_extensions import Required\r
from sqlalchemy import (\r
Table,\r
MetaData,\r
Column,\r
Integer,\r
String,\r
+ Text,\r
+ Enum,\r
# Date,\r
DateTime,\r
ForeignKey,\r
# from sqlalchemy.sql.sqltypes import Integer\r
\r
from o2ims.domain import ocloud as ocloudModel\r
+from o2ims.domain.resource_type import ResourceTypeEnum\r
\r
from o2common.helper import o2logging\r
logger = o2logging.get_logger(__name__)\r
Column("hash", String(255)),\r
\r
Column("resourceTypeId", String(255), primary_key=True),\r
+ Column("resourceTypeEnum", Enum(ResourceTypeEnum), nullable=False),\r
Column("oCloudId", ForeignKey("ocloud.oCloudId")),\r
Column("name", String(255)),\r
Column("vendor", String(255)),\r
Column("resourceTypeId", ForeignKey("resourcetype.resourceTypeId")),\r
Column("resourcePoolId", ForeignKey("resourcepool.resourcePoolId")),\r
# Column("globalAssetId", String(255)),\r
- # Column("oCloudId", ForeignKey("ocloud.oCloudId")),\r
Column("parentId", String(255)),\r
Column("description", String(255)),\r
- # Column("elements", String(255))\r
+ Column("elements", Text())\r
# Column("extensions", String(1024))\r
)\r
\r
parentid: str
+@dataclass
+class UpdateResourceType(UpdateStxObject):
+ parentid: str
+
+
@dataclass
class UpdateResource(UpdateStxObject):
parentid: str
+@dataclass
+class UpdatePserver(UpdateResource):
+ pass
+
+
@dataclass
class UpdatePserverCpu(UpdateResource):
pass
@dataclass
-class UpdatePserver(UpdateResource):
+class UpdatePserverMem(UpdateResource):
+ pass
+
+
+@dataclass
+class UpdatePserverIf(UpdateResource):
+ pass
+
+
+@dataclass
+class UpdatePserverPort(UpdateResource):
pass
@dataclass
class OcloudUpdated(Event):
oCloudId: str
+
+
+@dataclass
+class ResourceTypeUpdated(Event):
+ oCloudId: str
description: str = '') -> None:\r
super().__init__()\r
self.resourceTypeId = typeid\r
+ self.version_number = 0\r
self.oCloudId = ocloudid\r
- self.resourceTypeEnum = typeEnum.value\r
+ self.resourceTypeEnum = typeEnum\r
self.name = name\r
self.vender = vender\r
self.model = model\r
\r
class Resource(AgRoot):\r
def __init__(self, resourceId: str, resourceTypeId: str,\r
- resourcePoolId: str, oCloudId: str = '',\r
- parentId: str = '', elements: list = [],\r
+ resourcePoolId: str, parentId: str = '',\r
+ gAssetId: str = '', elements: str = '',\r
description: str = '') -> None:\r
super().__init__()\r
self.resourceId = resourceId\r
self.version_number = 0\r
- self.oCloudId = oCloudId\r
self.resourceTypeId = resourceTypeId\r
self.resourcePoolId = resourcePoolId\r
+ self.globalAssetId = gAssetId\r
self.parentId = parentId\r
- self.path = str()\r
self.elements = elements\r
self.description = description\r
self.extensions = []\r
self.deploymentManagers = []\r
self.resourceTypes = []\r
self.extensions = []\r
- # self.events = []\r
\r
# def addDeploymentManager(self,\r
# deploymentManager: DeploymentManager):\r
\r
\r
class ResourceTypeEnum(Enum):\r
- OCLOUD = 1,\r
- RESOURCE_POOL = 2,\r
- DMS = 3,\r
+ OCLOUD = 1\r
+ RESOURCE_POOL = 2\r
+ DMS = 3\r
PSERVER = 11\r
PSERVER_CPU = 12\r
PSERVER_RAM = 13\r
+ PSERVER_PORT = 14\r
+ PSERVER_IF = 15\r
\r
\r
class InvalidOcloudState(Exception):\r
class StxGenericModel(AgRoot):\r
def __init__(self, type: ResourceTypeEnum,\r
api_response: dict = None, content_hash=None) -> None:\r
+ super().__init__()\r
if api_response:\r
self.id = str(api_response.uuid)\r
self.type = type\r
def create_by(stxobj: StxGenericModel, parentid: str) -> DeploymentManager:
dmsendpoint = config.get_api_url() +\
- config.get_o2dms_api_base() + "/" + stxobj.id
+ config.get_o2dms_api_base() + "/" + stxobj.id
description = "A DMS"
ocloudid = parentid
supportedLocations = ''
target.hash = stxobj.hash
target.oCloudId = parentid
target.version_number = target.version_number + 1
+ target.events = []
# ocloud.content = stxobj.content
ocloud.hash = stxobj.hash
ocloud.version_number = ocloud.version_number + 1
+ ocloud.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_pserver_cpu(
+ cmd: commands.UpdatePserverCpu,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ p_resource = uow.resources.get(cmd.parentid)
+ resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+ res = uow.session.execute(
+ '''
+ SELECT "resourceTypeId", "oCloudId", "name"
+ FROM resourcetype
+ WHERE "resourceTypeEnum" = :resource_type_enum
+ ''',
+ dict(resource_type_enum=stxobj.type.name)
+ )
+ first = res.first()
+ if first is None:
+ resourcetype_id = str(uuid.uuid4())
+ uow.resource_types.add(ResourceType(
+ resourcetype_id,
+ 'pserver_cpu', stxobj.type,
+ resourcepool.oCloudId))
+ else:
+ resourcetype_id = first['resourceTypeId']
+
+ resource = uow.resources.get(stxobj.id)
+ if not resource:
+ logger.info("add the cpu of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, p_resource, resourcetype_id)
+ uow.resources.add(localmodel)
+
+ logger.info("Add the cpu of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource
+ if is_outdated(localmodel, stxobj):
+ logger.info("update cpu of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, p_resource)
+ uow.resources.update(localmodel)
+
+ logger.info("Update the cpu of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+ return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+ -> Resource:
+ # content = json.loads(stxobj.content)
+ resourcetype_id = resourcetype_id
+ resourcepool_id = parent.resourcePoolId
+ parent_id = parent.resourceId
+ gAssetId = '' # TODO: global ID
+ description = "A CPU resource of the physical server"
+ resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+ parent_id, gAssetId, stxobj.content, description)
+ resource.createtime = stxobj.createtime
+ resource.updatetime = stxobj.updatetime
+ resource.hash = stxobj.hash
+
+ return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourceId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.version_number = target.version_number + 1
+ target.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_pserver(
+ cmd: commands.UpdatePserver,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ resourcepool = uow.resource_pools.get(cmd.parentid)
+
+ # res = uow.session.execute(select(resourcetype).where(
+ # resourcetype.c.resourceTypeEnum == stxobj.type))
+ res = uow.session.execute(
+ '''
+ SELECT "resourceTypeId", "oCloudId", "name"
+ FROM resourcetype
+ WHERE "resourceTypeEnum" = :resource_type_enum
+ ''',
+ dict(resource_type_enum=stxobj.type.name)
+ )
+ first = res.first()
+ if first is None:
+ resourcetype_id = str(uuid.uuid4())
+ uow.resource_types.add(ResourceType(
+ resourcetype_id,
+ 'pserver', stxobj.type,
+ resourcepool.oCloudId))
+ else:
+ resourcetype_id = first['resourceTypeId']
+
+ resource = uow.resources.get(stxobj.id)
+ if not resource:
+ logger.info("add pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, cmd.parentid, resourcetype_id)
+ uow.resources.add(localmodel)
+
+ logger.info("Add the pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource
+ if is_outdated(localmodel, stxobj):
+ logger.info("update pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, cmd.parentid)
+ uow.resources.update(localmodel)
+
+ logger.info("Update the pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+ return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parentid: str, resourcetype_id: str) \
+ -> Resource:
+ # content = json.loads(stxobj.content)
+ resourcetype_id = resourcetype_id
+ resourcepool_id = parentid
+ parent_id = parentid
+ gAssetId = '' # TODO: global ID
+ description = "A physical server resource"
+ resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+ parent_id, gAssetId, stxobj.content, description)
+ resource.createtime = stxobj.createtime
+ resource.updatetime = stxobj.updatetime
+ resource.hash = stxobj.hash
+
+ return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourceId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.version_number = target.version_number + 1
+ target.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_pserver_if(
+ cmd: commands.UpdatePserverIf,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ p_resource = uow.resources.get(cmd.parentid)
+ resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+ res = uow.session.execute(
+ '''
+ SELECT "resourceTypeId", "oCloudId", "name"
+ FROM resourcetype
+ WHERE "resourceTypeEnum" = :resource_type_enum
+ ''',
+ dict(resource_type_enum=stxobj.type.name)
+ )
+ first = res.first()
+ if first is None:
+ resourcetype_id = str(uuid.uuid4())
+ uow.resource_types.add(ResourceType(
+ resourcetype_id,
+ 'pserver_if', stxobj.type,
+ resourcepool.oCloudId))
+ else:
+ resourcetype_id = first['resourceTypeId']
+
+ resource = uow.resources.get(stxobj.id)
+ if not resource:
+ logger.info("add the interface of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, p_resource, resourcetype_id)
+ uow.resources.add(localmodel)
+
+ logger.info("Add the interface of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource
+ if is_outdated(localmodel, stxobj):
+ logger.info("update interface of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, p_resource)
+ uow.resources.update(localmodel)
+
+ logger.info("Update the interface of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+ return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+ -> Resource:
+ # content = json.loads(stxobj.content)
+ resourcetype_id = resourcetype_id
+ resourcepool_id = parent.resourcePoolId
+ parent_id = parent.resourceId
+ gAssetId = '' # TODO: global ID
+ description = "A interface resource of the physical server"
+ resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+ parent_id, gAssetId, stxobj.content, description)
+ resource.createtime = stxobj.createtime
+ resource.updatetime = stxobj.updatetime
+ resource.hash = stxobj.hash
+
+ return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourceId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.version_number = target.version_number + 1
+ target.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_pserver_mem(
+ cmd: commands.UpdatePserverMem,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ p_resource = uow.resources.get(cmd.parentid)
+ resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+ res = uow.session.execute(
+ '''
+ SELECT "resourceTypeId", "oCloudId", "name"
+ FROM resourcetype
+ WHERE "resourceTypeEnum" = :resource_type_enum
+ ''',
+ dict(resource_type_enum=stxobj.type.name)
+ )
+ first = res.first()
+ if first is None:
+ resourcetype_id = str(uuid.uuid4())
+ uow.resource_types.add(ResourceType(
+ resourcetype_id,
+ 'pserver_mem', stxobj.type,
+ resourcepool.oCloudId))
+ else:
+ resourcetype_id = first['resourceTypeId']
+
+ resource = uow.resources.get(stxobj.id)
+ if not resource:
+ logger.info("add the memory of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, p_resource, resourcetype_id)
+ uow.resources.add(localmodel)
+
+ logger.info("Add the memory of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource
+ if is_outdated(localmodel, stxobj):
+ logger.info("update memory of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, p_resource)
+ uow.resources.update(localmodel)
+
+ logger.info("Update the memory of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+ return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+ -> Resource:
+ # content = json.loads(stxobj.content)
+ resourcetype_id = resourcetype_id
+ resourcepool_id = parent.resourcePoolId
+ parent_id = parent.resourceId
+ gAssetId = '' # TODO: global ID
+ description = "A memory resource of the physical server"
+ resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+ parent_id, gAssetId, stxobj.content, description)
+ resource.createtime = stxobj.createtime
+ resource.updatetime = stxobj.updatetime
+ resource.hash = stxobj.hash
+
+ return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourceId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.version_number = target.version_number + 1
+ target.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_pserver_port(
+ cmd: commands.UpdatePserverPort,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ p_resource = uow.resources.get(cmd.parentid)
+ resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+ res = uow.session.execute(
+ '''
+ SELECT "resourceTypeId", "oCloudId", "name"
+ FROM resourcetype
+ WHERE "resourceTypeEnum" = :resource_type_enum
+ ''',
+ dict(resource_type_enum=stxobj.type.name)
+ )
+ first = res.first()
+ if first is None:
+ resourcetype_id = str(uuid.uuid4())
+ uow.resource_types.add(ResourceType(
+ resourcetype_id,
+ 'pserver_port', stxobj.type,
+ resourcepool.oCloudId))
+ else:
+ resourcetype_id = first['resourceTypeId']
+
+ resource = uow.resources.get(stxobj.id)
+ if not resource:
+ logger.info("add the port of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, p_resource, resourcetype_id)
+ uow.resources.add(localmodel)
+
+ logger.info("Add the port of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource
+ if is_outdated(localmodel, stxobj):
+ logger.info("update port of pserver:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, p_resource)
+ uow.resources.update(localmodel)
+
+ logger.info("Update the port of pserver: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+ return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+ -> Resource:
+ # content = json.loads(stxobj.content)
+ resourcetype_id = resourcetype_id
+ resourcepool_id = parent.resourcePoolId
+ parent_id = parent.resourceId
+ gAssetId = '' # TODO: global ID
+ description = "A port resource of the physical server"
+ resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+ parent_id, gAssetId, stxobj.content, description)
+ resource.createtime = stxobj.createtime
+ resource.updatetime = stxobj.updatetime
+ resource.hash = stxobj.hash
+
+ return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourceId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.version_number = target.version_number + 1
+ target.events = []
--- /dev/null
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+import json
+
+from o2ims.domain.stx_object import StxGenericModel
+# from dataclasses import asdict
+# from typing import List, Dict, Callable, Type
+# TYPE_CHECKING
+from o2ims.domain import commands
+from o2common.service.unit_of_work import AbstractUnitOfWork
+# from o2ims.domain.resource_type import InvalidOcloudState
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import ResourcePool
+# if TYPE_CHECKING:
+# from . import unit_of_work
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+ pass
+
+
+def update_resourcepool(
+ cmd: commands.UpdateResourcePool,
+ uow: AbstractUnitOfWork
+):
+ stxobj = cmd.data
+ with uow:
+ resource_pool = uow.resource_pools.get(stxobj.id)
+ if not resource_pool:
+ logger.info("add resource pool:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ localmodel = create_by(stxobj, cmd.parentid)
+ uow.resource_pools.add(localmodel)
+
+ logger.info("Add the resource pool: " + stxobj.id
+ + ", name: " + stxobj.name)
+ else:
+ localmodel = resource_pool
+ if is_outdated(localmodel, stxobj):
+ logger.info("update resource pool:" + stxobj.name
+ + " update_at: " + str(stxobj.updatetime)
+ + " id: " + str(stxobj.id)
+ + " hash: " + str(stxobj.hash))
+ update_by(localmodel, stxobj, cmd.parentid)
+ uow.resource_pools.update(localmodel)
+
+ logger.info("Update the resource pool: " + stxobj.id
+ + ", name: " + stxobj.name)
+ uow.commit()
+
+
+def is_outdated(resourcepool: ResourcePool, stxobj: StxGenericModel):
+ return True if resourcepool.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parentid: str) -> ResourcePool:
+ content = json.loads(stxobj.content)
+ globalcloudId = stxobj.id # to be updated
+ description = "A Resource Pool"
+ resourcepool = ResourcePool(stxobj.id, stxobj.name,
+ content['location'],
+ parentid, globalcloudId, description)
+ resourcepool.createtime = stxobj.createtime
+ resourcepool.updatetime = stxobj.updatetime
+ resourcepool.hash = stxobj.hash
+
+ return resourcepool
+
+
+def update_by(target: ResourcePool, stxobj: StxGenericModel,
+ parentid: str) -> None:
+ if target.resourcePoolId != stxobj.id:
+ raise MismatchedModel("Mismatched Id")
+ content = json.loads(stxobj.content)
+ target.name = stxobj.name
+ target.location = content['location']
+ target.createtime = stxobj.createtime
+ target.updatetime = stxobj.updatetime
+ target.hash = stxobj.hash
+ target.oCloudId = parentid
+ target.version_number = target.version_number + 1
+ target.events = []
def _probe(self, parent: StxGenericModel):\r
hostid = parent.id\r
newmodels = self._client.list(hostid=hostid)\r
- # for newmodel in newmodels:\r
- # super()._compare_and_update(newmodel)\r
- # return newmodels\r
return [commands.UpdatePserverCpu(data=m, parentid=hostid)\r
for m in newmodels]\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from o2ims.domain.stx_object import StxGenericModel\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2ims.service.watcher.resource_watcher import ResourceWatcher\r
+from o2ims.domain import commands\r
+from o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerIfWatcher(ResourceWatcher):\r
+ def __init__(self, client: BaseClient,\r
+ bus: MessageBus) -> None:\r
+ super().__init__(client, bus)\r
+\r
+ def _targetname(self):\r
+ return "pserver_if"\r
+\r
+ def _probe(self, parent: StxGenericModel):\r
+ hostid = parent.id\r
+ newmodels = self._client.list(hostid=hostid)\r
+ return [commands.UpdatePserverIf(data=m, parentid=hostid)\r
+ for m in newmodels]\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from o2ims.domain.stx_object import StxGenericModel\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2ims.service.watcher.resource_watcher import ResourceWatcher\r
+from o2ims.domain import commands\r
+from o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerMemWatcher(ResourceWatcher):\r
+ def __init__(self, client: BaseClient,\r
+ bus: MessageBus) -> None:\r
+ super().__init__(client, bus)\r
+\r
+ def _targetname(self):\r
+ return "pserver_mem"\r
+\r
+ def _probe(self, parent: StxGenericModel):\r
+ hostid = parent.id\r
+ newmodels = self._client.list(hostid=hostid)\r
+ return [commands.UpdatePserverMem(data=m, parentid=hostid)\r
+ for m in newmodels]\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from o2ims.domain.stx_object import StxGenericModel\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2ims.service.watcher.resource_watcher import ResourceWatcher\r
+from o2ims.domain import commands\r
+from o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerPortWatcher(ResourceWatcher):\r
+ def __init__(self, client: BaseClient,\r
+ bus: MessageBus) -> None:\r
+ super().__init__(client, bus)\r
+\r
+ def _targetname(self):\r
+ return "pserver_port"\r
+\r
+ def _probe(self, parent: StxGenericModel):\r
+ hostid = parent.id\r
+ newmodels = self._client.list(hostid=hostid)\r
+ return [commands.UpdatePserverPort(data=m, parentid=hostid)\r
+ for m in newmodels]\r
def _probe(self, parent: StxGenericModel):\r
resourcepoolid = parent.id\r
newmodels = self._client.list(resourcepoolid=resourcepoolid)\r
- return [commands.UpdatePserverCpu(data=m, parentid=resourcepoolid)\r
+ return [commands.UpdatePserver(data=m, parentid=resourcepoolid)\r
for m in newmodels]\r
# See the License for the specific language governing permissions and
# limitations under the License.
-import uuid
from flask_restx import Resource
from o2ims.views import ocloud_view, api_ims_inventory_v1
from o2common.config import config
-from o2ims.domain.ocloud import Subscription
from o2ims.views.ocloud_dto import OcloudDTO, ResourceTypeDTO,\
ResourcePoolDTO, ResourceDTO, DeploymentManagerDTO, SubscriptionDTO
@api_ims_inventory_v1.marshal_with(post_resp, code=201)
def post(self):
data = api_ims_inventory_v1.payload
- sub_uuid = str(uuid.uuid4())
- subscription = Subscription(
- sub_uuid, data['callback'], data['consumerSubscriptionId'],
- data['filter'])
- ocloud_view.subscription_create(subscription, bus.uow)
- return {"subscriptionId": sub_uuid}, 201
+ result = ocloud_view.subscription_create(data, bus.uow)
+ return result, 201
@api_ims_inventory_v1.route("/subscriptions/<subscriptionID>")
@api_ims_inventory_v1.doc('Delete subscription by ID')
@api_ims_inventory_v1.response(204, 'Subscription deleted')
def delete(self, subscriptionID):
- with bus.uow:
- bus.uow.subscriptions.delete(subscriptionID)
- bus.uow.commit()
- return '', 204
+ result = ocloud_view.subscription_delete(subscriptionID, bus.uow)
+ return result, 204
def configure_namespace(app, bus_new):
# See the License for the specific language governing permissions and\r
# limitations under the License.\r
\r
+import uuid\r
from sqlalchemy import select\r
\r
from o2ims.adapter.orm import ocloud, resource, resourcetype, \\r
resourcepool, deploymentmanager, subscription\r
from o2common.service import unit_of_work\r
+from o2ims.views.ocloud_dto import SubscriptionDTO\r
from o2ims.domain.ocloud import Subscription\r
\r
\r
return None if first is None else dict(first)\r
\r
\r
-def subscription_create(subscription: Subscription,\r
+def subscription_create(subscriptionDto: SubscriptionDTO.subscription,\r
uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ sub_uuid = str(uuid.uuid4())\r
+ subscription = Subscription(\r
+ sub_uuid, subscriptionDto['callback'],\r
+ subscriptionDto['consumerSubscriptionId'],\r
+ subscriptionDto['filter'])\r
with uow:\r
uow.subscriptions.add(subscription)\r
uow.commit()\r
+ return {"subscriptionId": sub_uuid}\r
\r
\r
def subscription_delete(subscriptionId: str,\r
# See the License for the specific language governing permissions and\r
# limitations under the License.\r
\r
-import sys\r
+# import sys\r
+# import logging\r
import pytest\r
\r
from o2common.config import config\r
from o2ims.adapter.clients.ocloud_sa_client import StxSaClientImp\r
from cgtsclient.client import get_client\r
\r
-import logging\r
-\r
\r
@pytest.fixture\r
def real_stx_aio_client():\r
\r
\r
def test_get_instanceinfo(real_stx_aio_client):\r
- logger = logging.getLogger(__name__)\r
+ # logger = logging.getLogger(__name__)\r
stxclientimp = StxSaClientImp(real_stx_aio_client)\r
assert stxclientimp is not None\r
systeminfo = stxclientimp.getInstanceInfo()\r
assert host1 != host2\r
assert host1.id == host2.id\r
\r
+\r
def test_get_k8s_list(real_stx_aio_client):\r
stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
assert stxSaClientImp is not None\r
assert k8s1.name == k8s2.name\r
assert k8s1.id == k8s2.id\r
\r
+\r
def test_get_cpu_list(real_stx_aio_client):\r
stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
assert stxSaClientImp is not None\r
cpu2 = stxSaClientImp.getCpu(cpu1.id)\r
assert cpu1 != cpu2\r
assert cpu1.id == cpu2.id\r
+\r
+\r
+def test_get_mem_list(real_stx_aio_client):\r
+ stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+ assert stxSaClientImp is not None\r
+ hostlist = stxSaClientImp.getPserverList()\r
+ assert len(hostlist) > 0\r
+\r
+ memlist = stxSaClientImp.getMemList(hostid=hostlist[0].id)\r
+ assert len(memlist) > 0\r
+ mem1 = memlist[0]\r
+ mem2 = stxSaClientImp.getMem(mem1.id)\r
+ assert mem1 != mem2\r
+ assert mem1.id == mem2.id\r
+\r
+\r
+def test_get_if_list(real_stx_aio_client):\r
+ stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+ assert stxSaClientImp is not None\r
+ hostlist = stxSaClientImp.getPserverList()\r
+ assert len(hostlist) > 0\r
+\r
+ iflist = stxSaClientImp.getIfList(hostid=hostlist[0].id)\r
+ assert len(iflist) > 0\r
+ if1 = iflist[0]\r
+ if2 = stxSaClientImp.getIf(if1.id)\r
+ assert if1 != if2\r
+ assert if1.id == if2.id\r
+\r
+\r
+def test_get_port_list(real_stx_aio_client):\r
+ stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+ assert stxSaClientImp is not None\r
+ hostlist = stxSaClientImp.getPserverList()\r
+ assert len(hostlist) > 0\r
+\r
+ portlist = stxSaClientImp.getPortList(hostid=hostlist[0].id)\r
+ assert len(portlist) > 0\r
+ port1 = portlist[0]\r
+ port2 = stxSaClientImp.getPort(port1.id)\r
+ assert port1 != port2\r
+ assert port1.id == port2.id\r
ocloud1.update_by(ocloud)\r
\r
\r
-\r
class FakeStxObjRepo(StxObjectRepository):\r
def __init__(self):\r
super().__init__()\r
\r
def create_fake_bus(uow):\r
def update_ocloud(\r
- cmd: commands.UpdateOCloud,\r
- uow: AbstractUnitOfWork):\r
+ cmd: commands.UpdateOCloud,\r
+ uow: AbstractUnitOfWork):\r
return\r
\r
fakeuow = FakeUnitOfWork()\r
def _targetname(self):\r
return "fakeocloudwatcher"\r
\r
- def _probe(self, parent: object=None):\r
+ def _probe(self, parent: object = None):\r
# import pdb; pdb.set_trace()\r
self.fakeOcloudWatcherCounter += 1\r
# hacking to stop the blocking sched task\r
testedworker.stop()\r
return []\r
\r
-\r
# fakeRepo = FakeOcloudRepo()\r
fakeuow = FakeUnitOfWork()\r
bus = create_fake_bus(fakeuow)\r