|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Copyright 2014 Spanish National Research Council (CSIC) |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +"""Fixtures for cASO tests.""" |
| 18 | + |
| 19 | +import datetime |
| 20 | + |
| 21 | +import pytest |
| 22 | + |
| 23 | +import caso.record |
| 24 | + |
| 25 | +now = datetime.datetime(2023, 5, 25, 21, 59, 6, 0) |
| 26 | + |
| 27 | +valid_records_fields = [ |
| 28 | + dict( |
| 29 | + uuid="721cf1db-0e0f-4c24-a5ea-cd75e0f303e8", |
| 30 | + site_name="TEST-Site", |
| 31 | + name="VM Name 1", |
| 32 | + user_id="a4519d7d-f60a-4908-9d63-7d9e17422188", |
| 33 | + group_id="03b6a6c4-cf2b-48b9-82f1-69c52b9f30af", |
| 34 | + fqan="VO 1 FQAN", |
| 35 | + start_time=now - datetime.timedelta(days=5), |
| 36 | + end_time=now, |
| 37 | + compute_service="Fake Cloud Service", |
| 38 | + status="ACTIVE", |
| 39 | + image_id="b39a8ed9-e15d-4b71-ada2-daf88efbac0a", |
| 40 | + user_dn="User DN", |
| 41 | + benchmark_type=None, |
| 42 | + benchmark_value=None, |
| 43 | + memory=16, |
| 44 | + cpu_count=8, |
| 45 | + disk=250, |
| 46 | + public_ip_count=7, |
| 47 | + ), |
| 48 | + dict( |
| 49 | + uuid="a53738e1-13eb-4047-800c-067d14ce3d22", |
| 50 | + site_name="TEST-Site", |
| 51 | + name="VM Name 2", |
| 52 | + user_id="a4519d7d-f60a-4908-9d63-7d9e17422188", |
| 53 | + group_id="03b6a6c4-cf2b-48b9-82f1-69c52b9f30af", |
| 54 | + fqan="VO 2 FQAN", |
| 55 | + start_time=now - datetime.timedelta(days=6), |
| 56 | + end_time=now, |
| 57 | + compute_service="Fake Cloud Service", |
| 58 | + status="ACTIVE", |
| 59 | + image_id="b39a8ed9-e15d-4b71-ada2-daf88efbac0a", |
| 60 | + user_dn="User DN", |
| 61 | + benchmark_type=None, |
| 62 | + benchmark_value=None, |
| 63 | + memory=16, |
| 64 | + cpu_count=8, |
| 65 | + disk=250, |
| 66 | + public_ip_count=7, |
| 67 | + ), |
| 68 | +] |
| 69 | + |
| 70 | +valid_records_dict = [ |
| 71 | + { |
| 72 | + "CloudComputeService": "Fake Cloud Service", |
| 73 | + "CpuCount": 8, |
| 74 | + "CpuDuration": 3456000, |
| 75 | + "Disk": 250, |
| 76 | + "StartTime": 1684612746, |
| 77 | + "EndTime": 1685044746, |
| 78 | + "FQAN": "VO 1 FQAN", |
| 79 | + "GlobalUserName": "User DN", |
| 80 | + "ImageId": "b39a8ed9-e15d-4b71-ada2-daf88efbac0a", |
| 81 | + "LocalGroupId": "03b6a6c4-cf2b-48b9-82f1-69c52b9f30af", |
| 82 | + "LocalUserId": "a4519d7d-f60a-4908-9d63-7d9e17422188", |
| 83 | + "MachineName": "VM Name 1", |
| 84 | + "Memory": 16, |
| 85 | + "PublicIPCount": 7, |
| 86 | + "SiteName": "TEST-Site", |
| 87 | + "Status": "ACTIVE", |
| 88 | + "VMUUID": "721cf1db-0e0f-4c24-a5ea-cd75e0f303e8", |
| 89 | + "WallDuration": 432000, |
| 90 | + }, |
| 91 | + { |
| 92 | + "CloudComputeService": "Fake Cloud Service", |
| 93 | + "CpuCount": 8, |
| 94 | + "CpuDuration": 3456000, |
| 95 | + "Disk": 250, |
| 96 | + "StartTime": 1684526346, |
| 97 | + "EndTime": 1685044746, |
| 98 | + "FQAN": "VO 2 FQAN", |
| 99 | + "GlobalUserName": "User DN", |
| 100 | + "ImageId": "b39a8ed9-e15d-4b71-ada2-daf88efbac0a", |
| 101 | + "LocalGroupId": "03b6a6c4-cf2b-48b9-82f1-69c52b9f30af", |
| 102 | + "LocalUserId": "a4519d7d-f60a-4908-9d63-7d9e17422188", |
| 103 | + "MachineName": "VM Name 2", |
| 104 | + "Memory": 16, |
| 105 | + "PublicIPCount": 7, |
| 106 | + "SiteName": "TEST-Site", |
| 107 | + "Status": "ACTIVE", |
| 108 | + "VMUUID": "a53738e1-13eb-4047-800c-067d14ce3d22", |
| 109 | + "WallDuration": 432000, |
| 110 | + }, |
| 111 | +] |
| 112 | + |
| 113 | +# Record fixtures |
| 114 | + |
| 115 | + |
| 116 | +@pytest.fixture(scope="module") |
| 117 | +def cloud_record(): |
| 118 | + """Get a fixture for the CloudRecord.""" |
| 119 | + record = caso.record.CloudRecord(**valid_records_fields[0]) |
| 120 | + # Remove this when moving to Pydantic 2 |
| 121 | + record.wall_duration = 432000 |
| 122 | + record.cpu_duration = 3456000 |
| 123 | + return record |
| 124 | + |
| 125 | + |
| 126 | +@pytest.fixture(scope="module") |
| 127 | +def another_cloud_record(): |
| 128 | + """Get another fixture for the CloudRecord.""" |
| 129 | + record = caso.record.CloudRecord(**valid_records_fields[1]) |
| 130 | + record.wall_duration = 432000 |
| 131 | + record.cpu_duration = 3456000 |
| 132 | + return record |
| 133 | + |
| 134 | + |
| 135 | +@pytest.fixture(scope="module") |
| 136 | +def valid_record(): |
| 137 | + """Get a fixture for a valid record.""" |
| 138 | + return valid_records_dict[0] |
| 139 | + |
| 140 | + |
| 141 | +@pytest.fixture(scope="module") |
| 142 | +def valid_records(): |
| 143 | + """Get a fixture for valid records as a dict.""" |
| 144 | + return valid_records_dict |
| 145 | + |
| 146 | + |
| 147 | +@pytest.fixture(scope="module") |
| 148 | +def another_valid_record(): |
| 149 | + """Get another fixture for a valid record as a dict.""" |
| 150 | + return valid_records_dict[0] |
| 151 | + |
| 152 | + |
| 153 | +@pytest.fixture(scope="module") |
| 154 | +def cloud_record_list(cloud_record, another_cloud_record): |
| 155 | + """Get a fixture for a list of valid records.""" |
| 156 | + return [cloud_record, another_cloud_record] |
| 157 | + |
| 158 | + |
| 159 | +# SSM entries |
| 160 | + |
| 161 | + |
| 162 | +@pytest.fixture |
| 163 | +def expected_entries_cloud(): |
| 164 | + """Get a fixture for all cloud entries.""" |
| 165 | + ssm_entries = [ |
| 166 | + "CloudComputeService: Fake Cloud Service\n" |
| 167 | + "CpuCount: 8\n" |
| 168 | + "CpuDuration: 3456000\n" |
| 169 | + "Disk: 250\n" |
| 170 | + "EndTime: 1685044746\n" |
| 171 | + "FQAN: VO 1 FQAN\n" |
| 172 | + "GlobalUserName: User DN\n" |
| 173 | + "ImageId: b39a8ed9-e15d-4b71-ada2-daf88efbac0a\n" |
| 174 | + "LocalGroupId: 03b6a6c4-cf2b-48b9-82f1-69c52b9f30af\n" |
| 175 | + "LocalUserId: a4519d7d-f60a-4908-9d63-7d9e17422188\n" |
| 176 | + "MachineName: VM Name 1\n" |
| 177 | + "Memory: 16\n" |
| 178 | + "PublicIPCount: 7\n" |
| 179 | + "SiteName: TEST-Site\n" |
| 180 | + "StartTime: 1684612746\n" |
| 181 | + "Status: ACTIVE\n" |
| 182 | + "VMUUID: 721cf1db-0e0f-4c24-a5ea-cd75e0f303e8\n" |
| 183 | + "WallDuration: 432000", |
| 184 | + "CloudComputeService: Fake Cloud Service\n" |
| 185 | + "CpuCount: 8\n" |
| 186 | + "CpuDuration: 3456000\n" |
| 187 | + "Disk: 250\n" |
| 188 | + "EndTime: 1685044746\n" |
| 189 | + "FQAN: VO 2 FQAN\n" |
| 190 | + "GlobalUserName: User DN\n" |
| 191 | + "ImageId: b39a8ed9-e15d-4b71-ada2-daf88efbac0a\n" |
| 192 | + "LocalGroupId: 03b6a6c4-cf2b-48b9-82f1-69c52b9f30af\n" |
| 193 | + "LocalUserId: a4519d7d-f60a-4908-9d63-7d9e17422188\n" |
| 194 | + "MachineName: VM Name 2\n" |
| 195 | + "Memory: 16\n" |
| 196 | + "PublicIPCount: 7\n" |
| 197 | + "SiteName: TEST-Site\n" |
| 198 | + "StartTime: 1684526346\n" |
| 199 | + "Status: ACTIVE\n" |
| 200 | + "VMUUID: a53738e1-13eb-4047-800c-067d14ce3d22\n" |
| 201 | + "WallDuration: 432000", |
| 202 | + ] |
| 203 | + |
| 204 | + return ssm_entries |
0 commit comments