Skip to content

Commit

Permalink
CYBL-862 Fix issue with update aggregate and set metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed AbuAisha committed Aug 8, 2019
1 parent e85a02d commit 871f174
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
3.2.3:
- Fix bug with re-attaching port to server when run update deployment workflow
- Fix bug for update aggregate and set metadata
3.2.2:
- Fix major issue with ports/network ordering connected server instance
3.2.1:
Expand Down
26 changes: 18 additions & 8 deletions openstack_plugin/resources/compute/host_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
with_compat_node)
from openstack_plugin.constants import (RESOURCE_ID,
HOST_AGGREGATE_OPENSTACK_TYPE)
from openstack_plugin.utils import add_resource_list_to_runtime_properties
from openstack_plugin.utils import (
add_resource_list_to_runtime_properties,
reset_dict_empty_keys
)


def _add_hosts(openstack_resource, hosts):
Expand Down Expand Up @@ -130,13 +133,20 @@ def update(openstack_resource, args):
:param openstack_resource: Instance of openstack host aggregate resource
:param dict args: dict of information need to be updated
"""
# TODO This need to be uncomment whenever openstack allow for update
# operation since the following actions are only supported
# https://git.io/fhSFH
# args = reset_dict_empty_keys(args)
# openstack_resource.update(args)
raise NonRecoverableError(
'Openstack SDK does not support host aggregate update operation')
args = reset_dict_empty_keys(args)
if not args:
raise NonRecoverableError(
'Unable to update aggregate {0}, '
'args cannot be empty'.format(openstack_resource.resource_id))

# Check if metadata is exist so that we can update it if needed
if 'metadata' in args:
metadata = args.pop('metadata')
openstack_resource.set_metadata(metadata)

# Update only if args has value like (name | availability_zone)
if args:
openstack_resource.update(args)


@with_compat_node
Expand Down
71 changes: 65 additions & 6 deletions openstack_plugin/tests/compute/test_host_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,78 @@ def test_configure(self, mock_connection):
self.assertEqual(
len(self._ctx.instance.runtime_properties['hosts']), 2)

def test_update(self, _):
def test_update(self, mock_connection):
# Prepare the context for update operation
self._prepare_context_for_operation(
test_name='FlavorTestCase',
test_name='HostAggregateTestCase',
ctx_operation_name='cloudify.interfaces.lifecycle.update')

old_aggregate_instance = openstack.compute.v2.aggregate.Aggregate(**{
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
'name': 'test_host_aggregate',
'availability_zone': 'test_availability_zone',
})

new_aggregate_instance = openstack.compute.v2.aggregate.Aggregate(**{
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
'name': 'update_test_host_aggregate',
'availability_zone': 'test_availability_zone',
})

updated_config = {
'name': 'Updated Name'
'name': 'update_test_host_aggregate'
}

with self.assertRaises(NonRecoverableError):
# Call update aggregate
host_aggregate.update(args=updated_config)
# Mock get aggregate response
mock_connection().compute.get_aggregate = \
mock.MagicMock(return_value=old_aggregate_instance)

# Mock add host aggregate response
mock_connection().compute.update = \
mock.MagicMock(return_value=new_aggregate_instance)

host_aggregate.update(args=updated_config)

def test_update_metadata(self, mock_connection):
# Prepare the context for update operation
self._prepare_context_for_operation(
test_name='HostAggregateTestCase',
ctx_operation_name='cloudify.interfaces.lifecycle.update')

old_aggregate_instance = openstack.compute.v2.aggregate.Aggregate(**{
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
'name': 'test_host_aggregate',
'availability_zone': 'test_availability_zone',
})

new_aggregate_instance = openstack.compute.v2.aggregate.Aggregate(**{
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
'name': 'update_test_host_aggregate',
'availability_zone': 'test_availability_zone',
'properties': {
'key-1': 'value-1',
'key-2': 'value-2'
}
})

updated_config = {
'metadata': {
'key-1': 'value-1',
'key-2': 'value-2'
}
}

# Mock get aggregate response
mock_connection().compute.get_aggregate = \
mock.MagicMock(return_value=old_aggregate_instance)

# Mock add host aggregate response
mock_connection().compute.set_metadata = \
mock.MagicMock(return_value=new_aggregate_instance)

host_aggregate.update(args=updated_config)
# Update method is not going to be called since we set metadata
mock_connection().compute.update.assert_not_called()

def test_delete(self, mock_connection):
# Prepare the context for configure operation
Expand Down

0 comments on commit 871f174

Please sign in to comment.