This file is indexed.

/usr/lib/python2.7/dist-packages/os_faults/tests/unit/cmd/test_main.py is in python-os-faults 0.1.17-0ubuntu1.1.

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
100
101
102
103
104
105
106
107
108
109
# 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 os

from click import testing
import mock

from os_faults.api import cloud_management
from os_faults.api import node_collection
from os_faults.cmd import main
from os_faults.tests.unit import test


class MainTestCase(test.TestCase):

    def setUp(self):
        super(MainTestCase, self).setUp()
        self.runner = testing.CliRunner()

    def test_version(self):
        result = self.runner.invoke(main.main, ['--version'])
        self.assertEqual(0, result.exit_code)
        self.assertIn('Version', result.output)

    @mock.patch('os_faults.connect')
    def test_verify(self, mock_connect):
        with self.runner.isolated_filesystem():
            with open('my.yaml', 'w') as f:
                f.write('foo')
            result = self.runner.invoke(main.main, ['verify'],
                                        env={'OS_FAULTS_CONFIG': 'my.yaml'})
        self.assertEqual(0, result.exit_code)
        mock_connect.assert_called_once_with(config_filename='my.yaml')
        destructor = mock_connect.return_value
        destructor.verify.assert_called_once_with()

    @mock.patch('os_faults.connect')
    def test_verify_with_config(self, mock_connect):
        with self.runner.isolated_filesystem():
            with open('my.yaml', 'w') as f:
                f.write('foo')
            myconf = os.path.abspath(f.name)
            result = self.runner.invoke(main.main, ['verify', '-c', myconf])
        self.assertEqual(0, result.exit_code)
        mock_connect.assert_called_once_with(config_filename=myconf)
        destructor = mock_connect.return_value
        destructor.verify.assert_called_once_with()

    @mock.patch('os_faults.discover')
    def test_discover(self, mock_discover):
        mock_discover.return_value = {'foo': 'bar'}
        with self.runner.isolated_filesystem():
            with open('my.yaml', 'w') as f:
                f.write('foo')
            myconf = os.path.abspath(f.name)
            result = self.runner.invoke(main.main, ['discover', '-c', myconf,
                                                    'my-new.yaml'])
            self.assertEqual(0, result.exit_code)
            mock_discover.assert_called_once_with('foo')

            with open('my-new.yaml') as f:
                self.assertEqual('foo: bar\n', f.read())

    @mock.patch('os_faults.connect')
    def test_nodes(self, mock_connect):
        cloud_management_mock = mock.create_autospec(
            cloud_management.CloudManagement)
        mock_connect.return_value = cloud_management_mock
        cloud_management_mock.get_nodes.return_value.hosts = [
            node_collection.Host(
                ip='10.0.0.2', mac='09:7b:74:90:63:c1', fqdn='node1.local'),
            node_collection.Host(
                ip='10.0.0.3', mac='09:7b:74:90:63:c2', fqdn='node2.local')]

        with self.runner.isolated_filesystem():
            with open('my.yaml', 'w') as f:
                f.write('foo')
            myconf = os.path.abspath(f.name)
            result = self.runner.invoke(main.main, ['nodes', '-c', myconf])
        self.assertEqual(0, result.exit_code)
        self.assertEqual(
            '- fqdn: node1.local\n'
            '  ip: 10.0.0.2\n'
            '  mac: 09:7b:74:90:63:c1\n'
            '- fqdn: node2.local\n'
            '  ip: 10.0.0.3\n'
            '  mac: 09:7b:74:90:63:c2\n', result.output)

    @mock.patch('os_faults.registry.get_drivers')
    def test_drivers(self, mock_get_drivers):
        mock_get_drivers.return_value = {'foo': 1, 'bar': 2}

        with self.runner.isolated_filesystem():
            result = self.runner.invoke(main.main, ['drivers'])
        self.assertEqual(0, result.exit_code)
        self.assertEqual(
            '- bar\n'
            '- foo\n', result.output)