Example #1
0
    def test_mlx5_sriov_edit_openib_conf(self, mock_isfile):
        openib_conf_file = ifaces_utils.OPENIB_CONF_FILE
        sriov_boot_file = ifaces_utils.MLX5_SRIOV_BOOT_FILE

        conf_file_content = "OPENIBD_PRE_START\nOPENIBD_POST_START\n"\
            "OPENIBD_PRE_STOP\nOPENIBD_POST_STOP\n"

        conf_file_writelines_content = [
            "OPENIBD_PRE_START\n",
            "OPENIBD_POST_START=%s\n" % sriov_boot_file,
            "OPENIBD_PRE_STOP\n",
            "OPENIBD_POST_STOP\n"
        ]

        mock_isfile.return_value = True

        open_ = mock_open(read_data=conf_file_content)

        with patch.object(builtins, 'open', open_):
            ifaces_utils.add_mlx5_SRIOV_boot_script_in_openib_conf()
            mock_isfile.assert_called_once_with(openib_conf_file)

        self.assertEqual(
            open_.call_args_list,
            [call(openib_conf_file, 'r'), call(openib_conf_file, 'w')]
        )
        self.assertEqual(
            open_().writelines.mock_calls,
            [call(conf_file_writelines_content)]
        )
Example #2
0
    def test_mlx5_sriov_edit_openib_conf(self, mock_isfile):
        openib_conf_file = ifaces_utils.OPENIB_CONF_FILE
        sriov_boot_file = ifaces_utils.MLX5_SRIOV_BOOT_FILE

        conf_file_content = "OPENIBD_PRE_START\nOPENIBD_POST_START\n"\
            "OPENIBD_PRE_STOP\nOPENIBD_POST_STOP\n"

        conf_file_writelines_content = [
            "OPENIBD_PRE_START\n",
            "OPENIBD_POST_START=%s\n" % sriov_boot_file, "OPENIBD_PRE_STOP\n",
            "OPENIBD_POST_STOP\n"
        ]

        mock_isfile.return_value = True

        open_ = mock_open(read_data=conf_file_content)

        with patch.object(builtins, 'open', open_):
            ifaces_utils.add_mlx5_SRIOV_boot_script_in_openib_conf()
            mock_isfile.assert_called_once_with(openib_conf_file)

        self.assertEqual(
            open_.call_args_list,
            [call(openib_conf_file, 'r'),
             call(openib_conf_file, 'w')])
        self.assertEqual(open_().writelines.mock_calls,
                         [call(conf_file_writelines_content)])
Example #3
0
    def test_mlx5_sriov_edit_openib_conf_notfound(self, mock_isfile):
        openib_conf_file = ifaces_utils.OPENIB_CONF_FILE

        mock_isfile.return_value = False

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0088E'):
            ifaces_utils.add_mlx5_SRIOV_boot_script_in_openib_conf()
            mock_isfile.assert_called_once_with(openib_conf_file)
Example #4
0
    def test_mlx5_sriov_edit_openib_conf_notfound(self, mock_isfile):
        openib_conf_file = ifaces_utils.OPENIB_CONF_FILE

        mock_isfile.return_value = False

        with self.assertRaisesRegexp(OperationFailed, 'GINNET0088E'):
            ifaces_utils.add_mlx5_SRIOV_boot_script_in_openib_conf()
            mock_isfile.assert_called_once_with(openib_conf_file)