Skip to content

Commit

Permalink
Fix Ganglia integration test (GoogleCloudDataproc#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
medb authored Jun 10, 2019
1 parent 4b5e542 commit abc780b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
71 changes: 36 additions & 35 deletions ganglia/test_ganglia.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import unittest

from parameterized import parameterized

from integration_tests.dataproc_test_case import DataprocTestCase


Expand All @@ -10,51 +12,50 @@ class GangliaTestCase(DataprocTestCase):
TEST_SCRIPT_FILE_NAME = 'verify_ganglia_running.py'

def verify_instance(self, name):
self.upload_test_file(name)
self.__run_command_on_cluster(name,'yes | sudo apt-get install python3-pip')
self.__run_command_on_cluster(name,'sudo pip3 install requests-html')
test_script_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
self.TEST_SCRIPT_FILE_NAME)
self.upload_test_file(test_script_path, name)
self.__run_command_on_cluster(
name, 'yes | sudo apt-get install python3-pip')
self.__run_command_on_cluster(name, 'sudo pip3 install requests-html')
self.__run_test_file(name)
self.remove_test_script(name)
self.remove_test_script(self.TEST_SCRIPT_FILE_NAME, name)

def __run_test_file(self, name):
cmd = 'gcloud compute ssh {} -- "python3 {} "'.format(
name,
self.TEST_SCRIPT_FILE_NAME
)
cmd = 'gcloud compute ssh {} --command="python3 {}"'.format(
name, self.TEST_SCRIPT_FILE_NAME)
ret_code, stdout, stderr = self.run_command(cmd)
self.assertEqual(ret_code, 0, "Failed to run test file. Error: {}".format(stderr))
self.assertEqual(ret_code, 0,
"Failed to run test file. Error: {}".format(stderr))

def __run_command_on_cluster(self, name, command):
cmd = 'gcloud compute ssh {} -- "{} "'.format(
name,
command
)
cmd = 'gcloud compute ssh {} --command="{}"'.format(name, command)
ret_code, stdout, stderr = self.run_command(cmd)
self.assertEqual(ret_code, 0, "Failed to run command. Error: {}".format(stderr))

@parameterized.expand([
("SINGLE", "1.0", ["m"]),
("STANDARD", "1.0", ["m", "w-0"]),
("HA", "1.0", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.1", ["m"]),
("STANDARD", "1.1", ["m", "w-0"]),
("HA", "1.1", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.2", ["m"]),
("STANDARD", "1.2", ["m", "w-0"]),
("HA", "1.2", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.3", ["m"]),
("STANDARD", "1.3", ["m", "w-0"]),
("HA", "1.3", ["m-0", "m-1", "m-2", "w-0"]),
], testcase_func_name=DataprocTestCase.generate_verbose_test_name)
self.assertEqual(ret_code, 0,
"Failed to run command. Error: {}".format(stderr))

@parameterized.expand(
[
("SINGLE", "1.0", ["m"]),
("STANDARD", "1.0", ["m", "w-0"]),
("HA", "1.0", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.1", ["m"]),
("STANDARD", "1.1", ["m", "w-0"]),
("HA", "1.1", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.2", ["m"]),
("STANDARD", "1.2", ["m", "w-0"]),
("HA", "1.2", ["m-0", "m-1", "m-2", "w-0"]),
("SINGLE", "1.3", ["m"]),
("STANDARD", "1.3", ["m", "w-0"]),
("HA", "1.3", ["m-0", "m-1", "m-2", "w-0"]),
],
testcase_func_name=DataprocTestCase.generate_verbose_test_name)
def test_ganglia(self, configuration, dataproc_version, machine_suffixes):
self.createCluster(configuration, self.INIT_ACTIONS, dataproc_version)
for machine_suffix in machine_suffixes:
self.verify_instance(
"{}-{}".format(
self.getClusterName(),
machine_suffix
)
)
self.verify_instance("{}-{}".format(self.getClusterName(),
machine_suffix))


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion ganglia/verify_ganglia_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
import socket
import subprocess

from requests_html import HTMLSession

BASE = 'localhost'
Expand Down Expand Up @@ -56,6 +57,7 @@ def get_cluster_name(self):
stdout, stderr = p.communicate()
return stdout.decode("utf-8")


def validate_homepage(ganglia):
if ganglia.is_main_master:
if ganglia.cluster_name in ganglia.get_homepage_title():
Expand All @@ -70,7 +72,6 @@ def validate_homepage(ganglia):


def main():

"""Drives the script.
Returns:
Expand Down

0 comments on commit abc780b

Please sign in to comment.