Skip to content

Commit 7f8c805

Browse files
tox fixes
1 parent 6ccaa27 commit 7f8c805

File tree

9 files changed

+141
-106
lines changed

9 files changed

+141
-106
lines changed

SoftLayer/CLI/hardware/bandwidth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import formatting
98
from SoftLayer.CLI import helpers
109
from SoftLayer.CLI.virt.bandwidth import create_bandwidth_table
11-
from SoftLayer import utils
1210

1311

1412
@click.command()

SoftLayer/CLI/virt/bandwidth.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def cli(env, identifier, start_date, end_date, summary_period, quite_summary):
3838
title = "Bandwidth Report: %s - %s" % (start_date, end_date)
3939
table, sum_table = create_bandwidth_table(data, summary_period, title)
4040

41-
4241
env.fout(sum_table)
4342
if not quite_summary:
4443
env.fout(table)
4544

45+
4646
def create_bandwidth_table(data, summary_period, title="Bandwidth Report"):
4747
"""Create 2 tables, bandwidth and sumamry. Used here and in hw bandwidth command"""
4848

@@ -51,21 +51,21 @@ def create_bandwidth_table(data, summary_period, title="Bandwidth Report"):
5151
key = utils.clean_time(point['dateTime'])
5252
data_type = point['type']
5353
# conversion from byte to megabyte
54-
value = round(point['counter'] / 2 ** 20, 4)
54+
value = round(float(point['counter']) / 2 ** 20, 4)
5555
if formatted_data.get(key) is None:
5656
formatted_data[key] = {}
57-
formatted_data[key][data_type] = value
57+
formatted_data[key][data_type] = float(value)
5858

5959
table = formatting.Table(['Date', 'Pub In', 'Pub Out', 'Pri In', 'Pri Out'], title=title)
6060

6161
sum_table = formatting.Table(['Type', 'Sum GB', 'Average MBps', 'Max GB', 'Max Date'], title="Summary")
6262

6363
# Required to specify keyName because getBandwidthTotals returns other counter types for some reason.
6464
bw_totals = [
65-
{'keyName': 'publicIn_net_octet', 'sum': 0, 'max': 0, 'name': 'Pub In'},
66-
{'keyName': 'publicOut_net_octet', 'sum': 0, 'max': 0, 'name': 'Pub Out'},
67-
{'keyName': 'privateIn_net_octet', 'sum': 0, 'max': 0, 'name': 'Pri In'},
68-
{'keyName': 'privateOut_net_octet', 'sum': 0, 'max': 0, 'name': 'Pri Out'},
65+
{'keyName': 'publicIn_net_octet', 'sum': 0.0, 'max': 0, 'name': 'Pub In'},
66+
{'keyName': 'publicOut_net_octet', 'sum': 0.0, 'max': 0, 'name': 'Pub Out'},
67+
{'keyName': 'privateIn_net_octet', 'sum': 0.0, 'max': 0, 'name': 'Pri In'},
68+
{'keyName': 'privateOut_net_octet', 'sum': 0.0, 'max': 0, 'name': 'Pri Out'},
6969
]
7070

7171
for point in formatted_data:
@@ -80,7 +80,7 @@ def create_bandwidth_table(data, summary_period, title="Bandwidth Report"):
8080
table.add_row(new_row)
8181

8282
for bw_type in bw_totals:
83-
total = bw_type.get('sum', 0)
83+
total = bw_type.get('sum', 0.0)
8484
average = 0
8585
if total > 0:
8686
average = round(total / len(formatted_data) / summary_period, 4)
@@ -94,6 +94,7 @@ def create_bandwidth_table(data, summary_period, title="Bandwidth Report"):
9494

9595
return table, sum_table
9696

97+
9798
def mb_to_gb(mbytes):
9899
"""Converts a MegaByte int to GigaByte. mbytes/2^10"""
99100
return round(mbytes / 2 ** 10, 4)

SoftLayer/fixtures/SoftLayer_Metric_Tracking_Object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
# Using counter > 32bit int causes unit tests to fail.
16-
getBandwidthData =[
16+
getBandwidthData = [
1717
{
1818
'counter': 37.21,
1919
'dateTime': '2019-05-20T23:00:00-06:00',

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,3 @@
658658
}
659659
}
660660
]
661-

tests/CLI/modules/server_tests.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def test_server_details(self):
108108
self.assertEqual(output['owner'], 'chechu')
109109
self.assertEqual(output['Bandwidth'][0]['Allotment'], '250')
110110

111-
112111
def test_detail_vs_empty_tag(self):
113112
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
114113
mock.return_value = {
@@ -586,29 +585,45 @@ def test_toggle_ipmi_off(self):
586585
self.assertEqual(result.output, 'True\n')
587586

588587
def test_bandwidth_hw(self):
588+
if sys.version_info < (3, 6):
589+
self.skipTest("Test requires python 3.6+")
589590
result = self.run_command(['server', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01'])
590591
self.assert_no_fail(result)
591592

593+
date = '2019-05-20 23:00'
594+
# number of characters from the end of output to break so json can parse properly
595+
pivot = 157
596+
# only pyhon 3.7 supports the timezone format slapi uses
597+
if sys.version_info < (3, 7):
598+
date = '2019-05-20T23:00:00-06:00'
599+
pivot = 166
592600
# Since this is 2 tables, it gets returned as invalid json like "[{}][{}]"" instead of "[[{}],[{}]]"
593601
# so we just do some hacky string substitution to pull out the respective arrays that can be jsonifyied
594-
output_summary = json.loads(result.output[0:-157])
595-
output_list = json.loads(result.output[-158:])
602+
603+
output_summary = json.loads(result.output[0:-pivot])
604+
output_list = json.loads(result.output[-pivot:])
596605

597606
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
598-
self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00')
607+
self.assertEqual(output_summary[1]['Max Date'], date)
599608
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
600609
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
601610

602-
self.assertEqual(output_list[0]['Date'], '2019-05-20 23:00')
611+
self.assertEqual(output_list[0]['Date'], date)
603612
self.assertEqual(output_list[0]['Pub In'], 1.3503)
604613

605614
def test_bandwidth_hw_quite(self):
606-
result = self.run_command(['server', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01', '-q'])
615+
result = self.run_command(['server', 'bandwidth', '100', '--start_date=2019-01-01',
616+
'--end_date=2019-02-01', '-q'])
607617
self.assert_no_fail(result)
618+
date = '2019-05-20 23:00'
619+
620+
# only pyhon 3.7 supports the timezone format slapi uses
621+
if sys.version_info < (3, 7):
622+
date = '2019-05-20T23:00:00-06:00'
623+
608624
output_summary = json.loads(result.output)
609625

610626
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
611-
self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00')
627+
self.assertEqual(output_summary[1]['Max Date'], date)
612628
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
613629
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
614-

tests/CLI/modules/vs/vs_tests.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:license: MIT, see LICENSE for more details.
66
"""
77
import json
8+
import sys
89

910
import mock
1011

@@ -261,8 +262,7 @@ def test_detail_vs_ptr_error(self):
261262
result = self.run_command(['vs', 'detail', '100'])
262263
self.assert_no_fail(result)
263264
output = json.loads(result.output)
264-
self.assertEqual(output.get('ptr', None), None)
265-
265+
self.assertEqual(output.get('ptr', None), None)
266266

267267
def test_create_options(self):
268268
result = self.run_command(['vs', 'create-options'])
@@ -683,30 +683,49 @@ def test_usage_metric_data_empty(self):
683683
self.assertEqual(result.exit_code, 2)
684684
self.assertIsInstance(result.exception, exceptions.CLIAbort)
685685

686+
686687
def test_bandwidth_vs(self):
688+
if sys.version_info < (3, 6):
689+
self.skipTest("Test requires python 3.6+")
690+
687691
result = self.run_command(['vs', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01'])
688692
self.assert_no_fail(result)
689693

694+
695+
date = '2019-05-20 23:00'
696+
# number of characters from the end of output to break so json can parse properly
697+
pivot = 157
698+
# only pyhon 3.7 supports the timezone format slapi uses
699+
if sys.version_info < (3, 7):
700+
date = '2019-05-20T23:00:00-06:00'
701+
pivot = 166
690702
# Since this is 2 tables, it gets returned as invalid json like "[{}][{}]"" instead of "[[{}],[{}]]"
691703
# so we just do some hacky string substitution to pull out the respective arrays that can be jsonifyied
692-
output_summary = json.loads(result.output[0:-157])
693-
output_list = json.loads(result.output[-158:])
704+
705+
output_summary = json.loads(result.output[0:-pivot])
706+
output_list = json.loads(result.output[-pivot:])
694707

695708
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
696-
self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00')
709+
self.assertEqual(output_summary[1]['Max Date'], date)
697710
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
698711
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
699712

700-
self.assertEqual(output_list[0]['Date'], '2019-05-20 23:00')
713+
self.assertEqual(output_list[0]['Date'], date)
701714
self.assertEqual(output_list[0]['Pub In'], 1.3503)
702715

703716
def test_bandwidth_vs_quite(self):
704717
result = self.run_command(['vs', 'bandwidth', '100', '--start_date=2019-01-01', '--end_date=2019-02-01', '-q'])
705718
self.assert_no_fail(result)
719+
720+
date = '2019-05-20 23:00'
721+
722+
# only pyhon 3.7 supports the timezone format slapi uses
723+
if sys.version_info < (3, 7):
724+
date = '2019-05-20T23:00:00-06:00'
725+
706726
output_summary = json.loads(result.output)
707727

708728
self.assertEqual(output_summary[0]['Average MBps'], 0.3841)
709-
self.assertEqual(output_summary[1]['Max Date'], '2019-05-20 23:00')
729+
self.assertEqual(output_summary[1]['Max Date'], date)
710730
self.assertEqual(output_summary[2]['Max GB'], 0.1172)
711731
self.assertEqual(output_summary[3]['Sum GB'], 0.0009)
712-

tests/managers/hardware_tests.py

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_cancel_running_transaction(self):
327327
'activeTransaction': {'id': 4567}}
328328
self.assertRaises(SoftLayer.SoftLayerError,
329329
self.hardware.cancel_hardware,
330-
12345)
330+
12345)
331331

332332
def test_change_port_speed_public(self):
333333
self.hardware.change_port_speed(2, True, 100)
@@ -426,8 +426,10 @@ def test_get_tracking_id(self):
426426

427427
def test_get_bandwidth_data(self):
428428
result = self.hardware.get_bandwidth_data(1234, '2019-01-01', '2019-02-01', 'public', 1000)
429-
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getBandwidthData', args=('2019-01-01', '2019-02-01',
430-
'public', 1000), identifier=1000)
429+
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
430+
'getBandwidthData',
431+
args=('2019-01-01', '2019-02-01', 'public', 1000),
432+
identifier=1000)
431433
self.assertEqual(result[0]['type'], 'cpu0')
432434

433435
def test_get_bandwidth_allocation(self):
@@ -447,9 +449,9 @@ def test_get_extra_price_id_no_items(self):
447449

448450
def test_get_extra_price_mismatched(self):
449451
items = [
450-
{'keyName': 'TEST', 'prices':[{'id':1, 'locationGroupId': None, 'recurringFee':99}]},
451-
{'keyName': 'TEST', 'prices':[{'id':2, 'locationGroupId': 55, 'hourlyRecurringFee':99}]},
452-
{'keyName': 'TEST', 'prices':[{'id':3, 'locationGroupId': None, 'hourlyRecurringFee':99}]},
452+
{'keyName': 'TEST', 'prices': [{'id': 1, 'locationGroupId': None, 'recurringFee': 99}]},
453+
{'keyName': 'TEST', 'prices': [{'id': 2, 'locationGroupId': 55, 'hourlyRecurringFee': 99}]},
454+
{'keyName': 'TEST', 'prices': [{'id': 3, 'locationGroupId': None, 'hourlyRecurringFee': 99}]},
453455
]
454456
location = {
455457
'location': {
@@ -466,18 +468,18 @@ def test_get_extra_price_mismatched(self):
466468

467469
def test_get_bandwidth_price_mismatched(self):
468470
items = [
469-
{'itemCategory': {'categoryCode':'bandwidth'},
470-
'capacity': 100,
471-
'prices':[{'id':1, 'locationGroupId': None, 'hourlyRecurringFee':99}]
472-
},
473-
{'itemCategory': {'categoryCode':'bandwidth'},
474-
'capacity': 100,
475-
'prices':[{'id':2, 'locationGroupId': 55, 'recurringFee':99}]
476-
},
477-
{'itemCategory': {'categoryCode':'bandwidth'},
478-
'capacity': 100,
479-
'prices':[{'id':3, 'locationGroupId': None, 'recurringFee':99}]
480-
},
471+
{'itemCategory': {'categoryCode': 'bandwidth'},
472+
'capacity': 100,
473+
'prices': [{'id': 1, 'locationGroupId': None, 'hourlyRecurringFee': 99}]
474+
},
475+
{'itemCategory': {'categoryCode': 'bandwidth'},
476+
'capacity': 100,
477+
'prices': [{'id': 2, 'locationGroupId': 55, 'recurringFee': 99}]
478+
},
479+
{'itemCategory': {'categoryCode': 'bandwidth'},
480+
'capacity': 100,
481+
'prices': [{'id': 3, 'locationGroupId': None, 'recurringFee': 99}]
482+
},
481483
]
482484
location = {
483485
'location': {
@@ -494,14 +496,14 @@ def test_get_bandwidth_price_mismatched(self):
494496

495497
def test_get_os_price_mismatched(self):
496498
items = [
497-
{'itemCategory': {'categoryCode':'os'},
498-
'softwareDescription': {'referenceCode': 'TEST_OS'},
499-
'prices':[{'id':2, 'locationGroupId': 55, 'recurringFee':99}]
500-
},
501-
{'itemCategory': {'categoryCode':'os'},
502-
'softwareDescription': {'referenceCode': 'TEST_OS'},
503-
'prices':[{'id':3, 'locationGroupId': None, 'recurringFee':99}]
504-
},
499+
{'itemCategory': {'categoryCode': 'os'},
500+
'softwareDescription': {'referenceCode': 'TEST_OS'},
501+
'prices': [{'id': 2, 'locationGroupId': 55, 'recurringFee': 99}]
502+
},
503+
{'itemCategory': {'categoryCode': 'os'},
504+
'softwareDescription': {'referenceCode': 'TEST_OS'},
505+
'prices': [{'id': 3, 'locationGroupId': None, 'recurringFee': 99}]
506+
},
505507
]
506508
location = {
507509
'location': {
@@ -514,7 +516,7 @@ def test_get_os_price_mismatched(self):
514516
}
515517
}
516518
result = managers.hardware._get_os_price_id(items, 'TEST_OS', location)
517-
self.assertEqual(3, result)
519+
self.assertEqual(3, result)
518520

519521
def test_get_default_price_id_item_not_first(self):
520522
items = [{
@@ -557,31 +559,31 @@ def test_get_port_speed_price_id_no_items(self):
557559

558560
def test_get_port_speed_price_id_mismatch(self):
559561
items = [
560-
{'itemCategory': {'categoryCode':'port_speed'},
561-
'capacity':101,
562-
'attributes':[{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
563-
'prices':[{'id':1, 'locationGroupId': None, 'recurringFee':99}]
564-
},
565-
{'itemCategory': {'categoryCode':'port_speed'},
566-
'capacity':100,
567-
'attributes':[{'attributeTypeKeyName': 'IS_NOT_PRIVATE_NETWORK_ONLY'}],
568-
'prices':[{'id':2, 'locationGroupId': 55, 'recurringFee':99}]
569-
},
570-
{'itemCategory': {'categoryCode':'port_speed'},
571-
'capacity':100,
572-
'attributes':[{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}, {'attributeTypeKeyName': 'NON_LACP'}],
573-
'prices':[{'id':3, 'locationGroupId': 55, 'recurringFee':99}]
574-
},
575-
{'itemCategory': {'categoryCode':'port_speed'},
576-
'capacity':100,
577-
'attributes':[{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
578-
'prices':[{'id':4, 'locationGroupId': 12, 'recurringFee':99}]
579-
},
580-
{'itemCategory': {'categoryCode':'port_speed'},
581-
'capacity':100,
582-
'attributes':[{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
583-
'prices':[{'id':5, 'locationGroupId': None, 'recurringFee':99}]
584-
},
562+
{'itemCategory': {'categoryCode': 'port_speed'},
563+
'capacity': 101,
564+
'attributes': [{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
565+
'prices': [{'id': 1, 'locationGroupId': None, 'recurringFee': 99}]
566+
},
567+
{'itemCategory': {'categoryCode': 'port_speed'},
568+
'capacity': 100,
569+
'attributes': [{'attributeTypeKeyName': 'IS_NOT_PRIVATE_NETWORK_ONLY'}],
570+
'prices': [{'id': 2, 'locationGroupId': 55, 'recurringFee': 99}]
571+
},
572+
{'itemCategory': {'categoryCode': 'port_speed'},
573+
'capacity': 100,
574+
'attributes': [{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}, {'attributeTypeKeyName': 'NON_LACP'}],
575+
'prices': [{'id': 3, 'locationGroupId': 55, 'recurringFee': 99}]
576+
},
577+
{'itemCategory': {'categoryCode': 'port_speed'},
578+
'capacity': 100,
579+
'attributes': [{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
580+
'prices': [{'id': 4, 'locationGroupId': 12, 'recurringFee': 99}]
581+
},
582+
{'itemCategory': {'categoryCode': 'port_speed'},
583+
'capacity': 100,
584+
'attributes': [{'attributeTypeKeyName': 'IS_PRIVATE_NETWORK_ONLY'}],
585+
'prices': [{'id': 5, 'locationGroupId': None, 'recurringFee': 99}]
586+
},
585587
]
586588
location = {
587589
'location': {
@@ -594,10 +596,10 @@ def test_get_port_speed_price_id_mismatch(self):
594596
}
595597
}
596598
result = managers.hardware._get_port_speed_price_id(items, 100, True, location)
597-
self.assertEqual(5, result)
599+
self.assertEqual(5, result)
598600

599601
def test_matches_location(self):
600-
price = {'id':1, 'locationGroupId': 51, 'recurringFee':99}
602+
price = {'id': 1, 'locationGroupId': 51, 'recurringFee': 99}
601603
location = {
602604
'location': {
603605
'location': {
@@ -609,5 +611,4 @@ def test_matches_location(self):
609611
}
610612
}
611613
result = managers.hardware._matches_location(price, location)
612-
self.assertTrue(result)
613-
614+
self.assertTrue(result)

0 commit comments

Comments
 (0)