コード例 #1
0
    def test_invalid_module_enable_sriov_failure(self, mock_get_module):
        mock_get_module.return_value = 'unknown'

        expected_error_msg = "GINNET0076E"
        with self.assertRaisesRegexp(InvalidOperation, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('any_iface_name', {'num_vfs': 4})
コード例 #2
0
    def test_interface_lookup(self, mock_iface_info, mock_rdma_enabled,
                              mock_getdevs):
        iface_info_return = {
            'device': 'dummy_iface',
            'type': 'unknown',
            'status': 'down',
            'ipaddr': '99.99.99.99',
            'netmask': '255.255.255.0',
            'macaddr': 'aa:bb:cc:dd:ee:ff',
            'module': 'dummy_net_module'
        }
        mock_iface_info.return_value = iface_info_return
        mock_rdma_enabled.return_value = True
        mock_getdevs.return_value = ['dev1', 'dummy_iface', 'dev2']

        iface_model = InterfaceModel(objstore=self._objstore)
        iface_info = iface_model.lookup('dummy_iface')
        mock_iface_info.assert_called_once_with('dummy_iface')
        mock_rdma_enabled.assert_called_once_with('dummy_iface')
        mock_getdevs.called_once_with()

        self.assertEqual(iface_info.get('device'), 'dummy_iface')
        self.assertEqual(iface_info.get('type'), 'unknown')
        self.assertEqual(iface_info.get('status'), 'down')
        self.assertEqual(iface_info.get('ipaddr'), '99.99.99.99')
        self.assertEqual(iface_info.get('netmask'), '255.255.255.0')
        self.assertEqual(iface_info.get('macaddr'), 'aa:bb:cc:dd:ee:ff')
        self.assertEqual(iface_info.get('module'), 'dummy_net_module')
        self.assertTrue(iface_info.get('rdma_enabled'))
コード例 #3
0
    def test_mlx5_sriov_success_zero_VFs(self, mock_get_max_VF,
                                         mock_get_current_VF, mock_isfile,
                                         mock_get_module, mock_get_iface_list,
                                         mock_create_cfg_file,
                                         mock_add_boot_script):

        mock_get_max_VF.return_value = '8'
        mock_get_current_VF.return_value = '4'
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        mock_get_iface_list.side_effect = [
            set(['iface1', 'iface2']),
            set(['iface1', 'sriov1', 'sriov2', 'iface2'])
        ]

        open_ = mock_open(read_data='')

        with patch.object(builtins, 'open', open_):
            iface_model = InterfaceModel(objstore=self._objstore)
            task_obj = iface_model.enable_sriov('iface1', 0)
            self.task.wait(task_obj['id'])

            finished_task = self.task.lookup(task_obj['id'])
            self.assertEquals(finished_task['status'], 'finished')
            mock_isfile.assert_called_once_with(file1)

        self.assertEqual(open_.call_args_list, [call(file1, 'w')])
        self.assertEqual(open_().write.mock_calls, [call('0\n')])
        mock_create_cfg_file.assert_not_called()
        mock_add_boot_script.assert_called_once_with('iface1', 0)
コード例 #4
0
    def test_mlx5_sriov_no_system_files_failure(self, mock_get_max_VF,
                                                mock_isfile,
                                                mock_get_module):
        mock_get_max_VF.return_value = '8'
        mock_get_module.return_value = 'mlx5_core'

        call_file1_not_exist = \
            '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        call_file2_not_exist = \
            '/sys/class/net/%s/device/mlx5_num_vfs' % 'iface1'

        mock_isfile.side_effect = [False, False]

        mock_isfile_calls = [
            call(call_file1_not_exist),
            call(call_file2_not_exist)
        ]

        expected_error_msg = "GINNET0078E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            task_obj = iface_model.enable_sriov('iface1', 4)
            self.task.wait(task_obj['id'])

            mock_isfile.assert_has_calls(mock_isfile_calls)
コード例 #5
0
    def test_mlx5_sriov_success_zero_VFs(self, mock_get_max_VF,
                                         mock_get_current_VF,
                                         mock_isfile, mock_get_module,
                                         mock_get_iface_list,
                                         mock_create_cfg_file,
                                         mock_add_boot_script):

        mock_get_max_VF.return_value = '8'
        mock_get_current_VF.return_value = '4'
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        mock_get_iface_list.side_effect = [
            set(['iface1', 'iface2']),
            set(['iface1', 'sriov1', 'sriov2', 'iface2'])
        ]

        open_ = mock_open(read_data='')

        with patch.object(builtins, 'open', open_):
            iface_model = InterfaceModel(objstore=self._objstore)
            task_obj = iface_model.enable_sriov('iface1', 0)
            self.task.wait(task_obj['id'])

            finished_task = self.task.lookup(task_obj['id'])
            self.assertEquals(finished_task['status'], 'finished')
            mock_isfile.assert_called_once_with(file1)

        self.assertEqual(open_.call_args_list, [call(file1, 'w')])
        self.assertEqual(open_().write.mock_calls, [call('0\n')])
        mock_create_cfg_file.assert_not_called()
        mock_add_boot_script.assert_called_once_with('iface1', 0)
コード例 #6
0
    def test_invalid_module_enable_sriov_failure(self, mock_get_module):
        mock_get_module.return_value = 'unknown'

        expected_error_msg = "GINNET0076E"
        with self.assertRaisesRegexp(InvalidOperation, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('any_iface_name', {'num_vfs': 4})
コード例 #7
0
    def test_interface_lookup(self, mock_iface_info, mock_rdma_enabled,
                              mock_getdevs):
        iface_info_return = {
            'device': 'dummy_iface', 'type': 'unknown', 'status': 'down',
            'ipaddr': '99.99.99.99', 'netmask': '255.255.255.0',
            'macaddr': 'aa:bb:cc:dd:ee:ff', 'module': 'dummy_net_module'
        }
        mock_iface_info.return_value = iface_info_return
        mock_rdma_enabled.return_value = True
        mock_getdevs.return_value = ['dev1', 'dummy_iface', 'dev2']

        iface_model = InterfaceModel(objstore=self._objstore)
        iface_info = iface_model.lookup('dummy_iface')
        mock_iface_info.assert_called_once_with('dummy_iface')
        mock_rdma_enabled.assert_called_once_with('dummy_iface')
        mock_getdevs.called_once_with()

        self.assertEqual(iface_info.get('device'), 'dummy_iface')
        self.assertEqual(iface_info.get('type'), 'unknown')
        self.assertEqual(iface_info.get('status'), 'down')
        self.assertEqual(iface_info.get('ipaddr'), '99.99.99.99')
        self.assertEqual(iface_info.get('netmask'), '255.255.255.0')
        self.assertEqual(iface_info.get('macaddr'), 'aa:bb:cc:dd:ee:ff')
        self.assertEqual(iface_info.get('module'), 'dummy_net_module')
        self.assertTrue(iface_info.get('rdma_enabled'))
コード例 #8
0
    def test_mlx5_sriov_argument_failure(self, mock_get_max_VF,
                                         mock_get_module):

        mock_get_max_VF.return_value = '1'
        mock_get_module.return_value = 'mlx5_core'

        expected_error_msg = "GINNET0079E"
        with self.assertRaisesRegexp(InvalidParameter, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('any_iface_name', 'not_an_int')
コード例 #9
0
    def test_mlx5_sriov_not_enabled_in_FW(self, mock_isfile, mock_get_module):
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_totalvfs' % 'iface1'
        mock_isfile.return_value = False

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0082E'):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('iface1', 4)
            mock_isfile.assert_called_once_with(file1)
コード例 #10
0
    def test_mlx5_sriov_not_enabled_in_FW(self, mock_isfile, mock_get_module):
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_totalvfs' % 'iface1'
        mock_isfile.return_value = False

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0082E'):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('iface1', 4)
            mock_isfile.assert_called_once_with(file1)
コード例 #11
0
    def test_mlx5_sriov_argument_failure(self, mock_get_max_VF,
                                         mock_get_module):

        mock_get_max_VF.return_value = '1'
        mock_get_module.return_value = 'mlx5_core'

        expected_error_msg = "GINNET0079E"
        with self.assertRaisesRegexp(InvalidParameter, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('any_iface_name', 'not_an_int')
コード例 #12
0
    def test_mlx5_sriov_get_currentVF_value(self, mock_isfile):
        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        open_ = mock_open(read_data='5\n')

        with patch.object(builtins, 'open', open_):
            iface_model = InterfaceModel(objstore=self._objstore)
            curr_vf_str = iface_model._mlx5_SRIOV_get_current_VFs('iface1')
            mock_isfile.assert_called_once_with(file1)
            self.assertEqual(curr_vf_str, '5')

        self.assertEqual(open_.call_args_list, [call(file1, 'r')])
コード例 #13
0
    def test_mlx5_sriov_fails_if_VF_greater_max(self, mock_get_max_VF,
                                                mock_isfile, mock_get_module):

        mock_get_max_VF.return_value = '8'
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        with self.assertRaisesRegexp(InvalidParameter, 'GINNET0083E'):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('iface1', 16)
            mock_isfile.assert_called_once_with(file1)
コード例 #14
0
    def test_mlx5_sriov_get_currentVF_value(self, mock_isfile):
        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        open_ = mock_open(read_data='5\n')

        with patch.object(builtins, 'open', open_):
            iface_model = InterfaceModel(objstore=self._objstore)
            curr_vf_str = iface_model._mlx5_SRIOV_get_current_VFs('iface1')
            mock_isfile.assert_called_once_with(file1)
            self.assertEqual(curr_vf_str, '5')

        self.assertEqual(open_.call_args_list, [call(file1, 'r')])
コード例 #15
0
    def test_mlx5_sriov_fails_if_VF_greater_max(self, mock_get_max_VF,
                                                mock_isfile, mock_get_module):

        mock_get_max_VF.return_value = '8'
        mock_get_module.return_value = 'mlx5_core'

        file1 = '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        mock_isfile.return_value = True

        with self.assertRaisesRegexp(InvalidParameter, 'GINNET0083E'):
            iface_model = InterfaceModel(objstore=self._objstore)
            iface_model.enable_sriov('iface1', 16)
            mock_isfile.assert_called_once_with(file1)
コード例 #16
0
ファイル: test_interfaces.py プロジェクト: harche/ginger
    def test_mlx5_info_returns_SRIOV(self, mock_macaddr, mock_netmask,
                                     mock_ipaddr, mock_getdevs,
                                     mock_get_module):

        mock_get_module.return_value = 'mlx5_core'
        mock_getdevs.return_value = ['dev1', 'dummy_iface', 'dev2']
        mock_ipaddr.return_value = '99.99.99.99'
        mock_netmask.return_value = '255.255.255.0'
        mock_macaddr.return_value = 'aa:bb:cc:dd:ee:ff'

        iface_info = InterfaceModel().lookup('dummy_iface')

        mock_macaddr.assert_called_once_with('dummy_iface')
        mock_netmask.assert_called_once_with('dummy_iface')
        mock_ipaddr.assert_called_once_with('dummy_iface')
        mock_getdevs.assert_called_with()
        mock_get_module.assert_called_once_with('dummy_iface')

        self.assertEqual(iface_info.get('device'), 'dummy_iface')
        self.assertEqual(iface_info.get('type'), 'unknown')
        self.assertEqual(iface_info.get('status'), 'down')
        self.assertEqual(iface_info.get('ipaddr'), '99.99.99.99')
        self.assertEqual(iface_info.get('netmask'), '255.255.255.0')
        self.assertEqual(iface_info.get('macaddr'), 'aa:bb:cc:dd:ee:ff')
        self.assertEqual(iface_info.get('module'), 'mlx5_core')

        self.assertNotEqual({}, iface_info.get('actions'))
        sriov_dic = iface_info['actions']['SR-IOV']
        self.assertIsNotNone(sriov_dic.get('desc'))
        self.assertIsNotNone(sriov_dic.get('args'))
        self.assertIsNone(sriov_dic.get('method'))
        args = sriov_dic.get('args')
        self.assertIn('num_vfs', args.keys())
コード例 #17
0
 def test_deactivate_fail(self, mock_run_command, mock_get_interface_type):
     mock_run_command.return_value = ["", "Unable to deactivate", 1]
     mock_get_interface_type.return_value = "nic"
     interface = "test_eth0"
     cmd = ['ifdown', '%s' % interface]
     self.assertRaises(OperationFailed,
                       InterfaceModel(objstore=self._objstore).deactivate,
                       interface)
     mock_run_command.assert_called_once_with(cmd)
コード例 #18
0
ファイル: test_interfaces.py プロジェクト: phagan94/ginger
 def test_deactivate(self, mock_run_command, mock_get_interface_type,
                     mock_os):
     mock_run_command.return_value = ["", "", 0]
     mock_os.path.isfile.return_value = True
     mock_get_interface_type.return_value = "nic"
     interface = "test_eth0"
     cmd = ['ip', 'link', 'set', '%s' % interface, 'down']
     InterfaceModel(objstore=self._objstore).deactivate(interface)
     mock_run_command.assert_called_once_with(cmd)
コード例 #19
0
 def test_deactivate(self, mock_run_command, mock_get_interface_type):
     mock_run_command.return_value = ["", "", 0]
     mock_get_interface_type.return_value = "nic"
     interface = "test_eth0"
     calls = [(['ifdown', '%s' % interface], ),
              (['ip', 'link', 'set',
                '%s' % interface, 'down'], )]
     InterfaceModel(objstore=self._objstore).deactivate(interface)
     for i in range(0, 1):
         x, y = mock_run_command.call_args_list[i]
         assert x == calls[i]
     assert mock_run_command.call_count == 2
コード例 #20
0
ファイル: test_interfaces.py プロジェクト: phagan94/ginger
 def test_activate_no_config_file(self, mock_run_command,
                                  mock_get_interface_type, mock_os):
     mock_run_command.return_value = ["", "", 0]
     mock_os.path.isfile.return_value = False
     mock_get_interface_type.return_value = "nic"
     interface = "test_eth0"
     calls = [(['ip', 'link', 'set',
                '%s' % interface, 'up'], ), (['ifup',
                                              '%s' % interface], )]
     InterfaceModel(objstore=self._objstore).activate(interface)
     for i in range(0, 1):
         x, y = mock_run_command.call_args_list[i]
         assert x == calls[i]
     assert mock_run_command.call_count == 1
コード例 #21
0
    def test_mlx5_sriov_no_system_files_failure(self, mock_get_max_VF,
                                                mock_isfile, mock_get_module):
        mock_get_max_VF.return_value = '8'
        mock_get_module.return_value = 'mlx5_core'

        call_file1_not_exist = \
            '/sys/class/net/%s/device/sriov_numvfs' % 'iface1'
        call_file2_not_exist = \
            '/sys/class/net/%s/device/mlx5_num_vfs' % 'iface1'

        mock_isfile.side_effect = [False, False]

        mock_isfile_calls = [
            call(call_file1_not_exist),
            call(call_file2_not_exist)
        ]

        expected_error_msg = "GINNET0078E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            iface_model = InterfaceModel(objstore=self._objstore)
            task_obj = iface_model.enable_sriov('iface1', 4)
            self.task.wait(task_obj['id'])

            mock_isfile.assert_has_calls(mock_isfile_calls)
コード例 #22
0
 def test_activate(self, mock_run_command, mock_get_interface_type,
                   mock_os):
     mock_run_command.return_value = ["", "", 0]
     mock_os.path.isfile.return_value = False
     open_mock = mock.mock_open(read_data='1')
     mock_get_interface_type.return_value = "nic"
     interface = "test_eth0"
     calls = [(['ip', 'link', 'set',
                '%s' % interface, 'up'], ), (['ifup',
                                              '%s' % interface], )]
     with mock.patch('wok.plugins.ginger.model.nw_interfaces_utils.open',
                     open_mock,
                     create=True):
         self.assertRaises(OperationFailed,
                           InterfaceModel(objstore=self._objstore).activate,
                           interface)
     for i in range(0, 1):
         x, y = mock_run_command.call_args_list[i]
         assert x == calls[i]
     assert mock_run_command.call_count == 2