|
| 1 | +# Copyright 2026 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 | +End2end tests for Tape Library (on CPCs in DPM mode). |
| 17 | +
|
| 18 | +These tests do not change any existing Tape Library, but discover, |
| 19 | +modify and undefine test Tape Libraries. |
| 20 | +""" |
| 21 | + |
| 22 | +import pytest |
| 23 | +from requests.packages import urllib3 |
| 24 | + |
| 25 | +import zhmcclient |
| 26 | + |
| 27 | +from .utils import skip_warn, pick_test_resources, \ |
| 28 | + runtest_find_list, runtest_get_properties |
| 29 | + |
| 30 | +urllib3.disable_warnings() |
| 31 | + |
| 32 | +# Properties in minimalistic Tape Library objects (e.g. find_by_name()) |
| 33 | +TL_MINIMAL_PROPS = ['object-uri', 'name'] |
| 34 | + |
| 35 | +# Properties in Tape Library objects returned by list() without full props |
| 36 | +TL_LIST_PROPS = ['object-uri', 'cpc-uri', 'name', 'state'] |
| 37 | + |
| 38 | +# Properties whose values can change between retrievals of StorageGroup objs |
| 39 | +TL_VOLATILE_PROPS = [] |
| 40 | + |
| 41 | + |
| 42 | +def test_tl_find_list(hmc_session): |
| 43 | + """ |
| 44 | + Test list(), find(), findall(). |
| 45 | + """ |
| 46 | + client = zhmcclient.Client(hmc_session) |
| 47 | + console = client.consoles.console |
| 48 | + hd = hmc_session.hmc_definition |
| 49 | + |
| 50 | + # Pick the Tape Library to test with |
| 51 | + tl_list = console.tape_library.list() |
| 52 | + if not tl_list: |
| 53 | + skip_warn(f"No Tape Library defined on HMC {hd.host}") |
| 54 | + tl_list = pick_test_resources(tl_list) |
| 55 | + |
| 56 | + for tl in tl_list: |
| 57 | + print(f"Testing with Tape Library {tl.name!r}") |
| 58 | + runtest_find_list( |
| 59 | + hmc_session, console.tape_library, tl.name, |
| 60 | + 'name', 'object-uri', TL_VOLATILE_PROPS, |
| 61 | + TL_MINIMAL_PROPS, TL_LIST_PROPS) |
| 62 | + |
| 63 | + |
| 64 | +def test_tl_property(hmc_session): |
| 65 | + """ |
| 66 | + Test property related methods |
| 67 | + """ |
| 68 | + client = zhmcclient.Client(hmc_session) |
| 69 | + console = client.consoles.console |
| 70 | + hd = hmc_session.hmc_definition |
| 71 | + |
| 72 | + # Pick the Tape Library to test with |
| 73 | + tl_list = console.tape_library.list() |
| 74 | + if not tl_list: |
| 75 | + skip_warn(f"No Tape Library defined on HMC {hd.host}") |
| 76 | + tl_list = pick_test_resources(tl_list) |
| 77 | + |
| 78 | + for tl in tl_list: |
| 79 | + print(f"Testing with Tape Library {tl.name!r}") |
| 80 | + |
| 81 | + # Select a property that is not returned by list() |
| 82 | + non_list_prop = 'description' |
| 83 | + |
| 84 | + runtest_get_properties(tl.manager, non_list_prop) |
| 85 | + |
| 86 | + |
| 87 | +def test_tl_crud(hmc_session): |
| 88 | + """ |
| 89 | + Test update Tape Library |
| 90 | + """ |
| 91 | + client = zhmcclient.Client(hmc_session) |
| 92 | + console = client.consoles.console |
| 93 | + hd = hmc_session.hmc_definition |
| 94 | + tl_name_new = 'newtl1' |
| 95 | + |
| 96 | + # Pick the Tape Library to test with |
| 97 | + tl_list = console.tape_library.list() |
| 98 | + if not tl_list: |
| 99 | + skip_warn(f"No Tape Library defined on HMC {hd.host}") |
| 100 | + tl = tl_list[0] |
| 101 | + |
| 102 | + # Test updating a property of the Tape Library |
| 103 | + |
| 104 | + new_desc = "Updated Tape Library description." |
| 105 | + |
| 106 | + # The code to be tested |
| 107 | + tl.update_properties(dict(description=new_desc)) |
| 108 | + |
| 109 | + assert tl.properties['description'] == new_desc |
| 110 | + tl.pull_full_properties() |
| 111 | + assert tl.properties['description'] == new_desc |
| 112 | + |
| 113 | + # Test that Tape Library can be renamed |
| 114 | + |
| 115 | + # The code to be tested |
| 116 | + tl.update_properties(dict(name=tl_name_new)) |
| 117 | + tl.pull_full_properties() |
| 118 | + with pytest.raises(zhmcclient.NotFound): |
| 119 | + console.tape_library.find(name='Tape Library') |
0 commit comments