示例#1
0
    def test_pre_flight_ops(self, mock_tiller, mock_lint, mock_git):
        '''Test pre-flight checks and operations'''
        armada = Armada('')
        armada.tiller = mock_tiller
        armada.documents = yaml.safe_load_all(self.test_yaml)
        armada.config = Manifest(armada.documents).get_manifest()

        CHART_SOURCES = [('git://github.com/dummy/armada', 'chart_1'),
                         ('/tmp/dummy/armada', 'chart_2')]

        # mock methods called by pre_flight_ops()
        mock_tiller.tiller_status.return_value = True
        mock_lint.valid_manifest.return_value = True
        mock_git.git_clone.return_value = CHART_SOURCES[0][0]

        armada.pre_flight_ops()

        mock_git.git_clone.assert_called_once_with(CHART_SOURCES[0][0],
                                                   'master')
        for group in armada.config.get('armada').get('charts'):
            for counter, chart in enumerate(group.get('chart_group')):
                self.assertEqual(
                    chart.get('chart').get('source_dir')[0],
                    CHART_SOURCES[counter][0])
                self.assertEqual(
                    chart.get('chart').get('source_dir')[1],
                    CHART_SOURCES[counter][1])
示例#2
0
    def test_install(self, mock_tiller, mock_chartbuilder, mock_pre_flight,
                     mock_post_flight):
        '''Test install functionality from the sync() method'''

        # instantiate Armada and Tiller objects
        armada = Armada('', wait=True, timeout=1000)
        armada.tiller = mock_tiller
        tmp_doc = yaml.safe_load_all(self.test_yaml)
        armada.config = Manifest(tmp_doc).get_manifest()

        charts = armada.config['armada']['charts'][0]['chart_group']
        chart_1 = charts[0]['chart']
        chart_2 = charts[1]['chart']

        # mock irrelevant methods called by armada.sync()
        mock_tiller.list_charts.return_value = []
        mock_chartbuilder.get_source_path.return_value = None
        mock_chartbuilder.get_helm_chart.return_value = None

        armada.sync()

        # check params that should be passed to tiller.install_release()
        method_calls = [
            mock.call(mock_chartbuilder().get_helm_chart(),
                      "{}-{}".format(armada.config['armada']['release_prefix'],
                                     chart_1['release_name']),
                      chart_1['namespace'],
                      dry_run=armada.dry_run,
                      values=yaml.safe_dump(chart_1['values']),
                      wait=armada.wait,
                      timeout=1000),
            mock.call(mock_chartbuilder().get_helm_chart(),
                      "{}-{}".format(armada.config['armada']['release_prefix'],
                                     chart_2['release_name']),
                      chart_2['namespace'],
                      dry_run=armada.dry_run,
                      values=yaml.safe_dump(chart_2['values']),
                      wait=armada.wait,
                      timeout=1000)
        ]
        mock_tiller.install_release.assert_has_calls(method_calls)
示例#3
0
    def test_install(self, mock_tiller, mock_chartbuilder):
        '''Test install functionality from the sync() method'''

        # instantiate Armada and Tiller objects
        armada = Armada('', skip_pre_flight=True, wait=True, timeout=None)
        armada.tiller = mock_tiller
        armada.config = yaml.load(self.test_yaml)

        charts = armada.config['armada']['charts'][0]['chart_group']
        chart_1 = charts[0]['chart']
        chart_2 = charts[1]['chart']

        # mock irrelevant methods called by armada.sync()
        mock_tiller.list_charts.return_value = []
        mock_chartbuilder.source_clone.return_value = None
        mock_chartbuilder.get_helm_chart.return_value = None
        mock_chartbuilder.source_cleanup.return_value = None

        armada.sync()

        # check params that should be passed to tiller.install_release()
        method_calls = [
            mock.call(mock_chartbuilder().get_helm_chart(),
                      armada.dry_run,
                      chart_1['release_name'],
                      chart_1['namespace'],
                      armada.config['armada']['release_prefix'],
                      values=yaml.safe_dump(chart_1['values']),
                      wait=armada.wait,
                      timeout=chart_1['timeout']),
            mock.call(mock_chartbuilder().get_helm_chart(),
                      armada.dry_run,
                      chart_2['release_name'],
                      chart_2['namespace'],
                      armada.config['armada']['release_prefix'],
                      values=yaml.safe_dump(chart_2['values']),
                      wait=armada.wait,
                      timeout=chart_2['timeout'])
        ]
        mock_tiller.install_release.assert_has_calls(method_calls)
示例#4
0
    def test_install(self, mock_tiller, mock_chartbuilder):
        '''Test install functionality from the sync() method'''

        # instantiate Armada and Tiller objects
        armada = Armada('',
                        skip_pre_flight=True,
                        wait=True,
                        timeout=None)
        armada.tiller = mock_tiller
        armada.config = yaml.load(self.test_yaml)

        charts = armada.config['armada']['charts'][0]['chart_group']
        chart_1 = charts[0]['chart']
        chart_2 = charts[1]['chart']

        # mock irrelevant methods called by armada.sync()
        mock_tiller.list_charts.return_value = []
        mock_chartbuilder.source_clone.return_value = None
        mock_chartbuilder.get_helm_chart.return_value = None
        mock_chartbuilder.source_cleanup.return_value = None

        armada.sync()

        # check params that should be passed to tiller.install_release()
        method_calls = [mock.call(mock_chartbuilder().get_helm_chart(),
                                  armada.dry_run, chart_1['release_name'],
                                  chart_1['namespace'],
                                  armada.config['armada']['release_prefix'],
                                  values=yaml.safe_dump(chart_1['values']),
                                  wait=armada.wait,
                                  timeout=chart_1['timeout']),
                        mock.call(mock_chartbuilder().get_helm_chart(),
                                  armada.dry_run, chart_2['release_name'],
                                  chart_2['namespace'],
                                  armada.config['armada']['release_prefix'],
                                  values=yaml.safe_dump(chart_2['values']),
                                  wait=armada.wait,
                                  timeout=chart_2['timeout'])]
        mock_tiller.install_release.assert_has_calls(method_calls)
示例#5
0
    def test_post_flight_ops(self, mock_tiller, mock_lint, mock_git):
        '''Test post-flight operations'''
        armada = Armada('')
        armada.tiller = mock_tiller
        armada.config = yaml.load(self.test_yaml)

        CHART_SOURCES = [('git://github.com/dummy/armada', 'chart_1'),
                         ('/tmp/dummy/armada', 'chart_2')]

        # mock methods called by pre_flight_ops()
        mock_tiller.tiller_status.return_value = True
        mock_lint.valid_manifest.return_value = True
        mock_git.git_clone.return_value = CHART_SOURCES[0][0]
        armada.pre_flight_ops()

        armada.post_flight_ops()

        for group in yaml.load(self.test_yaml).get('armada').get('charts'):
            for counter, chart in enumerate(group.get('chart_group')):
                if chart.get('chart').get('source').get('type') == 'git':
                    mock_git.source_cleanup \
                            .assert_called_with(CHART_SOURCES[counter][0])