Merge "Change attach_info, cpid_info from string to a dict."

This commit is contained in:
Zuul 2019-07-10 04:05:36 +00:00 committed by Gerrit Code Review
commit 74c68900ba
6 changed files with 71 additions and 19 deletions

View File

@ -0,0 +1,27 @@
# Copyright 2019 Intel, 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 oslo_serialization import jsonutils
import collections
def pci_str_to_json(pci_address):
dbs, func = pci_address.split('.')
domain, bus, slot = dbs.split(':')
keys = ["domain", "bus", "device", "function"]
values = [domain, bus, slot, func]
bdf_dict = dict(zip(keys, values))
ordered_dict = collections.OrderedDict(sorted(bdf_dict.items()))
bdf_json = jsonutils.dumps(ordered_dict)
return bdf_json

View File

@ -17,13 +17,13 @@
Cyborg Intel FPGA driver implementation.
"""
# from cyborg.accelerator.drivers.fpga.base import FPGADriver
import glob
import os
import re
from oslo_serialization import jsonutils
from cyborg.accelerator.common import utils
from cyborg.agent import rc_fields
from cyborg.objects.driver_objects import driver_deployable, driver_device,\
driver_attach_handle, driver_controlpath_id, driver_attribute
@ -208,7 +208,7 @@ def _generate_driver_device(fpga, pf_has_vf):
def _generate_controlpath_id(fpga):
driver_cpid = driver_controlpath_id.DriverControlPathID()
driver_cpid.cpid_type = "PCI"
driver_cpid.cpid_info = fpga["devices"]
driver_cpid.cpid_info = utils.pci_str_to_json(fpga["devices"])
return driver_cpid
@ -221,7 +221,7 @@ def _generate_dep_list(fpga, pf_has_vf):
if not pf_has_vf:
driver_dep.num_accelerators = 1
driver_dep.attach_handle_list = \
[_generate_attach_handle(fpga, pf_has_vf)]
[_generate_attach_handle(fpga)]
driver_dep.name = fpga["name"]
# pf with sriov enabled, may have several regions and several vfs.
# For now, there is only region, this maybe improve in next release.
@ -230,15 +230,15 @@ def _generate_dep_list(fpga, pf_has_vf):
for vf in fpga["regions"]:
# Only vfs in regions can be attach, no pf.
driver_dep.attach_handle_list.append(
_generate_attach_handle(vf, False))
_generate_attach_handle(vf))
driver_dep.name = vf["name"]
return [driver_dep]
def _generate_attach_handle(fpga, pf_has_vf):
def _generate_attach_handle(fpga):
driver_ah = driver_attach_handle.DriverAttachHandle()
driver_ah.attach_type = "PCI"
driver_ah.attach_info = fpga["devices"]
driver_ah.attach_info = utils.pci_str_to_json(fpga["devices"])
driver_ah.in_use = False
return driver_ah

View File

@ -25,6 +25,7 @@ import subprocess
from cyborg.objects.driver_objects import driver_deployable, driver_device, \
driver_attach_handle, driver_controlpath_id
from cyborg.common import constants
from cyborg.accelerator.common import utils
LOG = logging.getLogger(__name__)
@ -91,7 +92,7 @@ def _generate_driver_device(gpu):
def _generate_controlpath_id(gpu):
driver_cpid = driver_controlpath_id.DriverControlPathID()
driver_cpid.cpid_type = "PCI"
driver_cpid.cpid_info = gpu["devices"]
driver_cpid.cpid_info = utils.pci_str_to_json(gpu["devices"])
return driver_cpid
@ -115,5 +116,5 @@ def _generate_attach_handle(gpu):
driver_ah = driver_attach_handle.DriverAttachHandle()
driver_ah.attach_type = "PCI"
driver_ah.in_use = False
driver_ah.attach_info = gpu["devices"]
driver_ah.attach_info = utils.pci_str_to_json(gpu["devices"])
return driver_ah

View File

@ -72,5 +72,4 @@ class ResourceTracker(object):
acc_list.extend(acc_driver.discover())
# Call conductor_api here to diff and report acc data. Now, we actually
# do not have the method report_data.
if acc_list:
self.conductor_api.report_data(context, self.host, acc_list)
self.conductor_api.report_data(context, self.host, acc_list)

View File

@ -43,12 +43,18 @@ class TestIntelFPGADriver(base.TestCase):
attach_handle_list = [
[
{'attach_type': 'PCI',
'attach_info': '0000:be:00.0',
'attach_info': '{"bus": "be", '
'"device": "00", '
'"domain": "0000", '
'"function": "0"}',
'in_use': False}
],
[
{'attach_type': 'PCI',
'attach_info': '0000:5e:00.1',
'attach_info': '{"bus": "5e", '
'"device": "00", '
'"domain": "0000", '
'"function": "1"}',
'in_use': False}
]
]
@ -63,8 +69,13 @@ class TestIntelFPGADriver(base.TestCase):
},
],
'controlpath_id':
{'cpid_info': '0000:be:00.0',
'cpid_type': 'PCI'}},
{
'cpid_info': '{"bus": "be", '
'"device": "00", '
'"domain": "0000", '
'"function": "0"}',
'cpid_type': 'PCI'}
},
{'vendor': '0x8086',
'type': 'FPGA',
'model': '0xbcc0',
@ -76,8 +87,14 @@ class TestIntelFPGADriver(base.TestCase):
},
],
'controlpath_id':
{'cpid_info': '0000:5e:00.0',
'cpid_type': 'PCI'}}]
{
'cpid_info': '{"bus": "5e", '
'"device": "00", '
'"domain": "0000", '
'"function": "0"}',
'cpid_type': 'PCI'}
}
]
intel = IntelFPGADriver()
fpgas = intel.discover()
list.sort(fpgas, key=lambda x: x._obj_deployable_list[0].name)

View File

@ -59,7 +59,10 @@ class TestGPUDriverUtils(base.TestCase):
self.assertEqual(1, len(gpu_list))
attach_handle_list = [
{'attach_type': 'PCI',
'attach_info': '0000:00:06.0',
'attach_info': '{"bus": "00", '
'"device": "06", '
'"domain": "0000", '
'"function": "0"}',
'in_use': False}
]
expected = {
@ -76,8 +79,13 @@ class TestGPUDriverUtils(base.TestCase):
'attach_handle_list': attach_handle_list
},
],
'controlpath_id': {'cpid_info': '0000:00:06.0', 'cpid_type': 'PCI'}
}
'controlpath_id': {'cpid_info': '{"bus": "00", '
'"device": "06", '
'"domain": "0000", '
'"function": "0"}',
'cpid_type': 'PCI'}
}
gpu_obj = gpu_list[0]
gpu_dict = gpu_obj.as_dict()
gpu_dep_list = gpu_dict['deployable_list']