From e61b2ed0aef65df93bc71806940ef2e33967c461 Mon Sep 17 00:00:00 2001 From: "Lee, Keerock" Date: Wed, 18 Dec 2019 01:25:09 -0800 Subject: [PATCH 1/2] Add proxy setting in Clearlinux VM Clearlinux is not using /etc/environment as environment file. This patch adds SetupProxy, ProxyCleanup under Clearlinux VM class, and applys /etc/profile to RemoteCommand as it's not picking up environment variable in non-interactive shell. --- perfkitbenchmarker/linux_virtual_machine.py | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/perfkitbenchmarker/linux_virtual_machine.py b/perfkitbenchmarker/linux_virtual_machine.py index 2571dab5be..96d2e783f3 100644 --- a/perfkitbenchmarker/linux_virtual_machine.py +++ b/perfkitbenchmarker/linux_virtual_machine.py @@ -1230,6 +1230,87 @@ def GetOsInfo(self): stdout, _ = self.RemoteCommand('swupd info | grep Installed') return "Clear Linux build: {0}".format(regex_util.ExtractGroup(CLEAR_BUILD_REGEXP, stdout)) + def SetupProxy(self): + """Sets up proxy configuration variables for the cloud environment.""" + super(ClearMixin, self).SetupProxy() + profile_file = '/etc/profile' + commands = [] + command_template = "grep -qxF '{0}' {1} || echo '{0}' | sudo tee -a {1}" + + if FLAGS.http_proxy: + commands.append(command_template.format( + 'export http_proxy=' + FLAGS.http_proxy, profile_file)) + commands.append(command_template.format( + 'export HTTP_PROXY=' + FLAGS.http_proxy, profile_file)) + + if FLAGS.https_proxy: + commands.append(command_template.format( + 'export https_proxy=' + FLAGS.https_proxy, profile_file)) + commands.append(command_template.format( + 'export HTTPS_PROXY=' + FLAGS.https_proxy, profile_file)) + + if FLAGS.ftp_proxy: + commands.append(command_template.format( + 'export ftp_proxy=' + FLAGS.ftp_proxy, profile_file)) + commands.append(command_template.format( + 'export FTP_PROXY=' + FLAGS.ftp_proxy, profile_file)) + + if FLAGS.no_proxy: + commands.append(command_template.format( + 'export no_proxy=' + FLAGS.no_proxy, profile_file)) + commands.append(command_template.format( + 'export NO_PROXY=' + FLAGS.no_proxy, profile_file)) + + if commands: + self.RemoteCommand(';'.join(commands)) + + def ProxyCleanup(self): + """ Restore to a state before SetupProxy() executed """ + super(ClearMixin, self).ProxyCleanup() + profile_file = '/etc/profile' + commands = [] + command_template = "sudo sed -i '\#^{0}$#d' {1}" + + if FLAGS.http_proxy: + commands.append(command_template.format( + 'export http_proxy=' + FLAGS.http_proxy, profile_file)) + commands.append(command_template.format( + 'export HTTP_PROXY=' + FLAGS.http_proxy, profile_file)) + if FLAGS.https_proxy: + commands.append(command_template.format( + 'export https_proxy=' + FLAGS.https_proxy, profile_file)) + commands.append(command_template.format( + 'export HTTPS_PROXY=' + FLAGS.https_proxy, profile_file)) + if FLAGS.ftp_proxy: + commands.append(command_template.format( + 'export ftp_proxy=' + FLAGS.ftp_proxy, profile_file)) + commands.append(command_template.format( + 'export FTP_PROXY=' + FLAGS.ftp_proxy, profile_file)) + if FLAGS.no_proxy: + commands.append(command_template.format( + 'export no_proxy=' + FLAGS.no_proxy, profile_file)) + commands.append(command_template.format( + 'export NO_PROXY=' + FLAGS.no_proxy, profile_file)) + + if commands: + self.RemoteCommand(";".join(commands)) + + def RemoteCommand(self, command, **kwargs): + """Runs a command inside the container. + + Args: + *args: Arguments passed directly to RemoteHostCommandWithReturnCode. + **kwargs: Keyword arguments passed directly to + RemoteHostCommandWithReturnCode. + + Returns: + A tuple of stdout and stderr from running the command. + """ + # Escapes bash sequences + command = ". /etc/profile; %s" % (command) + return self.RemoteHostCommand(command, **kwargs)[:2] + + class BaseContainerLinuxMixin(BaseLinuxMixin): """Class holding VM methods for minimal container-based OSes like Core OS.""" From fd5b5aea26be8626e29af2ec53a0aec2d228e252 Mon Sep 17 00:00:00 2001 From: "Lee, Keerock" Date: Mon, 30 Mar 2020 15:32:04 -0700 Subject: [PATCH 2/2] remove ProxyCleanup and fix SetupProxy in ClearMixin --- perfkitbenchmarker/linux_virtual_machine.py | 57 +++------------------ 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/perfkitbenchmarker/linux_virtual_machine.py b/perfkitbenchmarker/linux_virtual_machine.py index 1c222d3cdf..f8697f66e4 100644 --- a/perfkitbenchmarker/linux_virtual_machine.py +++ b/perfkitbenchmarker/linux_virtual_machine.py @@ -1314,65 +1314,25 @@ def SetupProxy(self): super(ClearMixin, self).SetupProxy() profile_file = '/etc/profile' commands = [] - command_template = "grep -qxF '{0}' {1} || echo '{0}' | sudo tee -a {1}" if FLAGS.http_proxy: - commands.append(command_template.format( - 'export http_proxy=' + FLAGS.http_proxy, profile_file)) - commands.append(command_template.format( - 'export HTTP_PROXY=' + FLAGS.http_proxy, profile_file)) + commands.append("echo 'export http_proxy=%s' | sudo tee -a %s" % ( + FLAGS.http_proxy, profile_file)) if FLAGS.https_proxy: - commands.append(command_template.format( - 'export https_proxy=' + FLAGS.https_proxy, profile_file)) - commands.append(command_template.format( - 'export HTTPS_PROXY=' + FLAGS.https_proxy, profile_file)) + commands.append("echo 'https_proxy=%s' | sudo tee -a %s" % ( + FLAGS.https_proxy, profile_file)) if FLAGS.ftp_proxy: - commands.append(command_template.format( - 'export ftp_proxy=' + FLAGS.ftp_proxy, profile_file)) - commands.append(command_template.format( - 'export FTP_PROXY=' + FLAGS.ftp_proxy, profile_file)) + commands.append("echo 'ftp_proxy=%s' | sudo tee -a %s" % ( + FLAGS.ftp_proxy, profile_file)) if FLAGS.no_proxy: - commands.append(command_template.format( - 'export no_proxy=' + FLAGS.no_proxy, profile_file)) - commands.append(command_template.format( - 'export NO_PROXY=' + FLAGS.no_proxy, profile_file)) - + commands.append("echo 'export no_proxy=%s' | sudo tee -a %s" % ( + FLAGS.no_proxy, profile_file)) if commands: self.RemoteCommand(';'.join(commands)) - def ProxyCleanup(self): - """ Restore to a state before SetupProxy() executed """ - super(ClearMixin, self).ProxyCleanup() - profile_file = '/etc/profile' - commands = [] - command_template = "sudo sed -i '\#^{0}$#d' {1}" - - if FLAGS.http_proxy: - commands.append(command_template.format( - 'export http_proxy=' + FLAGS.http_proxy, profile_file)) - commands.append(command_template.format( - 'export HTTP_PROXY=' + FLAGS.http_proxy, profile_file)) - if FLAGS.https_proxy: - commands.append(command_template.format( - 'export https_proxy=' + FLAGS.https_proxy, profile_file)) - commands.append(command_template.format( - 'export HTTPS_PROXY=' + FLAGS.https_proxy, profile_file)) - if FLAGS.ftp_proxy: - commands.append(command_template.format( - 'export ftp_proxy=' + FLAGS.ftp_proxy, profile_file)) - commands.append(command_template.format( - 'export FTP_PROXY=' + FLAGS.ftp_proxy, profile_file)) - if FLAGS.no_proxy: - commands.append(command_template.format( - 'export no_proxy=' + FLAGS.no_proxy, profile_file)) - commands.append(command_template.format( - 'export NO_PROXY=' + FLAGS.no_proxy, profile_file)) - - if commands: - self.RemoteCommand(";".join(commands)) def RemoteCommand(self, command, **kwargs): """Runs a command inside the container. @@ -1390,7 +1350,6 @@ def RemoteCommand(self, command, **kwargs): return self.RemoteHostCommand(command, **kwargs)[:2] - class BaseContainerLinuxMixin(BaseLinuxMixin): """Class holding VM methods for minimal container-based OSes like Core OS."""