From: HacKan Date: Wed, 24 Jan 2018 01:32:05 +0000 (-0300) Subject: [RM-7505] add support for archlinux X-Git-Tag: v2.0.1~11^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f60145b9860f20ed979d477d156e867cbf319d66;p=ceph-deploy.git [RM-7505] add support for archlinux hosts: add arch based on fedora and add detection for distro. util: add pacman package manager and archlinux default package. install: add distro detection and package selection --- diff --git a/ceph_deploy/hosts/__init__.py b/ceph_deploy/hosts/__init__.py index c8605d5..1df4f5a 100644 --- a/ceph_deploy/hosts/__init__.py +++ b/ceph_deploy/hosts/__init__.py @@ -7,7 +7,7 @@ on the type of distribution/version we are dealing with. import logging from ceph_deploy import exc from ceph_deploy.util import versions -from ceph_deploy.hosts import debian, centos, fedora, suse, remotes, rhel +from ceph_deploy.hosts import debian, centos, fedora, suse, remotes, rhel, arch from ceph_deploy.connection import get_connection logger = logging.getLogger() @@ -69,7 +69,8 @@ def get(hostname, module.is_el = module.normalized_name in ['redhat', 'centos', 'fedora', 'scientific', 'oracle', 'virtuozzo'] module.is_rpm = module.normalized_name in ['redhat', 'centos', 'fedora', 'scientific', 'suse', 'oracle', 'virtuozzo'] - module.is_deb = not module.is_rpm + module.is_deb = module.normalized_name in ['debian', 'ubuntu'] + module.is_pkgtarxz = module.normalized_name in ['arch'] module.release = release module.codename = codename module.conn = conn @@ -93,11 +94,12 @@ def _get_distro(distro, fallback=None, use_rhceph=False): 'ubuntu': debian, 'centos': centos, 'scientific': centos, - 'oracle' : centos, + 'oracle': centos, 'redhat': centos, 'fedora': fedora, 'suse': suse, - 'virtuozzo' : centos + 'virtuozzo': centos, + 'arch': arch } if distro == 'redhat' and use_rhceph: @@ -122,6 +124,8 @@ def _normalized_distro_name(distro): return 'ubuntu' elif distro.startswith('virtuozzo'): return 'virtuozzo' + elif distro.startswith('arch'): + return 'arch' return distro diff --git a/ceph_deploy/hosts/arch/__init__.py b/ceph_deploy/hosts/arch/__init__.py new file mode 100644 index 0000000..2e8c0ab --- /dev/null +++ b/ceph_deploy/hosts/arch/__init__.py @@ -0,0 +1,26 @@ +from . import mon # noqa +from ceph_deploy.hosts.centos.install import repo_install # noqa +from .install import install, mirror_install # noqa +from .uninstall import uninstall # noqa +from ceph_deploy.util import pkg_managers + +# Allow to set some information about this distro +# + +distro = None +release = None +codename = None + + +def choose_init(module): + """ + Select a init system + + Returns the name of a init system (upstart, sysvinit ...). + """ + + return 'systemd' + + +def get_packager(module): + return pkg_managers.Pacman(module) diff --git a/ceph_deploy/hosts/arch/install.py b/ceph_deploy/hosts/arch/install.py new file mode 100644 index 0000000..7625298 --- /dev/null +++ b/ceph_deploy/hosts/arch/install.py @@ -0,0 +1,49 @@ +from ceph_deploy.hosts.centos.install import repo_install, mirror_install # noqa +from ceph_deploy.hosts.common import map_components +from ceph_deploy.util.system import enable_service, start_service + + +NON_SPLIT_PACKAGES = [ + 'ceph-osd', + 'ceph-radosgw', + 'ceph-mds', + 'ceph-mon', + 'ceph-mgr', + 'ceph-common', + 'ceph-test' +] + +SYSTEMD_UNITS = [ + 'ceph.target', + 'ceph-radosgw.target', + 'ceph-rbd-mirror.target', + 'ceph-fuse.target', + 'ceph-mds.target', + 'ceph-mon.target', + 'ceph-mgr.target', + 'ceph-osd.target', +] +SYSTEMD_UNITS_SKIP_START = [ + 'ceph-mgr.target', + 'ceph-mon.target', +] +SYSTEMD_UNITS_SKIP_ENABLE = [ +] + + +def install(distro, version_kind, version, adjust_repos, **kw): + packages = map_components( + NON_SPLIT_PACKAGES, + kw.pop('components', []) + ) + + distro.packager.install( + packages + ) + + # Start and enable services + for unit in SYSTEMD_UNITS: + if unit not in SYSTEMD_UNITS_SKIP_START: + start_service(distro.conn, unit) + if unit not in SYSTEMD_UNITS_SKIP_ENABLE: + enable_service(distro.conn, unit) diff --git a/ceph_deploy/hosts/arch/mon/__init__.py b/ceph_deploy/hosts/arch/mon/__init__.py new file mode 100644 index 0000000..f266fb0 --- /dev/null +++ b/ceph_deploy/hosts/arch/mon/__init__.py @@ -0,0 +1,2 @@ +from ceph_deploy.hosts.common import mon_add as add # noqa +from ceph_deploy.hosts.common import mon_create as create # noqa diff --git a/ceph_deploy/hosts/arch/uninstall.py b/ceph_deploy/hosts/arch/uninstall.py new file mode 100644 index 0000000..0787392 --- /dev/null +++ b/ceph_deploy/hosts/arch/uninstall.py @@ -0,0 +1,50 @@ +import logging + +from ceph_deploy.util.system import disable_service, stop_service +from ceph_deploy.lib import remoto + + +SYSTEMD_UNITS = [ + 'ceph-mds.target', + 'ceph-mon.target', + 'ceph-osd.target', + 'ceph-radosgw.target', + 'ceph-fuse.target', + 'ceph-mgr.target', + 'ceph-rbd-mirror.target', + 'ceph.target', +] + + +def uninstall(distro, purge=False): + packages = [ + 'ceph', + ] + + hostname = distro.conn.hostname + LOG = logging.getLogger(hostname) + + # I need to stop and disable services prior package removal + LOG.info('stopping and disabling services on {}'.format(hostname)) + for unit in SYSTEMD_UNITS: + stop_service(distro.conn, unit) + disable_service(distro.conn, unit) + + # remoto.process.run( + # distro.conn, + # [ + # 'systemctl', + # 'daemon-reload', + # ] + # ) + + LOG.info('uninstalling packages on {}'.format(hostname)) + distro.packager.remove(packages) + + remoto.process.run( + distro.conn, + [ + 'systemctl', + 'reset-failed', + ] + ) diff --git a/ceph_deploy/install.py b/ceph_deploy/install.py index f7b19ed..b0fd6e6 100644 --- a/ceph_deploy/install.py +++ b/ceph_deploy/install.py @@ -63,6 +63,18 @@ def detect_components(args, distro): if distro.is_rpm: defaults = default_components.rpm + elif distro.is_pkgtarxz: + # archlinux doesn't have components! + flags = { + 'install_osd': 'ceph', + 'install_rgw': 'ceph', + 'install_mds': 'ceph', + 'install_mon': 'ceph', + 'install_mgr': 'ceph', + 'install_common': 'ceph', + 'install_tests': 'ceph', + } + defaults = default_components.pkgtarxz else: defaults = default_components.deb # different naming convention for deb than rpm for radosgw diff --git a/ceph_deploy/util/constants.py b/ceph_deploy/util/constants.py index 65775d9..a76dcd6 100644 --- a/ceph_deploy/util/constants.py +++ b/ceph_deploy/util/constants.py @@ -25,11 +25,12 @@ _base_components = [ 'ceph-mon', ] -default_components = namedtuple('DefaultComponents', ['rpm', 'deb']) +default_components = namedtuple('DefaultComponents', ['rpm', 'deb', 'pkgtarxz']) # the difference here is because RPMs currently name the radosgw differently than DEBs. # TODO: This needs to get unified once the packaging naming gets consistent default_components.rpm = tuple(_base_components + ['ceph-radosgw']) default_components.deb = tuple(_base_components + ['radosgw']) +default_components.pkgtarxz = tuple(['ceph']) gpg_key_base_url = "download.ceph.com/keys/" diff --git a/ceph_deploy/util/pkg_managers.py b/ceph_deploy/util/pkg_managers.py index bc20eb1..afd0842 100644 --- a/ceph_deploy/util/pkg_managers.py +++ b/ceph_deploy/util/pkg_managers.py @@ -325,3 +325,55 @@ class Zypper(PackageManager): def clean(self): cmd = self.executable + ['refresh'] return self._run(cmd) + + +class Pacman(PackageManager): + """ + Pacman package management + """ + + executable = [ + 'pacman', + '--noconfirm', + ] + name = 'pacman' + + def install(self, packages, **kw): + if isinstance(packages, str): + packages = [packages] + + extra_flags = kw.pop('extra_install_flags', None) + cmd = self.executable + [ + '-Sy', + ] + + if extra_flags: + if isinstance(extra_flags, str): + extra_flags = [extra_flags] + cmd.extend(extra_flags) + cmd.extend(packages) + return self._run(cmd) + + def remove(self, packages, **kw): + if isinstance(packages, str): + packages = [packages] + + extra_flags = kw.pop('extra_remove_flags', None) + cmd = self.executable + [ + '-R' + ] + if extra_flags: + if isinstance(extra_flags, str): + extra_flags = [extra_flags] + cmd.extend(extra_flags) + + cmd.extend(packages) + return self._run(cmd) + + def clean(self): + cmd = self.executable + ['-Syy'] + return self._run(cmd) + + def add_repo_gpg_key(self, url): + cmd = ['pacman-key', '-a', url] + self._run(cmd) diff --git a/ceph_deploy/util/system.py b/ceph_deploy/util/system.py index 05ee529..cff1305 100644 --- a/ceph_deploy/util/system.py +++ b/ceph_deploy/util/system.py @@ -86,3 +86,95 @@ def enable_service(conn, service='ceph'): 'on', ] ) + + +def disable_service(conn, service='ceph'): + """ + Disable a service on a remote host depending on the type of init system. + Obviously, this should be done for RHEL/Fedora/CentOS systems. + + This function does not do any kind of detection. + """ + if is_systemd(conn): + # Without the check, an error is raised trying to disable an + # already disabled service + if is_systemd_service_enabled(conn, service): + remoto.process.run( + conn, + [ + 'systemctl', + 'disable', + '{service}'.format(service=service), + ] + ) + + +def stop_service(conn, service='ceph'): + """ + Stop a service on a remote host depending on the type of init system. + Obviously, this should be done for RHEL/Fedora/CentOS systems. + + This function does not do any kind of detection. + """ + if is_systemd(conn): + # Without the check, an error is raised trying to stop an + # already stopped service + if is_systemd_service_active(conn, service): + remoto.process.run( + conn, + [ + 'systemctl', + 'stop', + '{service}'.format(service=service), + ] + ) + + +def start_service(conn, service='ceph'): + """ + Stop a service on a remote host depending on the type of init system. + Obviously, this should be done for RHEL/Fedora/CentOS systems. + + This function does not do any kind of detection. + """ + if is_systemd(conn): + remoto.process.run( + conn, + [ + 'systemctl', + 'start', + '{service}'.format(service=service), + ] + ) + + +def is_systemd_service_active(conn, service='ceph'): + """ + Detects if a systemd service is active or not. + """ + _, _, returncode = remoto.process.check( + conn, + [ + 'systemctl', + 'is-active', + '--quiet', + '{service}'.format(service=service), + ] + ) + return returncode == 0 + + +def is_systemd_service_enabled(conn, service='ceph'): + """ + Detects if a systemd service is enabled or not. + """ + _, _, returncode = remoto.process.check( + conn, + [ + 'systemctl', + 'is-enabled', + '--quiet', + '{service}'.format(service=service), + ] + ) + return returncode == 0