This file is indexed.

/usr/lib/python2.7/dist-packages/novaclient/tests/functional/v2/test_trigger_crash_dump.py is in python-novaclient 2:6.0.0-2.

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#    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 time

from novaclient.tests.functional import base
from novaclient.v2 import shell


class TestTriggerCrashDumpNovaClientV217(base.TenantTestBase):
    """Functional tests for trigger crash dump"""

    COMPUTE_API_VERSION = "2.17"

    # It's a resource-consuming task to implement full-flow (up to getting
    # and reading a dump file) functional test for trigger-crash-dump.
    # We need to upload Ubuntu image for booting an instance based on it,
    # and to install kdump with its further configuring on this instance.
    # Here, the "light" version of functional test is proposed.
    # It's based on knowledge that trigger-crash-dump uses a NMI injection,
    # and when the 'trigger-crash-dump' operation is executed,
    # instance's kernel receives the NMI signal, and an appropriate
    # message will appear in the instance's log.

    # The server status must be ACTIVE, PAUSED, RESCUED, RESIZED or ERROR.
    # If not, the conflictingRequest(409) code is returned

    def _assert_nmi(self, server_id, timeout=60, poll_interval=1):
        start_time = time.time()
        while time.time() - start_time < timeout:
            if 'trigger_crash_dump' in self.nova('instance-action-list %s ' %
                                                 server_id):
                break
            time.sleep(poll_interval)
        else:
            self.fail("Trigger crash dump hasn't been executed for server %s"
                      % server_id)

    def test_trigger_crash_dump_in_active_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_error_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('reset-state %s ' % server.id)
        shell._poll_for_status(
            self.client.servers.get, server.id,
            'active', ['error'])
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_paused_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('pause %s ' % server.id)
        shell._poll_for_status(
            self.client.servers.get, server.id,
            'active', ['paused'])
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_rescued_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('rescue %s ' % server.id)
        shell._poll_for_status(
            self.client.servers.get, server.id,
            'active', ['rescue'])
        self.wait_for_server_os_boot(server.id)
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_resized_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('resize %s %s' % (server.id, 'm1.small'))
        shell._poll_for_status(
            self.client.servers.get, server.id,
            'active', ['verify_resize'])
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_shutoff_state(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('stop %s ' % server.id)
        shell._poll_for_status(
            self.client.servers.get, server.id,
            'active', ['shutoff'])
        output = self.nova('trigger-crash-dump %s ' %
                           server.id, fail_ok=True, merge_stderr=True)
        self.assertIn("ERROR (Conflict): "
                      "Cannot 'trigger_crash_dump' instance %s "
                      "while it is in vm_state stopped (HTTP 409) " %
                      server.id, output)

    # If the specified server is locked, the conflictingRequest(409) code
    # is returned to a user without administrator privileges.
    def test_trigger_crash_dump_in_locked_state_admin(self):
        server = self._create_server()
        self.wait_for_server_os_boot(server.id)
        self.nova('lock %s ' % server.id)
        self.nova('trigger-crash-dump %s ' % server.id)
        self._assert_nmi(server.id)

    def test_trigger_crash_dump_in_locked_state_nonadmin(self):
        name = self.name_generate(prefix='server')
        server = self.another_nova('boot --flavor %s --image %s --poll %s' %
                                   (self.flavor.name, self.image.name, name))
        self.addCleanup(self.another_nova, 'delete', params=name)
        server_id = self._get_value_from_the_table(
            server, 'id')
        self.wait_for_server_os_boot(server_id)
        self.another_nova('lock %s ' % server_id)
        self.addCleanup(self.another_nova, 'unlock', params=name)
        output = self.another_nova('trigger-crash-dump %s ' %
                                   server_id, fail_ok=True, merge_stderr=True)
        # NOTE(mriedem): Depending on the version of the server you can get
        # different error messages back from this, so just assert that it's a
        # 409 either way.
        self.assertIn("ERROR (Conflict)", output)