Beispiel #1
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)
Beispiel #2
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()
Beispiel #3
0
class TestReckoner(TestBase):
    name = "test-pentagon-base"

    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)

    # def tearDown(self):
    #     self.a = None
    #     subprocess.call(['rm', '-rf', git_repo_path])

    def test_instance(self):
        self.assertIsInstance(self.a, Reckoner)

    def test_config_instance(self):
        self.assertIsInstance(self.a.config, Config)

    def test_install(self):
        self.assertTrue(self.a.install())
Beispiel #4
0
class TestReckoner(TestBase):
    name = "test-pentagon-base"

    @mock.patch('reckoner.course.get_helm_client', autospec=True)
    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)

    def test_instance(self):
        self.assertIsInstance(self.a, Reckoner)

    def test_config_instance(self):
        self.assertIsInstance(self.a.config, Config)

    @mock.patch('reckoner.repository.git', autospec=True)
    def test_install(self, mock_git_lib):
        self.assertEqual(self.a.install(), None)