Example #1
0
def run_simulation():
    Controller.logger = MagicMock()
    sendRequest_method = MagicMock()

    tmpfile = tempfile.gettempdir()

    config = AmbariConfig().getConfig()
    config.set('agent', 'prefix', tmpfile)

    scriptsDir = os.path.join(os.getcwd(), os.pardir, os.pardir, os.pardir,
                              'main', 'upgrade_stack')
    config.set('stack', 'upgradeScriptsDir', scriptsDir)

    ver_file = os.path.join(tmpfile, "version")

    with open(ver_file, "w") as text_file:
        text_file.write(agent_version)

    controller = Controller.Controller(config)
    controller.sendRequest = sendRequest_method
    controller.netutil.HEARTBEAT_IDDLE_INTERVAL_SEC = 0.1
    controller.netutil.HEARTBEAT_NOT_IDDLE_INTERVAL_SEC = 0.1
    controller.range = 1

    for responce in responces:
        queue.put(responce)

    def send_stub(url, data):
        logger.info("Controller sends data to %s :" % url)
        logger.info(pprint.pformat(data))
        if not queue.empty():
            responce = queue.get()
        else:
            responce = responces[-1]
            logger.info(
                "There is no predefined responce available, sleeping for 30 sec"
            )
            time.sleep(30)
        responce = json.loads(responce)
        responseId.inc()
        responce["responseId"] = responseId.val()
        responce = json.dumps(responce)
        logger.info("Returning data to Controller:" + responce)
        return responce

    sendRequest_method.side_effect = send_stub

    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(asctime)s %(filename)s:%(lineno)d - \
        %(message)s")
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    logger.info("Starting")

    controller.start()
    controller.actionQueue.IDLE_SLEEP_TIME = 0.1
    controller.run()
    def setUp(self, hostname_method, NetUtil_mock, lockMock, threadMock):

        Controller.logger = MagicMock()
        lockMock.return_value = MagicMock()
        NetUtil_mock.return_value = MagicMock()
        hostname_method.return_value = "test_hostname"

        config = MagicMock()
        config.get.return_value = "something"

        self.controller = Controller.Controller(config)
        self.controller.netutil.MINIMUM_INTERVAL_BETWEEN_HEARTBEATS = 0.1
        self.controller.netutil.HEARTBEAT_NOT_IDDLE_INTERVAL_SEC = 0.1
Example #3
0
  def setUp(self, hostname_method, lockMock, threadMock, read_agent_versionMock):

    Controller.logger = MagicMock()
    lockMock.return_value = MagicMock()
    hostname_method.return_value = "test_hostname"
    read_agent_versionMock.return_value = '2.1.0'

    config = MagicMock()
    #config.get.return_value = "something"
    config.get.return_value = "5"

    self.controller = Controller.Controller(config)
    self.controller.netutil.MINIMUM_INTERVAL_BETWEEN_HEARTBEATS = 0.1
    self.controller.netutil.HEARTBEAT_NOT_IDDLE_INTERVAL_SEC = 0.1