示例#1
0
    def test_get_os(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        linux_monkey = Monkey(
            guid=str(uuid.uuid4()),
            description=
            "Linux shay-Virtual-Machine 4.15.0-50-generic #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019 x86_64 x86_64"
        )
        windows_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="Windows bla bla bla")
        unknown_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="bla bla bla")
        linux_monkey.save()
        windows_monkey.save()
        unknown_monkey.save()

        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "windows",
                          Monkey.objects())))
        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "linux", Monkey.objects())))
        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "unknown",
                          Monkey.objects())))
示例#2
0
    def test_is_dead(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        alive_monkey_ttl = MonkeyTtl.create_ttl_expire_in(30)
        alive_monkey_ttl.save()
        alive_monkey = Monkey(guid=str(uuid.uuid4()),
                              dead=False,
                              ttl_ref=alive_monkey_ttl.id)
        alive_monkey.save()

        # MIA stands for Missing In Action
        mia_monkey_ttl = MonkeyTtl.create_ttl_expire_in(30)
        mia_monkey_ttl.save()
        mia_monkey = Monkey(guid=str(uuid.uuid4()),
                            dead=False,
                            ttl_ref=mia_monkey_ttl)
        mia_monkey.save()
        # Emulate timeout - ttl is manually deleted here, since we're using mongomock and not a real mongo instance.
        sleep(1)
        mia_monkey_ttl.delete()

        dead_monkey = Monkey(guid=str(uuid.uuid4()), dead=True)
        dead_monkey.save()

        # act + assert
        self.assertTrue(dead_monkey.is_dead())
        self.assertTrue(mia_monkey.is_dead())
        self.assertFalse(alive_monkey.is_dead())
示例#3
0
def runMonkey():
    mk = Monkey()
    print mk.get_conf()
    print mk.get_command()
    mk.run(mk.get_command())

    return static_file(
        'monkey.html',
        root='/Users/dongqingqing/PycharmProjects/ApkPerforTools/static/html')
示例#4
0
 def initialize(self, config):
     self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])
     self._grid = Grid(config.gridData)
     self._kickers = []
     print(self._config.kickersData)
     for kickerData in self._config.kickersData:
         kicker = Kicker(kickerData[0], kickerData[1])
         self._kickers.append(kicker)
     self.createKickers()
示例#5
0
def main():
    # testing base class - Animal
    animal = Animal("Luigi", 10)
    print(animal)

    # testing dereived class - Monkey
    mon = Monkey("Lily", 3)
    print(mon)
    print(mon.getNoise())
示例#6
0
    def test_get_tunneled_monkeys(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        linux_monkey = Monkey(guid=str(uuid.uuid4()),
                              description="Linux shay-Virtual-Machine")
        windows_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="Windows bla bla bla",
                                tunnel=linux_monkey)
        unknown_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="bla bla bla",
                                tunnel=windows_monkey)
        linux_monkey.save()
        windows_monkey.save()
        unknown_monkey.save()
        tunneled_monkeys = Monkey.get_tunneled_monkeys()
        test = bool(windows_monkey in tunneled_monkeys
                    and unknown_monkey in tunneled_monkeys
                    and linux_monkey not in tunneled_monkeys
                    and len(tunneled_monkeys) == 2)
        self.assertTrue(test, "Tunneling test")
示例#7
0
    def test_ttl_renewal(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        monkey = Monkey(guid=str(uuid.uuid4()))
        monkey.save()
        self.assertIsNone(monkey.ttl_ref)

        # act + assert
        monkey.renew_ttl()
        self.assertIsNotNone(monkey.ttl_ref)
示例#8
0
    def test_get_single_monkey_by_id(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        a_monkey = Monkey(guid=str(uuid.uuid4()))
        a_monkey.save()

        # Act + assert
        # Find the existing one
        self.assertIsNotNone(Monkey.get_single_monkey_by_id(a_monkey.id))
        # Raise on non-existent monkey
        self.assertRaises(MonkeyNotFoundError, Monkey.get_single_monkey_by_id,
                          "abcdefabcdefabcdefabcdef")
示例#9
0
    def connect(self):
        if self.needStop:
            return
        if self.url is None:
            print('need url for connect')
            return

        ecall('adb forward tcp:50001 tcp:50001')
        try:
            monkey = Monkey(self.url)
        except OSError:
            self.tryTimer = None
            self.tryTimer = Timer(1, self.connect)
            self.tryTimer.start()
            return
        self.monkey = monkey
        self.tryTimer = Timer(0.2, self._processConnectResult)
        self.tryTimer.start()
示例#10
0
		def handler(scene):
			frame = scene.frame_current
			if frame ==  10:
				self._grid = Grid(config.gridData)
				
			elif frame == 20:
				self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])

			n = 0

			for frame in range(40,80,10):
				moveVel = trajectory[n] - self._monkey.pos
				self._monkey.move(moveVel)
				n += 1
				print(n)
				break

			if frame == 250:
				self._monkey.delete(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])
示例#11
0
    def test_is_monkey(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        a_monkey = Monkey(guid=str(uuid.uuid4()))
        a_monkey.save()

        cache_info_before_query = Monkey.is_monkey.storage.backend.cache_info()
        self.assertEquals(cache_info_before_query.hits, 0)

        # not cached
        self.assertTrue(Monkey.is_monkey(a_monkey.id))
        fake_id = "123456789012"
        self.assertFalse(Monkey.is_monkey(fake_id))

        # should be cached
        self.assertTrue(Monkey.is_monkey(a_monkey.id))
        self.assertFalse(Monkey.is_monkey(fake_id))

        cache_info_after_query = Monkey.is_monkey.storage.backend.cache_info()
        self.assertEquals(cache_info_after_query.hits, 2)
示例#12
0
    def test_get_label_by_id(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        hostname_example = "a_hostname"
        ip_example = "1.1.1.1"
        linux_monkey = Monkey(guid=str(uuid.uuid4()),
                              description="Linux shay-Virtual-Machine",
                              hostname=hostname_example,
                              ip_addresses=[ip_example])
        linux_monkey.save()

        cache_info_before_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        self.assertEquals(cache_info_before_query.hits, 0)

        # not cached
        label = Monkey.get_label_by_id(linux_monkey.id)

        self.assertIsNotNone(label)
        self.assertIn(hostname_example, label)
        self.assertIn(ip_example, label)

        # should be cached
        _ = Monkey.get_label_by_id(linux_monkey.id)
        cache_info_after_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        self.assertEquals(cache_info_after_query.hits, 1)

        linux_monkey.set_hostname("Another hostname")

        # should be a miss
        label = Monkey.get_label_by_id(linux_monkey.id)
        cache_info_after_second_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        # still 1 hit only
        self.assertEquals(cache_info_after_second_query.hits, 1)
        self.assertEquals(cache_info_after_second_query.misses, 2)
示例#13
0
                        type=int,
                        help="Radio channel")

    parser.add_argument("--debug", action="store_true", default=False)

    args = parser.parse_args()

    if args.debug:
        import simplelogging.logsetup
        simplelogging.logsetup.setup_console()

    def closed():
        print("closed")
        reactor.callFromThread(reactor.stop)

    con = Monkey(args.connection, args.address, callback_reactor=reactor)
    con.set_closed_callback(closed)

    if args.channel is not None:
        reactor.callFromThread(con.set_channel, args.channel)

    pinger = PingSender(con, args)

    con.open()
    pinger.start()

    # Run the system
    reactor.run()

    con.close()
示例#14
0
from dog import Dog
from monkey import Monkey

d = Dog('Bob')
m = Monkey('Rolf')

d.walk()
m.eat()
示例#15
0
    g = Giraffe(4)
    g.say_hello()
    g.get_number_of_legs()
    g.how_do_i_move()
    g.how_much_do_i_weigh()
    g.am_i_extinct()

if What_animal == "Hippo":
    h = Hippo(4)
    h.say_hello()
    h.get_number_of_legs()
    h.how_do_i_move()
    h.how_much_do_i_weigh()
    h.am_i_extinct()

if What_animal == "Monkey":
    m = Monkey(2)
    m.say_hello()
    m.get_number_of_legs()
    m.how_do_i_move()
    m.how_much_do_i_weigh()
    m.am_i_extinct()

if What_animal == "Bee":
    be = Bee(0)
    be.say_hello()
    be.get_number_of_legs()
    be.how_do_i_move()
    be.how_much_do_i_weigh()
    be.am_i_extinct()
示例#16
0
import threading
import time

import monkey_global
from mongo.monkey_job import MonkeyJob
from monkey import Monkey

monkey_global.QUIET_ANSIBLE = True
monkey = Monkey(start_loop=False)

print("Starting test_instance")
aws_provider = monkey.providers[0]
print(aws_provider)
print(aws_provider.list_instances())
instance = list(aws_provider.instances.values())[0]
print(instance)

job = MonkeyJob.objects()[0]
job_yml = job.job_yml
print(job_yml)

print(instance.get_json())


def run(run_number):
    time.sleep(5)
    print("Starting install.....")
    for install_item in job_yml.get("install", []):
        print("Installing item: ", install_item)
        success = instance.install_dependency(install_item)
        if success == False:
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
hdlr = logging.FileHandler(monkey_global.LOG_FILE)
formatter = logging.Formatter(log_format, log_date_format)
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)

date_format = "monkey-%y-%m-%d-"
instance_number = 0
last_date = datetime.now().strftime(date_format)

lock = threading.Lock()
monkey = Monkey()

UNIQUE_UIDS = True

MONKEYFS_LOCAL_PATH = "ansible/monkeyfs"


def get_local_filesystem_for_provider(provider_name):
    found_provider = None
    for provider in monkey.providers:
        if provider.name == provider_name:
            found_provider = provider

    if found_provider is None:
        logger.info("Failed to find provider with specified name for job")
        return None
    def __init__(self, logPath, device_id, pkgName):
        Thread.__init__(self)

        self.monkeyInstance = Monkey(logPath, device_id, pkgName)
        self.logPath = logPath