Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2847f4

Browse files
added unit tests for vlan-add
1 parent 4b3519b commit b2847f4

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed

.secrets.baseline

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-10-03T22:08:00Z",
6+
"generated_at": "2023-10-12T20:19:44Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -238,7 +238,7 @@
238238
"hashed_secret": "fb5f2f1b65d1f2bc130ce9d5729b38d12f2b444e",
239239
"is_secret": false,
240240
"is_verified": false,
241-
"line_number": 260,
241+
"line_number": 273,
242242
"type": "Secret Keyword",
243243
"verified_result": null
244244
}
@@ -544,7 +544,7 @@
544544
"hashed_secret": "6367c48dd193d56ea7b0baad25b19455e529f5ee",
545545
"is_secret": false,
546546
"is_verified": false,
547-
"line_number": 57,
547+
"line_number": 58,
548548
"type": "Secret Keyword",
549549
"verified_result": null
550550
}

SoftLayer/CLI/hardware/detail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def cli(env, identifier, passwords, price, components):
8686
for component in result.get('networkComponents', []):
8787
# These are the Primary network components
8888
if component.get('primaryIpAddress', False):
89-
uplink = component.get('uplinkComponent')
90-
for trunk in uplink.get('networkVlanTrunks'):
89+
uplink = component.get('uplinkComponent', {})
90+
for trunk in uplink.get('networkVlanTrunks', []):
9191
trunk_vlan = trunk.get('networkVlan')
9292
vlan_table.add_row([
9393
trunk_vlan.get('networkSpace'),

SoftLayer/fixtures/SoftLayer_Hardware_Server.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,51 @@
130130
getReverseDomainRecords = [
131131
{'resourceRecords': [{'data': '2.0.1.10.in-addr.arpa'}]}]
132132
bootToRescueLayer = True
133-
getFrontendNetworkComponents = [
133+
134+
getNetworkComponents = [
134135
{'maxSpeed': 100},
135136
{
136137
'maxSpeed': 1000,
137138
'networkComponentGroup': {
138139
'groupTypeId': 2,
139140
'networkComponents': [{'maxSpeed': 1000}, {'maxSpeed': 1000}]
140-
}
141+
},
142+
'primaryIpAddress': '192.168.1.1',
143+
'id': 998877,
144+
'uplinkComponent': {}
141145
},
142146
{
143147
'maxSpeed': 1000,
144148
'networkComponentGroup': {
145149
'groupTypeId': 2,
146150
'networkComponents': [{'maxSpeed': 1000}, {'maxSpeed': 1000}]
147-
}
151+
},
152+
'id': 665544,
153+
'uplinkComponent': {}
148154
},
149155
{
150156
'maxSpeed': 1000,
151157
'networkComponentGroup': {
152158
'groupTypeId': 2,
153159
'networkComponents': [{'maxSpeed': 1000}, {'maxSpeed': 1000}]
154-
}
160+
},
161+
'id': 112233,
162+
'uplinkComponent': {}
155163
},
156164
{
157165
'maxSpeed': 1000,
158166
'networkComponentGroup': {
159167
'groupTypeId': 2,
160168
'networkComponents': [{'maxSpeed': 1000}, {'maxSpeed': 1000}]
161-
}
169+
},
170+
'primaryIpAddress': '10.0.0.1',
171+
'id': 123456,
172+
'uplinkComponent': {}
162173
}
163174
]
164-
getNetworkComponents = getFrontendNetworkComponents
175+
# This splits out the network components into 2 sections so they are different enough for tests
176+
getFrontendNetworkComponents = getNetworkComponents[0::1]
177+
getBackendNetworkComponents = getNetworkComponents[2::3]
165178

166179
getBandwidthAllotmentDetail = {
167180
'allocationId': 25465663,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addNetworkVlanTrunks = True
2+
clearNetworkVlanTrunks = True
3+
removeNetworkVlanTrunks = True

SoftLayer/fixtures/SoftLayer_Search.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,37 @@
4949
"type": "string"
5050
}]
5151
}]
52+
53+
54+
advancedSearchVlan = [
55+
{
56+
"matchedTerms": [
57+
"name:|IBMPrivate|",
58+
"name.sort:|IBMPrivate|"
59+
],
60+
"relevanceScore": "9.05",
61+
"resource": {
62+
"fullyQualifiedName": "dal10.bcr03.0000",
63+
"id": 11111,
64+
"name": "IBMPrivate",
65+
"vlanNumber": 0000,
66+
"networkSpace": "PRIVATE"
67+
},
68+
"resourceType": "SoftLayer_Network_Vlan"
69+
},
70+
{
71+
"matchedTerms": [
72+
"name:|IBMPublic|",
73+
"name.sort:|IBMPublic|"
74+
],
75+
"relevanceScore": "9.01",
76+
"resource": {
77+
"fullyQualifiedName": "dal10.bcr03.11111",
78+
"id": 999999,
79+
"name": "IBMPublic",
80+
"vlanNumber": 11111,
81+
"networkSpace": "PUBLIC"
82+
},
83+
"resourceType": "SoftLayer_Network_Vlan"
84+
}
85+
]

tests/CLI/modules/server_tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from SoftLayer.CLI import exceptions
1717
from SoftLayer.fixtures import SoftLayer_Product_Order
18+
from SoftLayer.fixtures import SoftLayer_Search
1819
from SoftLayer import SoftLayerError
1920
from SoftLayer import testing
2021
from SoftLayer import utils
@@ -1030,3 +1031,15 @@ def test_hardware_cancel_no_force(self, confirm_mock):
10301031

10311032
self.assertEqual(2, result.exit_code)
10321033
self.assertEqual('Aborted', result.exception.message)
1034+
1035+
def test_hardware_vlan_add(self):
1036+
mock = self.set_mock('SoftLayer_Search', 'advancedSearch')
1037+
mock.return_value = SoftLayer_Search.advancedSearchVlan
1038+
result = self.run_command(['hardware', 'vlan-add', '12345', '5555'])
1039+
self.assert_no_fail(result)
1040+
search_args = '_objectType:SoftLayer_Network_Vlan "5555"'
1041+
self.assert_called_with('SoftLayer_Search', 'advancedSearch', args=(search_args,))
1042+
self.assert_called_with('SoftLayer_Hardware_Server', 'getFrontendNetworkComponents', identifier=12345)
1043+
self.assert_called_with('SoftLayer_Hardware_Server', 'getBackendNetworkComponents', identifier=12345)
1044+
self.assert_called_with('SoftLayer_Network_Component', 'addNetworkVlanTrunks', identifier=998877)
1045+
self.assert_called_with('SoftLayer_Network_Component', 'addNetworkVlanTrunks', identifier=123456)

0 commit comments

Comments
 (0)