Esempio n. 1
0
class TestCourse(TestBase):

    @mock.patch('reckoner.course.get_helm_client', autospec=True)
    def setUp(self, mock_helm_client_course_scope, autospec=True):
        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_repo_update_return_string, '', 0)
        with open(test_course) as f:
            self.c = Course(f)

        self.test_repository = Repository(test_repository_dict, None)

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

    def test_course_values(self):
        self.assertIsInstance(self.c, Course)
        self.assertEqual([chart._release_name for chart in self.c.charts], test_release_names)
        self.assertNotEqual([chart.name for chart in self.c.charts], test_release_names,
                            msg="All the release names match the chart names, this may happen if you've edited the "
                                "test_course.yml and not provided an example with a different chart_name and chart.")
        self.assertEqual(self.c.repositories[0].name, test_repository_dict['name'])
        self.assertEqual(self.c.repositories[0].url, test_repository_dict['url'])
        self.assertEqual(list(self.c.minimum_versions.keys()), test_minimum_versions)
        self.assertIsInstance(self.c.repositories, list)

    def test_plot_course(self):
        self.configure_subprocess_mock('', '', 0)  # TODO: Lots of work do do here on installation of the list of charts
        self.c.plot(list(self.c._dict['charts']))
        self.assertEqual(self.c._charts_to_install, self.c.charts)
Esempio n. 2
0
    def test_failed_pre_install_hooks_fail_chart_installation(self, configMock, helmClientMock, yamlLoadMock, sysMock, repoMock, chartCallMock):
        """Test that the chart isn't installed when the pre_install hooks return any non-zero responses. This also assures we don't raise python errors with hook errors."""
        c = configMock()
        c.helm_args = ['provided args']
        c.local_development = False

        h = helmClientMock()
        h.client_version = '0.0.1'

        yamlLoadMock.load.return_value = {
            'charts': {
                'first-chart': {
                    'hooks': {
                        'pre_install': [
                            'run a failed command here',
                        ]
                    }
                }
            }
        }

        chartCallMock.return_value = Response(exitcode=1, command_string='mocked', stderr=' ', stdout=' ')

        course = Course(None)
        course.plot(['first-chart'])

        self.assertEqual(chartCallMock.call_count, 1)
        self.assertEqual(len(course.failed_charts), 1, "We should have only one failed chart install due to hook failure.")
Esempio n. 3
0
    def test_failed_pre_install_hooks_fail_chart_installation(
            self, configMock, helmClientMock, yamlLoadMock, sysMock, repoMock,
            hookCallMock, chartConfigMock):
        """Test that the chart isn't installed when the pre_install hooks return any non-zero responses. This also assures we don't raise python errors with hook errors."""
        c = configMock()
        c.continue_on_error = False
        c.helm_args = ['provided args']
        chartConfig = chartConfigMock()
        chartConfig.course_base_directory = '.'
        chartConfig.dryrun = False
        chartConfig.create_namespace = True
        chartConfig.cluster_namespaces = []

        h = helmClientMock(c.helm_args)
        h.client_version = '0.0.1'

        yamlLoadMock.load.return_value = {
            'charts': {
                'first-chart': {
                    'hooks': {
                        'pre_install': [
                            'run a failed command here',
                        ]
                    }
                }
            }
        }

        course = Course(None)
        results = course.plot(['first-chart'])

        self.assertEqual(
            len([result for result in results if result.failed]), 1,
            "We should have only one failed chart install due to hook failure."
        )
Esempio n. 4
0
class TestCourse(TestBase):
    def setUp(self):
        super(type(self), self).setUp()
        self.configure_subprocess_mock(test_repo_update_return_string, '', 0)
        with open(test_course) as f:
            self.c = Course(f)

        self.test_repository = Repository(test_repository_dict)

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

    def test_course_values(self):
        self.assertIsInstance(self.c, Course)
        self.assertEqual([chart._release_name for chart in self.c.charts],
                         test_release_names)
        self.assertNotEqual(
            [chart.name for chart in self.c.charts],
            test_release_names,
            msg=
            "All the release names match the chart names, this may happen if you've edited the "
            "test_course.yml and not provided an example with a different chart_name and chart."
        )
        self.assertEqual(self.c.repositories[0].name,
                         test_repository_dict['name'])
        self.assertEqual(self.c.repositories[0].url,
                         test_repository_dict['url'])
        self.assertEqual(self.c.minimum_versions.keys(), test_minimum_versions)
        self.assertIsInstance(self.c.repositories, list)

    def test_minimum_version(self):
        self.configure_subprocess_mock(test_helm_version_return_string, '', 0)
        self.c.minimum_versions['reckoner'] = test_reckoner_version
        self.assertRaises(MinimumVersionException,
                          self.c._compare_required_versions)

    def test_plot_course(self):
        self.configure_subprocess_mock(
            '', '', 0
        )  # TODO: Lots of work do do here on installation of the list of charts
        self.c.plot(list(self.c._dict['charts']))
        self.assertEqual(self.c._charts_to_install, self.c.charts)
Esempio n. 5
0
 def test_plot(self, mockHook, mockGetHelm, mockYAML):
     mockYAML.load.return_value = self.course_yaml
     course = Course(None)
     assert course.plot(['first-chart'])