|
| 1 | +""" |
| 2 | + SoftLayer.tests.CLI.modules.bandwidth_tests |
| 3 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | +
|
| 5 | + :license: MIT, see LICENSE for more details. |
| 6 | +""" |
| 7 | +from SoftLayer import testing |
| 8 | + |
| 9 | +import json |
| 10 | + |
| 11 | +from pprint import pprint as pp |
| 12 | + |
| 13 | + |
| 14 | +class BandwidthTests(testing.TestCase): |
| 15 | + def test_bandwidth_pools(self): |
| 16 | + result = self.run_command(['bandwidth', 'pools']) |
| 17 | + self.assert_no_fail(result) |
| 18 | + self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments') |
| 19 | + self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject') |
| 20 | + |
| 21 | + def test_acccount_bandwidth_pool_detail(self): |
| 22 | + result = self.run_command(['bandwidth', 'pools-detail', '123456']) |
| 23 | + self.assert_no_fail(result) |
| 24 | + self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject') |
| 25 | + |
| 26 | + def test_bandwidth_summary(self): |
| 27 | + search_mock = self.set_mock('SoftLayer_Search', 'advancedSearch') |
| 28 | + search_mock.side_effect = [_bandwidth_advanced_search(), [], [], []] |
| 29 | + result = self.run_command(['bandwidth', 'summary']) |
| 30 | + |
| 31 | + self.assert_no_fail(result) |
| 32 | + self.assert_called_with('SoftLayer_Search', 'advancedSearch') |
| 33 | + json_output = json.loads(result.output) |
| 34 | + pp(json_output) |
| 35 | + self.assertEqual(5, len(json_output)) |
| 36 | + self.assertEqual(100250634, json_output[0]['Id']) |
| 37 | + self.assertEqual('TestRegion', json_output[0]['Pool']) |
| 38 | + self.assertEqual('dal10', json_output[0]['Location']) |
| 39 | + self.assertEqual(['tag test', 'tag test2'], json_output[0]['Tags']) |
| 40 | + self.assertEqual('Virtual Private Rack', json_output[1]['Pool']) |
| 41 | + self.assertEqual('1.04 GB', json_output[2]['Total usage']) |
| 42 | + self.assertEqual('5.00 TB', json_output[2]['Allocation']) |
| 43 | + self.assertEqual('Unlimited', json_output[3]['Allocation']) |
| 44 | + self.assertEqual('Not Applicable', json_output[3]['Pool']) |
| 45 | + self.assertEqual('0.00 MB', json_output[3]['Data in']) |
| 46 | + self.assertEqual('0.00 MB', json_output[3]['Data out']) |
| 47 | + self.assertEqual('Pay-As-You-Go', json_output[4]['Allocation']) |
| 48 | + |
| 49 | + |
| 50 | +def _bandwidth_advanced_search(): |
| 51 | + result = [ |
| 52 | + { |
| 53 | + "matchedTerms": [], |
| 54 | + "relevanceScore": "1", |
| 55 | + "resource": { |
| 56 | + "fullyQualifiedDomainName": "test.com", |
| 57 | + "id": 100250634, |
| 58 | + "bandwidthAllocation": "250", |
| 59 | + "bandwidthAllotmentDetail": { |
| 60 | + "id": 53306635, |
| 61 | + "bandwidthAllotment": { |
| 62 | + "bandwidthAllotmentTypeId": 2, |
| 63 | + "id": 1289128, |
| 64 | + "name": "TestRegion" |
| 65 | + } |
| 66 | + }, |
| 67 | + "billingItem": { |
| 68 | + "createDate": "2022-03-07T05:28:44-06:00", |
| 69 | + "id": 937460400, |
| 70 | + "lastBillDate": "2023-05-03T23:07:54-06:00" |
| 71 | + }, |
| 72 | + "datacenter": { |
| 73 | + "id": 1441195, |
| 74 | + "name": "dal10" |
| 75 | + }, |
| 76 | + "inboundPublicBandwidthUsage": ".16204", |
| 77 | + "outboundPublicBandwidthUsage": ".01351", |
| 78 | + "primaryIpAddress": "169.46.48.110", |
| 79 | + "tagReferences": [ |
| 80 | + { |
| 81 | + "id": 172236920, |
| 82 | + "tag": { |
| 83 | + "id": 3414982, |
| 84 | + "name": "tag test" |
| 85 | + } |
| 86 | + }, |
| 87 | + { |
| 88 | + "id": 172236918, |
| 89 | + "tag": { |
| 90 | + "id": 3307656, |
| 91 | + "name": "tag test2" |
| 92 | + } |
| 93 | + } |
| 94 | + ] |
| 95 | + }, |
| 96 | + "resourceType": "SoftLayer_Virtual_Guest" |
| 97 | + }, |
| 98 | + { |
| 99 | + "matchedTerms": [], |
| 100 | + "relevanceScore": "1", |
| 101 | + "resource": { |
| 102 | + "fullyQualifiedDomainName": "test.cloud", |
| 103 | + "id": 1867001, |
| 104 | + "bandwidthAllocation": "20000", |
| 105 | + "bandwidthAllotmentDetail": { |
| 106 | + "id": 37331756, |
| 107 | + "bandwidthAllotment": { |
| 108 | + "bandwidthAllotmentTypeId": 1, |
| 109 | + "id": 138442, |
| 110 | + "name": "Virtual Private Rack" |
| 111 | + } |
| 112 | + }, |
| 113 | + "billingItem": { |
| 114 | + "createDate": "2020-04-27T14:02:03-06:00", |
| 115 | + "id": 658642904, |
| 116 | + "lastBillDate": "2023-05-03T23:07:47-06:00" |
| 117 | + }, |
| 118 | + "datacenter": { |
| 119 | + "id": 1441195, |
| 120 | + "name": "dal10" |
| 121 | + }, |
| 122 | + "inboundPublicBandwidthUsage": ".48562", |
| 123 | + "outboundPublicBandwidthUsage": ".1987", |
| 124 | + "primaryIpAddress": "169.48.191.246", |
| 125 | + "tagReferences": [ |
| 126 | + { |
| 127 | + "id": 1060153378, |
| 128 | + "tag": { |
| 129 | + "id": 4974546, |
| 130 | + "name": "tags" |
| 131 | + } |
| 132 | + } |
| 133 | + ] |
| 134 | + }, |
| 135 | + "resourceType": "SoftLayer_Hardware" |
| 136 | + }, |
| 137 | + { |
| 138 | + "matchedTerms": [], |
| 139 | + "relevanceScore": "1", |
| 140 | + "resource": { |
| 141 | + "fullyQualifiedDomainName": "testcommunity.cloud", |
| 142 | + "id": 3190740, |
| 143 | + "bandwidthAllocation": "5000", |
| 144 | + "bandwidthAllotmentDetail": { |
| 145 | + "id": 50932574, |
| 146 | + "bandwidthAllotment": { |
| 147 | + "bandwidthAllotmentTypeId": 1, |
| 148 | + "id": 138442, |
| 149 | + "name": "Virtual Private Rack" |
| 150 | + } |
| 151 | + }, |
| 152 | + "billingItem": { |
| 153 | + "createDate": "2022-08-11T11:39:55-06:00", |
| 154 | + "id": 983649084, |
| 155 | + "lastBillDate": "2023-05-03T23:07:48-06:00" |
| 156 | + }, |
| 157 | + "datacenter": { |
| 158 | + "id": 1441195, |
| 159 | + "name": "dal10" |
| 160 | + }, |
| 161 | + "inboundPublicBandwidthUsage": ".63179", |
| 162 | + "outboundPublicBandwidthUsage": ".40786", |
| 163 | + "primaryIpAddress": "52.118.38.243", |
| 164 | + "tagReferences": [] |
| 165 | + }, |
| 166 | + "resourceType": "SoftLayer_Hardware" |
| 167 | + }, |
| 168 | + { |
| 169 | + "matchedTerms": [], |
| 170 | + "relevanceScore": "1", |
| 171 | + "resource": { |
| 172 | + "id": 47758, |
| 173 | + "name": "SLADC307608-jt48", |
| 174 | + "billingItem": { |
| 175 | + "createDate": "2022-02-11T09:49:16-06:00", |
| 176 | + "id": 931026566, |
| 177 | + "lastBillDate": "2023-05-03T23:08:02-06:00" |
| 178 | + }, |
| 179 | + "datacenter": { |
| 180 | + "id": 2017603, |
| 181 | + "name": "wdc07" |
| 182 | + }, |
| 183 | + "primaryIpAddress": "169.62.12.146", |
| 184 | + "tagReferences": [] |
| 185 | + }, |
| 186 | + "resourceType": "SoftLayer_Network_Application_Delivery_Controller" |
| 187 | + }, |
| 188 | + { |
| 189 | + "matchedTerms": [], |
| 190 | + "relevanceScore": "1", |
| 191 | + "resource": { |
| 192 | + "fullyQualifiedDomainName": "lab-web.test.com", |
| 193 | + "id": 127890106, |
| 194 | + "bandwidthAllocation": "0", |
| 195 | + "bandwidthAllotmentDetail": { |
| 196 | + "id": 48915580, |
| 197 | + "bandwidthAllotment": { |
| 198 | + "bandwidthAllotmentTypeId": 1, |
| 199 | + "id": 138442, |
| 200 | + "name": "Virtual Private Rack" |
| 201 | + } |
| 202 | + }, |
| 203 | + "billingItem": { |
| 204 | + "createDate": "2022-02-08T08:33:14-06:00", |
| 205 | + "id": 930164384, |
| 206 | + "lastBillDate": "2023-05-03T23:07:56-06:00" |
| 207 | + }, |
| 208 | + "datacenter": { |
| 209 | + "id": 138124, |
| 210 | + "name": "dal05" |
| 211 | + }, |
| 212 | + "inboundPrivateBandwidthUsage": ".00002", |
| 213 | + "inboundPublicBandwidthUsage": ".19583", |
| 214 | + "outboundPrivateBandwidthUsage": ".00002", |
| 215 | + "outboundPublicBandwidthUsage": ".18446", |
| 216 | + "primaryIpAddress": "108.168.148.26", |
| 217 | + "tagReferences": [] |
| 218 | + }, |
| 219 | + "resourceType": "SoftLayer_Virtual_Guest" |
| 220 | + } |
| 221 | + ] |
| 222 | + return result |
0 commit comments