# Path: neutron_taas/common/utils.py
# def get_list_from_ranges_str(ranges_str):
# def get_ranges_str_from_list(ranges):
# 
# Path: neutron_taas/services/taas/drivers/linux/sriov_nic_exceptions.py
# class SriovNicSwitchDriverInvocationError(qexception.Invalid):
# class PciDeviceNotFoundById(qexception.NotFound):
# class PciSlotNotFound(qexception.NotFound):
# 
# Path: neutron_taas/services/taas/drivers/linux/sriov_nic_utils.py
# LOG = logging.getLogger(__name__)
#         VIRTFN_RE = re.compile(r"virtfn(\d+)")
# class SriovNicUtils(object):
#     def __init__(self):
#     def execute_sysfs_command(self, command, ts_port_params,
#                               src_port_params,
#                               common_vlans_ranges_str,
#                               vf_to_vf_all_vlans, direction):
#     def _get_sysfs_netdev_path(self, pci_addr, pf_interface):
#     def get_ifname_by_pci_address(self, pci_addr, pf_interface=False):
#     def get_mac_by_pci_address(self, pci_addr, pf_interface=False):
#     def get_vf_num_by_pci_address(self, pci_addr):
#     def get_net_name_by_vf_pci_address(self, vfaddress, pf_interface=False):
#     def get_sriov_port_params(self, sriov_port):
# 
# Path: neutron_taas/tests/base.py
# class TaasTestCase(base.BaseTestCase):


import copy
import re
from unittest import mock
from neutron_taas.common import utils as common_utils
from neutron_taas.services.taas.drivers.linux import sriov_nic_exceptions \
    as taas_exc
from neutron_taas.services.taas.drivers.linux import sriov_nic_utils
from neutron_taas.tests import base

    @mock.patch.object(sriov_nic_utils, 'os')
    @mock.patch.object(sriov_nic_utils, 'open', create=True)
    def test_get_mac_by_pci_address(self, mock_open, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        fake_file_handle = ["52:54:00:12:35:02"]
        fake_file_iter = fake_file_handle.__iter__()
        mock_open.return_value.__enter__.return_value = fake_file_iter
        self.assertEqual(
            "52:54:00:12:35:02", sriov_nic_utils.SriovNicUtils().
            get_mac_by_pci_address(12, False))

    @mock.patch.object(sriov_nic_utils, 'os')
    @mock.patch.object(sriov_nic_utils, 'open', create=True)
    def test_get_mac_by_pci_address_no_content(self, mock_open, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        fake_file_handle = []
        fake_file_iter = fake_file_handle.__iter__()
        mock_open.return_value.__enter__.return_value = fake_file_iter
        self.assertRaises(
            taas_exc.PciDeviceNotFoundById,
            sriov_nic_utils.SriovNicUtils().get_mac_by_pci_address, 12, False)

    @mock.patch.object(sriov_nic_utils, 'os')
    def test_get_mac_by_pci_address_wrong_dev_path(self, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        self.assertRaises(

# Path: neutron_taas/common/utils.py
# def get_list_from_ranges_str(ranges_str):
# def get_ranges_str_from_list(ranges):
# 
# Path: neutron_taas/services/taas/drivers/linux/sriov_nic_exceptions.py
# class SriovNicSwitchDriverInvocationError(qexception.Invalid):
# class PciDeviceNotFoundById(qexception.NotFound):
# class PciSlotNotFound(qexception.NotFound):
# 
# Path: neutron_taas/services/taas/drivers/linux/sriov_nic_utils.py
# LOG = logging.getLogger(__name__)
#         VIRTFN_RE = re.compile(r"virtfn(\d+)")
# class SriovNicUtils(object):
#     def __init__(self):
#     def execute_sysfs_command(self, command, ts_port_params,
#                               src_port_params,
#                               common_vlans_ranges_str,
#                               vf_to_vf_all_vlans, direction):
#     def _get_sysfs_netdev_path(self, pci_addr, pf_interface):
#     def get_ifname_by_pci_address(self, pci_addr, pf_interface=False):
#     def get_mac_by_pci_address(self, pci_addr, pf_interface=False):
#     def get_vf_num_by_pci_address(self, pci_addr):
#     def get_net_name_by_vf_pci_address(self, vfaddress, pf_interface=False):
#     def get_sriov_port_params(self, sriov_port):
# 
# Path: neutron_taas/tests/base.py
# class TaasTestCase(base.BaseTestCase):


# Path: neutron_taas/tests/unit/services/drivers/test_linux_sriov_utils.py
import copy
import re
from unittest import mock
from neutron_taas.common import utils as common_utils
from neutron_taas.services.taas.drivers.linux import sriov_nic_exceptions \
    as taas_exc
from neutron_taas.services.taas.drivers.linux import sriov_nic_utils
from neutron_taas.tests import base


    @mock.patch.object(sriov_nic_utils, 'os')
    @mock.patch.object(sriov_nic_utils, 'open', create=True)
    def test_get_mac_by_pci_address(self, mock_open, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        fake_file_handle = ["52:54:00:12:35:02"]
        fake_file_iter = fake_file_handle.__iter__()
        mock_open.return_value.__enter__.return_value = fake_file_iter
        self.assertEqual(
            "52:54:00:12:35:02", sriov_nic_utils.SriovNicUtils().
            get_mac_by_pci_address(12, False))

    @mock.patch.object(sriov_nic_utils, 'os')
    @mock.patch.object(sriov_nic_utils, 'open', create=True)
    def test_get_mac_by_pci_address_no_content(self, mock_open, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        fake_file_handle = []
        fake_file_iter = fake_file_handle.__iter__()
        mock_open.return_value.__enter__.return_value = fake_file_iter
        self.assertRaises(
            taas_exc.PciDeviceNotFoundById,
            sriov_nic_utils.SriovNicUtils().get_mac_by_pci_address, 12, False)

    @mock.patch.object(sriov_nic_utils, 'os')
    def test_get_mac_by_pci_address_wrong_dev_path(self, mock_os):
        mock_os.listdir.return_value = ['random1', 'random2']
        mock_os.path.join.return_value = 'random'
        self.assertRaises(

            taas_exc.PciDeviceNotFoundById,