From 31560e9a26e6a7e2e65d18924c938ee7a7683fb3 Mon Sep 17 00:00:00 2001 From: bobzhou Date: Mon, 17 Dec 2018 17:41:39 +0800 Subject: upload cyborg base mitaka version Change-Id: Iff52024026c9eff899246be70cc89fe6e65befff Signed-off-by: bobzhou --- .../cyborg/tests/unit/fake_virtual_function.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 cyborg_enhancement/mitaka_version/cyborg/cyborg/tests/unit/fake_virtual_function.py (limited to 'cyborg_enhancement/mitaka_version/cyborg/cyborg/tests/unit/fake_virtual_function.py') diff --git a/cyborg_enhancement/mitaka_version/cyborg/cyborg/tests/unit/fake_virtual_function.py b/cyborg_enhancement/mitaka_version/cyborg/cyborg/tests/unit/fake_virtual_function.py new file mode 100644 index 0000000..8184b0f --- /dev/null +++ b/cyborg_enhancement/mitaka_version/cyborg/cyborg/tests/unit/fake_virtual_function.py @@ -0,0 +1,72 @@ +# Copyright 2018 Huawei Technologies Co.,LTD. +# +# 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. + +import datetime + +from oslo_serialization import jsonutils +from oslo_utils import uuidutils + +from cyborg import objects +from cyborg.objects import fields +from cyborg.objects import virtual_function + + +def fake_db_virtual_function(**updates): + root_uuid = uuidutils.generate_uuid() + db_virtual_function = { + 'id': 1, + 'deleted': False, + 'uuid': root_uuid, + 'name': 'dp_name', + 'parent_uuid': None, + 'root_uuid': root_uuid, + 'pcie_address': '00:7f:bb.2', + 'host': 'host_name', + 'board': 'KU115', + 'vendor': 'Xilinx', + 'version': '1.0', + 'type': 'vf', + 'assignable': True, + 'instance_uuid': None, + 'availability': 'Available', + 'accelerator_id': 1 + } + + for name, field in virtual_function.VirtualFunction.fields.items(): + if name in db_virtual_function: + continue + if field.nullable: + db_virtual_function[name] = None + elif field.default != fields.UnspecifiedDefault: + db_virtual_function[name] = field.default + else: + raise Exception('fake_db_virtual_function needs help with %s' + % name) + + if updates: + db_virtual_function.update(updates) + + return db_virtual_function + + +def fake_virtual_function_obj(context, obj_vf_class=None, **updates): + if obj_vf_class is None: + obj_vf_class = objects.VirtualFunction + expected_attrs = updates.pop('expected_attrs', None) + vf = obj_vf_class._from_db_object(context, + obj_vf_class(), + fake_db_virtual_function(**updates), + expected_attrs=expected_attrs) + vf.obj_reset_changes() + return vf -- cgit 1.2.3-korg