Ejemplo n.º 1
0
class Test_Functions:
    def __init__(self):
        self.check_tools = Tools()

    def test_check_elk_connection(self):
        assert_equals(self.check_tools.check_elk_connection(), True,
                      'Must return True for E-L-K connections successfull')

    def test_ub_cost(self):
        result = subprocess.check_output([
            'curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'
        ],
                                         shell=True,
                                         stderr=subprocess.PIPE)
        result = subprocess.check_output([
            'curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'
        ],
                                         shell=True,
                                         stderr=subprocess.PIPE)
        result = subprocess.check_output([
            'curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'
        ],
                                         shell=True,
                                         stderr=subprocess.PIPE)
        print(result)
        result = simplejson.loads(result)
        sum_ub_cost = result["aggregations"]["sum_ub_cost"]["value"]
        assert_equals(float(format(sum_ub_cost, '.3f')), 0.201,
                      'Must return the exact sum as the csv file')
Ejemplo n.º 2
0
class Test_Functions:

    def __init__(self):
        self.check_tools = Tools()

    def test_check_elk_connection(self):
        assert_equals(
            self.check_tools.check_elk_connection(),
            True,
            'Must return True for E-L-K connections successfull'
        )

    def test_ub_cost(self):
        result = subprocess.check_output(['curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'],
            shell=True, stderr=subprocess.PIPE)
        result = subprocess.check_output(['curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'],
            shell=True, stderr=subprocess.PIPE)
        result = subprocess.check_output(['curl -XGET "http://elasticsearch:9200/aws-billing-2016.06/_search" -d "`cat /aws-elk-billing/test/tools/aggregate.json`"'],
            shell=True, stderr=subprocess.PIPE)
        print(result)
        result = simplejson.loads(result)
        sum_ub_cost = result["aggregations"]["sum_ub_cost"]["value"]
        assert_equals(
            float(format(sum_ub_cost,'.3f')),
            0.201,
            'Must return the exact sum as the csv file'
        )
Ejemplo n.º 3
0
added head source directory in path for import from any location and relative testing and pwd for open() relative files
'''
from tools.tools import Tools
import boto3

if __name__ == '__main__':

    # you must provide your credentials in the recomanded way, here we are
    # passing it by ENV variables
    s3 = boto3.client('s3')

    #initialize the tools class
    tools = Tools(s3)

    # checking for established connections between E-L-K
    tools.check_elk_connection()

    # function to index the default template mapping of the data
    tools.index_template()

    # getting the required buckets names to index from get_s3_bucket_dir_to_index()
    s3_dir_to_index = tools.get_s3_bucket_dir_to_index()
    if s3_dir_to_index == 1:
        print 'I could not find any billing report under Bucket ', os.environ[
            'S3_BUCKET_NAME'], ' under Path ', os.environ['S3_REPORT_PATH']
        sys.exit(1)

    # downloading the csv file with get_req_csv_from_s3() and then calling the index_csv() to index it in our elasticsearch
    for dir_name in s3_dir_to_index:
        gzip_filename = tools.get_latest_zip_filename(dir_name)
        csv_filename = tools.get_req_csv_from_s3(dir_name, gzip_filename)
Ejemplo n.º 4
0
'''
added head source directory in path for import from any location and relative testing and pwd for open() relative files
'''
from tools.tools import Tools
import boto3
import subprocess
import time

if __name__ == '__main__':

    print('Orchestrate-test Running')
    #initialize the tools class
    tools = Tools()

    # checking for established connections between E-L-K
    tools.check_elk_connection()

    # function to index the default template mapping of the data
    tools.index_template()
    
    # index a sample test file with sum of unblended cost 1.24185686
    tools.index_csv('test/sample/test_ub_cost_2016-06.csv', '20160601-20160701')
    # rows of data in the csv, must be given as string
    data_count = '315'
    while(True):
        index_names = subprocess.check_output(['curl -XGET "elasticsearch:9200/_cat/indices/"'], shell=True, stderr=subprocess.PIPE)
        if 'aws-billing-2016.06' in index_names and data_count in index_names:
            break

    index_names = subprocess.check_output(['curl -XGET "elasticsearch:9200/_cat/indices/"'], shell=True, stderr=subprocess.PIPE)
    print(index_names)