Exemplo n.º 1
0
class TestsSetup(object):
    def __init__(self,
                 qmf_binary,
                 agentKeyword,
                 agentClass,
                 dbus_binary=None,
                 dbus_settings=[]):
        self.broker = MatahariBroker()
        self.broker.start()
        time.sleep(3)
        self.qmf_agent = MatahariQMFAgent(qmf_binary)
        self.qmf_agent.start()

        if dbus_binary is None:
            global haveDBus
            haveDBus = False
        if haveDBus:
            self.dbus_agent = MatahariDBusAgent(dbus_binary)
            self.dbus_agent.start()
        else:
            self.dbus_agent = None

        time.sleep(3)

        self._connectToBroker('localhost', '49001')
        if haveDBus:
            self.dbus = MatahariDBusObject(*dbus_settings)
        else:
            self.dbus = None

        self.agentKeyword = agentKeyword
        self.agentClass = agentClass
        self.qmf = self._findAgent(cmd.getoutput('hostname'))
        self.reQuery()

    def tearDown(self):
        self._disconnect()
        if self.dbus_agent is not None:
            self.dbus_agent.stop()
        self.qmf_agent.stop()
        self.broker.stop()

    def _disconnect(self):
        self.session.close()
        self.connection.close()

    def reQuery(self):
        self.qmf.update()
        self.qmf.props = self.qmf.getProperties()
        if haveDBus:
            self.dbus.reQuery()

    def _findAgent(self, hostname):
        loop_count = 0
        while loop_count < 70:
            agents = self.session.getAgents()
            sys.stderr.write("Agents: %s\n" % str(agents))
            for agent in agents:
                if self.agentKeyword in str(agent):
                    if agent.getAttributes().get('hostname') == hostname:
                        objs = agent.query("{class:" + self.agentClass +
                                           ",package:'org.matahariproject'}")
                        if objs and len(objs):
                            return objs[0]
            time.sleep(1)
            loop_count = loop_count + 1
        sys.exit("specific " + self.agentKeyword + " agent for " + hostname +
                 " not found.")

    def _connectToBroker(self, hostname, port):
        self.connection = cqpid.Connection(hostname + ":" + port)
        self.connection.open()
        self.session = ConsoleSession(self.connection)
        self.session.open()
def connectToBroker(hostname, port):
    connection = cqpid.Connection(hostname + ":" + port)
    connection.open()
    session = ConsoleSession(connection)
    session.open()
    return [ connection, session ]
Exemplo n.º 3
0
def connectToBroker(hostname, port):
    connection = cqpid.Connection(hostname + ":" + port)
    connection.open()
    session = ConsoleSession(connection)
    session.open()
    return [connection, session]
Exemplo n.º 4
0
class TestsSetup(object):
    def __init__(self, qmf_binary, agentKeyword, agentClass, dbus_binary=None, dbus_settings=[]):
        self.broker = MatahariBroker()
        self.broker.start()
        time.sleep(3)
        self.qmf_agent = MatahariQMFAgent(qmf_binary)
        self.qmf_agent.start()

        if dbus_binary is None:
            global haveDBus
            haveDBus = False
        if haveDBus:
            self.dbus_agent = MatahariDBusAgent(dbus_binary)
            self.dbus_agent.start()
        else:
            self.dbus_agent = None

        time.sleep(3)

        self._connectToBroker("localhost", "49001")
        if haveDBus:
            self.dbus = MatahariDBusObject(*dbus_settings)
        else:
            self.dbus = None

        self.agentKeyword = agentKeyword
        self.agentClass = agentClass
        self.qmf = self._findAgent(cmd.getoutput("hostname"))
        self.reQuery()

    def tearDown(self):
        self._disconnect()
        if self.dbus_agent is not None:
            self.dbus_agent.stop()
        self.qmf_agent.stop()
        self.broker.stop()

    def _disconnect(self):
        self.session.close()
        self.connection.close()

    def reQuery(self):
        self.qmf.update()
        self.qmf.props = self.qmf.getProperties()
        if haveDBus:
            self.dbus.reQuery()

    def _findAgent(self, hostname):
        loop_count = 0
        while loop_count < 70:
            agents = self.session.getAgents()
            sys.stderr.write("Agents: %s\n" % str(agents))
            for agent in agents:
                if self.agentKeyword in str(agent):
                    if agent.getAttributes().get("hostname") == hostname:
                        objs = agent.query("{class:" + self.agentClass + ",package:'org.matahariproject'}")
                        if objs and len(objs):
                            return objs[0]
            time.sleep(1)
            loop_count = loop_count + 1
        sys.exit("specific " + self.agentKeyword + " agent for " + hostname + " not found.")

    def _connectToBroker(self, hostname, port):
        self.connection = cqpid.Connection(hostname + ":" + port)
        self.connection.open()
        self.session = ConsoleSession(self.connection)
        self.session.open()