def plot(ctx, run_all, log_level, course_file=None, dry_run=False, debug=False, only=None, helm_args=None, continue_on_error=False, create_namespace=True, update_repos=True): """ Install charts with given arguments as listed in yaml file argument """ coloredlogs.install(level=log_level) Config().update_repos = update_repos if not run_all: if len(only) < 1: logging.error("You must pass either --run-all or --only.") ctx.exit(1) try: # Check Schema of Course FileA with open(course_file.name, 'rb') as course_file_stream: validate_course_file(course_file_stream) # Load Reckoner r = Reckoner(course_file=course_file, dryrun=dry_run, debug=debug, helm_args=helm_args, continue_on_error=continue_on_error, create_namespace=create_namespace) # Convert tuple to list only = list(only) r.install(only) except exception.ReckonerException as err: click.echo( click.style( "⛵🔥 Encountered errors while reading course file ⛵🔥", fg="bright_red")) click.echo(click.style("{}".format(err), fg="red")) logging.debug(traceback.format_exc()) ctx.exit(1) except Exception as err: # This handles exceptions cleanly, no expected stack traces from reckoner code click.echo( click.style( "⛵🔥 Encountered unexpected error in Reckoner! Run with DEBUG log level to see details, for example:\n\nreckoner --log-level=DEBUG plot course.yml -o <heading> --dry-run\n\n(or without heading if running the full chart). ⛵🔥", fg="bright_red")) if 'log_level' in ctx.parent.params and ctx.parent.params[ 'log_level'].lower() in ['debug', 'trace']: click.echo(click.style("{}".format(err), fg='bright_red')) logging.debug(traceback.format_exc()) ctx.exit(1) if r.results.has_errors: click.echo( click.style( "⛵🔥 Encountered errors while running the course ⛵🔥", fg="bright_red")) for result in r.results.results_with_errors: click.echo(click.style("\n* * * * *\n", fg="bright_red")) click.echo(click.style(str(result), fg="bright_red")) ctx.exit(1)
def setUpModule(): coloredlogs.install(level="DEBUG") config = Config() config.local_development = True os.makedirs(test_helm_archive) os.environ['HELM_HOME'] = test_files_path
def execute(cls, helm_command): """Executed the command provided in the init. Only allowed to be executed once!""" # initialize the instance of the provider instance = cls(helm_command) # start by creating a command line arguments list with the command being first args = list([instance._helm_binary]) # if command has a space in it (like get manifests), split on space # and append each segment as it's own list item to make `call` happy for command_segment in instance._helm_command.command.split(' '): args.append(command_segment) for arg in instance._helm_command.arguments: args.append(arg) call_response = call(args, path=Config().course_base_directory) return HelmCmdResponse( exit_code=call_response.exitcode, stdout=call_response.stdout, stderr=call_response.stderr, command=helm_command, )
def test_course_base_dir_doesnt_raise(self): config = Config() try: config.course_base_directory except TypeError as e: self.fail( f"accessing course.course_base_directory of an empty Config() threw TypeError: {e}" )
def diff(ctx, only, run_all, log_level, course_file=None, helm_args=None, update_repos=True): """Output diff of the templates that would be installed and the manifests that are currently installed""" coloredlogs.install(level=log_level) if not run_all: if len(only) < 1: logging.error("You must pass either --run-all or --only.") ctx.exit(1) Config().update_repos = update_repos try: # Check Schema of Course FileA with open(course_file.name, 'rb') as course_file_stream: validate_course_file(course_file_stream) # Load Reckoner r = Reckoner(course_file=course_file, helm_args=helm_args) # Convert tuple to list only = list(only) logging.debug(f'Only diffing the following charts: {only}') diff_results = r.diff(only) for result in diff_results: print(result.response) except exception.ReckonerException as err: click.echo( click.style( "⛵🔥 Encountered errors while reading course file ⛵🔥", fg="bright_red")) click.echo(click.style("{}".format(err), fg="red")) logging.debug(traceback.format_exc()) ctx.exit(1) except Exception as err: # This handles exceptions cleanly, no expected stack traces from reckoner code click.echo( click.style( "⛵🔥 Encountered unexpected error in Reckoner! Run with DEBUG log level to see details, for example:\n\nreckoner --log-level=DEBUG plot course.yml -o <heading> --dry-run\n\n(or without heading if running the full chart). ⛵🔥", fg="bright_red")) if 'log_level' in ctx.parent.params and ctx.parent.params[ 'log_level'].lower() in ['debug', 'trace']: click.echo(click.style("{}".format(err), fg='bright_red')) logging.debug(traceback.format_exc()) ctx.exit(1) if r.results.has_errors: click.echo( click.style( "⛵🔥 Encountered errors while running the course ⛵🔥", fg="bright_red")) for result in r.results.results_with_errors: click.echo(click.style("\n* * * * *\n", fg="bright_red")) click.echo(click.style(str(result), fg="bright_red")) ctx.exit(1)
def test_update_repos(self): config = Config() # Test default True self.assertTrue(config.update_repos) # Test set False config.update_repos = False self.assertFalse(config.update_repos) # Test set True config.update_repos = True self.assertTrue(config.update_repos)
def test_course_base_dir_never_empty(self): config = Config() config.course_path = 'course.yaml' self.assertNotEqual( '', config.course_base_directory, "course_base_path has to be None or a real path " "(including '.') because of how it is used in " "Popen. Cannot be an empty string.") self.assertIsNone(config.course_base_directory) config.course_path = '/some/full/path/course.yml' self.assertEqual('/some/full/path', config.course_base_directory) config.course_path = './course.yaml' self.assertEqual('.', config.course_base_directory) config.course_path = '../../relative/course.yml' self.assertEqual('../../relative', config.course_base_directory)
def test_course_base_dir_never_empty(self, mock_dir): config = Config() config.course_path = 'course.yaml' self.assertNotEqual( '', config.course_base_directory, "course_base_path has to be None or a real path " "(including '.') because of how it is used in " "Popen. Cannot be an empty string.") config.course_path = '/some/full/path/course.yml' self.assertEqual('/some/full/path', config.course_base_directory) mock_dir.return_value = "/some/fake/path" config.course_path = './course.yaml' self.assertEqual('/some/fake/path', config.course_base_directory) # relative path to /some/fake/path config.course_path = '../../relative/course.yml' self.assertEqual('/some/relative', config.course_base_directory)
def setUp(self): super(type(self), self).setUp() self.c1 = Config() self.c2 = Config()
def setUpModule(): coloredlogs.install(level="DEBUG") Config() os.makedirs(test_helm_archive) os.environ['HELM_HOME'] = test_files_path