Skip to content

Commit 34b1740

Browse files
committed
Enabled to pass parameters how to connect ACOS appliance
All actions can't connect an ACOS appliance when its SSL feature is disabled because BaseAction that leads processing to handle acos.Client never pass parameters to manupirate how to connect ACOS appliance. This commit fixed it to be able to pass those parameters from the "specified_target" parameter that is equipped every action.
1 parent 97aa130 commit 34b1740

File tree

4 files changed

+72
-6
lines changed

4 files changed

+72
-6
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.5.0
4+
5+
* Enabled to pass parameters how to connect ACOS appliance
6+
37
## v1.4.0
48

59
* Added actions to get slb template lists.

actions/acoslib/action.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ def login(self, target, specified_target=None):
2424
config = specified_target
2525
else:
2626
config = next(x for x in self.config['appliance'] if x['target'] == target)
27+
28+
extra_params = {
29+
"max_retries": config.get("max_retries", 3),
30+
"port": config.get("port", 443),
31+
"protocol": config.get("protocol", "https"),
32+
"timeout": config.get("timeout", 5),
33+
}
34+
2735
return acos.Client(config['target'],
2836
config['api_version'],
2937
config['userid'],
30-
config['passwd'])
38+
config['passwd'],
39+
**extra_params)
3140
except acos.errors.ACOSUnsupportedVersion as e:
3241
self.logger.error(e)
3342
except KeyError as e:

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords:
77
- load balancer
88
- ADC
99
- network
10-
version: 1.4.0
10+
version: 1.5.0
1111
author: Hiroyasu OHYAMA
1212
1313
python_versions:

tests/test_specified_target.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,60 @@ def setUp(self):
1616

1717
@mock.patch('acos_client.Client')
1818
def test_specified_target_without_one_target(self, mock_client):
19-
# set mock of action
20-
mock_action = mock.Mock()
21-
mock_action.slb.server.get.return_value = 'test-result'
19+
def side_effect(*args, **extra_params):
20+
# This checks authentication information that is passed to acos.Client
21+
self.assertEqual(args, ('appliance_acos_v2.1', 'v2.1', 'admin', 'hoge'))
2222

23-
mock_client.return_value = mock_action
23+
# This checks default extra params are set
24+
self.assertEqual(extra_params, {
25+
'max_retries': 3, 'port': 443, 'protocol': 'https', 'timeout': 5
26+
})
27+
28+
# set mock of action
29+
mock_action = mock.Mock()
30+
mock_action.slb.server.get.return_value = 'test-result'
31+
32+
return mock_action
33+
34+
mock_client.side_effect = side_effect
35+
36+
# execute action
37+
params = {
38+
'object_path': 'slb.server',
39+
'action': 'get',
40+
'name': 'hoge',
41+
'one_target': False,
42+
'specified_target': {
43+
'target': 'appliance_acos_v2.1',
44+
'userid': 'admin',
45+
'passwd': 'hoge',
46+
'api_version': 'v2.1',
47+
}
48+
}
49+
result = self.action.run(**params)
50+
51+
self.assertTrue(result[0])
52+
self.assertEqual(result[1], 'test-result')
53+
self.assertEqual(len(self._log_handler.messages['error']), 0)
54+
55+
@mock.patch('acos_client.Client')
56+
def test_specified_target_with_extra_params(self, mock_client):
57+
def side_effect(*args, **extra_params):
58+
# This checks authentication information that is passed to acos.Client
59+
self.assertEqual(args, ('appliance_acos_v2.1', 'v2.1', 'admin', 'hoge'))
60+
61+
# This checks extra params are set as user specified
62+
self.assertEqual(extra_params, {
63+
'max_retries': 10, 'port': 80, 'protocol': 'http', 'timeout': 10
64+
})
65+
66+
# set mock of action
67+
mock_action = mock.Mock()
68+
mock_action.slb.server.get.return_value = 'test-result'
69+
70+
return mock_action
71+
72+
mock_client.side_effect = side_effect
2473

2574
# execute action
2675
params = {
@@ -33,6 +82,10 @@ def test_specified_target_without_one_target(self, mock_client):
3382
'userid': 'admin',
3483
'passwd': 'hoge',
3584
'api_version': 'v2.1',
85+
'max_retries': 10,
86+
'port': 80,
87+
'protocol': 'http',
88+
'timeout': 10,
3689
}
3790
}
3891
result = self.action.run(**params)

0 commit comments

Comments
 (0)