This file is indexed.

/usr/lib/python2.7/dist-packages/magnum/tests/unit/cmd/test_template_manage.py is in python-magnum 3.1.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2016 - Fujitsu, Ltd.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

import mock

from magnum.cmd import template_manage
from magnum.tests import base


class TestMagnumTemplateManage(base.TestCase):

    # Fake entrypoints method
    @staticmethod
    def _fake_entry(num_of_entries):
        while num_of_entries:
            fake_entry = mock.MagicMock()
            fake_entry.name = 'magnum_' + 'test_' + \
                              'foo_' + 'bar'*num_of_entries
            fake_cls = mock.MagicMock()
            fake_definition = fake_cls()
            fake_definition.provides = [{'coe': 'foo', 'os': 'bar',
                                         'server_type': 'test'}]
            fake_definition.template_path = 'fake_path'
            yield fake_entry, fake_cls
            num_of_entries -= 1

    @mock.patch.object(template_manage.TemplateManager, 'run')
    @mock.patch('sys.argv', ['foo', 'bar'])
    def test_none_arg(self, mock_run):
        args = None
        template_manage.main(args)
        mock_run.assert_called_once_with(['bar'])

    # NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
    # produce_output in order to assert with fake value
    @mock.patch('magnum.cmd.template_manage.TemplateList.produce_output')
    @mock.patch('magnum.drivers.common.template_def.TemplateDefinition')
    def test_correct_arg_with_details_and_path(self, mock_tdef, mock_produce):
        args = ['list-templates', '-d', '-p']
        mock_tdef.load_entry_points.return_value = self._fake_entry(1)
        template_manage.main(args)
        mock_tdef.load_entry_points.assert_called_once_with()
        mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
                                             [('magnum_test_foo_bar',
                                               False, 'test',
                                               'bar', 'foo', 'fake_path')])

    # NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
    # produce_output in order to assert with fake value
    @mock.patch('magnum.cmd.template_manage.TemplateList.produce_output')
    @mock.patch('magnum.drivers.common.template_def.TemplateDefinition')
    def test_correct_arg_without_details_and_path(self, mock_tdef,
                                                  mock_produce):
        args = ['list-templates']
        mock_tdef.load_entry_points.return_value = self._fake_entry(1)
        template_manage.main(args)
        mock_tdef.load_entry_points.assert_called_once_with()
        mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
                                             [('magnum_test_foo_bar', False)])

    # NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
    # produce_output in order to assert with fake value
    @mock.patch('magnum.cmd.template_manage.TemplateList.produce_output')
    @mock.patch('magnum.drivers.common.template_def.TemplateDefinition')
    def test_correct_arg_with_enabled_template(self, mock_tdef, mock_produce):
        args = ['list-templates', '--enabled']
        self.config(enabled_definitions={'magnum_test_foo_bar'},
                    group='cluster')
        mock_tdef.load_entry_points.return_value = self._fake_entry(2)
        template_manage.main(args)
        mock_tdef.load_entry_points.assert_called_once_with()
        mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
                                             [('magnum_test_foo_bar', True)])

    # NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
    # produce_output in order to assert with fake value
    @mock.patch('magnum.cmd.template_manage.TemplateList.produce_output')
    @mock.patch('magnum.drivers.common.template_def.TemplateDefinition')
    def test_correct_arg_with_disabled_template(self, mock_tdef, mock_produce):
        args = ['list-templates', '--disable']
        self.config(enabled_definitions={'magnum_test_foo_bar'},
                    group='cluster')
        mock_tdef.load_entry_points.return_value = self._fake_entry(2)
        template_manage.main(args)
        mock_tdef.load_entry_points.assert_called_once_with()
        mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
                                             [('magnum_test_foo_barbar',
                                               False)])