예제 #1
0
def upgrade_charm():
    pre_install_hooks()

    # Ensure older passwd files in /var/lib/juju are moved to
    # /var/lib/rabbitmq which will end up replicated if clustered
    for f in [f for f in os.listdir('/var/lib/juju')
              if os.path.isfile(os.path.join('/var/lib/juju', f))]:
        if f.endswith('.passwd'):
            s = os.path.join('/var/lib/juju', f)
            d = os.path.join('/var/lib/charm/{}'.format(service_name()), f)

            log('upgrade_charm: Migrating stored passwd'
                ' from %s to %s.' % (s, d))
            shutil.move(s, d)
    if is_elected_leader('res_rabbitmq_vip'):
        rabbit.migrate_passwords_to_peer_relation()

    # explicitly update buggy file name naigos.passwd
    old = os.path.join('var/lib/rabbitmq', 'naigos.passwd')
    if os.path.isfile(old):
        new = os.path.join('var/lib/rabbitmq', 'nagios.passwd')
        shutil.move(old, new)

    # NOTE(freyes): cluster_with() will take care of marking the node as
    # 'clustered' for existing deployments (LP: #1691510).
    rabbit.cluster_with()

    # Ensure all client connections are up to date on upgrade
    update_clients()
def cluster_changed():
    unison.ssh_authorized_peers(user=rabbit.SSH_USER,
                                group='rabbit',
                                peer_interface='cluster',
                                ensure_local_user=True)
    rabbit.synchronize_service_credentials()

    if utils.is_relation_made('ha'):
        utils.juju_log('INFO',
                       'hacluster relation is present, skipping native '
                       'rabbitmq cluster config.')
        return
    l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1]
    r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1]
    if l_unit_no < r_unit_no:
        utils.juju_log('INFO', 'cluster_joined: Relation lesser.')
        return

    cookie = utils.relation_get('cookie')
    if cookie is None:
        utils.juju_log('INFO',
                       'cluster_joined: cookie not yet set.')
        return

    if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
        utils.juju_log('INFO', 'Cookie already synchronized with peer.')
    else:
        utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.')
        rabbit.service('stop')
        with open(rabbit.COOKIE_PATH, 'wb') as out:
            out.write(cookie)
        rabbit.service('start')

    # cluster with other nodes
    rabbit.cluster_with()
예제 #3
0
def cluster_changed(relation_id=None, remote_unit=None):
    # Future travelers beware ordering is significant
    rdata = relation_get(rid=relation_id, unit=remote_unit)

    # sync passwords
    blacklist = ['hostname', 'private-address', 'public-address']
    whitelist = [a for a in rdata.keys() if a not in blacklist]
    peer_echo(includes=whitelist)

    cookie = peer_retrieve('cookie')
    if not cookie:
        log('cluster_changed: cookie not yet set.', level=INFO)
        return

    if rdata:
        hostname = rdata.get('hostname', None)
        private_address = rdata.get('private-address', None)

        if hostname and private_address:
            rabbit.update_hosts_file({private_address: hostname})

    # sync the cookie with peers if necessary
    update_cookie()

    if is_relation_made('ha') and \
            config('ha-vip-only') is False:
        log('hacluster relation is present, skipping native '
            'rabbitmq cluster config.', level=INFO)
        return

    # NOTE(freyes): all the nodes need to marked as 'clustered' (LP: #1691510)
    rabbit.cluster_with()

    if not is_leader():
        update_nrpe_checks()
예제 #4
0
def cluster_changed():
    unison.ssh_authorized_peers(user=rabbit.SSH_USER,
                                group='rabbit',
                                peer_interface='cluster',
                                ensure_local_user=True)
    rabbit.synchronize_service_credentials()

    if utils.is_relation_made('ha'):
        utils.juju_log(
            'INFO', 'hacluster relation is present, skipping native '
            'rabbitmq cluster config.')
        return
    l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1]
    r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1]
    if l_unit_no < r_unit_no:
        utils.juju_log('INFO', 'cluster_joined: Relation lesser.')
        return

    cookie = utils.relation_get('cookie')
    if cookie is None:
        utils.juju_log('INFO', 'cluster_joined: cookie not yet set.')
        return

    if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
        utils.juju_log('INFO', 'Cookie already synchronized with peer.')
    else:
        utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.')
        rabbit.service('stop')
        with open(rabbit.COOKIE_PATH, 'wb') as out:
            out.write(cookie)
        rabbit.service('start')

    # cluster with other nodes
    rabbit.cluster_with()
def cluster_changed():
    if utils.is_relation_made('ha'):
        utils.juju_log('INFO',
                       'hacluster relation is present, skipping native '\
                       'rabbitmq cluster config.')
        return
    l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1]
    r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1]
    if l_unit_no < r_unit_no:
        utils.juju_log('INFO', 'cluster_joined: Relation lesser.')
        return

    remote_host = utils.relation_get('host')
    cookie = utils.relation_get('cookie')
    if None in [remote_host, cookie]:
        utils.juju_log('INFO',
                       'cluster_joined: remote_host|cookie not yet set.')
        return

    if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
        utils.juju_log('INFO', 'Cookie already synchronized with peer.')
        return

    utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.')
    rabbit.service('stop')
    with open(rabbit.COOKIE_PATH, 'wb') as out:
        out.write(cookie)
    rabbit.service('start')
    rabbit.cluster_with(remote_host)
 def test_cluster_with_no_leader(self, mock_cmp_pkgrevno, mock_clustered,
                                 mock_leader_node, mock_running_nodes,
                                 mock_time, mock_check_output,
                                 mock_check_call, mock_wait_app):
     mock_clustered.return_value = False
     mock_leader_node.return_value = None
     mock_running_nodes.return_value = ['rabbit@juju-devel5-machine-19']
     rabbit_utils.cluster_with()
     self.assertEqual(0, mock_check_output.call_count)
예제 #7
0
 def test_cluster_with_no_leader(self, mock_cmp_pkgrevno, mock_clustered,
                                 mock_leader_node, mock_running_nodes,
                                 mock_time, mock_check_output,
                                 mock_check_call, mock_wait_app):
     mock_clustered.return_value = False
     mock_leader_node.return_value = None
     mock_running_nodes.return_value = ['rabbit@juju-devel5-machine-19']
     rabbit_utils.cluster_with()
     self.assertEqual(0, mock_check_output.call_count)
 def test_cluster_with_clustered(self, mock_cmp_pkgrevno, mock_clustered,
                                 mock_leader_node, mock_running_nodes,
                                 mock_time, mock_check_output,
                                 mock_check_call):
     mock_clustered.return_value = True
     mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'
     mock_running_nodes.return_value = [
         'rabbit@juju-devel5-machine-19', 'rabbit@juju-devel7-machine-11'
     ]
     rabbit_utils.cluster_with()
     self.assertEqual(0, mock_check_output.call_count)
def cluster_changed():
    # Future travelers beware ordering is significant
    rdata = relation_get()
    # sync passwords
    blacklist = ['hostname', 'private-address', 'public-address']
    whitelist = [a for a in rdata.keys() if a not in blacklist]
    peer_echo(includes=whitelist)

    cookie = peer_retrieve('cookie')
    if not cookie:
        log('cluster_joined: cookie not yet set.', level=INFO)
        return

    rdata = relation_get()
    if rdata:
        hostname = rdata.get('hostname', None)
        private_address = rdata.get('private-address', None)

        if hostname and private_address:
            rabbit.update_hosts_file({private_address: hostname})

    if not is_sufficient_peers():
        log('Not enough peers, waiting until leader is configured',
            level=INFO)
        return

    # sync the cookie with peers if necessary
    update_cookie()

    if is_relation_made('ha') and \
            config('ha-vip-only') is False:
        log('hacluster relation is present, skipping native '
            'rabbitmq cluster config.', level=INFO)
        return

    # cluster with node?
    try:
        if not is_leader():
            rabbit.cluster_with()
            update_nrpe_checks()
    except NotImplementedError:
        if is_newer():
            rabbit.cluster_with()
            update_nrpe_checks()

    # If cluster has changed peer db may have changed so run amqp_changed
    # to sync any changes
    for rid in relation_ids('amqp'):
        for unit in related_units(rid):
            amqp_changed(relation_id=rid, remote_unit=unit)
def cluster_changed(relation_id=None, remote_unit=None):
    # Future travelers beware ordering is significant
    rdata = relation_get(rid=relation_id, unit=remote_unit)

    # sync passwords
    blacklist = ['hostname', 'private-address', 'public-address']
    whitelist = [a for a in rdata.keys() if a not in blacklist]
    peer_echo(includes=whitelist)

    cookie = peer_retrieve('cookie')
    if not cookie:
        log('cluster_changed: cookie not yet set.', level=INFO)
        return

    if rdata:
        hostname = rdata.get('hostname', None)
        private_address = rdata.get('private-address', None)

        if hostname and private_address:
            rabbit.update_hosts_file({private_address: hostname})

    # sync the cookie with peers if necessary
    update_cookie()

    if is_relation_made('ha') and \
            config('ha-vip-only') is False:
        log(
            'hacluster relation is present, skipping native '
            'rabbitmq cluster config.',
            level=INFO)
        return

    if rabbit.is_sufficient_peers():
        # NOTE(freyes): all the nodes need to marked as 'clustered'
        # (LP: #1691510)
        rabbit.cluster_with()
        # Local rabbit maybe clustered now so check and inform clients if
        # needed.
        update_clients()
        if is_leader():
            if (leader_get(rabbit.CLUSTER_MODE_KEY) != config(
                    rabbit.CLUSTER_MODE_KEY)):
                log("Informing peers via leaderdb to change {} to {}".format(
                    rabbit.CLUSTER_MODE_KEY, config(rabbit.CLUSTER_MODE_KEY)))
                leader_set(
                    {rabbit.CLUSTER_MODE_KEY: config(rabbit.CLUSTER_MODE_KEY)})
                rabbit.ConfigRenderer(rabbit.CONFIG_FILES).write_all()

    if not is_leader() and is_relation_made('nrpe-external-master'):
        update_nrpe_checks()
 def test_cluster_with_not_clustered(self, mock_cmp_pkgrevno,
                                     mock_clustered, mock_leader_node,
                                     mock_running_nodes, mock_time,
                                     mock_check_output, mock_check_call,
                                     mock_wait_app, mock_relation_set):
     mock_cmp_pkgrevno.return_value = True
     mock_clustered.return_value = False
     mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'
     mock_running_nodes.return_value = ['rabbit@juju-devel5-machine-19']
     rabbit_utils.cluster_with()
     mock_check_output.assert_called_with([
         rabbit_utils.RABBITMQ_CTL, 'join_cluster',
         'rabbit@juju-devel7-machine-11'
     ],
                                          stderr=-2)
 def test_cluster_with_clustered(self, mock_cmp_pkgrevno, mock_clustered,
                                 mock_leader_node, mock_running_nodes,
                                 mock_time, mock_check_output,
                                 mock_check_call, mock_peer_retrieve,
                                 mock_relation_id, mock_relation_get,
                                 mock_is_unit_paused_set):
     mock_is_unit_paused_set.return_value = False
     mock_clustered.return_value = True
     mock_peer_retrieve.return_value = 'juju-devel7-machine-11'
     mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'
     mock_running_nodes.return_value = ['rabbit@juju-devel5-machine-19',
                                        'rabbit@juju-devel7-machine-11']
     mock_relation_id.return_value = 'cluster:1'
     rabbit_utils.cluster_with()
     self.assertEqual(0, mock_check_output.call_count)
예제 #13
0
 def test_cluster_with_clustered(self, mock_cmp_pkgrevno, mock_clustered,
                                 mock_leader_node, mock_running_nodes,
                                 mock_time, mock_check_output,
                                 mock_check_call, mock_peer_retrieve,
                                 mock_relation_id, mock_relation_get,
                                 mock_is_unit_paused_set):
     mock_is_unit_paused_set.return_value = False
     mock_clustered.return_value = True
     mock_peer_retrieve.return_value = 'juju-devel7-machine-11'
     mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'
     mock_running_nodes.return_value = [
         'rabbit@juju-devel5-machine-19', 'rabbit@juju-devel7-machine-11'
     ]
     mock_relation_id.return_value = 'cluster:1'
     rabbit_utils.cluster_with()
     self.assertEqual(0, mock_check_output.call_count)
def cluster_changed():
    cookie = peer_retrieve('cookie')
    if not cookie:
        log('cluster_joined: cookie not yet set.', level=INFO)
        return

    rdata = relation_get()
    if config('prefer-ipv6') and rdata.get('hostname'):
        private_address = rdata['private-address']
        hostname = rdata['hostname']
        if hostname:
            rabbit.update_hosts_file({private_address: hostname})

    # sync passwords
    blacklist = ['hostname', 'private-address', 'public-address']
    whitelist = [a for a in rdata.keys() if a not in blacklist]
    peer_echo(includes=whitelist)

    if not is_sufficient_peers():
        # Stop rabbit until leader has finished configuring
        service_stop('rabbitmq-server')
        return

    # sync the cookie with peers if necessary
    update_cookie()

    if is_relation_made('ha') and \
            config('ha-vip-only') is False:
        log('hacluster relation is present, skipping native '
            'rabbitmq cluster config.', level=INFO)
        return

    # cluster with node?
    try:
        if not is_leader():
            rabbit.cluster_with()
            update_nrpe_checks()
    except NotImplementedError:
        if is_newer():
            rabbit.cluster_with()
            update_nrpe_checks()

    # If cluster has changed peer db may have changed so run amqp_changed
    # to sync any changes
    for rid in relation_ids('amqp'):
        for unit in related_units(rid):
            amqp_changed(relation_id=rid, remote_unit=unit)
 def test_cluster_with_not_clustered(self, mock_cmp_pkgrevno,
                                     mock_clustered, mock_leader_node,
                                     mock_running_nodes, mock_time,
                                     mock_check_output, mock_check_call,
                                     mock_wait_app,
                                     mock_relation_set, mock_cluster_wait,
                                     mock_is_unit_paused_set):
     mock_is_unit_paused_set.return_value = False
     mock_cmp_pkgrevno.return_value = True
     mock_clustered.return_value = False
     mock_leader_node.return_value = 'rabbit@juju-devel7-machine-11'
     mock_running_nodes.return_value = ['rabbit@juju-devel5-machine-19']
     rabbit_utils.cluster_with()
     mock_cluster_wait.assert_called_once_with()
     mock_check_output.assert_called_with([rabbit_utils.RABBITMQ_CTL,
                                           'join_cluster',
                                           'rabbit@juju-devel7-machine-11'],
                                          stderr=-2)
def upgrade_charm():
    pre_install_hooks()

    # Ensure older passwd files in /var/lib/juju are moved to
    # /var/lib/rabbitmq which will end up replicated if clustered
    for f in [
            f for f in os.listdir('/var/lib/juju')
            if os.path.isfile(os.path.join('/var/lib/juju', f))
    ]:
        if f.endswith('.passwd'):
            s = os.path.join('/var/lib/juju', f)
            d = os.path.join('/var/lib/charm/{}'.format(service_name()), f)

            log('upgrade_charm: Migrating stored passwd'
                ' from %s to %s.' % (s, d))
            shutil.move(s, d)
    if is_elected_leader('res_rabbitmq_vip'):
        rabbit.migrate_passwords_to_peer_relation()

    # explicitly update buggy file name naigos.passwd
    old = os.path.join('var/lib/rabbitmq', 'naigos.passwd')
    if os.path.isfile(old):
        new = os.path.join('var/lib/rabbitmq', 'nagios.passwd')
        shutil.move(old, new)

    # NOTE(freyes): cluster_with() will take care of marking the node as
    # 'clustered' for existing deployments (LP: #1691510).
    rabbit.cluster_with()

    # Ensure all client connections are up to date on upgrade
    update_clients()

    # BUG:#1804348
    # for the check_rabbitmq.py script, python3-amqplib needs to be installed;
    # if previous version was a python2 version of the charm this won't happen
    # unless the source is changed.  Ensure it is installed here if needed.
    # LP:#1928802 - also include python3-croniter as its needed for
    # check_rabbitmq_queues.py as of change ab79c3ee
    apt_update(fatal=True)
    missing_packages = filter_installed_packages(
        ['python3-amqplib', 'python3-croniter'])
    if missing_packages:
        apt_install(missing_packages, fatal=True)
def upgrade_charm():
    pre_install_hooks()

    # Ensure older passwd files in /var/lib/juju are moved to
    # /var/lib/rabbitmq which will end up replicated if clustered
    for f in [f for f in os.listdir('/var/lib/juju')
              if os.path.isfile(os.path.join('/var/lib/juju', f))]:
        if f.endswith('.passwd'):
            s = os.path.join('/var/lib/juju', f)
            d = os.path.join('/var/lib/charm/{}'.format(service_name()), f)

            log('upgrade_charm: Migrating stored passwd'
                ' from %s to %s.' % (s, d))
            shutil.move(s, d)
    if is_elected_leader('res_rabbitmq_vip'):
        rabbit.migrate_passwords_to_peer_relation()

    # explicitly update buggy file name naigos.passwd
    old = os.path.join('var/lib/rabbitmq', 'naigos.passwd')
    if os.path.isfile(old):
        new = os.path.join('var/lib/rabbitmq', 'nagios.passwd')
        shutil.move(old, new)

    # NOTE(freyes): cluster_with() will take care of marking the node as
    # 'clustered' for existing deployments (LP: #1691510).
    rabbit.cluster_with()

    # Ensure all client connections are up to date on upgrade
    update_clients()

    # BUG:#1804348
    # for the check_rabbitmq.py script, python3-amqplib needs to be installed;
    # if previous version was a python2 version of the charm this won't happen
    # unless the source is changed.  Ensure it is installed here if needed.
    apt_update(fatal=True)
    if filter_installed_packages(['python3-amqplib']):
        apt_install(['python3-amqplib'], fatal=True)
def cluster_changed(relation_id=None, remote_unit=None):
    # Future travelers beware ordering is significant
    rdata = relation_get(rid=relation_id, unit=remote_unit)

    # sync passwords
    blacklist = ['hostname', 'private-address', 'public-address']
    whitelist = [a for a in rdata.keys() if a not in blacklist]
    peer_echo(includes=whitelist)

    cookie = peer_retrieve('cookie')
    if not cookie:
        log('cluster_changed: cookie not yet set.', level=INFO)
        return

    if rdata:
        hostname = rdata.get('hostname', None)
        private_address = rdata.get('private-address', None)

        if hostname and private_address:
            rabbit.update_hosts_file({private_address: hostname})

    # sync the cookie with peers if necessary
    update_cookie()

    if is_relation_made('ha') and \
            config('ha-vip-only') is False:
        log('hacluster relation is present, skipping native '
            'rabbitmq cluster config.', level=INFO)
        return

    if rabbit.is_sufficient_peers():
        # NOTE(freyes): all the nodes need to marked as 'clustered' (LP: #1691510)
        rabbit.cluster_with()

    if not is_leader() and is_relation_made('nrpe-external-master'):
        update_nrpe_checks()
    def test_cluster_with_single_node(self, mock_peer_retrieve,
                                      mock_running_nodes, mock_relation_id,
                                      mock_relation_get,
                                      mock_get_unit_hostname,
                                      mock_relation_set, mock_time):

        mock_peer_retrieve.return_value = 'localhost'
        mock_running_nodes.return_value = ['rabbit@localhost']
        mock_relation_id.return_value = 'cluster:1'
        mock_relation_get.return_value = False
        mock_get_unit_hostname.return_value = 'localhost'
        mock_time.return_value = 1234.1

        self.assertFalse(rabbit_utils.cluster_with())

        mock_relation_set.assert_called_with(relation_id='cluster:1',
                                             clustered='localhost',
                                             timestamp=1234.1)
    def test_cluster_with_single_node(self, mock_peer_retrieve,
                                      mock_running_nodes, mock_relation_id,
                                      mock_relation_get,
                                      mock_get_unit_hostname,
                                      mock_relation_set, mock_time,
                                      mock_is_unit_paused_set):
        mock_is_unit_paused_set.return_value = False
        mock_peer_retrieve.return_value = 'localhost'
        mock_running_nodes.return_value = ['rabbit@localhost']
        mock_relation_id.return_value = 'cluster:1'
        mock_relation_get.return_value = False
        mock_get_unit_hostname.return_value = 'localhost'
        mock_time.return_value = 1234.1

        self.assertFalse(rabbit_utils.cluster_with())

        mock_relation_set.assert_called_with(relation_id='cluster:1',
                                             clustered='localhost',
                                             timestamp=1234.1)