Exemplo n.º 1
0
def get_juju_status(application=None, unit=None):
    if application:
        return juju_utils.get_application_status(application=application,
                                                 unit=unit)
    if unit:
        application = unit.split('/')[0]
        return juju_utils.get_application_status(application=application,
                                                 unit=unit)
    return json.loads(juju_utils.get_full_juju_status().to_json())
Exemplo n.º 2
0
    def test_get_application_status(self):
        self.patch_object(juju_utils, "get_full_juju_status")
        self.get_full_juju_status.return_value = self.juju_status

        # Full status juju object return
        self.assertEqual(juju_utils.get_application_status(), self.juju_status)
        self.get_full_juju_status.assert_called_once()

        # Application only dictionary return
        self.assertEqual(
            juju_utils.get_application_status(application=self.application),
            self.application_data)

        # Unit no application dictionary return
        self.assertEqual(juju_utils.get_application_status(unit=self.unit),
                         self.unit_data)
Exemplo n.º 3
0
    def test_910_pause_and_resume(self):
        """The services can be paused and resumed."""
        logging.debug('Checking pause and resume actions...')

        status = zaza.model.get_status().applications[self.application_name]

        # libjuju juju status no longer has units for subordinate charms
        # Use the application it is subordinate-to to check workload status
        if status.get("units") is None and status.get("subordinate-to"):
            primary_status = juju_utils.get_application_status(
                status.get("subordinate-to")[0])
            leader = None
            for unit in primary_status["units"]:
                if primary_status["units"][unit].get('leader'):
                    leader = unit

        if primary_status["units"][leader].get("subordinates"):
            for subordinate in primary_status["units"][leader]["subordinates"]:
                logging.info("Pausing {}".format(subordinate))
                zaza.model.run_action(subordinate, "pause")
                zaza.model.block_until_unit_wl_status(leader, "blocked")

                logging.info("Resuming {}".format(subordinate))
                zaza.model.run_action(subordinate, "resume")
                zaza.model.block_until_unit_wl_status(leader, "active")

        _states = {
            "hacluster": {
                "workload-status": "active",
                "workload-status-message": "Unit is ready and clustered"
            }
        }
        zaza.model.wait_for_application_states(states=_states)
        logging.debug('OK')
Exemplo n.º 4
0
    def test_900_action_cleanup(self):
        """The services can be cleaned up."""
        status = zaza.model.get_status().applications[self.application_name]

        # libjuju juju status no longer has units for subordinate charms
        # Use the application it is subordinate-to to check workload status
        if status.get("units") is None and status.get("subordinate-to"):
            primary_status = juju_utils.get_application_status(
                status.get("subordinate-to")[0])
            leader = None
            for unit in primary_status["units"]:
                if primary_status["units"][unit].get('leader'):
                    leader = unit

        if primary_status["units"][leader].get("subordinates"):
            for subordinate in primary_status["units"][leader]["subordinates"]:
                logging.info("Cleaning {}".format(subordinate))
                _action = "cleanup"
                action_id = zaza.model.run_action(subordinate, "cleanup")
                assert "success" in action_id.data["results"]["result"], (
                    "Set hacluster action {} failed: {}".format(
                        _action, action_id.data))

                logging.info(
                    "Cleaning action w/resource {}".format(subordinate))
                params = {'resource': 'res_ks_haproxy'}
                _action = "cleanup res_ks_haproxy"
                zaza.model.run_action(subordinate,
                                      "cleanup",
                                      action_params=params)
                assert "success" in action_id.data["results"]["result"], (
                    "Set hacluster action {} failed: {}".format(
                        _action, action_id.data))
Exemplo n.º 5
0
def get_subordinate_applications():
    return [
        application for application in
        juju_utils.get_full_juju_status().applications.keys()
        if juju_utils.get_application_status(application)['subordinate-to']
    ]