Example #1
0
    def update_state(self, worker_context, silent=False):
        self._ensure_cache(worker_context)
        if self.state == GONE:
            self.log.debug("not updating state of deleted router")
            return self.state

        if self.router_obj.management_port is None:
            self.log.debug("no management port, marking router as down")
            self.state = DOWN
            return self.state

        addr = _get_management_address(self.router_obj)
        for i in xrange(cfg.CONF.max_retries):
            if router_api.is_alive(addr, cfg.CONF.akanda_mgt_service_port):
                if self.state != CONFIGURED:
                    self.state = UP
                break
            if not silent:
                self.log.debug("Alive check failed. Attempt %d of %d", i, cfg.CONF.max_retries)
            time.sleep(cfg.CONF.retry_delay)
        else:
            old_state = self.state
            self._check_boot_timeout()

            # If the router isn't responding, make sure Nova knows about it
            instance = worker_context.nova_client.get_instance(self.router_obj)
            if instance is None and self.state != ERROR:
                self.log.info("No router VM was found; rebooting")
                self.state = DOWN

            # update_state() is called from Alive() to check the
            # status of the router. If we can't talk to the API at
            # that point, the router should be considered missing and
            # we should reboot it, so mark it down if we think it was
            # configured before.
            if old_state == CONFIGURED and self.state != ERROR:
                self.log.debug("Did not find router alive, marking it as down")
                self.state = DOWN

        # After the router is all the way up, record how long it took
        # to boot and accept a configuration.
        if self._currently_booting and self.state == CONFIGURED:
            # If we didn't boot the server (because we were restarted
            # while it remained running, for example), we won't have a
            # last_boot time to log.
            if self.last_boot:
                boot_duration = datetime.utcnow() - self.last_boot
                self.log.info(
                    "Router booted in %s seconds after %s attempts",
                    boot_duration.total_seconds(),
                    self._boot_counter.count,
                )
            # Always reset the boot counter, even if we didn't boot
            # the server ourself, so we don't accidentally think we
            # have an erroring router.
            self._boot_counter.reset()
            # We've reported how long it took to boot and reset the
            # counter, so we are no longer "currently" booting.
            self._currently_booting = False
        return self.state
    def test_is_alive_exception(self):
        self.mock_get.side_effect = Exception

        self.assertFalse(akanda_client.is_alive('fe80::2', 5000))
        self.mock_get.assert_called_once_with(
            'http://[fe80::2]:5000/v1/firewall/labels',
            timeout=3.0
        )
    def test_is_alive_bad_status(self):
        self.mock_get.return_value.status_code = 500

        self.assertFalse(akanda_client.is_alive('fe80::2', 5000))
        self.mock_get.assert_called_once_with(
            'http://[fe80::2]:5000/v1/firewall/labels',
            timeout=3.0
        )
    def test_is_alive_success(self):
        self.mock_get.return_value.status_code = 200

        self.assertTrue(akanda_client.is_alive('fe80::2', 5000))
        self.mock_get.assert_called_once_with(
            'http://[fe80::2]:5000/v1/firewall/rules',
            timeout=3.0
        )
Example #5
0
    def is_alive(self, management_address):
        """Determines whether the managed resource is alive

        :returns: bool True if alive, False if not
        """
        return akanda_client.is_alive(management_address, self.mgt_port)
Example #6
0
    def test_is_alive_exception(self):
        self.mock_get.side_effect = Exception

        self.assertFalse(akanda_client.is_alive('fe80::2', 5000))
        self.mock_get.assert_called_once_with(
            'http://[fe80::2]:5000/v1/firewall/rules', timeout=3.0)
Example #7
0
    def test_is_alive_bad_status(self):
        self.mock_get.return_value.status_code = 500

        self.assertFalse(akanda_client.is_alive('fe80::2', 5000))
        self.mock_get.assert_called_once_with(
            'http://[fe80::2]:5000/v1/firewall/rules', timeout=3.0)
Example #8
0
    def update_state(self, worker_context, silent=False):
        self._ensure_cache(worker_context)
        if self.state == GONE:
            self.log.debug('not updating state of deleted router')
            return self.state

        if self.router_obj.management_port is None:
            self.log.debug('no management port, marking router as down')
            self.state = DOWN
            return self.state

        addr = _get_management_address(self.router_obj)
        for i in xrange(cfg.CONF.max_retries):
            if router_api.is_alive(addr, cfg.CONF.akanda_mgt_service_port):
                if self.state != CONFIGURED:
                    self.state = UP
                break
            if not silent:
                self.log.debug(
                    'Alive check failed. Attempt %d of %d',
                    i,
                    cfg.CONF.max_retries,
                )
            time.sleep(cfg.CONF.retry_delay)
        else:
            old_state = self.state
            self._check_boot_timeout()

            # If the router isn't responding, make sure Nova knows about it
            instance = worker_context.nova_client.get_instance(self.router_obj)
            if instance is None and self.state != ERROR:
                self.log.info('No router VM was found; rebooting')
                self.state = DOWN

            # update_state() is called from Alive() to check the
            # status of the router. If we can't talk to the API at
            # that point, the router should be considered missing and
            # we should reboot it, so mark it down if we think it was
            # configured before.
            if old_state == CONFIGURED and self.state != ERROR:
                self.log.debug(
                    'Did not find router alive, marking it as down', )
                self.state = DOWN

        # After the router is all the way up, record how long it took
        # to boot and accept a configuration.
        if self._currently_booting and self.state == CONFIGURED:
            # If we didn't boot the server (because we were restarted
            # while it remained running, for example), we won't have a
            # last_boot time to log.
            if self.last_boot:
                boot_duration = (datetime.utcnow() - self.last_boot)
                self.log.info('Router booted in %s seconds after %s attempts',
                              boot_duration.total_seconds(),
                              self._boot_counter.count)
            # Always reset the boot counter, even if we didn't boot
            # the server ourself, so we don't accidentally think we
            # have an erroring router.
            self._boot_counter.reset()
            # We've reported how long it took to boot and reset the
            # counter, so we are no longer "currently" booting.
            self._currently_booting = False
        return self.state
Example #9
0
    def is_alive(self, management_address):
        """Determines whether the managed resource is alive

        :returns: bool True if alive, False if not
        """
        return akanda_client.is_alive(management_address, self.mgt_port)