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

Commit 4442971

Browse files
authored
Merge pull request #289 from HewlettPackard/bugfix/avoid-failures-when-adding-osdeploymentsettings-on-sp
Fixed #288
2 parents d90325a + 9154667 commit 4442971

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [#172](https://github.com/HewlettPackard/oneview-ansible/issues/172) Allow credentials to be defined inside the playbooks
44
- [#282](https://github.com/HewlettPackard/oneview-ansible/issues/282) Updating a Server Profile causes Server Hardware reboots for operations which do not require it
55
- [#285](https://github.com/HewlettPackard/oneview-ansible/issues/285) Modules cannot unassign a Server Hardware or create SP with unassigned SH
6+
- [#288](https://github.com/HewlettPackard/oneview-ansible/issues/288) Adding osCustomAttributes to a SP which had none before results in failure
67

78
# v4.0.0
89
#### Notes

library/oneview_server_profile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def __present(self, data, resource):
321321
self.__validations_for_os_custom_attributes(data, merged_data, resource)
322322

323323
if not ResourceComparator.compare(resource, merged_data):
324+
324325
resource = self.__update_server_profile(merged_data, resource)
325326
changed = True
326327
msg = self.MSG_UPDATED
@@ -332,10 +333,12 @@ def __present(self, data, resource):
332333
# Removes .mac entries from resource os_custom_attributes if no .mac passed into data params.
333334
# Swaps True values for 'true' string, and False values for 'false' string to avoid common user errors.
334335
def __validations_for_os_custom_attributes(self, data, merged_data, resource):
335-
if data.get('osDeploymentSettings') is None:
336-
return False
337-
elif data.get('osDeploymentSettings').get('osCustomAttributes') is None:
338-
return False
336+
if data.get('osDeploymentSettings') is None or resource.get('osDeploymentSettings') is None:
337+
return
338+
elif data.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
339+
return
340+
elif resource.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
341+
return
339342
attributes_merged = merged_data.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
340343
attributes_resource = resource.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
341344
dp_uri = resource.get('osDeploymentSettings', {}).get('osDeploymentPlanUri', None)

test/test_oneview_server_profile.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,38 @@ def test_should_unassign_server_hardware(self):
19041904
ansible_facts=mock_facts
19051905
)
19061906

1907+
def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_resource(self):
1908+
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
1909+
sp_get_value['osDeploymentSettings'] = {}
1910+
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
1911+
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))
1912+
1913+
self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
1914+
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
1915+
self.mock_ansible_module.params = deepcopy(PARAMS_FOR_UPDATE)
1916+
1917+
ServerProfileModule().run()
1918+
1919+
self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])
1920+
1921+
def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_data(self):
1922+
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
1923+
sp_get_value['osDeploymentSettings'] = {}
1924+
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
1925+
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))
1926+
sp_exit_value['osDeploymentSettings']['osCustomAttributes'] = None
1927+
1928+
params_for_update = deepcopy(PARAMS_FOR_UPDATE)
1929+
params_for_update['data']['osDeploymentSettings']['osCustomAttributes'] = None
1930+
1931+
self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
1932+
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
1933+
self.mock_ansible_module.params = params_for_update
1934+
1935+
ServerProfileModule().run()
1936+
1937+
self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])
1938+
19071939

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

0 commit comments

Comments
 (0)