|
| 1 | +import pytest |
| 2 | + |
| 3 | +from conftest import ( |
| 4 | + IMAGES_DIR, |
| 5 | + SCSI_ID, |
| 6 | + FILE_SIZE_1_MIB, |
| 7 | + STATUS_SUCCESS, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +# route("/scsi/attach", methods=["POST"]) |
| 12 | +def test_attach_image(http_client, create_test_image, detach_devices): |
| 13 | + test_image = create_test_image() |
| 14 | + |
| 15 | + response = http_client.post( |
| 16 | + "/scsi/attach", |
| 17 | + data={ |
| 18 | + "file_name": test_image, |
| 19 | + "file_size": FILE_SIZE_1_MIB, |
| 20 | + "scsi_id": SCSI_ID, |
| 21 | + "unit": 0, |
| 22 | + "type": "SCHD", |
| 23 | + }, |
| 24 | + ) |
| 25 | + response_data = response.json() |
| 26 | + |
| 27 | + assert response.status_code == 200 |
| 28 | + assert response_data["status"] == STATUS_SUCCESS |
| 29 | + assert response_data["messages"][0]["message"] == ( |
| 30 | + f"Attached {test_image} as Hard Disk to SCSI ID {SCSI_ID} LUN 0" |
| 31 | + ) |
| 32 | + |
| 33 | + # Cleanup |
| 34 | + detach_devices() |
| 35 | + |
| 36 | + |
| 37 | +# route("/scsi/attach_device", methods=["POST"]) |
| 38 | +@pytest.mark.parametrize( |
| 39 | + "device_name,device_config", |
| 40 | + [ |
| 41 | + # TODO: Fix networking in container, else SCBR attachment fails |
| 42 | + # ("X68000 Host Bridge", {"type": "SCBR", "interface": "eth0", "inet": "10.10.20.1/24"}), |
| 43 | + ("DaynaPORT SCSI/Link", {"type": "SCDP", "interface": "eth0", "inet": "10.10.20.1/24"}), |
| 44 | + ("Host Services", {"type": "SCHS"}), |
| 45 | + ("Printer", {"type": "SCLP", "timeout": 30, "cmd": "lp -oraw %f"}), |
| 46 | + ], |
| 47 | +) |
| 48 | +def test_attach_device(http_client, detach_devices, device_name, device_config): |
| 49 | + device_config["scsi_id"] = SCSI_ID |
| 50 | + device_config["unit"] = 0 |
| 51 | + |
| 52 | + response = http_client.post( |
| 53 | + "/scsi/attach_device", |
| 54 | + data=device_config, |
| 55 | + ) |
| 56 | + |
| 57 | + response_data = response.json() |
| 58 | + |
| 59 | + assert response.status_code == 200 |
| 60 | + assert response_data["status"] == STATUS_SUCCESS |
| 61 | + assert response_data["messages"][0]["message"] == ( |
| 62 | + f"Attached {device_name} to SCSI ID {SCSI_ID} LUN 0" |
| 63 | + ) |
| 64 | + |
| 65 | + # Cleanup |
| 66 | + detach_devices() |
| 67 | + |
| 68 | + |
| 69 | +# route("/scsi/detach", methods=["POST"]) |
| 70 | +def test_detach_device(http_client, create_test_image): |
| 71 | + test_image = create_test_image() |
| 72 | + |
| 73 | + http_client.post( |
| 74 | + "/scsi/attach", |
| 75 | + data={ |
| 76 | + "file_name": test_image, |
| 77 | + "file_size": FILE_SIZE_1_MIB, |
| 78 | + "scsi_id": SCSI_ID, |
| 79 | + "unit": 0, |
| 80 | + "type": "SCHD", |
| 81 | + }, |
| 82 | + ) |
| 83 | + |
| 84 | + response = http_client.post( |
| 85 | + "/scsi/detach", |
| 86 | + data={ |
| 87 | + "scsi_id": SCSI_ID, |
| 88 | + "unit": 0, |
| 89 | + }, |
| 90 | + ) |
| 91 | + |
| 92 | + response_data = response.json() |
| 93 | + |
| 94 | + response.status_code == 200 |
| 95 | + response_data["status"] == STATUS_SUCCESS |
| 96 | + response_data["messages"][0]["message"] == f"Detached SCSI ID {SCSI_ID} LUN 0" |
| 97 | + |
| 98 | + |
| 99 | +# route("/scsi/detach_all", methods=["POST"]) |
| 100 | +def test_detach_all_devices(http_client, create_test_image, list_attached_images): |
| 101 | + test_images = [] |
| 102 | + scsi_ids = [4, 5, 6] |
| 103 | + |
| 104 | + for scsi_id in scsi_ids: |
| 105 | + test_image = create_test_image() |
| 106 | + test_images.append(test_image) |
| 107 | + |
| 108 | + http_client.post( |
| 109 | + "/scsi/attach", |
| 110 | + data={ |
| 111 | + "file_name": test_image, |
| 112 | + "file_size": FILE_SIZE_1_MIB, |
| 113 | + "scsi_id": scsi_id, |
| 114 | + "unit": 0, |
| 115 | + "type": "SCHD", |
| 116 | + }, |
| 117 | + ) |
| 118 | + |
| 119 | + assert list_attached_images() == test_images |
| 120 | + |
| 121 | + response = http_client.post("/scsi/detach_all") |
| 122 | + response_data = response.json() |
| 123 | + |
| 124 | + assert response.status_code == 200 |
| 125 | + assert response_data["status"] == STATUS_SUCCESS |
| 126 | + assert list_attached_images() == [] |
| 127 | + |
| 128 | + |
| 129 | +# route("/scsi/eject", methods=["POST"]) |
| 130 | +def test_eject_device(http_client, create_test_image, detach_devices): |
| 131 | + test_image = create_test_image() |
| 132 | + |
| 133 | + http_client.post( |
| 134 | + "/scsi/attach", |
| 135 | + data={ |
| 136 | + "file_name": test_image, |
| 137 | + "file_size": FILE_SIZE_1_MIB, |
| 138 | + "scsi_id": SCSI_ID, |
| 139 | + "unit": 0, |
| 140 | + "type": "SCCD", # CD-ROM |
| 141 | + }, |
| 142 | + ) |
| 143 | + |
| 144 | + response = http_client.post( |
| 145 | + "/scsi/eject", |
| 146 | + data={ |
| 147 | + "scsi_id": SCSI_ID, |
| 148 | + "unit": 0, |
| 149 | + }, |
| 150 | + ) |
| 151 | + |
| 152 | + response_data = response.json() |
| 153 | + |
| 154 | + assert response.status_code == 200 |
| 155 | + assert response_data["status"] == STATUS_SUCCESS |
| 156 | + assert response_data["messages"][0]["message"] == f"Ejected SCSI ID {SCSI_ID} LUN 0" |
| 157 | + |
| 158 | + # Cleanup |
| 159 | + detach_devices() |
| 160 | + |
| 161 | + |
| 162 | +# route("/scsi/info", methods=["POST"]) |
| 163 | +def test_show_device_info(http_client, create_test_image, detach_devices): |
| 164 | + test_image = create_test_image() |
| 165 | + |
| 166 | + http_client.post( |
| 167 | + "/scsi/attach", |
| 168 | + data={ |
| 169 | + "file_name": test_image, |
| 170 | + "file_size": FILE_SIZE_1_MIB, |
| 171 | + "scsi_id": SCSI_ID, |
| 172 | + "unit": 0, |
| 173 | + "type": "SCHD", |
| 174 | + }, |
| 175 | + ) |
| 176 | + |
| 177 | + response = http_client.post( |
| 178 | + "/scsi/info", |
| 179 | + data={ |
| 180 | + "scsi_id": SCSI_ID, |
| 181 | + }, |
| 182 | + ) |
| 183 | + |
| 184 | + response_data = response.json() |
| 185 | + |
| 186 | + assert response.status_code == 200 |
| 187 | + assert response_data["status"] == STATUS_SUCCESS |
| 188 | + assert "device_info" in response_data["data"] |
| 189 | + assert response_data["data"]["device_info"]["file"] == f"{IMAGES_DIR}/{test_image}" |
| 190 | + |
| 191 | + # Cleanup |
| 192 | + detach_devices() |
| 193 | + |
| 194 | + |
| 195 | +# route("/scsi/reserve", methods=["POST"]) |
| 196 | +# route("/scsi/release", methods=["POST"]) |
| 197 | +def test_reserve_and_release_device(http_client): |
| 198 | + scsi_id = 0 |
| 199 | + |
| 200 | + response = http_client.post( |
| 201 | + "/scsi/reserve", |
| 202 | + data={ |
| 203 | + "scsi_id": scsi_id, |
| 204 | + "memo": "TEST", |
| 205 | + }, |
| 206 | + ) |
| 207 | + |
| 208 | + response_data = response.json() |
| 209 | + |
| 210 | + assert response.status_code == 200 |
| 211 | + assert response_data["status"] == STATUS_SUCCESS |
| 212 | + assert response_data["messages"][0]["message"] == f"Reserved SCSI ID {scsi_id}" |
| 213 | + |
| 214 | + response = http_client.post( |
| 215 | + "/scsi/release", |
| 216 | + data={ |
| 217 | + "scsi_id": scsi_id, |
| 218 | + }, |
| 219 | + ) |
| 220 | + |
| 221 | + response_data = response.json() |
| 222 | + |
| 223 | + assert response.status_code == 200 |
| 224 | + assert response_data["status"] == STATUS_SUCCESS |
| 225 | + assert response_data["messages"][0]["message"] == ( |
| 226 | + f"Released the reservation for SCSI ID {scsi_id}" |
| 227 | + ) |
0 commit comments