Skip to content

Commit

Permalink
Unpin awscli version to fix installation on Ubuntu 22.
Browse files Browse the repository at this point in the history
Installation fails due to the Cython3 dependency installation failing: yaml/pyyaml#601 (the same issue as GoogleCloudPlatform@b53f2cd39)

It was previously pinned to support Python 3.5, but that is no longer installed on supported operating systems.

PiperOrigin-RevId: 554644132
  • Loading branch information
pmkc authored and gadgilrajeev committed Mar 29, 2024
1 parent 28a4892 commit f932b33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 87 deletions.
46 changes: 8 additions & 38 deletions perfkitbenchmarker/linux_packages/awscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,20 @@

"""Package for installing the AWS CLI."""

from perfkitbenchmarker import errors

# TODO(user): Migrate to awscli v2, see
# https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html.
# TODO(user): Updating to v1 head will not work since awscli stopped
# support of python 3.5 the OS sometimes installs. We should find a
# way to pin this version to 3.7 which would probably involve changing the
# python 3 linux package.
_VERSION = '1.19.75'
_SUSE_PKG_NAME = 'aws-cli'


def Install(vm):
"""Installs the awscli package on the VM."""
version, _ = vm.RemoteCommand('aws --version', ignore_failure=True)
for package_with_versions in version.split():
if ('aws-cli' in package_with_versions and
package_with_versions.split('/')[1] >= _VERSION):
# awscli is already installed and at a later version.
return
# Check if AWS is already installed.
if vm.TryRemoteCommand('aws --version'):
return
vm.Install('pip3')
vm.RemoteCommand(
f"sudo pip3 install 'awscli=={_VERSION}' "
# awscli 0.18 depends on a specific PyYAML version, and the AWS Ubuntu AMI
# ships with an old python-yaml Deb package that pip3 can't upgrade so we
'sudo pip3 install awscli '
# awscli depends on a specific PyYAML version, and the AWS Ubuntu AMI
# ships with a python-yaml Deb package that pip3 can't upgrade so we
# ignore it.
# TODO(user): remove version when we update AWS-cli
'--ignore-installed --force-reinstall')


def YumInstall(vm):
"""Installs the awscli package on the VM."""
# amazon linux 2 has awscli pre-installed. Check to see if it exists and
# install it if it does not.
try:
vm.RemoteCommand('yum list installed awscli')
except errors.VirtualMachine.RemoteCommandError:
Install(vm)


def ZypperInstall(vm):
stdout, _ = vm.RemoteCommand(f'zypper search -i {_SUSE_PKG_NAME}')
if _SUSE_PKG_NAME not in stdout:
Install(vm)
'--ignore-installed --force-reinstall'
)


def Uninstall(vm):
Expand Down
57 changes: 8 additions & 49 deletions tests/linux_packages/aws_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import unittest
import mock
from perfkitbenchmarker import errors
from perfkitbenchmarker.linux_packages import awscli


Expand All @@ -25,60 +24,20 @@ def setUp(self):
super().setUp()
self.vm = mock.Mock()

def test_install_returns_with_late_version(self):
awscli._VERSION = '1.10.44'
self.vm.RemoteCommand.return_value = ('aws-cli/1.19.99 Linux/1.2', 'unused')
def test_install_found(self):
self.vm.TryRemoteCommand.return_value = True
awscli.Install(self.vm)
self.vm.RemoteCommand.assert_called_once_with(
'aws --version', ignore_failure=True
)
self.vm.TryRemoteCommand.assert_called_once_with('aws --version')

def test_full_install_returns_with_no_version(self):
awscli._VERSION = '1.10.44'
self.vm.RemoteCommand.return_value = ('what is aws?', 'unused')
def test_install_not_found(self):
self.vm.TryRemoteCommand.return_value = False
awscli.Install(self.vm)
self.assertEqual(
[
mock.call('aws --version', ignore_failure=True),
mock.call(
"sudo pip3 install 'awscli==1.10.44' --ignore-installed "
'--force-reinstall'
),
],
self.vm.RemoteCommand.call_args_list,
)
self.vm.TryRemoteCommand.assert_called_once_with('aws --version')
self.vm.Install.assert_called_once_with('pip3')

def test_yum_install_found(self):
self.vm.RemoteCommand.return_value = ('fine', 'unused')
awscli.YumInstall(self.vm)
self.vm.RemoteCommand.assert_called_once_with('yum list installed awscli')

def test_yum_install_not_found(self):
self.vm.RemoteCommand.side_effect = (
errors.VirtualMachine.RemoteCommandError('not found')
)
# First raise is expected, second isn't but can't swap from raise to not.
with self.assertRaises(errors.VirtualMachine.RemoteCommandError):
awscli.YumInstall(self.vm)
self.assertEqual(
[
mock.call('yum list installed awscli'),
mock.call('aws --version', ignore_failure=True),
],
self.vm.RemoteCommand.call_args_list,
self.vm.RemoteCommand.assert_called_once_with(
'sudo pip3 install awscli --ignore-installed --force-reinstall'
)

def test_zypper_install_found(self):
self.vm.RemoteCommand.return_value = ('zypper found aws-cli', 'unused')
awscli.ZypperInstall(self.vm)
self.vm.RemoteCommand.assert_called_once_with('zypper search -i aws-cli')

def test_zypper_install_not_found(self):
self.vm.RemoteCommand.return_value = ('fine but not cli', 'unused')
awscli.ZypperInstall(self.vm)
self.assertGreater(self.vm.RemoteCommand.call_count, 1)


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

0 comments on commit f932b33

Please sign in to comment.