Exemple #1
0
 def setUp(self):
     super(type(self), self).setUp()
     self.configure_subprocess_mock(test_tiller_present_return_string, '',
                                    0)
     with open(test_course) as f:
         self.a = Reckoner(file=f, local_development=True)
     self.charts = self.a.course.charts
Exemple #2
0
 def setUp(self, mock_helm_client_course_scope):
     mock_helm_client_course_instance = mock_helm_client_course_scope([])
     mock_helm_client_course_instance.version = "100.100.100"
     super(type(self), self).setUp()
     self.configure_subprocess_mock(test_tiller_present_return_string, '', 0)
     with open(test_course) as f:
         self.a = Reckoner(course_file=f)
Exemple #3
0
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)
Exemple #4
0
    def test_reckoner_raises_errors_on_bad_client_response(
            self, mock_config, mock_helm_client, *args):
        """Make sure helm client exceptions are raised"""
        # Check helm client exception checking command
        helm_instance = mock_helm_client()
        helm_instance.check_helm_command.side_effect = [
            HelmClientException('broken')
        ]
        with self.assertRaises(ReckonerException):
            Reckoner()
        helm_instance.check_helm_command.assert_called_once()

        mock_helm_client.side_effect = [
            Exception("it's a mock: had an error starting helm client")
        ]
        with self.assertRaises(ReckonerException):
            Reckoner()
Exemple #5
0
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)
Exemple #6
0
    def test_reckoner_raises_no_charts_correctly(self, mock_config,
                                                 mock_helm_client,
                                                 mock_course):
        """Assure we fail when NoChartsToInstall is bubbled up"""
        course_instance = mock_course()
        course_instance.plot.side_effect = [NoChartsToInstall('none')]

        reckoner_instance = Reckoner()
        with self.assertRaises(ReckonerCommandException):
            reckoner_instance.install()
Exemple #7
0
 def setUp(self):
     super(type(self), self).setUp()
     # This will eventually be need for integration testing
     # repo = git.Repo.init(git_repo_path)
     # os.chdir(git_repo_path)
     # subprocess.call(["helm", "create", "chart"])
     # # Create git chart in a git repo, then have it checkout the repo from that location
     # logging.debug(os.listdir("./"))
     # os.chdir("../")
     self.configure_subprocess_mock(test_tiller_present_return_string, '',
                                    0)
     with open(test_course) as f:
         self.a = Reckoner(file=f, local_development=True)
Exemple #8
0
    def test_reckoner_raises_errors_on_bad_client_response(
            self, mock_sys, mock_config, mock_helm_client, *args):
        """Make sure helm client exceptions are raised"""
        mock_sys.exit.return_value = True

        # Check helm client exception checking command
        helm_instance = mock_helm_client()
        helm_instance.check_helm_command.side_effect = [
            HelmClientException('broken')
        ]
        Reckoner()
        mock_sys.exit.assert_called_once()
        helm_instance.check_helm_command.assert_called_once()