def test_upgrade_charm_leader(self, ssh_authorized_peers,
                                  mock_synchronize_ca,
                                  mock_update_hash_from_path,
                                  mock_ensure_ssl_cert_master,
                                  mock_is_elected_leader,
                                  mock_relation_ids,
                                  mock_log,
                                  mock_is_db_initialised,
                                  mock_is_db_ready,
                                  git_requested,
                                  os_release):
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_is_elected_leader.return_value = False
        mock_relation_ids.return_value = []
        mock_ensure_ssl_cert_master.return_value = True
        # Ensure always returns diff
        mock_update_hash_from_path.side_effect = \
            lambda hash, *args, **kwargs: hash.update(str(uuid.uuid4()))

        self.is_elected_leader.return_value = True
        self.filter_installed_packages.return_value = []
        git_requested.return_value = False
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        ssh_authorized_peers.assert_called_with(
            user=self.ssh_user, group='juju_keystone',
            peer_interface='cluster', ensure_local_user=True)
        self.assertTrue(mock_synchronize_ca.called)
        self.log.assert_called_with(
            'Firing identity_changed hook for all related services.')
        self.assertTrue(self.ensure_initial_admin.called)
    def test_upgrade_charm_not_leader_no_packages(
        self,
        mock_stop_manager_instance,
        mock_relation_ids,
        mock_log,
        os_release,
        update,
        mock_maybe_do_policyd_overrides,
        mock_bootstrap_keystone,
        mock_get_subordinate_release_packages,
    ):
        os_release.return_value = 'havana'

        self.filter_installed_packages.return_value = []
        self.is_elected_leader.return_value = False
        mock_get_subordinate_release_packages.return_value = \
            os_utils.SubordinatePackages(set(), set())
        hooks.upgrade_charm()
        self.assertFalse(self.apt_install.called)
        self.assertTrue(self.log.called)
        self.assertFalse(update.called)
        mock_bootstrap_keystone.assert_called_once_with(configs=ANY)
        mock_stop_manager_instance.assert_called_once()
        mock_maybe_do_policyd_overrides.assert_called_once_with(
            ANY, "keystone", restart_handler=ANY)
    def test_upgrade_charm_leader(self, ssh_authorized_peers,
                                  mock_synchronize_ca,
                                  mock_update_hash_from_path,
                                  mock_ensure_ssl_cert_master,
                                  mock_is_elected_leader,
                                  mock_relation_ids,
                                  mock_log,
                                  mock_is_db_initialised,
                                  mock_is_db_ready,
                                  git_requested):
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_is_elected_leader.return_value = False
        mock_relation_ids.return_value = []
        mock_ensure_ssl_cert_master.return_value = True
        # Ensure always returns diff
        mock_update_hash_from_path.side_effect = \
            lambda hash, *args, **kwargs: hash.update(str(uuid.uuid4()))

        self.is_elected_leader.return_value = True
        self.filter_installed_packages.return_value = []
        git_requested.return_value = False
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        ssh_authorized_peers.assert_called_with(
            user=self.ssh_user, group='juju_keystone',
            peer_interface='cluster', ensure_local_user=True)
        self.assertTrue(mock_synchronize_ca.called)
        self.log.assert_called_with(
            'Firing identity_changed hook for all related services.')
        self.assertTrue(self.ensure_initial_admin.called)
    def test_upgrade_charm_leader_no_packages(
            self, mock_stop_manager_instance, mock_relation_ids, mock_log,
            mock_is_db_initialised, mock_is_db_ready, os_release, update,
            mock_maybe_do_policyd_overrides, mock_protect_service_accounts,
            mock_bootstrap_keystone, mock_get_subordinate_release_packages):
        os_release.return_value = 'havana'
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_relation_ids.return_value = []
        self.remove_old_packages.return_value = True
        self.services.return_value = ['apache2']

        self.filter_installed_packages.return_value = []
        mock_get_subordinate_release_packages.return_value = \
            os_utils.SubordinatePackages(set(), set())
        hooks.upgrade_charm()
        self.assertFalse(self.apt_install.called)
        self.assertTrue(update.called)
        self.remove_old_packages.assert_called_once_with()
        self.service_restart.assert_called_with('apache2')
        mock_bootstrap_keystone.assert_called_once_with(configs=ANY)
        mock_stop_manager_instance.assert_called_once_with()
        mock_maybe_do_policyd_overrides.assert_called_once_with(
            ANY, "keystone", restart_handler=ANY)
        mock_protect_service_accounts.assert_called_once_with()
    def test_upgrade_charm_not_leader(self, mock_relation_ids, mock_log,
                                      os_release, update):
        os_release.return_value = 'havana'

        self.filter_installed_packages.return_value = []
        self.is_elected_leader.return_value = False
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        self.assertTrue(self.log.called)
        self.assertFalse(update.called)
    def test_upgrade_charm_leader(self, mock_relation_ids, mock_log,
                                  mock_is_db_initialised, mock_is_db_ready,
                                  os_release, update):
        os_release.return_value = 'havana'
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_relation_ids.return_value = []

        self.filter_installed_packages.return_value = []
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        self.assertTrue(update.called)
    def test_upgrade_charm_not_leader_no_packages(self,
                                                  mock_stop_manager_instance,
                                                  mock_relation_ids,
                                                  mock_log,
                                                  os_release, update):
        os_release.return_value = 'havana'

        self.filter_installed_packages.return_value = []
        self.is_elected_leader.return_value = False
        hooks.upgrade_charm()
        self.assertFalse(self.apt_install.called)
        self.assertTrue(self.log.called)
        self.assertFalse(update.called)
        mock_stop_manager_instance.assert_called_once()
Beispiel #8
0
    def test_upgrade_charm_not_leader_no_packages(
            self, mock_stop_manager_instance, mock_relation_ids, mock_log,
            os_release, update, mock_maybe_do_policyd_overrides):
        os_release.return_value = 'havana'

        self.filter_installed_packages.return_value = []
        self.is_elected_leader.return_value = False
        hooks.upgrade_charm()
        self.assertFalse(self.apt_install.called)
        self.assertTrue(self.log.called)
        self.assertFalse(update.called)
        mock_stop_manager_instance.assert_called_once()
        mock_maybe_do_policyd_overrides.assert_called_once_with(
            ANY, "keystone")
    def test_upgrade_charm_leader(self,
                                  mock_relation_ids,
                                  mock_log,
                                  mock_is_db_initialised,
                                  mock_is_db_ready,
                                  os_release,
                                  update):
        os_release.return_value = 'havana'
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_relation_ids.return_value = []
        self.remove_old_packages.return_value = True
        self.services.return_value = ['apache2']

        self.filter_installed_packages.return_value = []
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        self.assertTrue(update.called)
        self.remove_old_packages.assert_called_once_with()
        self.service_restart.assert_called_with('apache2')
    def test_upgrade_charm_not_leader(self, ssh_authorized_peers,
                                      mock_update_hash_from_path,
                                      mock_ensure_ssl_cert_master,
                                      mock_relation_ids,
                                      mock_log, git_requested):
        mock_relation_ids.return_value = []
        mock_ensure_ssl_cert_master.return_value = False
        # Ensure always returns diff
        mock_update_hash_from_path.side_effect = \
            lambda hash, *args, **kwargs: hash.update(str(uuid.uuid4()))

        self.is_elected_leader.return_value = False
        self.filter_installed_packages.return_value = []
        git_requested.return_value = False
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        ssh_authorized_peers.assert_called_with(
            user=self.ssh_user, group='juju_keystone',
            peer_interface='cluster', ensure_local_user=True)
        self.assertTrue(self.log.called)
        self.assertFalse(self.ensure_initial_admin.called)
Beispiel #11
0
    def test_upgrade_charm_leader(self, mock_stop_manager_instance,
                                  mock_relation_ids, mock_log,
                                  mock_is_db_initialised, mock_is_db_ready,
                                  os_release, update,
                                  mock_maybe_do_policyd_overrides):
        os_release.return_value = 'havana'
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_relation_ids.return_value = []
        self.remove_old_packages.return_value = True
        self.services.return_value = ['apache2']

        self.filter_installed_packages.return_value = ['something']
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        self.assertTrue(update.called)
        self.remove_old_packages.assert_called_once_with()
        self.service_restart.assert_called_with('apache2')
        mock_stop_manager_instance.assert_called_once_with()
        mock_maybe_do_policyd_overrides.assert_called_once_with(
            ANY, "keystone")
    def test_upgrade_charm_not_leader(self, ssh_authorized_peers,
                                      mock_update_hash_from_path,
                                      mock_ensure_ssl_cert_master,
                                      mock_relation_ids,
                                      mock_log, git_requested,
                                      os_release, update):
        mock_relation_ids.return_value = []
        mock_ensure_ssl_cert_master.return_value = False
        # Ensure always returns diff
        mock_update_hash_from_path.side_effect = \
            lambda hash, *args, **kwargs: hash.update(str(uuid.uuid4()))

        self.is_elected_leader.return_value = False
        self.filter_installed_packages.return_value = []
        git_requested.return_value = False
        hooks.upgrade_charm()
        self.assertTrue(self.apt_install.called)
        ssh_authorized_peers.assert_called_with(
            user=self.ssh_user, group='juju_keystone',
            peer_interface='cluster', ensure_local_user=True)
        self.assertTrue(self.log.called)
        self.assertFalse(update.called)
    def test_upgrade_charm_leader_no_packages(self,
                                              mock_stop_manager_instance,
                                              mock_relation_ids,
                                              mock_log,
                                              mock_is_db_initialised,
                                              mock_is_db_ready,
                                              os_release,
                                              update):
        os_release.return_value = 'havana'
        mock_is_db_initialised.return_value = True
        mock_is_db_ready.return_value = True
        mock_relation_ids.return_value = []
        self.remove_old_packages.return_value = True
        self.services.return_value = ['apache2']

        self.filter_installed_packages.return_value = []
        hooks.upgrade_charm()
        self.assertFalse(self.apt_install.called)
        self.assertTrue(update.called)
        self.remove_old_packages.assert_called_once_with()
        self.service_restart.assert_called_with('apache2')
        mock_stop_manager_instance.assert_called_once_with()