forked from p15670423/monkey
GCP handler implemented
This commit is contained in:
parent
0f5f01c4b1
commit
a29408c07d
|
@ -0,0 +1,4 @@
|
|||
# Automatic blackbox tests
|
||||
### Prerequisites
|
||||
1. Download google sdk: https://cloud.google.com/sdk/docs/
|
||||
2. Download service account key GCP console -> IAM -> service accounts(you can use the same key used to authenticate terraform scripts)
|
|
@ -0,0 +1,34 @@
|
|||
import subprocess
|
||||
|
||||
|
||||
class GCPHandler(object):
|
||||
|
||||
AUTHENTICATION_COMMAND = "gcloud auth activate-service-account --key-file=%s"
|
||||
MACHINE_STARTING_COMMAND = "gcloud compute instances start %s --zone=%s"
|
||||
MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s"
|
||||
|
||||
def __init__(self, key_path="../gcp_keys/gcp_key.json", zone="europe-west3-a"):
|
||||
self.zone = zone
|
||||
try:
|
||||
subprocess.call(GCPHandler.get_auth_command(key_path), shell=True)
|
||||
print("GCP Handler initialized successfully")
|
||||
except Exception as e:
|
||||
print("GCP Handler failed to initialize: %s." % e)
|
||||
|
||||
def start_machines(self, machine_list):
|
||||
try:
|
||||
subprocess.call((GCPHandler.MACHINE_STARTING_COMMAND % (machine_list, self.zone)), shell=True)
|
||||
print("GCP machines successfully started.")
|
||||
except Exception as e:
|
||||
print("GCP Handler failed to start GCP machines: %s" % e)
|
||||
|
||||
def stop_machines(self, machine_list):
|
||||
try:
|
||||
subprocess.call((GCPHandler.MACHINE_STOPPING_COMMAND % (machine_list, self.zone)), shell=True)
|
||||
print("GCP machines stopped successfully.")
|
||||
except Exception as e:
|
||||
print("GCP Handler failed to stop network machines: %s" % e)
|
||||
|
||||
@staticmethod
|
||||
def get_auth_command(key_path):
|
||||
return GCPHandler.AUTHENTICATION_COMMAND % key_path
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
from .gcp_machine_handlers import GCPHandler
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -6,12 +7,15 @@ from config import *
|
|||
|
||||
|
||||
class TestMonkeyBlackbox(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
GCPHandler().start_machines("elastic-4")
|
||||
print("Setting up all GCP machines...")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
GCPHandler().stop_machines("elastic-4")
|
||||
print("Killing all GCP machines...")
|
||||
|
||||
def generic_blackbox_test_case(self, config_file_path, analyzers):
|
||||
|
|
Loading…
Reference in New Issue