File: test_system.py

package info (click to toggle)
python-dracclient 3.1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,008 kB
  • sloc: xml: 18,999; python: 7,076; makefile: 23
file content (91 lines) | stat: -rw-r--r-- 3,822 bytes parent folder | download | duplicates (3)
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
#
#    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
import requests_mock

import dracclient.client
from dracclient.resources import system
from dracclient.resources import uris
from dracclient.tests import base
from dracclient.tests import utils as test_utils


class ClientSystemConfigurationTestCase(base.BaseTest):

    def setUp(self):
        super(ClientSystemConfigurationTestCase, self).setUp()
        self.drac_client = dracclient.client.DRACClient(
            **test_utils.FAKE_ENDPOINT)

    @requests_mock.Mocker()
    @mock.patch.object(dracclient.client.WSManClient,
                       'wait_until_idrac_is_ready', spec_set=True,
                       autospec=True)
    def test_list_system_settings(
            self, mock_requests, mock_wait_until_idrac_is_ready):
        expected_enum_attr = system.SystemEnumerableAttribute(
            name='ChassisLEDState',
            instance_id='System.Embedded.1#ChassisPwrState.1#ChassisLEDState',  # noqa
            read_only=False,
            current_value='Off',
            pending_value=None,
            fqdd='System.Embedded.1',
            group_id='ChassisPwrState.1',
            possible_values=['Unknown', 'Blinking', 'Off'])
        expected_string_attr = system.SystemStringAttribute(
            name='UserDefinedString',
            instance_id='System.Embedded.1#LCD.1#UserDefinedString',
            read_only=False,
            current_value=None,
            pending_value=None,
            fqdd='System.Embedded.1',
            group_id='LCD.1',
            min_length=0,
            max_length=62)
        expected_integer_attr = system.SystemIntegerAttribute(
            name='PowerCapValue',
            instance_id='System.Embedded.1#ServerPwr.1#PowerCapValue',
            read_only=False,
            current_value=555,
            pending_value=None,
            fqdd='System.Embedded.1',
            group_id='ServerPwr.1',
            lower_bound=302,
            upper_bound=578)

        mock_requests.post('https://1.2.3.4:443/wsman', [
            {'text': test_utils.SystemEnumerations[
                uris.DCIM_SystemEnumeration]['ok']},
            {'text': test_utils.SystemEnumerations[
                uris.DCIM_SystemString]['ok']},
            {'text': test_utils.SystemEnumerations[
                uris.DCIM_SystemInteger]['ok']}])

        system_settings = self.drac_client.list_system_settings()

        self.assertEqual(44, len(system_settings))
        # enumerable attribute
        self.assertIn('System.Embedded.1#ChassisPwrState.1#ChassisLEDState',
                      system_settings)
        self.assertEqual(expected_enum_attr, system_settings[
                         'System.Embedded.1#ChassisPwrState.1#ChassisLEDState'])  # noqa
        # string attribute
        self.assertIn('System.Embedded.1#LCD.1#UserDefinedString',
                      system_settings)
        self.assertEqual(expected_string_attr, system_settings[
                         'System.Embedded.1#LCD.1#UserDefinedString'])
        self.assertIn('System.Embedded.1#ServerPwr.1#PowerCapValue',
                      system_settings)
        self.assertEqual(expected_integer_attr,
                         system_settings['System.Embedded.1#ServerPwr.1#PowerCapValue'])  # noqa