Skip to content

Commit

Permalink
bug fix for update os volume
Browse files Browse the repository at this point in the history
  • Loading branch information
VenkateshRavula committed Jun 8, 2020
1 parent 015251c commit 7beb787
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Ansible Modules for HPE OneView Change Log

## v5.6.1 (unreleased)

#### Bug fixes & Enhancements
- [#481](https://github.com/HewlettPackard/oneview-ansible/issues/481) oneview_volume is not idempotent

## v5.6.0

Extends support of the SDK to OneView REST API version 1600 (OneView v5.20).
Expand Down
11 changes: 9 additions & 2 deletions library/oneview_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class VolumeModule(OneViewModule):
MSG_ALREADY_ABSENT = 'Volume is already absent.'
MSG_NO_OPTIONS_PROVIDED = 'No options provided.'
MSG_NEW_NAME_INVALID = 'Rename failed: the new name provided is being used by another Volume.'
MSG_NO_CHANGES_PROVIDED = 'No changed have been provided fro the update.'
MSG_NO_CHANGES_PROVIDED = 'No changes have been provided for the update.'

def __init__(self):
argument_spec = dict(
Expand Down Expand Up @@ -313,7 +313,14 @@ def __update(self):
self.data["name"] = self.data.pop("newName")

merged_data = self.current_resource.data.copy()
merged_data.update(self.data)
input_data = self.data.copy()

if input_data.get("properties"):
del input_data["properties"]
if input_data.get("templateUri"):
input_data["volumeTemplateUri"] = input_data.pop("templateUri")

merged_data.update(input_data)

if compare(self.current_resource.data, merged_data):
changed = False
Expand Down
22 changes: 21 additions & 1 deletion test/test_oneview_volume.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
###
# Copyright (2016-2017) Hewlett Packard Enterprise Development LP
# Copyright (2016-2020) Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,6 +65,12 @@
state='present',
data=dict(properties=dict(name='Volume with Storage Pool')))

PARAMS_FOR_UPDATE_template = dict(
config='config.json',
state='present',
data=dict(name='Volume with Storage Pool',
templateUri='/rest/fake')
)

PARAMS_FOR_UPDATE_OK = dict(
config='config.json',
Expand Down Expand Up @@ -269,6 +275,20 @@ def test_should_remove_volume_with_suppress_device_updates(self):
msg=VolumeModule.MSG_DELETED
)

def test_update_should_do_nothing_when_volume_already_exists_with_template(self):
self.resource.data = PARAMS_FOR_UPDATE_template["data"]
self.resource.get_by_name.return_value = self.resource

self.mock_ansible_module.params = PARAMS_FOR_PRESENT

VolumeModule().run()

self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
msg=VolumeModule.MSG_NO_CHANGES_PROVIDED,
ansible_facts=dict(storage_volume=self.resource.data)
)

def test_update_should_do_nothing_when_volume_already_exists_and_is_equal(self):
self.resource.data = PARAMS_FOR_PRESENT["data"]
self.resource.get_by_name.return_value = self.resource
Expand Down

0 comments on commit 7beb787

Please sign in to comment.