Example #1
0
 def test_garbage_stderr(self, stub_check, capsys):
     stub_check(([], ['could not contact platform'], 1))
     with pytest.raises(SystemExit):
         hosts.container_platform('kubernetes')
     stdout, stderr = capsys.readouterr()
     assert 'Unable to load JSON from stdout' in stdout
     assert 'could not contact platform' in stdout
Example #2
0
 def test_no_context(self, stub_check):
     check = stub_check((['{"items": {}}'], [], 1))
     hosts.container_platform('kubernetes')
     command = check.calls[0]['args'][1]
     assert command == [
         'kubectl', '--request-timeout=5', 'get', '-n',
         'rook-ceph', 'pods', '-o', 'json'
     ]
Example #3
0
 def test_oc_with_context(self, stub_check):
     contents = dedent("""
     [openshift]
     context = 87
     """)
     conf = configuration.load_string(contents)
     ceph_medic.config.file = conf
     check = stub_check((['{"items": {}}'], [], 1))
     hosts.container_platform()
     command = check.calls[0]['args'][1]
     assert command == [
         'oc', '--context', '87', '--request-timeout=5', 'get', '-n',
         'rook-ceph', 'pods', '-o', 'json'
     ]
Example #4
0
    def main(self, argv):
        options = [
            '--cluster',
            '--ssh-config',
            '--inventory',
            '--config',
            '--verbosity',
        ]
        parser = Transport(argv,
                           options=options,
                           check_help=False,
                           check_version=False)
        parser.parse_args()

        self.config_path = parser.get('--config', configuration.location())

        # load medic configuration
        loaded_config = configuration.load(
            path=parser.get('--config', self.config_path))

        # this is the earliest we can have enough config to setup logging
        log.setup(loaded_config)
        ceph_medic.config.file = loaded_config
        global_options = dict(ceph_medic.config.file._sections['global'])

        # SSH config
        ceph_medic.config.ssh_config = parser.get(
            '--ssh-config', global_options.get('--ssh-config'))
        if ceph_medic.config.ssh_config:
            ssh_config_path = ceph_medic.config.ssh_config
            if not os.path.exists(ssh_config_path):
                terminal.error("the given ssh config path does not exist: %s" %
                               ssh_config_path)
                sys.exit()

        ceph_medic.config.cluster_name = parser.get('--cluster', 'ceph')
        ceph_medic.metadata['cluster_name'] = 'ceph'

        # Deployment Type
        deployment_type = ceph_medic.config.file.get_safe(
            'global', 'deployment_type', 'baremetal')
        if deployment_type in ['kubernetes', 'openshift', 'k8s', 'oc']:
            pod_hosts = hosts.container_platform(deployment_type)
            ceph_medic.config.nodes = pod_hosts
            ceph_medic.config.hosts_file = ':memory:'
            self.hosts_file = ':memory:'
        else:
            # Hosts file
            self.hosts_file = parser.get('--inventory',
                                         configuration.get_host_file())

            # find the hosts files, by the CLI first, fallback to the configuration
            # file, and lastly if none of those are found or defined, try to load
            # from well known locations (cwd, and /etc/ansible/)
            loaded_hosts = configuration.load_hosts(
                parser.get('--inventory',
                           global_options.get('--inventory', self.hosts_file)))
            ceph_medic.config.nodes = loaded_hosts.nodes
            ceph_medic.config.hosts_file = loaded_hosts.filename
            self.hosts_file = loaded_hosts.filename

        parser.catch_version = ceph_medic.__version__
        parser.mapper = self.mapper
        parser.catch_help = self.help(parser.subhelp())
        if len(argv) <= 1:
            return parser.print_help()
        ceph_medic.config.config_path = self.config_path
        parser.dispatch()
        parser.catches_help()
        parser.catches_version()

        # Verbosity
        verbosity = parser.get('--verbosity', 'debug')
        ceph_medic.config.verbosity = verbosity.lowercase()
Example #5
0
 def test_kubectl_executable_fails(self, monkeypatch, capsys):
     monkeypatch.setattr(hosts.process, 'check', lambda *a: failed_check())
     hosts.container_platform('kubernetes')
     stdout, stderr = capsys.readouterr()
     assert 'Unable to retrieve the pods using command' in stdout
     assert 'kubectl --request-timeout=5 get -n rook-ceph pods -o json' in stdout