Charm Interface - MySQL InnoDB Cluster
Go to file
Hervé Beraud 0340770712 Use unittest.mock instead of mock
The mock third party library was needed for mock support in py2
runtimes. Since we now only support py36 and later, we can use the
standard lib unittest.mock module instead.

Note that https://github.com/openstack/charms.openstack is used during tests
and he need `mock`, unfortunatelly it doesn't declare `mock` in its
requirements so it retrieve mock from other charm project (cross dependency).
So we depend on charms.openstack first and when
Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI
will pass without errors.

Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142
Change-Id: I5212f10fed28ad11f123b0c4210be0f232b3a38a
2021-12-15 10:08:51 +00:00
unit_tests Use unittest.mock instead of mock 2021-12-15 10:08:51 +00:00
.gitignore MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
.gitreview Scale-in and Scale-out of mysql-innodb-cluster 2020-05-15 15:22:37 -07:00
.stestr.conf MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
.travis.yml MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
.zuul.yaml Use unittest.mock instead of mock 2021-12-15 10:08:51 +00:00
LICENSE MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
README.md MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
interface.yaml MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00
peers.py Scale-in and Scale-out of mysql-innodb-cluster 2020-05-15 15:22:37 -07:00
test-requirements.txt Use unittest.mock instead of mock 2021-12-15 10:08:51 +00:00
tox.ini MySQL InnoDB Cluster Interface 2019-10-04 07:50:33 -07:00

README.md

Overview

This interface layer handles the intra-cluster relations for msyql-innodb-cluster.

Usage

Peers

The interface layer will set the following state:

  • {relation_name}.connected The cluster relation is established.
  • {relation_name}.available The cluster relation data is complete.
  • {relation_name}.clustered All cluster units are clustered.

Cluster relation information can be set on the relation with the following methods:

Set the cluster relation information to connect to this unit:

    def cluster.set_cluster_connection_info(
        "192.168.1.5", "clusteruser", "passwd")

Indicate this unit's readiness for clustering:

    cluster.set_unit_configure_ready():

Indicate this unit has been clustered:

    cluster.set_unit_clustered(self):
    cluster.set_unit_configure_ready(self):

For example:


@reactive.when('cluster.connected')
@reactive.when_not('cluster.available')
def send_cluster_connection_info(cluster):
    with charm.provide_charm_instance() as instance:
        cluster.set_cluster_connection_info(
            instance.cluster_address,
            instance.cluster_user,
            instance.cluster_password)


@reactive.when('cluster.available')
def create_remote_cluster_user(cluster):
    with charm.provide_charm_instance() as instance:
        for unit in cluster.all_joined_units:
            instance.create_cluster_user(
                unit.received['cluster-address'],
                unit.received['cluster-user'],
                unit.received['cluster-password'])

        cluster.set_unit_configure_ready()

@reactive.when('leadership.set.cluster-created')
@reactive.when('cluster.available')
def signal_clustered(cluster):
    # Optimize clustering by causing a cluster relation changed
    with charm.provide_charm_instance() as instance:
        if reactive.is_flag_set(
                "leadership.set.cluster-instance-clustered-{}"
                .format(instance.cluster_address)):
            cluster.set_unit_clustered()
        instance.assess_status()

The interface will automatically determine the network space binding on the local unit to present to the MySQL InnoDB cluster based on the name of the relation. This can be overridden using the cluster_host parameter of the set_cluster_connection_info method.