|
9 | 9 | import mock |
10 | 10 |
|
11 | 11 | from SoftLayer.CLI import exceptions |
| 12 | +from SoftLayer.fixtures import SoftLayer_Virtual_Guest as SoftLayer_Virtual_Guest |
12 | 13 | from SoftLayer import SoftLayerAPIError |
13 | 14 | from SoftLayer import testing |
14 | 15 |
|
@@ -220,6 +221,49 @@ def test_detail_vs_no_dedicated_host_hostname(self): |
220 | 221 | self.assertEqual(json.loads(result.output)['dedicated_host_id'], 37401) |
221 | 222 | self.assertIsNone(json.loads(result.output)['dedicated_host']) |
222 | 223 |
|
| 224 | + def test_detail_vs_security_group(self): |
| 225 | + vg_return = SoftLayer_Virtual_Guest.getObject |
| 226 | + sec_group = [ |
| 227 | + { |
| 228 | + 'id': 35386715, |
| 229 | + 'name': 'eth', |
| 230 | + 'port': 0, |
| 231 | + 'speed': 100, |
| 232 | + 'status': 'ACTIVE', |
| 233 | + 'primaryIpAddress': '10.175.106.149', |
| 234 | + 'securityGroupBindings': [ |
| 235 | + { |
| 236 | + 'id': 1620971, |
| 237 | + 'networkComponentId': 35386715, |
| 238 | + 'securityGroupId': 128321, |
| 239 | + 'securityGroup': { |
| 240 | + 'id': 128321, |
| 241 | + 'name': 'allow_all' |
| 242 | + } |
| 243 | + } |
| 244 | + ] |
| 245 | + } |
| 246 | + ] |
| 247 | + |
| 248 | + vg_return['networkComponents'] = sec_group |
| 249 | + mock = self.set_mock('SoftLayer_Virtual_Guest', 'getObject') |
| 250 | + mock.return_value = vg_return |
| 251 | + result = self.run_command(['vs', 'detail', '100']) |
| 252 | + self.assert_no_fail(result) |
| 253 | + output = json.loads(result.output) |
| 254 | + self.assertEqual(output['security_groups'][0]['id'], 128321) |
| 255 | + self.assertEqual(output['security_groups'][0]['name'], 'allow_all') |
| 256 | + self.assertEqual(output['security_groups'][0]['interface'], 'PRIVATE') |
| 257 | + |
| 258 | + def test_detail_vs_ptr_error(self): |
| 259 | + mock = self.set_mock('SoftLayer_Virtual_Guest', 'getReverseDomainRecords') |
| 260 | + mock.side_effect = SoftLayerAPIError("SoftLayer_Exception", "Not Found") |
| 261 | + result = self.run_command(['vs', 'detail', '100']) |
| 262 | + self.assert_no_fail(result) |
| 263 | + output = json.loads(result.output) |
| 264 | + self.assertEqual(output.get('ptr', None), None) |
| 265 | + |
| 266 | + |
223 | 267 | def test_create_options(self): |
224 | 268 | result = self.run_command(['vs', 'create-options']) |
225 | 269 |
|
@@ -638,3 +682,37 @@ def test_usage_metric_data_empty(self): |
638 | 682 | '--summary_period=300']) |
639 | 683 | self.assertEqual(result.exit_code, 2) |
640 | 684 | self.assertIsInstance(result.exception, exceptions.CLIAbort) |
| 685 | + |
| 686 | + def test_bandwidth_vs(self): |
| 687 | + result = self.run_command(['vs', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01']) |
| 688 | + self.assert_no_fail(result) |
| 689 | + |
| 690 | + # Since this is 2 tables, it gets returned as invalid json like "[{}][{}]"" instead of "[[{}],[{}]]" |
| 691 | + # so we just do some hacky string substitution to pull out the respective arrays that can be jsonifyied |
| 692 | + |
| 693 | + from pprint import pprint as pp |
| 694 | + pp(result.output) |
| 695 | + print("FUCK") |
| 696 | + pp(result.output[0:-157]) |
| 697 | + |
| 698 | + output_summary = json.loads(result.output[0:-157]) |
| 699 | + output_list = json.loads(result.output[-158:]) |
| 700 | + |
| 701 | + self.assertEqual(output_summary[0]['Average MBps'], 0.3841) |
| 702 | + self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00') |
| 703 | + self.assertEqual(output_summary[2]['Max GB'], 0.1172) |
| 704 | + self.assertEqual(output_summary[3]['Sum GB'], 0.0009) |
| 705 | + |
| 706 | + self.assertEqual(output_list[0]['Date'], '2019-05-20 23:00') |
| 707 | + self.assertEqual(output_list[0]['Pub In'], 1.3503) |
| 708 | + |
| 709 | + def test_bandwidth_vs_quite(self): |
| 710 | + result = self.run_command(['vs', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01', '-q']) |
| 711 | + self.assert_no_fail(result) |
| 712 | + output_summary = json.loads(result.output) |
| 713 | + |
| 714 | + self.assertEqual(output_summary[0]['Average MBps'], 0.3841) |
| 715 | + self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00') |
| 716 | + self.assertEqual(output_summary[2]['Max GB'], 0.1172) |
| 717 | + self.assertEqual(output_summary[3]['Sum GB'], 0.0009) |
| 718 | + |
0 commit comments