Exemple #1
0
def t4():
    pretty = '%s t4' % __file__
    print(pretty)

    config = get_database_config()
    broker = Broker()
    w1 = broker.get({'type': 'workspace'})
    w2 = broker.get({'type': 'workspace'})
    w3 = broker.get({'type': 'workspace'})
    w4 = broker.get({'type': 'workspace'})
    guid, json_data = get_guid_and_json()

    # must exit silently ...

    # no config
    try:
        ave.panotti.shout(guid, json_data, w1.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (no config file), exception: %s' % e)
        return False

    # empty config
    make_config(w2, {})
    try:
        ave.panotti.shout(guid, json_data, w2.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (empty config), exception: %s' % e)
        return False

    # enabled
    make_config(w3, config)
    db = mock_database(w3, config)
    try:
        ave.panotti.shout(guid, json_data, w3.get_path())
    except Exception as e:
        return failed('Unexpected exception: %s' % e, db.name)
    time.sleep(1)
    verify_single_entry(db, json_data)

    # disabled
    config['enabled'] = False
    make_config(w4, config)
    try:
        ave.panotti.shout(guid, json_data, w4.get_path())
    except Exception as e:
        return failed('Expected silent exit (disabled),exception: %s' % e,
                      db.name)

    time.sleep(1)
    # no entry was added
    verify_single_entry(db, json_data)

    delete_database(config)
    return True
Exemple #2
0
def t2():
    pretty = '%s t2' % __file__
    print(pretty)

    broker = Broker()
    w = broker.get({'type': 'workspace'})
    config = get_database_config()
    db = mock_database(w, config)
    guid, json_data = get_guid_and_json()

    expected = 100
    try:
        for i in range(0, expected):
            ave.panotti.shout(guid, json_data, w.get_path())
    except Exception as e:
        return failed('Exception in shout %s' % e, db.name)

    res = None
    for r in range(3):
        time.sleep(1)  # give it a moment
        res = len(query(db))
        if res == expected:
            break

    if res != expected:
        return failed(
            'Wrong nr of records: %d, expected: %d' % (res, expected), db.name)

    delete_database(config)
    return True
Exemple #3
0
def t3():
    pretty = '%s t3' % __file__
    print(pretty)

    db_name = 'panotti_test'
    port = 2929292
    host = 'nosuchhostcanbefound'
    invalid_config = {
        'db': db_name,
        'host': host,
        'port': port,
        'enabled': True
    }

    broker = Broker()
    w = broker.get({'type': 'workspace'})
    guid, json_data = get_guid_and_json()
    # configure for db, but do not create
    make_config(w, invalid_config)

    try:
        ave.panotti.shout(guid, json_data, w.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (urlopen error), exception: %s' % e)
        return False
    return True
Exemple #4
0
class StdOutRedirector(object):
    broker = None
    workspace = None
    path = None
    file = None
    original = None
    def __init__(self):
        self.broker = Broker()
        self.workspace = self.broker.get({'type':'workspace'})
        self.path = self.workspace.make_tempdir()
        self.file = self.workspace.make_tempfile(self.path)

    def redirect(self):
        self.original = sys.stdout
        sys.stdout = open(self.file, 'r+')

    def flush(self):
        sys.stdout.flush()

    def get_content(self):
        self.flush()
        f = open(self.file)
        content = f.read()
        return content

    def clear(self):
        f = open(self.file, 'w')
        f.truncate()

    def reset(self):
        sys.stdout = self.original

    def __del__(self):
        self.reset()
Exemple #5
0
def t2():
    pretty = common.get_test_pretty()
    print(pretty)

    b = Broker()
    w = b.get({'type': 'workspace'})
    file_name = 'test.log'

    guid = base64.urlsafe_b64encode(uuid.uuid1().bytes).replace('=', '')

    logger = Logger(w, guid, file_path=file_name)

    # log to get url
    result = logger.log_it('i', '')

    logger.set_lowest_log_level('w')

    test_text = 'Test that should not be written to log'

    logger.log_it('i', test_text)

    flocker_url = '%s/%s' % (logger.parse_flocker_data(result)[0], file_name)

    log_file = urllib2.urlopen(flocker_url)

    for line in log_file:
        if test_text in line:
            print('FAIL %s: "%s" found in log when log level was to low' %
                  (pretty, test_text))
            return False

    return True
Exemple #6
0
def t1():
    pretty = common.get_test_pretty()
    print(pretty)

    b = Broker()
    w = b.get({'type': 'workspace'})
    file_name = 'test.log'

    guid = common.generate_id()

    logger = Logger(w, guid, file_path=file_name)

    result = logger.log_it('i', 'Test')

    flocker_url = '%s/%s' % (logger.parse_flocker_data(result)[0], file_name)

    log_file = urllib2.urlopen(flocker_url)

    lines = []

    for line in log_file:
        lines.append(line)

    exp_data = ['Initiating Test Job Log in flocker', 'Test']

    for i in range(len(exp_data)):
        if exp_data[i] not in lines[i]:
            print(
                'FAIL %s: Unexpected first line in log: %s, expected text "%s" '
                'not found.' % (pretty, lines[i], exp_data[i]))
            return False

    return True
Exemple #7
0
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    broker = Broker()
    w = broker.get({'type': 'workspace'})
    config = get_database_config()
    db = mock_database(w, config)
    guid, json_data = get_guid_and_json()

    ave.panotti.shout(guid, json_data, w.get_path())
    time.sleep(1)  # give it a moment
    if not verify_single_entry(db, json_data):
        return False
    delete_database(config)
    return True
Exemple #8
0
def run_smoke_off_site(report=True):
    passed = []
    failed = []
    errors = []
    target = 0
    logger_broker = Broker()
    logger_ws = logger_broker.get({'type': 'workspace'})
    try:
        guid = vcsjob.get_guid()
    except Exception as e:
        guid = 'local_guid'
    logger = Logger(logger_ws, guid)

    b, w, h = allocate_by_profiles()
    logger.log_it(
        'd', 'allocated: %s' % json.dumps([h.profile, w.profile], indent=3))

    label = h.get_build_label()

    t, p, f, e = run_module(tests.popup, (w, h), True, report, logger)
    target += t
    passed.extend(p)
    failed.extend(f)
    errors.extend(e)

    t, p, f, e = run_module(tests.adb, (w, h), True, report, logger)
    target += t
    passed.extend(p)
    failed.extend(f)
    errors.extend(e)

    t, p, f, e = run_module(tests.android, (w, h, label), True, report, logger)
    target += t
    passed.extend(p)
    failed.extend(f)
    errors.extend(e)

    t, p, f, e = run_module(tests.gtest, (w, h), True, report, logger)
    target += t
    passed.extend(p)
    failed.extend(f)
    errors.extend(e)

    if len(passed) != target:
        return vcsjob.FAILURES
    return vcsjob.OK
Exemple #9
0
def allocate_by_profiles(local=False):
    # get profiles from vcsjob file and attempt to allocate the resources.
    # return as a tuple including the broker:
    #     (<broker>, <allocated 1>, <allocated 2>,...)
    profiles = vcsjob.get_profiles()
    b = Broker()
    try:
        allocated = b.get(*profiles)
    except (Busy, NoSuch, Exit) as e:
        print('BUSY: %s' % e)
        sys.exit(vcsjob.BUSY)
    res = [b]
    allocated = [allocated] if not '__iter__' in dir(allocated) else allocated
    for a in allocated:
        if local and a.profile['type'] == 'handset':
            if a.profile['platform'] == 'android':
                a = PatchedAndroidHandset(HandsetProfile(a.get_profile()))
            else:
                a = Handset(HandsetProfile(a.get_profile()))
        res.append(a)
    return tuple(res)
Exemple #10
0
def t5():
    pretty = '%s t5' % __file__
    print(pretty)

    broker = Broker()
    w = broker.get({'type': 'workspace'})
    config = get_database_config()
    make_config(w, config)

    guid, json_data = get_guid_and_json()
    # must be a dictionary
    invalid_data = [{'title': 'decibel-mock', 'url': 'http://link'}]
    # must be a string of length >= 10
    short_guid = 'short'
    invalid_guid = ['wrong', 'type', 'of', 'guid']

    # must exit silently ...

    # short guid
    try:
        ave.panotti.shout(short_guid, json_data, w.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (short guid), exception: %s' % e)
        return False
    # invalid type of guid
    try:
        ave.panotti.shout(invalid_guid, json_data, w.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (invalid guid), exception: %s' % e)
        return False
    # invalid type of data
    try:
        ave.panotti.shout(guid, invalid_data, w.get_path())
    except Exception as e:
        print('FAIL: Expected silent exit (invalid json), exception: %s' % e)
        return False

    return True
Exemple #11
0
def t3():
    """
    Verifying that a temporary down flocker connection does not cause dropped
    log lines
    """
    pretty = common.get_test_pretty()
    print(pretty)

    b = Broker()
    w = b.get({'type': 'workspace'})
    file_name = 'test.log'
    test_text = 'Log Line 2'

    guid = base64.urlsafe_b64encode(uuid.uuid1().bytes).replace('=', '')

    logger = MockLoggerFlockerDown(w, guid, file_path=file_name)

    logger.log_it('i', 'Log Line 1')
    logger.fail_flocker = True
    logger.log_it('i', test_text)
    result = logger.log_it('i', 'Log Line 3')
    logger.fail_flocker = False
    result = logger.log_it('i', 'Log Line 4')
    flocker_url = '%s/%s' % (logger.parse_flocker_data(result)[0], file_name)

    log_file = urllib2.urlopen(flocker_url)

    found = False
    for line in log_file:
        if test_text in line:
            found = True
    if not found:
        print('FAIL %s: "%s" not found in log, should have been saved while '
              'flocker was down' % (pretty, test_text))
        return False
    return True
Exemple #12
0
def t4():
    """
    Verifying that Flocker log ling is shouted to panotti when flocker comes up
    if it is down at init
    """
    pretty = common.get_test_pretty()
    print(pretty)

    b = Broker()
    w = b.get({'type': 'workspace'})
    file_name = 'test.log'
    test_text = 'http:'

    guid = base64.urlsafe_b64encode(uuid.uuid1().bytes).replace('=', '')

    logger = MockLoggerFlockerDown(w,
                                   guid,
                                   file_path=file_name,
                                   fail_flocker=True)

    logger.log_it('i', 'Log Line 1')
    logger.fail_flocker = False
    result = logger.log_it('i', 'Log Line 2')
    flocker_url = '%s/%s' % (logger.parse_flocker_data(result)[0], file_name)

    log_file = urllib2.urlopen(flocker_url)

    found = False
    for line in log_file:
        if test_text in line:
            found = True
    if not found:
        print('FAIL %s: "%s" not found in log, should have been saved while '
              'flocker was down' % (pretty, test_text))
        return False
    return True
Exemple #13
0
def all_usb_power(debug=False, report=False):
    profiles = vcsjob.get_profiles()
    b = Broker()
    r, h = b.get(*profiles)
    result = run_suite([(tests.usb_power, (b, r, h))], report)