def is_docker_present(): try: vm_type = docker.vm_type() docker.validate_docker_vm(vm_type) return True except DockerValidationError: return False
def start(self): if major_version(self.image_version) == 1: pass else: log = logging.getLogger(__name__) log.info( headline( 'Starting logging feature based on elasticsearch and kibana' )) log.info( 'conductr-kibana bundle is packaged as a Docker image. Checking Docker requirements..' ) docker.validate_docker_vm(docker.vm_type()) log.info('Docker is installed and configured correctly.') elasticsearch = select_bintray_uri('conductr-elasticsearch', self.version_args) log.info('Deploying bundle %s..' % elasticsearch['bundle']) elasticsearch_load_command = ['load', elasticsearch['bundle'], '--disable-instructions'] + \ parse_offline_mode_arg(self.offline_mode) conduct_main.run(elasticsearch_load_command, configure_logging=False) conduct_main.run( ['run', elasticsearch['name'], '--disable-instructions'], configure_logging=False) kibana = select_bintray_uri('conductr-kibana', self.version_args) log.info('Deploying bundle %s..' % kibana['bundle']) kibana_load_command = ['load', kibana['bundle'], '--disable-instructions'] + \ parse_offline_mode_arg(self.offline_mode) conduct_main.run(kibana_load_command, configure_logging=False) conduct_main.run([ 'run', kibana['name'], '--disable-instructions', '--wait-timeout', '600' ], configure_logging=False)
def run(_args=[], configure_logging=True): # Parse arguments if not _args: _args = sys.argv[1:] parser = build_parser() argcomplete.autocomplete(parser) args = parser.parse_args(_args) # Print help or execute subparser function if not vars(args).get('func'): parser.print_help() # Validate image_version elif vars(args).get('func').__name__ == 'run' and not args.image_version: parser.exit( 'The version of ConductR need to be set.\n' 'Please visit https://www.lightbend.com/product/conductr/developer ' 'to obtain the current version information.') # Call sandbox function elif vars(args).get('func').__name__ == 'version': logging_setup.configure_logging(args) args.func(args) else: if configure_logging: logging_setup.configure_logging(args) # Check that all feature arguments are valid if vars(args).get('func').__name__ == 'run': invalid_features = [ f for f, *a in args.features if f not in feature_names ] if invalid_features: parser.exit('Invalid features: %s (choose from %s)' % (', '.join("'%s'" % f for f in invalid_features), ', '.join( "'%s'" % f for f in feature_names))) conflicting_features = feature_conflicts( [name for name, *args in args.features]) if len(conflicting_features) > 0: messages = [] for p, fs in conflicting_features.items(): messages.append("'{0}' provided by ({1})".format( p, ', '.join(map(lambda e: "'" + e + "'", fs)))) parser.exit('Conflicting features: {0}'.format( ', '.join(messages))) # Docker VM validation args.vm_type = docker.vm_type() if vars(args).get( 'func').__name__ == 'run' and is_sandbox_docker_based( args.image_version): docker.validate_docker_vm(args.vm_type) result = args.func(args) if not result: sys.exit(1)
def test_docker_insufficient_ram(self): stdout_mock = MagicMock() docker_info_mock = MagicMock( return_value=b'\nTotal Memory: 2 GiB\nCPUs: 4') logging_setup.configure_logging(MagicMock(), output=stdout_mock) with patch('conductr_cli.terminal.docker_info', docker_info_mock): docker.validate_docker_vm(DockerVmType.DOCKER_ENGINE) docker_info_mock.assert_called_with()
def test_no_vm_found(self): stdout_mock = MagicMock() logging_setup.configure_logging(MagicMock(), err_output=stdout_mock) with self.assertRaises(DockerValidationError) as error: docker.validate_docker_vm(DockerVmType.NONE) self.assertEqual([ 'Docker is not installed.', 'We recommend to use one of following the Docker distributions depending on your OS:', ' Linux: Docker Engine', ' MacOS: Docker for Mac', 'For more information checkout: https://www.docker.com/products/overview' ], error.exception.messages)
def test_docker_insufficient_cpu(self): stdout_mock = MagicMock() docker_info_mock = MagicMock( return_value=b'\nTotal Memory: 3.8 GiB\nCPUs: 1') logging_setup.configure_logging(MagicMock(), output=stdout_mock) with patch('conductr_cli.terminal.docker_info', docker_info_mock): docker.validate_docker_vm(DockerVmType.DOCKER_ENGINE) docker_info_mock.assert_called_with() self.assertEqual( as_warn( 'Warning: Docker has an insufficient no. of CPUs 1 - please increase to a minimum of 2 CPUs\n' ), self.output(stdout_mock))
def test_docker_not_running(self): stdout_mock = MagicMock() docker_info_mock = MagicMock( side_effect=CalledProcessError(-1, 'test only')) logging_setup.configure_logging(MagicMock(), err_output=stdout_mock) with \ patch('conductr_cli.terminal.docker_info', docker_info_mock), \ self.assertRaises(DockerValidationError) as error: docker.validate_docker_vm(DockerVmType.DOCKER_ENGINE) docker_info_mock.assert_called_with() self.assertEqual([ 'Docker is installed but not running.', 'Please start Docker with one of the Docker flavors based on your OS:', ' Linux: Docker service', ' MacOS: Docker for Mac', 'A successful Docker startup can be verified with: docker info', ], error.exception.messages)
def run(): # Parse arguments parser = build_parser() argcomplete.autocomplete(parser) args = parser.parse_args() # Print help or execute subparser function if not vars(args).get('func'): parser.print_help() # Validate image_version elif vars(args).get('func').__name__ == 'run' and not args.image_version: parser.exit('The version of ConductR need to be set.\n' 'Please visit https://www.lightbend.com/product/conductr/developer ' 'to obtain the current version information.') # Call sandbox function elif vars(args).get('func').__name__ == 'version': logging_setup.configure_logging(args) args.func(args) else: logging_setup.configure_logging(args) # Check that all feature arguments are valid if vars(args).get('func').__name__ == 'run': if args.features and args.no_wait: parser.exit('Option --no-wait is not allowed when starting ConductR with option --feature') invalid_features = [f for f, *a in args.features if f not in feature_names] if invalid_features: parser.exit('Invalid features: %s (choose from %s)' % (', '.join("'%s'" % f for f in invalid_features), ', '.join("'%s'" % f for f in feature_names))) # Docker VM validation args.vm_type = docker.vm_type() if vars(args).get('func').__name__ == 'run' and major_version(args.image_version) == 1: docker.validate_docker_vm(args.vm_type) result = args.func(args) if not result: exit(1)