Merge "Remove 'locked' from server object"
This commit is contained in:
commit
fce0cb4c25
@ -41,7 +41,6 @@
|
||||
"description": null,
|
||||
"key_name": null,
|
||||
"partitions": {},
|
||||
"locked": false,
|
||||
"name": "test",
|
||||
"fault": null,
|
||||
"created_at": "2017-09-13T08:36:06Z",
|
||||
|
@ -7,7 +7,6 @@
|
||||
"mogan_object.data": {
|
||||
"status": "error",
|
||||
"node": "node-0",
|
||||
"locked": false,
|
||||
"uuid": "c6e12c34-8917-4b95-938e-e146faf1de97",
|
||||
"availability_zone": null,
|
||||
"fault": {
|
||||
|
@ -22,7 +22,6 @@
|
||||
"description": null,
|
||||
"key_name": null,
|
||||
"partitions": {},
|
||||
"locked": false,
|
||||
"name": "test",
|
||||
"fault": null,
|
||||
"created_at": "2017-09-13T08:36:06Z",
|
||||
|
@ -41,7 +41,6 @@
|
||||
"description": null,
|
||||
"key_name": null,
|
||||
"partitions": {},
|
||||
"locked": false,
|
||||
"name": "test",
|
||||
"fault": null,
|
||||
"created_at": "2017-09-13T08:15:21Z",
|
||||
|
@ -41,7 +41,6 @@
|
||||
"description": null,
|
||||
"key_name": null,
|
||||
"partitions": {},
|
||||
"locked": false,
|
||||
"name": "test",
|
||||
"fault": null,
|
||||
"created_at": "2017-09-13T08:15:21Z",
|
||||
|
@ -449,6 +449,9 @@ class Server(base.APIBase):
|
||||
if not pecan.request.context.is_admin:
|
||||
setattr(self, field, wtypes.Unset)
|
||||
continue
|
||||
if field == 'locked_by':
|
||||
setattr(self, 'locked', bool(kwargs.get('locked_by')))
|
||||
continue
|
||||
# Skip fields we do not expose.
|
||||
if not hasattr(self, field):
|
||||
continue
|
||||
|
@ -82,7 +82,6 @@ def upgrade():
|
||||
sa.Column('node_uuid', sa.String(length=36), nullable=True),
|
||||
sa.Column('extra', sa.Text(), nullable=True),
|
||||
sa.Column('partitions', sa.Text(), nullable=True),
|
||||
sa.Column('locked', sa.Boolean(), nullable=True),
|
||||
sa.Column('affinity_zone', sa.String(length=255), nullable=True),
|
||||
sa.Column('locked_by', sa.Enum('admin', 'owner'), nullable=True),
|
||||
sa.Column('key_name', sa.String(length=255), nullable=True),
|
||||
|
@ -90,7 +90,6 @@ class Server(Base):
|
||||
launched_at = Column(DateTime, nullable=True)
|
||||
extra = Column(db_types.JsonEncodedDict)
|
||||
partitions = Column(db_types.JsonEncodedDict)
|
||||
locked = Column(Boolean)
|
||||
locked_by = Column(Enum('owner', 'admin'))
|
||||
affinity_zone = Column(String(255), nullable=True)
|
||||
key_name = Column(String(255), nullable=True)
|
||||
|
@ -46,7 +46,7 @@ MAX_USERDATA_SIZE = 65535
|
||||
def check_server_lock(function):
|
||||
@six.wraps(function)
|
||||
def inner(self, context, server, *args, **kwargs):
|
||||
if server.locked and not context.is_admin:
|
||||
if server.locked_by and not context.is_admin:
|
||||
raise exception.ServerIsLocked(server_uuid=server.uuid)
|
||||
return function(self, context, server, *args, **kwargs)
|
||||
return inner
|
||||
@ -118,7 +118,6 @@ class API(object):
|
||||
'flavor_uuid': flavor['uuid'],
|
||||
'name': name,
|
||||
'description': description,
|
||||
'locked': False,
|
||||
'metadata': metadata or {},
|
||||
'partitions': partitions or {},
|
||||
'availability_zone': availability_zone,
|
||||
@ -478,11 +477,10 @@ class API(object):
|
||||
"""Lock the given server."""
|
||||
|
||||
is_owner = server.project_id == context.project_id
|
||||
if server.locked and is_owner:
|
||||
if server.locked_by and is_owner:
|
||||
return
|
||||
|
||||
LOG.debug('Locking server: %s', server.uuid)
|
||||
server.locked = True
|
||||
server.locked_by = 'owner' if is_owner else 'admin'
|
||||
server.save()
|
||||
|
||||
@ -490,7 +488,6 @@ class API(object):
|
||||
"""Unlock the given server."""
|
||||
|
||||
LOG.debug('Unlocking server: %s', server.uuid)
|
||||
server.locked = False
|
||||
server.locked_by = None
|
||||
server.save()
|
||||
|
||||
@ -702,7 +699,6 @@ class API(object):
|
||||
'power_state': states.NOSTATE,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'locked': False,
|
||||
'metadata': metadata or {},
|
||||
'availability_zone': None}
|
||||
|
||||
|
@ -31,7 +31,6 @@ class ServerPayload(base.NotificationPayloadBase):
|
||||
'power_state': ('server', 'power_state'),
|
||||
'flavor_uuid': ('server', 'flavor_uuid'),
|
||||
'description': ('server', 'description'),
|
||||
'locked': ('server', 'locked'),
|
||||
'locked_by': ('server', 'locked_by'),
|
||||
'affinity_zone': ('server', 'affinity_zone'),
|
||||
'metadata': ('server', 'metadata'),
|
||||
@ -55,7 +54,6 @@ class ServerPayload(base.NotificationPayloadBase):
|
||||
'launched_at': fields.DateTimeField(nullable=True),
|
||||
'updated_at': fields.DateTimeField(nullable=True),
|
||||
'status': fields.StringField(nullable=True),
|
||||
'locked': fields.BooleanField(nullable=True),
|
||||
'locked_by': fields.StringField(nullable=True),
|
||||
'affinity_zone': fields.StringField(nullable=True),
|
||||
'metadata': fields.FlexibleDictField(nullable=True),
|
||||
|
@ -54,7 +54,6 @@ class Server(base.MoganObject, object_base.VersionedObjectDictCompat):
|
||||
'launched_at': object_fields.DateTimeField(nullable=True),
|
||||
'metadata': object_fields.FlexibleDictField(nullable=True),
|
||||
'partitions': object_fields.FlexibleDictField(nullable=True),
|
||||
'locked': object_fields.BooleanField(default=False),
|
||||
'locked_by': object_fields.StringField(nullable=True),
|
||||
'affinity_zone': object_fields.StringField(nullable=True),
|
||||
'key_name': object_fields.StringField(nullable=True),
|
||||
|
@ -64,7 +64,6 @@ def get_test_server(**kw):
|
||||
'partitions': kw.get('partitions', {}),
|
||||
'updated_at': kw.get('updated_at'),
|
||||
'created_at': kw.get('created_at'),
|
||||
'locked': kw.get('locked', False),
|
||||
'locked_by': kw.get('locked_by', None),
|
||||
'affinity_zone': kw.get('affinity_zone', 'ZON1'),
|
||||
'key_name': kw.get('key_name', 'test_key')
|
||||
|
@ -238,16 +238,14 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
user_id=self.user_id, project_id=self.project_id)
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
self.engine_api.lock(self.context, fake_server_obj)
|
||||
self.assertTrue(fake_server_obj.locked)
|
||||
self.assertEqual('owner', fake_server_obj.locked_by)
|
||||
|
||||
def test_unlock_by_owner(self):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
self.engine_api.unlock(self.context, fake_server_obj)
|
||||
self.assertFalse(fake_server_obj.locked)
|
||||
self.assertIsNone(fake_server_obj.locked_by)
|
||||
|
||||
def test_lock_by_admin(self):
|
||||
@ -256,24 +254,22 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
admin_context = context.get_admin_context()
|
||||
self.engine_api.lock(admin_context, fake_server_obj)
|
||||
self.assertTrue(fake_server_obj.locked)
|
||||
self.assertEqual('admin', fake_server_obj.locked_by)
|
||||
|
||||
def test_unlock_by_admin(self):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
admin_context = context.get_admin_context()
|
||||
self.engine_api.unlock(admin_context, fake_server_obj)
|
||||
self.assertFalse(fake_server_obj.locked)
|
||||
self.assertIsNone(fake_server_obj.locked_by)
|
||||
|
||||
@mock.patch('mogan.engine.api.API._delete_server')
|
||||
def test_delete_locked_server_with_non_admin(self, mock_deleted):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
self.assertRaises(exception.ServerIsLocked,
|
||||
self.engine_api.delete,
|
||||
@ -284,7 +280,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
def test_power_locked_server_with_non_admin(self, mock_powered):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
self.assertRaises(exception.ServerIsLocked,
|
||||
self.engine_api.power,
|
||||
@ -295,7 +291,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
def test_delete_locked_server_with_admin(self, mock_deleted):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
admin_context = context.get_admin_context()
|
||||
self.engine_api.delete(admin_context, fake_server_obj)
|
||||
@ -305,7 +301,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
def test_power_locked_server_with_admin(self, mock_powered):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
admin_context = context.get_admin_context()
|
||||
self.engine_api.power(admin_context, fake_server_obj, 'reboot')
|
||||
@ -315,7 +311,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
def test_rebuild_locked_server_with_non_admin(self, mock_rebuild):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
self.assertRaises(exception.ServerIsLocked,
|
||||
self.engine_api.rebuild,
|
||||
@ -328,7 +324,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
|
||||
mock_get_image):
|
||||
fake_server = db_utils.get_test_server(
|
||||
user_id=self.user_id, project_id=self.project_id,
|
||||
locked=True, locked_by='owner')
|
||||
locked_by='owner')
|
||||
fake_server_obj = self._create_fake_server_obj(fake_server)
|
||||
admin_context = context.get_admin_context()
|
||||
mock_get_image.side_effect = None
|
||||
|
@ -226,9 +226,9 @@ class TestNotificationBase(test_base.TestCase):
|
||||
|
||||
|
||||
notification_object_data = {
|
||||
'ServerPayload': '1.0-55ce3a2c615a32c80b152aaf2b905703',
|
||||
'ServerPayload': '1.0-30fefa8478f1b9b35c66868377fb6dfd',
|
||||
'ServerAddressesPayload': '1.0-69caf4c36f36756bb1f6970d093ee1f6',
|
||||
'ServerActionPayload': '1.0-a22c2f18b8dd17a3990e5b4c64989d26',
|
||||
'ServerActionPayload': '1.0-8dc4429afa34d86ab92c9387e3ccd0c3',
|
||||
'ServerActionNotification': '1.0-20087e599436bd9db62ae1fb5e2dfef2',
|
||||
'ExceptionPayload': '1.0-7c31986d8d78bed910c324965c431e18',
|
||||
'EventType': '1.0-93493dd78bdfed806fca70c91d85cbb4',
|
||||
|
@ -382,7 +382,7 @@ class _TestObject(object):
|
||||
# version bump. It is md5 hash of object fields and remotable methods.
|
||||
# The fingerprint values should only be changed if there is a version bump.
|
||||
expected_object_fingerprints = {
|
||||
'Server': '1.0-6b13b984cd3656a977456a12d3d1c167',
|
||||
'Server': '1.0-1480ee88a244bf44492f61f20a022a6f',
|
||||
'ServerFault': '1.0-74349ff701259e4834b4e9dc2dac1b12',
|
||||
'ServerFaultList': '1.0-43e8aad0258652921f929934e9e048fd',
|
||||
'Flavor': '1.0-9f7166aa387d89ec40cd699019d0c9a9',
|
||||
|
Loading…
Reference in New Issue
Block a user