Пример #1
0
    def _mlx5_SRIOV_enable_task(self, cb, params):
        iface = params.get('name')
        num_vfs = params.get('num_vfs')

        sriov_file = self._mlx5_SRIOV_get_numvf_config_file(iface)

        cb('Setting SR-IOV for %s' % iface)

        try:
            with open(sriov_file, 'w') as f:
                f.write('0\n')

            if num_vfs == 0:
                add_config_to_mlx5_SRIOV_boot_script(iface, num_vfs)
            else:
                ifaces_without_sriov = \
                    cfgInterfacesHelper.get_interface_list()

                with open(sriov_file, 'w') as f:
                    f.write(str(num_vfs) + '\n')

                add_config_to_mlx5_SRIOV_boot_script(iface, num_vfs)

                new_ifaces = self._wait_VFs_setup(ifaces_without_sriov)

                for new_iface in new_ifaces:
                    cfgInterfacesHelper.create_interface_cfg_file(new_iface)

        except Exception as e:
            raise OperationFailed("GINNET0085E", {'err': e.message})

        cb('SR-IOV setup for %s completed' % iface, True)
Пример #2
0
    def test_create_cfg_file_fails_no_mac_address(self, mock_isfile,
                                                  mock_run_cmd):
        interface = 'dummyiface'

        file_path = '/etc/sysconfig/network-scripts/ifcfg-%s' % interface
        mock_isfile.return_value = False

        ip_link_no_macaddr_return = 'dummyiface: there is no mac address here'

        mock_run_cmd.return_value = [ip_link_no_macaddr_return, 0, 0]

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0081E'):
            cfgInterfacesHelper.create_interface_cfg_file('dummyiface')
            mock_isfile.assert_called_once_with(file_path)
Пример #3
0
    def test_create_cfg_file_fails_no_mac_address(self, mock_isfile,
                                                  mock_run_cmd):
        interface = 'dummyiface'

        file_path = '/etc/sysconfig/network-scripts/ifcfg-%s' % interface
        mock_isfile.return_value = False

        ip_link_no_macaddr_return = 'dummyiface: there is no mac address here'

        mock_run_cmd.return_value = [ip_link_no_macaddr_return, 0, 0]

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0081E'):
            cfgInterfacesHelper.create_interface_cfg_file('dummyiface')
            mock_isfile.assert_called_once_with(file_path)
Пример #4
0
    def test_create_minimal_config_file(self, mock_isfile, mock_run_cmd):
        interface = 'dummyiface'

        file_path = '/etc/sysconfig/network-scripts/ifcfg-%s' % interface
        mock_isfile.return_value = False

        ip_link_return = 'dummyiface: (...) qlen 1000\    '\
            'link/ether 52:54:00:e0:95:c0 brd ff:ff:ff:ff:ff:ff'

        mock_run_cmd.return_value = [ip_link_return, 0, 0]

        cfg_file_content = cfgInterfacesHelper.get_cfgfile_content(interface)

        open_ = mock_open(read_data='')

        with patch.object(builtins, 'open', open_):
            cfgInterfacesHelper.create_interface_cfg_file('dummyiface')
            mock_isfile.assert_called_once_with(file_path)

        self.assertEqual(open_.call_args_list, [call(file_path, 'w')])
        self.assertEqual(open_().write.mock_calls, [call(cfg_file_content)])
Пример #5
0
    def test_create_minimal_config_file(self, mock_isfile, mock_run_cmd):
        interface = 'dummyiface'

        file_path = '/etc/sysconfig/network-scripts/ifcfg-%s' % interface
        mock_isfile.return_value = False

        ip_link_return = 'dummyiface: (...) qlen 1000\    '\
            'link/ether 52:54:00:e0:95:c0 brd ff:ff:ff:ff:ff:ff'

        mock_run_cmd.return_value = [ip_link_return, 0, 0]

        cfg_file_content = cfgInterfacesHelper.get_cfgfile_content(interface)

        open_ = mock_open(read_data='')

        with patch.object(builtins, 'open', open_):
            cfgInterfacesHelper.create_interface_cfg_file('dummyiface')
            mock_isfile.assert_called_once_with(file_path)

        self.assertEqual(open_.call_args_list, [call(file_path, 'w')])
        self.assertEqual(open_().write.mock_calls, [call(cfg_file_content)])