Browse Source

Remove 'locked' from server object

locked_by can be used to check the lock status, there's no
need to keep locked field.

Change-Id: I3761ab710cf67d56163a39add4c51ee48f940a36
Closes-Bug: #1727944
changes/67/515667/2
Zhenguo Niu 1 year ago
parent
commit
448556bab0

+ 0
- 1
doc/notification_samples/server-create-end.json View File

@@ -41,7 +41,6 @@
41 41
             "description": null,
42 42
             "key_name": null,
43 43
             "partitions": {},
44
-            "locked": false,
45 44
             "name": "test",
46 45
             "fault": null,
47 46
             "created_at": "2017-09-13T08:36:06Z",

+ 0
- 1
doc/notification_samples/server-create-error.json View File

@@ -7,7 +7,6 @@
7 7
         "mogan_object.data": {
8 8
             "status": "error",
9 9
             "node": "node-0",
10
-            "locked": false,
11 10
             "uuid": "c6e12c34-8917-4b95-938e-e146faf1de97",
12 11
             "availability_zone": null,
13 12
             "fault": {

+ 0
- 1
doc/notification_samples/server-create-start.json View File

@@ -22,7 +22,6 @@
22 22
             "description": null,
23 23
             "key_name": null,
24 24
             "partitions": {},
25
-            "locked": false,
26 25
             "name": "test",
27 26
             "fault": null,
28 27
             "created_at": "2017-09-13T08:36:06Z",

+ 0
- 1
doc/notification_samples/server-delete-end.json View File

@@ -41,7 +41,6 @@
41 41
             "description": null,
42 42
             "key_name": null,
43 43
             "partitions": {},
44
-            "locked": false,
45 44
             "name": "test",
46 45
             "fault": null,
47 46
             "created_at": "2017-09-13T08:15:21Z",

+ 0
- 1
doc/notification_samples/server-delete-start.json View File

@@ -41,7 +41,6 @@
41 41
             "description": null,
42 42
             "key_name": null,
43 43
             "partitions": {},
44
-            "locked": false,
45 44
             "name": "test",
46 45
             "fault": null,
47 46
             "created_at": "2017-09-13T08:15:21Z",

+ 3
- 0
mogan/api/controllers/v1/servers.py View File

@@ -449,6 +449,9 @@ class Server(base.APIBase):
449 449
                 if not pecan.request.context.is_admin:
450 450
                     setattr(self, field, wtypes.Unset)
451 451
                     continue
452
+            if field == 'locked_by':
453
+                setattr(self, 'locked', bool(kwargs.get('locked_by')))
454
+                continue
452 455
             # Skip fields we do not expose.
453 456
             if not hasattr(self, field):
454 457
                 continue

+ 0
- 1
mogan/db/sqlalchemy/alembic/versions/91941bf1ebc9_initial_migration.py View File

@@ -82,7 +82,6 @@ def upgrade():
82 82
         sa.Column('node_uuid', sa.String(length=36), nullable=True),
83 83
         sa.Column('extra', sa.Text(), nullable=True),
84 84
         sa.Column('partitions', sa.Text(), nullable=True),
85
-        sa.Column('locked', sa.Boolean(), nullable=True),
86 85
         sa.Column('affinity_zone', sa.String(length=255), nullable=True),
87 86
         sa.Column('locked_by', sa.Enum('admin', 'owner'), nullable=True),
88 87
         sa.Column('key_name', sa.String(length=255), nullable=True),

+ 0
- 1
mogan/db/sqlalchemy/models.py View File

@@ -90,7 +90,6 @@ class Server(Base):
90 90
     launched_at = Column(DateTime, nullable=True)
91 91
     extra = Column(db_types.JsonEncodedDict)
92 92
     partitions = Column(db_types.JsonEncodedDict)
93
-    locked = Column(Boolean)
94 93
     locked_by = Column(Enum('owner', 'admin'))
95 94
     affinity_zone = Column(String(255), nullable=True)
96 95
     key_name = Column(String(255), nullable=True)

+ 2
- 6
mogan/engine/api.py View File

@@ -46,7 +46,7 @@ MAX_USERDATA_SIZE = 65535
46 46
 def check_server_lock(function):
47 47
     @six.wraps(function)
48 48
     def inner(self, context, server, *args, **kwargs):
49
-        if server.locked and not context.is_admin:
49
+        if server.locked_by and not context.is_admin:
50 50
             raise exception.ServerIsLocked(server_uuid=server.uuid)
51 51
         return function(self, context, server, *args, **kwargs)
52 52
     return inner
@@ -118,7 +118,6 @@ class API(object):
118 118
             'flavor_uuid': flavor['uuid'],
119 119
             'name': name,
120 120
             'description': description,
121
-            'locked': False,
122 121
             'metadata': metadata or {},
123 122
             'partitions': partitions or {},
124 123
             'availability_zone': availability_zone,
@@ -476,11 +475,10 @@ class API(object):
476 475
         """Lock the given server."""
477 476
 
478 477
         is_owner = server.project_id == context.project_id
479
-        if server.locked and is_owner:
478
+        if server.locked_by and is_owner:
480 479
             return
481 480
 
482 481
         LOG.debug('Locking server: %s', server.uuid)
483
-        server.locked = True
484 482
         server.locked_by = 'owner' if is_owner else 'admin'
485 483
         server.save()
486 484
 
@@ -488,7 +486,6 @@ class API(object):
488 486
         """Unlock the given server."""
489 487
 
490 488
         LOG.debug('Unlocking server: %s', server.uuid)
491
-        server.locked = False
492 489
         server.locked_by = None
493 490
         server.save()
494 491
 
@@ -700,7 +697,6 @@ class API(object):
700 697
             'power_state': states.NOSTATE,
701 698
             'name': name,
702 699
             'description': description,
703
-            'locked': False,
704 700
             'metadata': metadata or {},
705 701
             'availability_zone': None}
706 702
 

+ 0
- 2
mogan/notifications/objects/server.py View File

@@ -31,7 +31,6 @@ class ServerPayload(base.NotificationPayloadBase):
31 31
         'power_state': ('server', 'power_state'),
32 32
         'flavor_uuid': ('server', 'flavor_uuid'),
33 33
         'description': ('server', 'description'),
34
-        'locked': ('server', 'locked'),
35 34
         'locked_by': ('server', 'locked_by'),
36 35
         'affinity_zone': ('server', 'affinity_zone'),
37 36
         'metadata': ('server', 'metadata'),
@@ -55,7 +54,6 @@ class ServerPayload(base.NotificationPayloadBase):
55 54
         'launched_at': fields.DateTimeField(nullable=True),
56 55
         'updated_at': fields.DateTimeField(nullable=True),
57 56
         'status': fields.StringField(nullable=True),
58
-        'locked': fields.BooleanField(nullable=True),
59 57
         'locked_by': fields.StringField(nullable=True),
60 58
         'affinity_zone': fields.StringField(nullable=True),
61 59
         'metadata': fields.FlexibleDictField(nullable=True),

+ 0
- 1
mogan/objects/server.py View File

@@ -54,7 +54,6 @@ class Server(base.MoganObject, object_base.VersionedObjectDictCompat):
54 54
         'launched_at': object_fields.DateTimeField(nullable=True),
55 55
         'metadata': object_fields.FlexibleDictField(nullable=True),
56 56
         'partitions': object_fields.FlexibleDictField(nullable=True),
57
-        'locked': object_fields.BooleanField(default=False),
58 57
         'locked_by': object_fields.StringField(nullable=True),
59 58
         'affinity_zone': object_fields.StringField(nullable=True),
60 59
         'key_name': object_fields.StringField(nullable=True),

+ 0
- 1
mogan/tests/unit/db/utils.py View File

@@ -64,7 +64,6 @@ def get_test_server(**kw):
64 64
         'partitions': kw.get('partitions', {}),
65 65
         'updated_at': kw.get('updated_at'),
66 66
         'created_at': kw.get('created_at'),
67
-        'locked': kw.get('locked', False),
68 67
         'locked_by': kw.get('locked_by', None),
69 68
         'affinity_zone': kw.get('affinity_zone', 'ZON1'),
70 69
         'key_name': kw.get('key_name', 'test_key')

+ 8
- 12
mogan/tests/unit/engine/test_engine_api.py View File

@@ -237,16 +237,14 @@ class ComputeAPIUnitTest(base.DbTestCase):
237 237
             user_id=self.user_id, project_id=self.project_id)
238 238
         fake_server_obj = self._create_fake_server_obj(fake_server)
239 239
         self.engine_api.lock(self.context, fake_server_obj)
240
-        self.assertTrue(fake_server_obj.locked)
241 240
         self.assertEqual('owner', fake_server_obj.locked_by)
242 241
 
243 242
     def test_unlock_by_owner(self):
244 243
         fake_server = db_utils.get_test_server(
245 244
             user_id=self.user_id, project_id=self.project_id,
246
-            locked=True, locked_by='owner')
245
+            locked_by='owner')
247 246
         fake_server_obj = self._create_fake_server_obj(fake_server)
248 247
         self.engine_api.unlock(self.context, fake_server_obj)
249
-        self.assertFalse(fake_server_obj.locked)
250 248
         self.assertIsNone(fake_server_obj.locked_by)
251 249
 
252 250
     def test_lock_by_admin(self):
@@ -255,24 +253,22 @@ class ComputeAPIUnitTest(base.DbTestCase):
255 253
         fake_server_obj = self._create_fake_server_obj(fake_server)
256 254
         admin_context = context.get_admin_context()
257 255
         self.engine_api.lock(admin_context, fake_server_obj)
258
-        self.assertTrue(fake_server_obj.locked)
259 256
         self.assertEqual('admin', fake_server_obj.locked_by)
260 257
 
261 258
     def test_unlock_by_admin(self):
262 259
         fake_server = db_utils.get_test_server(
263 260
             user_id=self.user_id, project_id=self.project_id,
264
-            locked=True, locked_by='owner')
261
+            locked_by='owner')
265 262
         fake_server_obj = self._create_fake_server_obj(fake_server)
266 263
         admin_context = context.get_admin_context()
267 264
         self.engine_api.unlock(admin_context, fake_server_obj)
268
-        self.assertFalse(fake_server_obj.locked)
269 265
         self.assertIsNone(fake_server_obj.locked_by)
270 266
 
271 267
     @mock.patch('mogan.engine.api.API._delete_server')
272 268
     def test_delete_locked_server_with_non_admin(self, mock_deleted):
273 269
         fake_server = db_utils.get_test_server(
274 270
             user_id=self.user_id, project_id=self.project_id,
275
-            locked=True, locked_by='owner')
271
+            locked_by='owner')
276 272
         fake_server_obj = self._create_fake_server_obj(fake_server)
277 273
         self.assertRaises(exception.ServerIsLocked,
278 274
                           self.engine_api.delete,
@@ -283,7 +279,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
283 279
     def test_power_locked_server_with_non_admin(self, mock_powered):
284 280
         fake_server = db_utils.get_test_server(
285 281
             user_id=self.user_id, project_id=self.project_id,
286
-            locked=True, locked_by='owner')
282
+            locked_by='owner')
287 283
         fake_server_obj = self._create_fake_server_obj(fake_server)
288 284
         self.assertRaises(exception.ServerIsLocked,
289 285
                           self.engine_api.power,
@@ -294,7 +290,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
294 290
     def test_delete_locked_server_with_admin(self, mock_deleted):
295 291
         fake_server = db_utils.get_test_server(
296 292
             user_id=self.user_id, project_id=self.project_id,
297
-            locked=True, locked_by='owner')
293
+            locked_by='owner')
298 294
         fake_server_obj = self._create_fake_server_obj(fake_server)
299 295
         admin_context = context.get_admin_context()
300 296
         self.engine_api.delete(admin_context, fake_server_obj)
@@ -304,7 +300,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
304 300
     def test_power_locked_server_with_admin(self, mock_powered):
305 301
         fake_server = db_utils.get_test_server(
306 302
             user_id=self.user_id, project_id=self.project_id,
307
-            locked=True, locked_by='owner')
303
+            locked_by='owner')
308 304
         fake_server_obj = self._create_fake_server_obj(fake_server)
309 305
         admin_context = context.get_admin_context()
310 306
         self.engine_api.power(admin_context, fake_server_obj, 'reboot')
@@ -314,7 +310,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
314 310
     def test_rebuild_locked_server_with_non_admin(self, mock_rebuild):
315 311
         fake_server = db_utils.get_test_server(
316 312
             user_id=self.user_id, project_id=self.project_id,
317
-            locked=True, locked_by='owner')
313
+            locked_by='owner')
318 314
         fake_server_obj = self._create_fake_server_obj(fake_server)
319 315
         self.assertRaises(exception.ServerIsLocked,
320 316
                           self.engine_api.rebuild,
@@ -327,7 +323,7 @@ class ComputeAPIUnitTest(base.DbTestCase):
327 323
                                               mock_get_image):
328 324
         fake_server = db_utils.get_test_server(
329 325
             user_id=self.user_id, project_id=self.project_id,
330
-            locked=True, locked_by='owner')
326
+            locked_by='owner')
331 327
         fake_server_obj = self._create_fake_server_obj(fake_server)
332 328
         admin_context = context.get_admin_context()
333 329
         mock_get_image.side_effect = None

+ 2
- 2
mogan/tests/unit/notifications/test_notification.py View File

@@ -226,9 +226,9 @@ class TestNotificationBase(test_base.TestCase):
226 226
 
227 227
 
228 228
 notification_object_data = {
229
-    'ServerPayload': '1.0-55ce3a2c615a32c80b152aaf2b905703',
229
+    'ServerPayload': '1.0-30fefa8478f1b9b35c66868377fb6dfd',
230 230
     'ServerAddressesPayload': '1.0-69caf4c36f36756bb1f6970d093ee1f6',
231
-    'ServerActionPayload': '1.0-a22c2f18b8dd17a3990e5b4c64989d26',
231
+    'ServerActionPayload': '1.0-8dc4429afa34d86ab92c9387e3ccd0c3',
232 232
     'ServerActionNotification': '1.0-20087e599436bd9db62ae1fb5e2dfef2',
233 233
     'ExceptionPayload': '1.0-7c31986d8d78bed910c324965c431e18',
234 234
     'EventType': '1.0-93493dd78bdfed806fca70c91d85cbb4',

+ 1
- 1
mogan/tests/unit/objects/test_objects.py View File

@@ -382,7 +382,7 @@ class _TestObject(object):
382 382
 # version bump. It is md5 hash of object fields and remotable methods.
383 383
 # The fingerprint values should only be changed if there is a version bump.
384 384
 expected_object_fingerprints = {
385
-    'Server': '1.0-6b13b984cd3656a977456a12d3d1c167',
385
+    'Server': '1.0-1480ee88a244bf44492f61f20a022a6f',
386 386
     'ServerFault': '1.0-74349ff701259e4834b4e9dc2dac1b12',
387 387
     'ServerFaultList': '1.0-43e8aad0258652921f929934e9e048fd',
388 388
     'Flavor': '1.0-9f7166aa387d89ec40cd699019d0c9a9',

Loading…
Cancel
Save