Ejemplo n.º 1
0
    def testRunningWithSpecificResource(self):
        shard = self.agent.get_shard_id()
        res = dict(epu=20, core=1)
        recp = yield self.agent.request(shard, res)
        db = self.driver._database_connection
        doc = yield db.get_document(IRecipient(recp).key)
        self.assertIsInstance(doc.resources, dict)
        for key, val in res.iteritems():
            self.assertEqual(val, doc.resources[key].value)
        yield self.wait_for_idle(20)
        doc = yield db.reload_document(doc)

        host_id = doc.partners[0].recipient.key
        host_medium = yield self.driver.find_agent(host_id)
        host = host_medium.get_agent()
        _, allocated = yield host.list_resource()
        self.assertEqual(1, allocated['core'])

        # now use start_agent directly
        desc = Descriptor3(resources=dict(core=resource.AllocatedScalar(1)))
        desc = yield self.driver._database_connection.save_document(desc)
        self.info('starting')
        recp = yield host.start_agent(desc)
        desc = yield self.driver._database_connection.reload_document(desc)
        self.assertIsInstance(desc.resources, dict)
        self.assertEqual(['core'], desc.resources.keys())
        _, allocated = yield host.list_resource()
        self.assertEqual(2, allocated['core'])
Ejemplo n.º 2
0
    def _try_next(self, state):
        state.current_index += 1
        try:
            partner = state.hosts[state.current_index]
        except IndexError:
            return self._fail(
                'No of the Host Partners managed to start a partner %r' %\
                (state.descriptor.type_name, ))

        f = host.start_agent(state.agent, partner, state.descriptor)
        f.add_errback(self._failed_to_start, partner)
        return f
Ejemplo n.º 3
0
    def testRunningWithSpecificResource(self):
        shard = self.agent.get_own_address().shard
        res = dict(epu=20, core=1)
        recp = yield self.agent.request(shard, res)
        doc = yield self.driver._database_connection.get_document(
            IRecipient(recp).key)
        self.assertIsInstance(doc.resources, resource.ScalarResource)
        self.assertEqual(res, doc.resources.values)
        host_id = doc.partners[0].recipient.key
        host_medium = yield self.driver.find_agent(host_id)
        host = host_medium.get_agent()
        _, allocated = yield host.list_resource()
        self.assertEqual(1, allocated['core'])

        # now use start_agent directly
        desc = Descriptor3(resources=resource.ScalarResource(core=1))
        desc = yield self.driver._database_connection.save_document(desc)
        self.info('starting')
        recp = yield host.start_agent(desc)
        desc = yield self.driver._database_connection.reload_document(desc)
        self.assertIsInstance(desc.resources, resource.ScalarResource)
        self.assertEqual({'core': 1}, desc.resources.values)
        _, allocated = yield host.list_resource()
        self.assertEqual(2, allocated['core'])