Skip to content

Commit

Permalink
Merge pull request #28 from StackStorm-Exchange/feature/base_action/e…
Browse files Browse the repository at this point in the history
…nabled_to_set_method_of_connection_to_appliance

Enabled to pass parameters how to connect ACOS appliance
  • Loading branch information
nzlosh committed May 19, 2023
2 parents 97aa130 + 34b1740 commit 2ae7fb4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.5.0

* Enabled to pass parameters how to connect ACOS appliance

## v1.4.0

* Added actions to get slb template lists.
Expand Down
11 changes: 10 additions & 1 deletion actions/acoslib/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ def login(self, target, specified_target=None):
config = specified_target
else:
config = next(x for x in self.config['appliance'] if x['target'] == target)

extra_params = {
"max_retries": config.get("max_retries", 3),
"port": config.get("port", 443),
"protocol": config.get("protocol", "https"),
"timeout": config.get("timeout", 5),
}

return acos.Client(config['target'],
config['api_version'],
config['userid'],
config['passwd'])
config['passwd'],
**extra_params)
except acos.errors.ACOSUnsupportedVersion as e:
self.logger.error(e)
except KeyError as e:
Expand Down
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords:
- load balancer
- ADC
- network
version: 1.4.0
version: 1.5.0
author: Hiroyasu OHYAMA
email: [email protected]
python_versions:
Expand Down
61 changes: 57 additions & 4 deletions tests/test_specified_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,60 @@ def setUp(self):

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

mock_client.return_value = mock_action
# This checks default extra params are set
self.assertEqual(extra_params, {
'max_retries': 3, 'port': 443, 'protocol': 'https', 'timeout': 5
})

# set mock of action
mock_action = mock.Mock()
mock_action.slb.server.get.return_value = 'test-result'

return mock_action

mock_client.side_effect = side_effect

# execute action
params = {
'object_path': 'slb.server',
'action': 'get',
'name': 'hoge',
'one_target': False,
'specified_target': {
'target': 'appliance_acos_v2.1',
'userid': 'admin',
'passwd': 'hoge',
'api_version': 'v2.1',
}
}
result = self.action.run(**params)

self.assertTrue(result[0])
self.assertEqual(result[1], 'test-result')
self.assertEqual(len(self._log_handler.messages['error']), 0)

@mock.patch('acos_client.Client')
def test_specified_target_with_extra_params(self, mock_client):
def side_effect(*args, **extra_params):
# This checks authentication information that is passed to acos.Client
self.assertEqual(args, ('appliance_acos_v2.1', 'v2.1', 'admin', 'hoge'))

# This checks extra params are set as user specified
self.assertEqual(extra_params, {
'max_retries': 10, 'port': 80, 'protocol': 'http', 'timeout': 10
})

# set mock of action
mock_action = mock.Mock()
mock_action.slb.server.get.return_value = 'test-result'

return mock_action

mock_client.side_effect = side_effect

# execute action
params = {
Expand All @@ -33,6 +82,10 @@ def test_specified_target_without_one_target(self, mock_client):
'userid': 'admin',
'passwd': 'hoge',
'api_version': 'v2.1',
'max_retries': 10,
'port': 80,
'protocol': 'http',
'timeout': 10,
}
}
result = self.action.run(**params)
Expand Down

0 comments on commit 2ae7fb4

Please sign in to comment.