Skip to content

Commit

Permalink
Fix RedHat install of non-default fortran version.
Browse files Browse the repository at this point in the history
The SCL version of sudo is broken, this disables that version that is first in the PATH so that the regular sudo is used.

https://bugzilla.redhat.com/show_bug.cgi?id=1319936

Adds a symlink from /usr/bin/gfortran-<version> to the SCL installed version.

PiperOrigin-RevId: 352897972
  • Loading branch information
cwilkes authored and copybara-github committed Jan 21, 2021
1 parent 4d55c5b commit 6549b88
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions perfkitbenchmarker/linux_packages/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def _YumInstallVersion(vm, version):
vm.InstallPackages(f'{devtoolset}-gcc-gfortran')
# Sets the path to use the newly installed version
vm.RemoteCommand(f'echo "source scl_source enable {devtoolset}" >> .bashrc')
# SCL's sudo is broken, remove it to use the normal /bin/sudo
vm.RemoteCommand(f'sudo rm /opt/rh/{devtoolset}/root/usr/bin/sudo')
# Normally a gfortran-{version} symlink is installed, create one
sym_link = f'/usr/bin/gfortran-{version}'
real_path = f'/opt/rh/{devtoolset}/root/usr/bin/gfortran'
vm.RemoteCommand(
f'sudo alternatives --install {sym_link} fortran {real_path} 100')


def _AptInstallVersion(vm, version):
Expand Down
67 changes: 67 additions & 0 deletions tests/linux_packages/fortran_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Lint as: python3
"""Tests for Fortran package."""

import unittest
import mock
from perfkitbenchmarker.linux_packages import fortran
from tests import pkb_common_test_case


def MockVm():
vm = mock.Mock()
# For the logging call
vm.RemoteCommand.return_value = 'fortran_version', ''
return vm


class FortranRepoTestCase(pkb_common_test_case.PkbCommonTestCase):

def assertRemoteCommandsCalled(self, expected_calls, vm):
# call_args_list.assert.... hard to read
for command, call_arg_entry in zip(expected_calls,
vm.RemoteCommand.call_args_list):
self.assertEqual(command, call_arg_entry[0][0])
self.assertLen(vm.RemoteCommand.call_args_list, len(expected_calls))

def testAptInstall(self) -> None:
# test when no --fortran_version is passed in
vm = MockVm()
fortran.AptInstall(vm)
vm.InstallPackages.assert_called_with('gfortran')

def testYumInstall(self) -> None:
# test when no --fortran_version is passed in
vm = MockVm()
fortran.YumInstall(vm)
vm.InstallPackages.assert_called_with('gcc-gfortran libgfortran')

def testAptInstallVersion(self) -> None:
vm = MockVm()
fortran._AptInstallVersion(vm, 9)
vm.Install.assert_called_with('ubuntu_toolchain')
vm.InstallPackages.assert_called_with('gfortran-9')
expected_commands = [
'sudo update-alternatives --install /usr/bin/gfortran gfortran '
'/usr/bin/gfortran-9 100'
]
self.assertRemoteCommandsCalled(expected_commands, vm)

def testYumInstallVersion(self) -> None:
vm = MockVm()
fortran._YumInstallVersion(vm, 9)
vm.InstallPackages.assert_has_calls([
mock.call('centos-release-scl-rh'),
mock.call('devtoolset-9-gcc-gfortran')
])
scl_bin = '/opt/rh/devtoolset-9/root/usr/bin'
expected_commands = [
'echo "source scl_source enable devtoolset-9" >> .bashrc',
f'sudo rm {scl_bin}/sudo',
'sudo alternatives --install /usr/bin/gfortran-9 fortran '
f'{scl_bin}/gfortran 100'
]
self.assertRemoteCommandsCalled(expected_commands, vm)


if __name__ == '__main__':
unittest.main()

0 comments on commit 6549b88

Please sign in to comment.