diff --git a/changes/2239.incompatible.rst b/changes/2239.incompatible.rst new file mode 100644 index 00000000..8d14ddf0 --- /dev/null +++ b/changes/2239.incompatible.rst @@ -0,0 +1,7 @@ +FC-type storage groups do not have a property "candidate-adapter-port-uris". +The :meth:`zhmcclient.StorageGroup.list_candidate_adapter_ports` method +raised ``KeyError`` when called for FC-type storage groups. However, this was +not documented. Changed the method to return `None` when called for +FC-type storage groups and documented that. This is an incompatible change +for users that handle that ``KeyError`` exception. If you have such code, +it needs to be changed to test for `None` instead. diff --git a/zhmcclient/_storage_group.py b/zhmcclient/_storage_group.py index 9604b3dc..ebd4a3ee 100644 --- a/zhmcclient/_storage_group.py +++ b/zhmcclient/_storage_group.py @@ -674,7 +674,9 @@ def list_candidate_adapter_ports(self, full_properties=False): Return the current candidate storage adapter port list of this FCP storage group. - This operation only applies to storage groups of type "fcp". + This operation only returns candicate adapter ports for storage groups + of type "fcp". + When called for storage groups of type "fc", it returns `None`. The result reflects the actual list of ports used by the CPC, including any changes that have been made during discovery. The source for this @@ -693,12 +695,12 @@ def list_candidate_adapter_ports(self, full_properties=False): following short set: "element-uri", "element-id", "class", "parent". - TODO: Verify short list of properties. - Returns: - List of :class:`~zhmcclient.Port` objects representing the - current candidate storage adapter ports of this storage group. + List of :class:`~zhmcclient.Port` objects representing the current + candidate storage adapter ports of this FCP-type storage group. + + `None` for FC-type storage groups. Raises: @@ -709,20 +711,22 @@ def list_candidate_adapter_ports(self, full_properties=False): """ sg_cpc = self.cpc adapter_mgr = sg_cpc.adapters + port_uris = self.prop('candidate-adapter-port-uris', None) + if port_uris is None: + # FC-type storage group + return None port_list = [] - port_uris = self.get_property('candidate-adapter-port-uris') - if port_uris: - for port_uri in port_uris: - m = re.match(r'^(/api/adapters/[^/]*)/.*', port_uri) - - adapter_uri = m.group(1) - adapter = adapter_mgr.resource_object(adapter_uri) - - port_mgr = adapter.ports - port = port_mgr.resource_object(port_uri) - port_list.append(port) - if full_properties: - port.pull_full_properties() + for port_uri in port_uris: + m = re.match(r'^(/api/adapters/[^/]*)/.*', port_uri) + + adapter_uri = m.group(1) + adapter = adapter_mgr.resource_object(adapter_uri) + + port_mgr = adapter.ports + port = port_mgr.resource_object(port_uri) + port_list.append(port) + if full_properties: + port.pull_full_properties() return port_list