|
| 1 | +# (C) Copyright [2020] Hewlett Packard Enterprise Development LP |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +# copy of this software and associated documentation files (the "Software"), |
| 5 | +# to deal in the Software without restriction, including without limitation |
| 6 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 | +# and/or sell copies of the Software, and to permit persons to whom the |
| 8 | +# Software is furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included |
| 11 | +# in all copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 | +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 | +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 | +# OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + |
| 21 | + |
| 22 | +from .base_test import BaseTestCase, MockResponse |
| 23 | + |
| 24 | + |
| 25 | +def mockApiSetup(): |
| 26 | + |
| 27 | + BaseTestCase.registerHttpGetHandler( |
| 28 | + url="https://127.0.0.1:8080/api/v1/tenant/", |
| 29 | + response=MockResponse( |
| 30 | + json_data={ |
| 31 | + "_embedded": { |
| 32 | + "tenants": [ |
| 33 | + { |
| 34 | + "status": "ready", |
| 35 | + "tenant_type": "docker", |
| 36 | + "features": { |
| 37 | + "ml_project": False, |
| 38 | + "kubernetes_access": False, |
| 39 | + }, |
| 40 | + "persistent_supported": True, |
| 41 | + "member_key_available": "all_admins", |
| 42 | + "quota": {}, |
| 43 | + "cluster_isolation_supported": True, |
| 44 | + "inusequota": { |
| 45 | + "disk": 0, |
| 46 | + "cores": 0, |
| 47 | + "memory": 0, |
| 48 | + "persistent": 0, |
| 49 | + "gpus": 0, |
| 50 | + }, |
| 51 | + "external_user_groups": [], |
| 52 | + "gpu_usage_supported": True, |
| 53 | + "_links": {"self": {"href": "/api/v1/tenant/1"}}, |
| 54 | + "filesystem_mount_supported": True, |
| 55 | + "tenant_enforcements": [], |
| 56 | + "label": { |
| 57 | + "name": "Site Admin", |
| 58 | + "description": ( |
| 59 | + "Site Admin Tenant" |
| 60 | + " for BlueData clusters" |
| 61 | + ), |
| 62 | + }, |
| 63 | + "constraints_supported": False, |
| 64 | + "tenant_storage_quota_supported": False, |
| 65 | + }, |
| 66 | + { |
| 67 | + "status": "ready", |
| 68 | + "tenant_type": "docker", |
| 69 | + "features": { |
| 70 | + "ml_project": False, |
| 71 | + "kubernetes_access": False, |
| 72 | + }, |
| 73 | + "persistent_supported": True, |
| 74 | + "member_key_available": "all_admins", |
| 75 | + "quota": {}, |
| 76 | + "cluster_isolation_supported": True, |
| 77 | + "inusequota": { |
| 78 | + "disk": 0, |
| 79 | + "cores": 0, |
| 80 | + "memory": 0, |
| 81 | + "persistent": 0, |
| 82 | + "gpus": 0, |
| 83 | + }, |
| 84 | + "external_user_groups": [], |
| 85 | + "gpu_usage_supported": True, |
| 86 | + "_links": {"self": {"href": "/api/v1/tenant/2"}}, |
| 87 | + "filesystem_mount_supported": True, |
| 88 | + "tenant_enforcements": [], |
| 89 | + "label": { |
| 90 | + "name": "Demo Tenant", |
| 91 | + "description": ( |
| 92 | + "Demo Tenant for BlueData Clusters" |
| 93 | + ), |
| 94 | + }, |
| 95 | + "constraints_supported": True, |
| 96 | + "tenant_storage_quota_supported": True, |
| 97 | + "qos_multiplier": 1, |
| 98 | + }, |
| 99 | + ] |
| 100 | + }, |
| 101 | + "_links": {"self": {"href": "/api/v1/tenant"}}, |
| 102 | + }, |
| 103 | + status_code=200, |
| 104 | + headers={}, |
| 105 | + ), |
| 106 | + ) |
| 107 | + |
| 108 | + BaseTestCase.registerHttpGetHandler( |
| 109 | + url="https://127.0.0.1:8080/api/v1/tenant/1", |
| 110 | + response=MockResponse( |
| 111 | + json_data={ |
| 112 | + "status": "ready", |
| 113 | + "features": {"ml_project": False, "kubernetes_access": False,}, |
| 114 | + "persistent_supported": True, |
| 115 | + "member_key_available": "all_admins", |
| 116 | + "quota": {}, |
| 117 | + "cluster_isolation_supported": True, |
| 118 | + "inusequota": { |
| 119 | + "disk": 0, |
| 120 | + "cores": 0, |
| 121 | + "memory": 0, |
| 122 | + "persistent": 0, |
| 123 | + "gpus": 0, |
| 124 | + }, |
| 125 | + "external_user_groups": [], |
| 126 | + "gpu_usage_supported": True, |
| 127 | + "_links": {"self": {"href": "/api/v1/tenant/1"}}, |
| 128 | + "filesystem_mount_supported": True, |
| 129 | + "tenant_enforcements": [], |
| 130 | + "label": { |
| 131 | + "name": "Site Admin", |
| 132 | + "description": ("Site Admin Tenant for BlueData clusters"), |
| 133 | + }, |
| 134 | + "constraints_supported": False, |
| 135 | + "tenant_storage_quota_supported": False, |
| 136 | + }, |
| 137 | + status_code=200, |
| 138 | + headers={}, |
| 139 | + ), |
| 140 | + ) |
| 141 | + |
| 142 | + BaseTestCase.registerHttpGetHandler( |
| 143 | + url="https://127.0.0.1:8080/api/v1/tenant/2", |
| 144 | + response=MockResponse( |
| 145 | + json_data={ |
| 146 | + "status": "ready", |
| 147 | + "tenant_type": "docker", |
| 148 | + "features": {"ml_project": False, "kubernetes_access": False,}, |
| 149 | + "persistent_supported": True, |
| 150 | + "member_key_available": "all_admins", |
| 151 | + "quota": {}, |
| 152 | + "cluster_isolation_supported": True, |
| 153 | + "inusequota": { |
| 154 | + "disk": 0, |
| 155 | + "cores": 0, |
| 156 | + "memory": 0, |
| 157 | + "persistent": 0, |
| 158 | + "gpus": 0, |
| 159 | + }, |
| 160 | + "external_user_groups": [], |
| 161 | + "gpu_usage_supported": True, |
| 162 | + "_links": {"self": {"href": "/api/v1/tenant/2"}}, |
| 163 | + "filesystem_mount_supported": True, |
| 164 | + "tenant_enforcements": [], |
| 165 | + "label": { |
| 166 | + "name": "Demo Tenant", |
| 167 | + "description": "Demo Tenant for BlueData Clusters", |
| 168 | + }, |
| 169 | + "constraints_supported": True, |
| 170 | + "tenant_storage_quota_supported": True, |
| 171 | + "qos_multiplier": 1, |
| 172 | + }, |
| 173 | + status_code=200, |
| 174 | + headers={}, |
| 175 | + ), |
| 176 | + ) |
| 177 | + |
| 178 | + BaseTestCase.registerHttpGetHandler( |
| 179 | + url="https://127.0.0.1:8080/api/v1/tenant/100", |
| 180 | + response=MockResponse( |
| 181 | + json_data={}, |
| 182 | + status_code=404, |
| 183 | + headers={}, |
| 184 | + raise_for_status_flag=True, |
| 185 | + ), |
| 186 | + ) |
0 commit comments