Internal change.

PiperOrigin-RevId: 303773475
This commit is contained in:
Zach Koopmans
2020-03-30 10:44:55 -07:00
committed by gVisor bot
parent 1876f10e15
commit 4aee370640
5 changed files with 32 additions and 14 deletions
@@ -53,6 +53,8 @@ class GCloudProducer(machine_producer.MachineProducer):
ssh_key_file: path to a valid ssh private key. See README on vaild ssh keys.
ssh_user: string of user name for ssh_key
ssh_password: string of password for ssh key
internal: if true, use internal IPs of instances. Used if bm-tools is
running on a GCP vm when a firewall is set for external IPs.
mock: a mock printer which will print mock data if required. Mock data is
recorded output from subprocess calls (returncode, stdout, args).
condition: mutex for this class around machine creation and deleteion.
@@ -66,6 +68,7 @@ class GCloudProducer(machine_producer.MachineProducer):
ssh_key_file: str,
ssh_user: str,
ssh_password: str,
internal: bool,
mock: gcloud_mock_recorder.MockPrinter = None):
self.image = image
self.zone = zone
@@ -74,6 +77,7 @@ class GCloudProducer(machine_producer.MachineProducer):
self.ssh_key_file = ssh_key_file
self.ssh_user = ssh_user
self.ssh_password = ssh_password
self.internal = internal
self.mock = mock
self.condition = threading.Condition()
@@ -129,15 +133,13 @@ class GCloudProducer(machine_producer.MachineProducer):
machines = []
for instance in instances:
name = instance["name"]
external = instance["networkInterfaces"][0]["accessConfigs"][0]["natIP"]
internal = instance["networkInterfaces"][0]["networkIP"]
kwargs = {
"hostname":
instance["networkInterfaces"][0]["accessConfigs"][0]["natIP"],
"key_path":
self.ssh_key_file,
"username":
self.ssh_user,
"key_password":
self.ssh_password
"hostname": internal if self.internal else external,
"key_path": self.ssh_key_file,
"username": self.ssh_user,
"key_password": self.ssh_password
}
machines.append(machine.RemoteMachine(name=name, **kwargs))
return machines
@@ -190,6 +192,8 @@ class GCloudProducer(machine_producer.MachineProducer):
for name in names:
cmd = "gcloud compute ssh {user}@{name}".format(
user=self.ssh_user, name=name).split(" ")
if self.internal:
cmd.append("--internal-ip")
cmd.append("--ssh-key-file={key}".format(key=self.ssh_key_file))
cmd.append("--zone={zone}".format(zone=self.zone))
cmd.append("--command=uname")
+4 -3
View File
@@ -120,8 +120,8 @@ def run_mock(ctx, **kwargs):
@runner.command("run-gcp", commands.GCPCommand)
@click.pass_context
def run_gcp(ctx, image_file: str, zone_file: str, machine_type: str,
installers: List[str], **kwargs):
def run_gcp(ctx, image_file: str, zone_file: str, internal: bool,
machine_type: str, installers: List[str], **kwargs):
"""Runs all benchmarks on GCP instances."""
# Resolve all files.
@@ -137,7 +137,8 @@ def run_gcp(ctx, image_file: str, zone_file: str, machine_type: str,
installers,
ssh_key_file=key_file,
ssh_user=harness.DEFAULT_USER,
ssh_password="")
ssh_password="",
internal=internal)
try:
run(ctx, producer, **kwargs)
+7
View File
@@ -111,6 +111,12 @@ class GCPCommand(RunCommand):
default=os.path.join(
os.path.dirname(__file__), "../../tools/images/zone.txt"),
)
internal = click.core.Option(
("--internal/--no-internal",),
help="""Use instance internal IPs. Used if bm-tools runner is running on
GCP instance with firewall rules blocking external IPs.""",
default=False,
)
installers = click.core.Option(
("--installers",),
help="The set of installers to use.",
@@ -124,6 +130,7 @@ class GCPCommand(RunCommand):
self.params.extend([
image_file,
zone_file,
internal,
machine_type,
installers,
])
+2 -1
View File
@@ -29,7 +29,8 @@ gcloud config set compute/zone ${ZONE}
bazel run //benchmarks:benchmarks -- \
--verbose \
run-gcp \
startup \
"(startup|absl)" \
--internal \
--runtime=runc \
--runtime=runsc \
--installers=head
+7 -2
View File
@@ -63,13 +63,18 @@ trap cleanup EXIT
# Wait for the instance to become available (up to 5 minutes).
declare timeout=300
declare success=0
declare internal=""
declare -r start=$(date +%s)
declare -r end=$((${start}+${timeout}))
while [[ "$(date +%s)" -lt "${end}" ]] && [[ "${success}" -lt 3 ]]; do
if gcloud compute ssh --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- env - true 2>/dev/null; then
if gcloud compute ssh --zone "${internal}" "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- env - true 2>/dev/null; then
success=$((${success}+1))
elif gcloud compute ssh --zone --internal-ip "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- env - true 2>/dev/null; then
success=$((${success}+1))
internal="--internal-ip"
fi
done
if [[ "${success}" -eq "0" ]]; then
echo "connect timed out after ${timeout} seconds."
exit 1
@@ -77,7 +82,7 @@ fi
# Run the install scripts provided.
for arg; do
gcloud compute ssh --zone "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- sudo bash - <"${arg}" >/dev/null
gcloud compute ssh --zone "${internal}" "${ZONE}" "${USERNAME}"@"${INSTANCE_NAME}" -- sudo bash - <"${arg}" >/dev/null
done
# Stop the instance; required before creating an image.