# Path: ceph_deploy/install.py
# def install(args):
#     args = sanitize_args(args)
# 
#     if args.repo:
#         return install_repo(args)
# 
#     gpgcheck = 0 if args.nogpgcheck else 1
# 
#     if args.version_kind == 'stable':
#         version = args.release
#     else:
#         version = getattr(args, args.version_kind)
# 
#     version_str = args.version_kind
# 
#     if version:
#         version_str += ' version {version}'.format(version=version)
#     LOG.debug(
#         'Installing %s on cluster %s hosts %s',
#         version_str,
#         args.cluster,
#         ' '.join(args.host),
#     )
# 
#     for hostname in args.host:
#         LOG.debug('Detecting platform for host %s ...', hostname)
#         distro = hosts.get(
#             hostname,
#             username=args.username,
#             # XXX this should get removed once ceph packages are split for
#             # upstream. If default_release is True, it means that the user is
#             # trying to install on a RHEL machine and should expect to get RHEL
#             # packages. Otherwise, it will need to specify either a specific
#             # version, or repo, or a development branch. Other distro users
#             # should not see any differences.
#             use_rhceph=args.default_release,
#             )
#         LOG.info(
#             'Distro info: %s %s %s',
#             distro.name,
#             distro.release,
#             distro.codename
#         )
# 
#         components = detect_components(args, distro)
#         if distro.init == 'sysvinit' and args.cluster != 'ceph':
#             LOG.error('refusing to install on host: %s, with custom cluster name: %s' % (
#                     hostname,
#                     args.cluster,
#                 )
#             )
#             LOG.error('custom cluster names are not supported on sysvinit hosts')
#             continue
# 
#         rlogger = logging.getLogger(hostname)
#         rlogger.info('installing Ceph on %s' % hostname)
# 
#         cd_conf = getattr(args, 'cd_conf', None)
# 
#         # custom repo arguments
#         repo_url = os.environ.get('CEPH_DEPLOY_REPO_URL') or args.repo_url
#         gpg_url = os.environ.get('CEPH_DEPLOY_GPG_URL') or args.gpg_url
#         gpg_fallback = gpg.url('release')
# 
#         if gpg_url is None and repo_url:
#             LOG.warning('--gpg-url was not used, will fallback')
#             LOG.warning('using GPG fallback: %s', gpg_fallback)
#             gpg_url = gpg_fallback
# 
#         if args.local_mirror:
#             if args.username:
#                 hostname = "%s@%s" % (args.username, hostname)
#             remoto.rsync(hostname, args.local_mirror, '/opt/ceph-deploy/repo', distro.conn.logger, sudo=True)
#             repo_url = 'file:///opt/ceph-deploy/repo'
#             gpg_url = 'file:///opt/ceph-deploy/repo/release.asc'
# 
#         if repo_url:  # triggers using a custom repository
#             # the user used a custom repo url, this should override anything
#             # we can detect from the configuration, so warn about it
#             if cd_conf:
#                 if cd_conf.get_default_repo():
#                     rlogger.warning('a default repo was found but it was \
#                         overridden on the CLI')
#                 if args.release in cd_conf.get_repos():
#                     rlogger.warning('a custom repo was found but it was \
#                         overridden on the CLI')
# 
#             rlogger.info('using custom repository location: %s', repo_url)
#             distro.mirror_install(
#                 distro,
#                 repo_url,
#                 gpg_url,
#                 args.adjust_repos,
#                 components=components,
#                 gpgcheck=gpgcheck,
#                 args=args
#             )
# 
#         # Detect and install custom repos here if needed
#         elif should_use_custom_repo(args, cd_conf, repo_url):
#             LOG.info('detected valid custom repositories from config file')
#             custom_repo(distro, args, cd_conf, rlogger)
# 
#         else:  # otherwise a normal installation
#             distro.install(
#                 distro,
#                 args.version_kind,
#                 version,
#                 args.adjust_repos,
#                 components=components,
#                 gpgcheck = gpgcheck,
#                 args=args
#             )
# 
#         # Check the ceph version we just installed
#         hosts.common.ceph_version(distro.conn)
#         distro.conn.exit()


from mock import Mock
from ceph_deploy import install

    def setup(self):
        self.args = Mock()
        # set the default behavior we set in cli.py
        self.args.default_release = False
        self.args.stable = None

    def test_args_release_not_specified(self):
        self.args.release = None
        result = install.sanitize_args(self.args)
        # XXX
        # we should get `args.release` to be the latest release
        # but we don't want to be updating this test every single
        # time there is a new default value, and we can't programatically
        # change that. Future improvement: make the default release a
        # variable in `ceph_deploy/__init__.py`
        assert result.default_release is True

    def test_args_release_is_specified(self):
        self.args.release = 'dumpling'
        result = install.sanitize_args(self.args)
        assert result.default_release is False

    def test_args_release_stable_is_used(self):
        self.args.stable = 'dumpling'
        result = install.sanitize_args(self.args)
        assert result.release == 'dumpling'

    def test_args_stable_is_not_used(self):
        self.args.release = 'dumpling'

# Path: ceph_deploy/install.py
# def install(args):
#     args = sanitize_args(args)
# 
#     if args.repo:
#         return install_repo(args)
# 
#     gpgcheck = 0 if args.nogpgcheck else 1
# 
#     if args.version_kind == 'stable':
#         version = args.release
#     else:
#         version = getattr(args, args.version_kind)
# 
#     version_str = args.version_kind
# 
#     if version:
#         version_str += ' version {version}'.format(version=version)
#     LOG.debug(
#         'Installing %s on cluster %s hosts %s',
#         version_str,
#         args.cluster,
#         ' '.join(args.host),
#     )
# 
#     for hostname in args.host:
#         LOG.debug('Detecting platform for host %s ...', hostname)
#         distro = hosts.get(
#             hostname,
#             username=args.username,
#             # XXX this should get removed once ceph packages are split for
#             # upstream. If default_release is True, it means that the user is
#             # trying to install on a RHEL machine and should expect to get RHEL
#             # packages. Otherwise, it will need to specify either a specific
#             # version, or repo, or a development branch. Other distro users
#             # should not see any differences.
#             use_rhceph=args.default_release,
#             )
#         LOG.info(
#             'Distro info: %s %s %s',
#             distro.name,
#             distro.release,
#             distro.codename
#         )
# 
#         components = detect_components(args, distro)
#         if distro.init == 'sysvinit' and args.cluster != 'ceph':
#             LOG.error('refusing to install on host: %s, with custom cluster name: %s' % (
#                     hostname,
#                     args.cluster,
#                 )
#             )
#             LOG.error('custom cluster names are not supported on sysvinit hosts')
#             continue
# 
#         rlogger = logging.getLogger(hostname)
#         rlogger.info('installing Ceph on %s' % hostname)
# 
#         cd_conf = getattr(args, 'cd_conf', None)
# 
#         # custom repo arguments
#         repo_url = os.environ.get('CEPH_DEPLOY_REPO_URL') or args.repo_url
#         gpg_url = os.environ.get('CEPH_DEPLOY_GPG_URL') or args.gpg_url
#         gpg_fallback = gpg.url('release')
# 
#         if gpg_url is None and repo_url:
#             LOG.warning('--gpg-url was not used, will fallback')
#             LOG.warning('using GPG fallback: %s', gpg_fallback)
#             gpg_url = gpg_fallback
# 
#         if args.local_mirror:
#             if args.username:
#                 hostname = "%s@%s" % (args.username, hostname)
#             remoto.rsync(hostname, args.local_mirror, '/opt/ceph-deploy/repo', distro.conn.logger, sudo=True)
#             repo_url = 'file:///opt/ceph-deploy/repo'
#             gpg_url = 'file:///opt/ceph-deploy/repo/release.asc'
# 
#         if repo_url:  # triggers using a custom repository
#             # the user used a custom repo url, this should override anything
#             # we can detect from the configuration, so warn about it
#             if cd_conf:
#                 if cd_conf.get_default_repo():
#                     rlogger.warning('a default repo was found but it was \
#                         overridden on the CLI')
#                 if args.release in cd_conf.get_repos():
#                     rlogger.warning('a custom repo was found but it was \
#                         overridden on the CLI')
# 
#             rlogger.info('using custom repository location: %s', repo_url)
#             distro.mirror_install(
#                 distro,
#                 repo_url,
#                 gpg_url,
#                 args.adjust_repos,
#                 components=components,
#                 gpgcheck=gpgcheck,
#                 args=args
#             )
# 
#         # Detect and install custom repos here if needed
#         elif should_use_custom_repo(args, cd_conf, repo_url):
#             LOG.info('detected valid custom repositories from config file')
#             custom_repo(distro, args, cd_conf, rlogger)
# 
#         else:  # otherwise a normal installation
#             distro.install(
#                 distro,
#                 args.version_kind,
#                 version,
#                 args.adjust_repos,
#                 components=components,
#                 gpgcheck = gpgcheck,
#                 args=args
#             )
# 
#         # Check the ceph version we just installed
#         hosts.common.ceph_version(distro.conn)
#         distro.conn.exit()


# Path: ceph_deploy/tests/test_install.py
from mock import Mock
from ceph_deploy import install


    def setup(self):
        self.args = Mock()
        # set the default behavior we set in cli.py
        self.args.default_release = False
        self.args.stable = None

    def test_args_release_not_specified(self):
        self.args.release = None
        result = install.sanitize_args(self.args)
        # XXX
        # we should get `args.release` to be the latest release
        # but we don't want to be updating this test every single
        # time there is a new default value, and we can't programatically
        # change that. Future improvement: make the default release a
        # variable in `ceph_deploy/__init__.py`
        assert result.default_release is True

    def test_args_release_is_specified(self):
        self.args.release = 'dumpling'
        result = install.sanitize_args(self.args)
        assert result.default_release is False

    def test_args_release_stable_is_used(self):
        self.args.stable = 'dumpling'
        result = install.sanitize_args(self.args)
        assert result.release == 'dumpling'

    def test_args_stable_is_not_used(self):
        self.args.release = 'dumpling'

        result = install.sanitize_args(self.args)