• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zhmcclient / python-zhmcclient / test-4031

13 Oct 2025 06:35AM UTC coverage: 54.12% (-25.6%) from 79.76%
test-4031

Pull #2016

github

web-flow
Merge 12651f3c9 into 617900654
Pull Request #2016: Reduced number of HMC sessions in end2end tests

24 of 49 new or added lines in 7 files covered. (48.98%)

2871 existing lines in 56 files now uncovered.

6239 of 11528 relevant lines covered (54.12%)

6.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.02
/zhmcclient/_virtual_function.py
1
# Copyright 2016,2021 IBM Corp. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#    http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
"""
16
A :term:`Virtual Function` is a logical entity that provides a
17
:term:`Partition` with access to
18
:term:`Accelerator Adapters <Accelerator Adapter>`.
19

20
Virtual Function resources are contained in Partition resources.
21

22
Virtual Functions only exist in :term:`CPCs <CPC>` that are in DPM mode.
23
"""
24

25

UNCOV
26
import copy
×
27

UNCOV
28
from ._manager import BaseManager
×
UNCOV
29
from ._resource import BaseResource
×
UNCOV
30
from ._logging import logged_api_call
×
UNCOV
31
from ._utils import RC_VIRTUAL_FUNCTION
×
32

UNCOV
33
__all__ = ['VirtualFunctionManager', 'VirtualFunction']
×
34

35

UNCOV
36
class VirtualFunctionManager(BaseManager):
×
37
    """
38
    Manager providing access to the
39
    :term:`Virtual Functions <Virtual Function>` in a particular
40
    :term:`Partition`.
41

42
    Derived from :class:`~zhmcclient.BaseManager`; see there for common methods
43
    and attributes.
44

45
    Objects of this class are not directly created by the user; they are
46
    accessible via the following instance variable of a
47
    :class:`~zhmcclient.Partition` object (in DPM mode):
48

49
    * :attr:`~zhmcclient.Partition.virtual_functions`
50

51
    HMC/SE version requirements:
52

53
    * SE version >= 2.13.1
54
    """
55

UNCOV
56
    def __init__(self, partition):
×
57
        # This function should not go into the docs.
58
        # Parameters:
59
        #   partition (:class:`~zhmcclient.Partition`):
60
        #     Partition defining the scope for this manager.
61
        super().__init__(
12✔
62
            resource_class=VirtualFunction,
63
            class_name=RC_VIRTUAL_FUNCTION,
64
            session=partition.manager.session,
65
            parent=partition,
66
            base_uri=f'{partition.uri}/virtual-functions',
67
            oid_prop='element-id',
68
            uri_prop='element-uri',
69
            name_prop='name',
70
            query_props=[],
71
            list_has_name=False)
72

UNCOV
73
    @property
×
UNCOV
74
    def partition(self):
×
75
        """
76
        :class:`~zhmcclient.Partition`: :term:`Partition` defining the scope
77
        for this manager.
78
        """
79
        return self._parent
12✔
80

UNCOV
81
    @logged_api_call
×
UNCOV
82
    def list(self, full_properties=False, filter_args=None):
×
83
        """
84
        List the Virtual Functions of this Partition.
85

86
        Any resource property may be specified in a filter argument. For
87
        details about filter arguments, see :ref:`Filtering`.
88

89
        The listing of resources is handled in an optimized way:
90

91
        * If this manager is enabled for :ref:`auto-updating`, a locally
92
          maintained resource list is used (which is automatically updated via
93
          inventory notifications from the HMC) and the provided filter
94
          arguments are applied.
95

96
        * Otherwise, if the filter arguments specify the resource name as a
97
          single filter argument with a straight match string (i.e. without
98
          regular expressions), an optimized lookup is performed based on a
99
          locally maintained name-URI cache.
100

101
        * Otherwise, the corresponding array property for this resource in the
102
          parent object is used to list the resources, and the provided filter
103
          arguments are applied.
104

105
        HMC/SE version requirements:
106

107
        * SE version >= 2.13.1
108

109
        Authorization requirements:
110

111
        * Object-access permission to this Partition.
112

113
        Parameters:
114

115
          full_properties (bool):
116
            Controls whether the full set of resource properties should be
117
            retrieved, vs. only the short set as returned by the list
118
            operation.
119

120
          filter_args (dict):
121
            Filter arguments that narrow the list of returned resources to
122
            those that match the specified filter arguments. For details, see
123
            :ref:`Filtering`.
124

125
            `None` causes no filtering to happen, i.e. all resources are
126
            returned.
127

128
        Returns:
129

130
          : A list of :class:`~zhmcclient.VirtualFunction` objects.
131

132
        Raises:
133

134
          :exc:`~zhmcclient.HTTPError`
135
          :exc:`~zhmcclient.ParseError`
136
          :exc:`~zhmcclient.AuthError`
137
          :exc:`~zhmcclient.ConnectionError`
138
          :exc:`~zhmcclient.FilterConversionError`
139
        """
140
        return self._list_with_parent_array(
12✔
141
            self.partition, 'virtual-function-uris', full_properties,
142
            filter_args)
143

UNCOV
144
    @logged_api_call
×
UNCOV
145
    def create(self, properties):
×
146
        """
147
        Create a Virtual Function in this Partition.
148

149
        HMC/SE version requirements:
150

151
        * SE version >= 2.13.1
152

153
        Authorization requirements:
154

155
        * Object-access permission to this Partition.
156
        * Object-access permission to the backing accelerator Adapter.
157
        * Task permission for the "Partition Details" task.
158

159
        Parameters:
160

161
          properties (dict): Initial property values.
162
            Allowable properties are defined in section 'Request body contents'
163
            in section 'Create Virtual Function' in the :term:`HMC API` book.
164

165
        Returns:
166

167
          VirtualFunction:
168
            The resource object for the new Virtual Function.
169
            The object will have its 'element-uri' property set as returned by
170
            the HMC, and will also have the input properties set.
171

172
        Raises:
173

174
          :exc:`~zhmcclient.HTTPError`
175
          :exc:`~zhmcclient.ParseError`
176
          :exc:`~zhmcclient.AuthError`
177
          :exc:`~zhmcclient.ConnectionError`
178
        """
179
        result = self.session.post(self.partition.uri + '/virtual-functions',
12✔
180
                                   body=properties)
181
        # There should not be overlaps, but just in case there are, the
182
        # returned props should overwrite the input props:
183
        props = copy.deepcopy(properties)
12✔
184
        props.update(result)
12✔
185
        name = props.get(self._name_prop, None)
12✔
186
        uri = props[self._uri_prop]
12✔
187
        vf = VirtualFunction(self, uri, name, props)
12✔
188
        self._name_uri_cache.update(name, uri)
12✔
189
        return vf
12✔
190

191

UNCOV
192
class VirtualFunction(BaseResource):
×
193
    """
194
    Representation of a :term:`Virtual Function`.
195

196
    Derived from :class:`~zhmcclient.BaseResource`; see there for common
197
    methods and attributes.
198

199
    For the properties of a Virtual Function, see section
200
    'Data model - Virtual Function Element Object' in section
201
    'Partition object' in the :term:`HMC API` book.
202

203
    Objects of this class are not directly created by the user; they are
204
    returned from creation or list functions on their manager object
205
    (in this case, :class:`~zhmcclient.VirtualFunctionManager`).
206

207
    HMC/SE version requirements:
208

209
    * SE version >= 2.13.1
210
    """
211

UNCOV
212
    def __init__(self, manager, uri, name=None, properties=None):
×
213
        # This function should not go into the docs.
214
        #   manager (:class:`~zhmcclient.VirtualFunctionManager`):
215
        #     Manager object for this resource object.
216
        #   uri (string):
217
        #     Canonical URI path of the resource.
218
        #   name (string):
219
        #     Name of the resource.
220
        #   properties (dict):
221
        #     Properties to be set for this resource object. May be `None` or
222
        #     empty.
223
        assert isinstance(manager, VirtualFunctionManager), (
12✔
224
            "VirtualFunction init: Expected manager type "
225
            f"{VirtualFunctionManager}, got {type(manager)}")
226
        super().__init__(manager, uri, name, properties)
12✔
227

UNCOV
228
    @logged_api_call
×
UNCOV
229
    def delete(self):
×
230
        """
231
        Delete this Virtual Function.
232

233
        HMC/SE version requirements:
234

235
        * SE version >= 2.13.1
236

237
        Authorization requirements:
238

239
        * Object-access permission to the Partition of this Virtual Function.
240
        * Task permission for the "Partition Details" task.
241

242
        Raises:
243

244
          :exc:`~zhmcclient.HTTPError`
245
          :exc:`~zhmcclient.ParseError`
246
          :exc:`~zhmcclient.AuthError`
247
          :exc:`~zhmcclient.ConnectionError`
248
        """
249
        # pylint: disable=protected-access
250
        self.manager.session.delete(self._uri, resource=self)
12✔
251
        self.manager._name_uri_cache.delete(
12✔
252
            self.get_properties_local(self.manager._name_prop, None))
253

254
        parent_vf_uris = self.manager.parent.get_properties_local(
12✔
255
            'virtual-function-uris')
256
        if parent_vf_uris:
12✔
257
            try:
12✔
258
                parent_vf_uris.remove(self._uri)
12✔
259
            except ValueError:
×
260
                pass
×
261

262
        self.cease_existence_local()
12✔
263

UNCOV
264
    @logged_api_call
×
UNCOV
265
    def update_properties(self, properties):
×
266
        """
267
        Update writeable properties of this Virtual Function.
268

269
        This method serializes with other methods that access or change
270
        properties on the same Python object.
271

272
        HMC/SE version requirements:
273

274
        * SE version >= 2.13.1
275

276
        Authorization requirements:
277

278
        * Object-access permission to the Partition of this Virtual Function.
279
        * When updating the "adapter-uri" property, object-access permission to
280
          the Adapter identified in that URI.
281
        * Task permission for the "Partition Details" task.
282

283
        Parameters:
284

285
          properties (dict): New values for the properties to be updated.
286
            Properties not to be updated are omitted.
287
            Allowable properties are the properties with qualifier (w) in
288
            section 'Data model - Virtual Function element object' in the
289
            :term:`HMC API` book.
290

291
        Raises:
292

293
          :exc:`~zhmcclient.HTTPError`
294
          :exc:`~zhmcclient.ParseError`
295
          :exc:`~zhmcclient.AuthError`
296
          :exc:`~zhmcclient.ConnectionError`
297
        """
298
        # pylint: disable=protected-access
299
        self.manager.session.post(self.uri, resource=self, body=properties)
12✔
300
        is_rename = self.manager._name_prop in properties
12✔
301
        if is_rename:
12✔
302
            # Delete the old name from the cache
303
            self.manager._name_uri_cache.delete(self.name)
×
304
        self.update_properties_local(copy.deepcopy(properties))
12✔
305
        if is_rename:
12✔
306
            # Add the new name to the cache
307
            self.manager._name_uri_cache.update(self.name, self.uri)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc