Merge "Remove 'spec' from profile-update service api"
This commit is contained in:
commit
eb3da2de8f
|
@ -10,7 +10,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import functools
|
||||
import uuid
|
||||
|
||||
|
@ -242,51 +241,26 @@ class EngineService(service.Service):
|
|||
return profile.to_dict()
|
||||
|
||||
@request_context
|
||||
def profile_update(self, context, profile_id, name=None, spec=None,
|
||||
permission=None, metadata=None):
|
||||
def profile_update(self, context, profile_id, name=None, permission=None,
|
||||
metadata=None):
|
||||
LOG.info(_LI("Updating profile '%(id)s.'"), {'id': profile_id})
|
||||
|
||||
db_profile = self.profile_find(context, profile_id)
|
||||
if spec is None:
|
||||
profile = profile_base.Profile.load(context, profile=db_profile)
|
||||
changed = False
|
||||
if name is not None and name != profile.name:
|
||||
profile.name = name
|
||||
changed = True
|
||||
if permission is not None and permission != profile.permission:
|
||||
profile.permission = permission
|
||||
changed = True
|
||||
if metadata is not None and metadata != profile.metadata:
|
||||
profile.metadata = metadata
|
||||
changed = True
|
||||
if changed:
|
||||
profile.store(context)
|
||||
|
||||
LOG.info(_LI("Profile '%(id)s' is updated."), {'id': profile_id})
|
||||
return profile.to_dict()
|
||||
|
||||
type_name, version = schema.get_spec_version(db_profile.spec)
|
||||
plugin = environment.global_env().get_profile(type_name)
|
||||
|
||||
new_spec = copy.deepcopy(db_profile.spec)
|
||||
new_spec.update(spec)
|
||||
kwargs = {
|
||||
'user': db_profile.user,
|
||||
'project': db_profile.project,
|
||||
'domain': db_profile.domain,
|
||||
'permission': permission or db_profile.permission,
|
||||
'metadata': metadata or db_profile.meta_data,
|
||||
}
|
||||
|
||||
new_name = name or db_profile.name
|
||||
profile = plugin(new_name, new_spec, **kwargs)
|
||||
profile.validate()
|
||||
profile.store(context)
|
||||
|
||||
LOG.info(_LI("New Profile '%(new_id)s' is created based on profile "
|
||||
"'%(old_id)s'."),
|
||||
{'new_id': profile.id, 'old_id': profile_id})
|
||||
profile = profile_base.Profile.load(context, profile=db_profile)
|
||||
changed = False
|
||||
if name is not None and name != profile.name:
|
||||
profile.name = name
|
||||
changed = True
|
||||
if permission is not None and permission != profile.permission:
|
||||
profile.permission = permission
|
||||
changed = True
|
||||
if metadata is not None and metadata != profile.metadata:
|
||||
profile.metadata = metadata
|
||||
changed = True
|
||||
if changed:
|
||||
profile.store(context)
|
||||
|
||||
LOG.info(_LI("Profile '%(id)s' is updated."), {'id': profile_id})
|
||||
return profile.to_dict()
|
||||
|
||||
@request_context
|
||||
|
|
|
@ -337,43 +337,6 @@ class ProfileTest(base.SenlinTestCase):
|
|||
p = self.eng.profile_get(self.ctx, pid)
|
||||
self.assertEqual({'bar': 'foo'}, p['metadata'])
|
||||
|
||||
def test_profile_update_new_spec(self):
|
||||
p1 = self.eng.profile_create(self.ctx, 'p-1', self.spec,
|
||||
permission='1111',
|
||||
metadata={'foo': 'bar'})
|
||||
pid = p1['id']
|
||||
|
||||
# update spec only
|
||||
new_spec = {
|
||||
'type': 'TestProfile',
|
||||
'version': '1.0',
|
||||
'properties': {'INT': 2}
|
||||
}
|
||||
p2 = self.eng.profile_update(self.ctx, pid, spec=new_spec)
|
||||
self.assertNotEqual(pid, p2['id'])
|
||||
# spec changed but other fields not changed
|
||||
self.assertEqual(new_spec, p2['spec'])
|
||||
self.assertEqual('p-1', p2['name'])
|
||||
self.assertEqual('1111', p2['permission'])
|
||||
self.assertEqual({'foo': 'bar'}, p2['metadata'])
|
||||
|
||||
p = self.eng.profile_get(self.ctx, p2['id'])
|
||||
self.assertEqual(new_spec, p['spec'])
|
||||
self.assertEqual('p-1', p['name'])
|
||||
self.assertEqual('1111', p['permission'])
|
||||
self.assertEqual({'foo': 'bar'}, p['metadata'])
|
||||
|
||||
# update spec with other fields
|
||||
p2 = self.eng.profile_update(self.ctx, pid, name='p-2',
|
||||
permission='1100', spec=new_spec)
|
||||
|
||||
self.assertNotEqual(pid, p2['id'])
|
||||
# spec changed with other fields changed properly
|
||||
self.assertEqual(new_spec, p2['spec'])
|
||||
self.assertEqual('p-2', p2['name'])
|
||||
self.assertEqual('1100', p2['permission'])
|
||||
self.assertEqual({'foo': 'bar'}, p2['metadata'])
|
||||
|
||||
def test_profile_update_not_found(self):
|
||||
ex = self.assertRaises(rpc.ExpectedException,
|
||||
self.eng.profile_update,
|
||||
|
@ -400,25 +363,6 @@ class ProfileTest(base.SenlinTestCase):
|
|||
self.assertEqual(pid, p4['id'])
|
||||
self.assertEqual('p-4', p4['name'])
|
||||
|
||||
def test_profile_update_err_validate(self):
|
||||
p1 = self.eng.profile_create(self.ctx, 'p-1', self.spec,
|
||||
permission='1111',
|
||||
metadata={'foo': 'bar'})
|
||||
pid = p1['id']
|
||||
|
||||
new_spec = {
|
||||
'type': 'TestProfile',
|
||||
'version': '1.0',
|
||||
'properties': {
|
||||
'bad': 'yes',
|
||||
}
|
||||
}
|
||||
ex = self.assertRaises(rpc.ExpectedException,
|
||||
self.eng.profile_update,
|
||||
self.ctx, pid, spec=new_spec)
|
||||
|
||||
self.assertEqual(exception.SpecValidationFailed, ex.exc_info[0])
|
||||
|
||||
def test_profile_delete(self):
|
||||
p1 = self.eng.profile_create(self.ctx, 'p-1', self.spec,
|
||||
permission='1111',
|
||||
|
|
Loading…
Reference in New Issue