Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #289 from HewlettPackard/bugfix/avoid-failures-whe…
Browse files Browse the repository at this point in the history
…n-adding-osdeploymentsettings-on-sp

Fixed #288
  • Loading branch information
fgbulsoni authored Sep 13, 2017
2 parents d90325a + 9154667 commit 4442971
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [#172](https://github.com/HewlettPackard/oneview-ansible/issues/172) Allow credentials to be defined inside the playbooks
- [#282](https://github.com/HewlettPackard/oneview-ansible/issues/282) Updating a Server Profile causes Server Hardware reboots for operations which do not require it
- [#285](https://github.com/HewlettPackard/oneview-ansible/issues/285) Modules cannot unassign a Server Hardware or create SP with unassigned SH
- [#288](https://github.com/HewlettPackard/oneview-ansible/issues/288) Adding osCustomAttributes to a SP which had none before results in failure

# v4.0.0
#### Notes
Expand Down
11 changes: 7 additions & 4 deletions library/oneview_server_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def __present(self, data, resource):
self.__validations_for_os_custom_attributes(data, merged_data, resource)

if not ResourceComparator.compare(resource, merged_data):

resource = self.__update_server_profile(merged_data, resource)
changed = True
msg = self.MSG_UPDATED
Expand All @@ -332,10 +333,12 @@ def __present(self, data, resource):
# Removes .mac entries from resource os_custom_attributes if no .mac passed into data params.
# Swaps True values for 'true' string, and False values for 'false' string to avoid common user errors.
def __validations_for_os_custom_attributes(self, data, merged_data, resource):
if data.get('osDeploymentSettings') is None:
return False
elif data.get('osDeploymentSettings').get('osCustomAttributes') is None:
return False
if data.get('osDeploymentSettings') is None or resource.get('osDeploymentSettings') is None:
return
elif data.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
return
elif resource.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
return
attributes_merged = merged_data.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
attributes_resource = resource.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
dp_uri = resource.get('osDeploymentSettings', {}).get('osDeploymentPlanUri', None)
Expand Down
32 changes: 32 additions & 0 deletions test/test_oneview_server_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,38 @@ def test_should_unassign_server_hardware(self):
ansible_facts=mock_facts
)

def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_resource(self):
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
sp_get_value['osDeploymentSettings'] = {}
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))

self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
self.mock_ansible_module.params = deepcopy(PARAMS_FOR_UPDATE)

ServerProfileModule().run()

self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])

def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_data(self):
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
sp_get_value['osDeploymentSettings'] = {}
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))
sp_exit_value['osDeploymentSettings']['osCustomAttributes'] = None

params_for_update = deepcopy(PARAMS_FOR_UPDATE)
params_for_update['data']['osDeploymentSettings']['osCustomAttributes'] = None

self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
self.mock_ansible_module.params = params_for_update

ServerProfileModule().run()

self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 4442971

Please sign in to comment.