Merge "Bug fix: Allow name update for domains"
This commit is contained in:
commit
59d448dcc0
@ -0,0 +1,3 @@
|
||||
---
|
||||
fixes:
|
||||
- Fix for update_domain() where 'name' was not updatable.
|
@ -1038,7 +1038,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
|
||||
with _utils.shade_exceptions(
|
||||
"Error in updating domain {domain}".format(domain=domain_id)):
|
||||
domain = self.manager.submitTask(_tasks.DomainUpdate(
|
||||
domain=domain_id, description=description, enabled=enabled))
|
||||
domain=domain_id, name=name, description=description,
|
||||
enabled=enabled))
|
||||
return _utils.normalize_domains([domain])[0]
|
||||
|
||||
def delete_domain(self, domain_id):
|
||||
|
@ -63,3 +63,15 @@ class TestDomain(base.TestCase):
|
||||
results = self.cloud.search_domains(filters=dict(name=domain_name))
|
||||
self.assertEqual(1, len(results))
|
||||
self.assertEqual(domain_name, results[0]['name'])
|
||||
|
||||
def test_update_domain(self):
|
||||
domain = self.cloud.create_domain(self.domain_prefix, 'description')
|
||||
self.assertEqual(self.domain_prefix, domain['name'])
|
||||
self.assertEqual('description', domain['description'])
|
||||
self.assertTrue(domain['enabled'])
|
||||
updated = self.cloud.update_domain(domain['id'], name='updated name',
|
||||
description='updated description',
|
||||
enabled=False)
|
||||
self.assertEqual('updated name', updated['name'])
|
||||
self.assertEqual('updated description', updated['description'])
|
||||
self.assertFalse(updated['enabled'])
|
||||
|
@ -14,8 +14,10 @@
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
import shade
|
||||
from shade import meta
|
||||
from shade.tests.unit import base
|
||||
from shade.tests import fakes
|
||||
|
||||
@ -46,3 +48,65 @@ class TestDomains(base.TestCase):
|
||||
self.assertFalse(mock_keystone.domains.list.called)
|
||||
self.assertTrue(mock_keystone.domains.get.called)
|
||||
self.assertEqual(domain['name'], 'a-domain')
|
||||
|
||||
@mock.patch.object(shade._utils, 'normalize_domains')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_create_domain(self, mock_keystone, mock_normalize):
|
||||
mock_keystone.domains.create.return_value = domain_obj
|
||||
self.cloud.create_domain(domain_obj.name,
|
||||
domain_obj.description)
|
||||
mock_keystone.domains.create.assert_called_once_with(
|
||||
name=domain_obj.name, description=domain_obj.description,
|
||||
enabled=True)
|
||||
mock_normalize.assert_called_once_with([meta.obj_to_dict(domain_obj)])
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_create_domain_exception(self, mock_keystone):
|
||||
mock_keystone.domains.create.side_effect = Exception()
|
||||
with testtools.ExpectedException(
|
||||
shade.OpenStackCloudException,
|
||||
"Failed to create domain domain_name"
|
||||
):
|
||||
self.cloud.create_domain('domain_name')
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'update_domain')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_delete_domain(self, mock_keystone, mock_update):
|
||||
mock_update.return_value = dict(id='update_domain_id')
|
||||
self.cloud.delete_domain('domain_id')
|
||||
mock_update.assert_called_once_with('domain_id', enabled=False)
|
||||
mock_keystone.domains.delete.assert_called_once_with(
|
||||
domain='update_domain_id')
|
||||
|
||||
@mock.patch.object(shade.OperatorCloud, 'update_domain')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_delete_domain_exception(self, mock_keystone, mock_update):
|
||||
mock_keystone.domains.delete.side_effect = Exception()
|
||||
with testtools.ExpectedException(
|
||||
shade.OpenStackCloudException,
|
||||
"Failed to delete domain domain_id"
|
||||
):
|
||||
self.cloud.delete_domain('domain_id')
|
||||
|
||||
@mock.patch.object(shade._utils, 'normalize_domains')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_update_domain(self, mock_keystone, mock_normalize):
|
||||
mock_keystone.domains.update.return_value = domain_obj
|
||||
self.cloud.update_domain('domain_id',
|
||||
name='new name',
|
||||
description='new description',
|
||||
enabled=False)
|
||||
mock_keystone.domains.update.assert_called_once_with(
|
||||
domain='domain_id', name='new name',
|
||||
description='new description', enabled=False)
|
||||
mock_normalize.assert_called_once_with(
|
||||
[meta.obj_to_dict(domain_obj)])
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'keystone_client')
|
||||
def test_update_domain_exception(self, mock_keystone):
|
||||
mock_keystone.domains.update.side_effect = Exception()
|
||||
with testtools.ExpectedException(
|
||||
shade.OpenStackCloudException,
|
||||
"Error in updating domain domain_id"
|
||||
):
|
||||
self.cloud.delete_domain('domain_id')
|
||||
|
Loading…
Reference in New Issue
Block a user