示例#1
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
示例#2
0
文件: runners.py 项目: yiu31802/ave
def all_atf(local=False):
    b = Broker()

    if local:
        prefix = os.path.dirname(os.path.dirname(__file__))
        prefix = os.path.join(prefix, 'packaging')
    else:
        prefix = '/'
    apk_dir = os.path.join(prefix, 'usr', 'share', 'ave', 'galatea')

    h = b.get_resources({'type': 'handset', 'platform': 'android'})
    h.reinstall(os.path.join(apk_dir, 'galatea-kk-mr1-shinano2.apk'))

    h.disable_keyguard()
    h.stay_awake(True)

    tests.atf.t1(h)
    tests.atf.t2(h)
    tests.atf.t3(h)
    tests.atf.t4(h)
    tests.atf.t5(h)
    tests.atf.t6(h)
    tests.atf.t7(h)
    tests.atf.t8(h)
    tests.atf.t9(h)
    tests.atf.t10(h)

    h.stay_awake(False)
示例#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
示例#4
0
def t12(h1, h2):
    pretty = '%s t12' % __file__
    print(pretty)
    home = ave.config.load_etc()['home']
    key = ave.config.load_authkeys(home)
    b = Broker(authkey=key["admin"])
    handsets = b.list_handsets()
    serial = h1.get_profile()["serial"]
    for h in handsets:
        if h['serial'] == serial and h['power_state'] == 'boot_completed':
            # check software build type like "[ro.build.type]: [userdebug]"
            if h['sw_type'] is None or re.compile("\w").match(h['sw_type']):
                pass
            else:
                print("can't get normal profile['sw_type'] value.")
                return False
            # check phone operator code like "'sim.operator.numeric': '46000,46001'"
            if h['sim.operator.numeric'] is None or re.compile(
                    "\d{5},?(\d{5})?").match(h['sim.operator.numeric']):
                pass
            else:
                print(
                    "can't get normal profile['sim.operator.numeric'] value.")
                return False
            # check the country name of the service provider.
            if h['sim.country'] is None or re.compile('\w{1,9}').match(
                    h['sim.country']):
                pass
            else:
                print("can't get normal profile['sim.country'] value.")
                return False
            break
    return True
示例#5
0
文件: logger.py 项目: yiu31802/ave
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
示例#6
0
文件: logger.py 项目: yiu31802/ave
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
示例#7
0
def all_handset_lister(local=False):
    from ave.broker import Broker
    b = Broker()
    h1, r1 = b.get_resource({'type': 'handset'}, {
        'type': 'relay',
        'circuits': ['usb.pc.vcc']
    })
    h2 = b.get_resource({'type': 'handset'})

    if local:
        from ave.handset.handset import Handset
        from ave.handset.profile import HandsetProfile
        h1 = Handset(HandsetProfile(h1.get_profile()))
        h2 = Handset(HandsetProfile(h2.get_profile()))

    # many of the tests manipulate r1 to disconnect h1. close it after each
    # test to make sure the handset is in a usable state
    tests.handset_lister.t1()
    tests.handset_lister.t2(h1, h2, r1)
    r1.set_circuit('usb.pc.vcc', True)
    h1.wait_power_state('boot_completed', 5)
    tests.handset_lister.t3(h1, h2, r1)
    r1.set_circuit('usb.pc.vcc', True)
    h1.wait_power_state('boot_completed', 5)
    tests.handset_lister.t4(h1, h2, r1)
    r1.set_circuit('usb.pc.vcc', True)
    h1.wait_power_state('boot_completed', 5)
    tests.handset_lister.t5(h1, h2, r1)
    r1.set_circuit('usb.pc.vcc', True)
    h1.wait_power_state('boot_completed', 5)
    tests.handset_lister.t6(h1, h2, r1)
    r1.set_circuit('usb.pc.vcc', True)
    h1.wait_power_state('boot_completed', 5)
示例#8
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
示例#9
0
文件: common.py 项目: yiu31802/ave
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()
示例#10
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
示例#11
0
文件: runners.py 项目: yiu31802/ave
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
示例#12
0
 def run(self):
     try:
         from ave.broker import Broker
         authkeys = ave.config.load_authkeys(self.home)
         broker = Broker(None, self.timeout, authkeys['share'], self.home)
     except Exception, e:
         self.log('ERROR: could not create broker client: %s' % e)
         return # early return
示例#13
0
文件: runners.py 项目: yiu31802/ave
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)
示例#14
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
示例#15
0
文件: logger.py 项目: yiu31802/ave
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
示例#16
0
文件: logger.py 项目: yiu31802/ave
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
示例#17
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)
示例#18
0
文件: common.py 项目: yiu31802/ave
 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)