def init(provider, reset_config): if provider is not None: return provider_common.provider_init(provider, reset_config) if os.path.exists(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = 'Current directory is already initialized' error = exceptions.CloudifyCliError(msg) error.possible_solutions = [ "Run 'cfy init -r' to force re-initialization " "(might overwrite existing " "configuration files if exist) " ] raise error else: shutil.rmtree(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME)) settings = utils.CloudifyWorkingDirectorySettings() utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() configure_loggers() get_logger().info('Initialization completed successfully')
def init(reset_config, skip_logging=False): if os.path.exists( os.path.join(utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = 'Current directory is already initialized' error = exceptions.CloudifyCliError(msg) error.possible_solutions = [ "Run 'cfy init -r' to force re-initialization " "(might overwrite existing " "configuration files if exist) " ] raise error else: shutil.rmtree( os.path.join(utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME)) settings = utils.CloudifyWorkingDirectorySettings() utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() configure_loggers() if not skip_logging: get_logger().info('Initialization completed successfully')
def setUp(self): self.inputs = yaml.load(open('blueprints/inputs.yaml')) self.inputs.update(self.vcloud_config) self.tempdir = tempfile.mkdtemp() self.workdir = os.getcwd() logger.configure_loggers() self.failed = True self.conf = Objectview(self.inputs)
def test_configure_colors_for_events_and_logs(self): self.assertNotEquals(ColorfulEvent, logs.EVENT_CLASS) with mock.patch("colorama.init") as m: # calling logs configuration method logger.configure_loggers() # verifying that colorama was initialized and # ColorfulEvent is used for events and logs output self.assertEquals(ColorfulEvent, logs.EVENT_CLASS) m.assert_called_once_with(autoreset=True)
def test_configure_colors_for_events_and_logs(self): self.assertNotEquals(ColorfulEvent, logs.EVENT_CLASS) with mock.patch('colorama.init') as m: # calling logs configuration method logger.configure_loggers() # verifying that colorama was initialized and # ColorfulEvent is used for events and logs output self.assertEquals(ColorfulEvent, logs.EVENT_CLASS) m.assert_called_once_with(autoreset=True)
def test_inputs_to_dict_error_handling(self): configure_loggers() input_str = "my_key1=my_value1;my_key2" resource_name = "my_resource_name" expected_err_msg = \ ("Invalid input: {0}. {1} must represent a dictionary. " "Valid values can be one of:\n " "- a path to a YAML file\n " "- a path to a directory containing YAML files\n " "- a single quoted wildcard based path ") self.assertRaisesRegexp( CloudifyCliError, expected_err_msg.format(input_str, resource_name), utils.inputs_to_dict, input_str, resource_name)
def main(args): workflow_id = args[1] configure_loggers() logger = get_logger() manager_ip = utils.get_management_server_ip() client = utils.get_rest_client(manager_ip) deployments = client.deployments.list() results = map(lambda d: deployment_failed_tasks(client, workflow_id, d), deployments) failure_detected = False for res in results: if res.get('type') == RESULT_TASKS: tasks = res.get('failed_tasks') exc = res.get('execution') if tasks: failure_detected = True msg = FAILURE_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) get_events_logger()(tasks) logger.info('Total tasks failed: {0}\n'.format(len(tasks))) else: msg = OK_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) elif res.get('type') == RESULT_NOT_INSTALLED: deployment = res.get('deployment') logger.info(NOT_INSTALLED_MSG_FORMAT.format(deployment.id)) else: deployment = res.get('deployment') failure_detected = True logger.info(NO_EXECUTION_MSG_FORMAT.format(deployment.id, workflow_id)) if failure_detected: logger.info('Failure detected.') return int(failure_detected)
def main(args): workflow_id = args[1] configure_loggers() logger = get_logger() manager_ip = utils.get_management_server_ip() client = utils.get_rest_client(manager_ip) deployments = client.deployments.list() results = map(lambda d: deployment_failed_tasks(client, workflow_id, d), deployments) failure_detected = False for res in results: if res.get('type') == RESULT_TASKS: tasks = res.get('failed_tasks') exc = res.get('execution') if tasks: failure_detected = True msg = FAILURE_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) get_events_logger()(tasks) logger.info('Total tasks failed: {0}\n'.format(len(tasks))) else: msg = OK_MSG_FORMAT.format(exc.deployment_id, workflow_id, exc.id) logger.info(msg) elif res.get('type') == RESULT_NOT_INSTALLED: deployment = res.get('deployment') logger.info(NOT_INSTALLED_MSG_FORMAT.format(deployment.id)) else: deployment = res.get('deployment') failure_detected = True logger.info( NO_EXECUTION_MSG_FORMAT.format(deployment.id, workflow_id)) if failure_detected: logger.info('Failure detected.') return int(failure_detected)
def _configure_loggers(): from cloudify_cli import logger logger.configure_loggers()
def _reset_verbosity_and_loggers(self): cli.verbosity_level = cli.NO_VERBOSE logs.EVENT_VERBOSITY_LEVEL = cli.NO_VERBOSE logger.configure_loggers()