GCP handler implemented

This commit is contained in:
VakarisZ 2019-08-27 18:12:14 +03:00
parent 0f5f01c4b1
commit a29408c07d
3 changed files with 42 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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):