diff --git a/config.yaml b/config.yaml index ecf5c48..418c719 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,7 @@ options: + source: + type: string + description: Package install location for Percona XtraDB Cluster (defaults to distro for >= 14.04) dataset-size: default: '80%' type: string diff --git a/hooks/mysql.py b/hooks/mysql.py index bcbfed3..8324867 100644 --- a/hooks/mysql.py +++ b/hooks/mysql.py @@ -21,6 +21,7 @@ except ImportError: class MySQLHelper(): + def __init__(self, host='localhost'): self.host = host @@ -120,13 +121,13 @@ def get_mysql_password(username=None, password=None): else: mkdir(os.path.dirname(_passwd_file), owner='root', group='root', - perms=0770) + perms=0o770) # Force permissions - for some reason the chmod in makedirs fails - os.chmod(os.path.dirname(_passwd_file), 0770) + os.chmod(os.path.dirname(_passwd_file), 0o770) _password = password or pwgen(length=32) write_file(_passwd_file, _password, owner='root', group='root', - perms=0660) + perms=0o660) return _password diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index 46b18f3..78d4b27 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -19,11 +19,13 @@ from charmhelpers.core.hookenv import ( from charmhelpers.core.host import ( service_restart, file_hash, - write_file + write_file, + lsb_release ) from charmhelpers.fetch import ( apt_update, apt_install, + add_source, ) from percona_utils import ( PACKAGES, @@ -56,7 +58,11 @@ hooks = Hooks() @hooks.hook('install') def install(): - setup_percona_repo() + if config('source') is None and \ + lsb_release()['DISTRIB_CODENAME'] < 'trusty': + setup_percona_repo() + elif config('source') is not None: + add_source(config('source')) configure_mysql_root_password(config('root-password')) render_config() # Render base configuation (no cluster) apt_update(fatal=True) @@ -78,7 +84,7 @@ def render_config(clustered=False, hosts=[]): context.update(parse_config()) write_file(path=MY_CNF, content=render_template(os.path.basename(MY_CNF), context), - perms=0444) + perms=0o444) @hooks.hook('cluster-relation-joined') @@ -235,7 +241,7 @@ def ha_relation_joined(): resource_params = { 'res_mysql_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' % (vip, vip_cidr, vip_iface), - } + } groups = {'grp_percona_cluster': 'res_mysql_vip'} for rel_id in relation_ids('ha'): diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 9bcff4a..bbb6554 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -111,12 +111,15 @@ def configure_sstuser(sst_password): def configure_mysql_root_password(password): ''' Configure debconf with root password ''' dconf = Popen(['debconf-set-selections'], stdin=PIPE) - package = "percona-server-server" + # Set both percona and mysql password options to cover + # both upstream and distro packages. + packages = ["percona-server-server", "mysql-server"] root_pass = get_mysql_root_password(password) - dconf.stdin.write("%s %s/root_password password %s\n" % - (package, package, root_pass)) - dconf.stdin.write("%s %s/root_password_again password %s\n" % - (package, package, root_pass)) + for package in packages: + dconf.stdin.write("%s %s/root_password password %s\n" % + (package, package, root_pass)) + dconf.stdin.write("%s %s/root_password_again password %s\n" % + (package, package, root_pass)) dconf.communicate() dconf.wait()