Transform keypair.import notification
The keypair.import.start and keypair.import.end notifications has been transformed to the versioned notification framework. Change-Id: Icadc53d84fa021aae0f9ec2e18e9125de98e00f6 Implements: bp versioned-notification-transformation-queens
This commit is contained in:
parent
aa4da3ff61
commit
a4c7ab8851
17
doc/notification_samples/keypair-import-end.json
Normal file
17
doc/notification_samples/keypair-import-end.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"priority": "INFO",
|
||||
"payload": {
|
||||
"nova_object.version": "1.0",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.name": "KeypairPayload",
|
||||
"nova_object.data": {
|
||||
"user_id": "fake",
|
||||
"name": "my-key",
|
||||
"fingerprint": "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated-by-Nova",
|
||||
"type": "ssh"
|
||||
}
|
||||
},
|
||||
"event_type": "keypair.import.end",
|
||||
"publisher_id": "nova-api:fake-mini"
|
||||
}
|
17
doc/notification_samples/keypair-import-start.json
Normal file
17
doc/notification_samples/keypair-import-start.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"priority": "INFO",
|
||||
"payload": {
|
||||
"nova_object.version": "1.0",
|
||||
"nova_object.namespace": "nova",
|
||||
"nova_object.name": "KeypairPayload",
|
||||
"nova_object.data": {
|
||||
"user_id": "fake",
|
||||
"name": "my-key",
|
||||
"fingerprint": null,
|
||||
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated-by-Nova",
|
||||
"type": "ssh"
|
||||
}
|
||||
},
|
||||
"event_type": "keypair.import.start",
|
||||
"publisher_id": "nova-api:fake-mini"
|
||||
}
|
@ -4815,16 +4815,29 @@ class KeypairAPI(base.Base):
|
||||
|
||||
self._notify(context, 'import.start', key_name)
|
||||
|
||||
fingerprint = self._generate_fingerprint(public_key, key_type)
|
||||
|
||||
keypair = objects.KeyPair(context)
|
||||
keypair.user_id = user_id
|
||||
keypair.name = key_name
|
||||
keypair.type = key_type
|
||||
keypair.fingerprint = fingerprint
|
||||
keypair.fingerprint = None
|
||||
keypair.public_key = public_key
|
||||
|
||||
compute_utils.notify_about_keypair_action(
|
||||
context=context,
|
||||
keypair=keypair,
|
||||
action=fields_obj.NotificationAction.IMPORT,
|
||||
phase=fields_obj.NotificationPhase.START)
|
||||
|
||||
fingerprint = self._generate_fingerprint(public_key, key_type)
|
||||
|
||||
keypair.fingerprint = fingerprint
|
||||
keypair.create()
|
||||
|
||||
compute_utils.notify_about_keypair_action(
|
||||
context=context,
|
||||
keypair=keypair,
|
||||
action=fields_obj.NotificationAction.IMPORT,
|
||||
phase=fields_obj.NotificationPhase.END)
|
||||
self._notify(context, 'import.end', key_name)
|
||||
|
||||
return keypair
|
||||
|
@ -52,7 +52,8 @@ class EventType(NotificationObject):
|
||||
# NotificationActionField enum
|
||||
# Version 1.7: REMOVE_FIXED_IP replaced with INTERFACE_DETACH in
|
||||
# NotificationActionField enum
|
||||
VERSION = '1.7'
|
||||
# Version 1.8: IMPORT value is added to NotificationActionField enum
|
||||
VERSION = '1.8'
|
||||
|
||||
fields = {
|
||||
'object': fields.StringField(nullable=False),
|
||||
|
@ -43,6 +43,8 @@ class KeypairPayload(base.NotificationPayloadBase):
|
||||
@base.notification_sample('keypair-create-end.json')
|
||||
@base.notification_sample('keypair-delete-start.json')
|
||||
@base.notification_sample('keypair-delete-end.json')
|
||||
@base.notification_sample('keypair-import-start.json')
|
||||
@base.notification_sample('keypair-import-end.json')
|
||||
@nova_base.NovaObjectRegistry.register_notification
|
||||
class KeypairNotification(base.NotificationBase):
|
||||
# Version 1.0: Initial version
|
||||
|
@ -825,6 +825,7 @@ class NotificationAction(BaseNovaEnum):
|
||||
VOLUME_ATTACH = 'volume_attach'
|
||||
VOLUME_DETACH = 'volume_detach'
|
||||
CREATE = 'create'
|
||||
IMPORT = 'import'
|
||||
EVACUATE = 'evacuate'
|
||||
RESIZE_FINISH = 'resize_finish'
|
||||
LIVE_MIGRATION_ABORT = 'live_migration_abort'
|
||||
@ -849,7 +850,7 @@ class NotificationAction(BaseNovaEnum):
|
||||
ALL = (UPDATE, EXCEPTION, DELETE, PAUSE, UNPAUSE, RESIZE, VOLUME_SWAP,
|
||||
SUSPEND, POWER_ON, REBOOT, SHUTDOWN, SNAPSHOT, INTERFACE_ATTACH,
|
||||
POWER_OFF, SHELVE, RESUME, RESTORE, EXISTS, RESCUE, VOLUME_ATTACH,
|
||||
VOLUME_DETACH, CREATE, EVACUATE, RESIZE_FINISH,
|
||||
VOLUME_DETACH, CREATE, IMPORT, EVACUATE, RESIZE_FINISH,
|
||||
LIVE_MIGRATION_ABORT, LIVE_MIGRATION_POST_DEST, LIVE_MIGRATION_POST,
|
||||
LIVE_MIGRATION_PRE, LIVE_MIGRATION_ROLLBACK,
|
||||
LIVE_MIGRATION_ROLLBACK_DEST, REBUILD, INTERFACE_DETACH,
|
||||
|
@ -169,6 +169,16 @@ class NotificationSampleTestBase(test.TestCase,
|
||||
}}
|
||||
self.api.post_keypair(keypair_req)
|
||||
|
||||
keypair_expected_notifications = [
|
||||
'keypair-import-start',
|
||||
'keypair-import-end'
|
||||
]
|
||||
self.assertLessEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
for notification in keypair_expected_notifications:
|
||||
self._verify_notification(
|
||||
notification,
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS.pop(0))
|
||||
|
||||
server = self._build_minimal_create_server_request(
|
||||
self.api, 'some-server',
|
||||
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
|
||||
|
@ -55,3 +55,26 @@ class TestKeypairNotificationSample(
|
||||
"public_key": keypair['public_key']
|
||||
},
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[3])
|
||||
|
||||
def test_keypair_import(self):
|
||||
pub_key = ('ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGg'
|
||||
'B4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0l'
|
||||
'RE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv'
|
||||
'9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYc'
|
||||
'pSxsIbECHw== Generated-by-Nova')
|
||||
keypair_req = {
|
||||
"keypair": {
|
||||
"name": "my-key",
|
||||
"user_id": "fake",
|
||||
"public_key": pub_key,
|
||||
"type": "ssh"}}
|
||||
|
||||
self.api.post_keypair(keypair_req)
|
||||
|
||||
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS))
|
||||
self._verify_notification(
|
||||
'keypair-import-start',
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[0])
|
||||
self._verify_notification(
|
||||
'keypair-import-end',
|
||||
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
|
||||
|
@ -195,7 +195,8 @@ class CreateKeypairTestCase(KeypairAPITestCase, CreateImportSharedTestMixIn):
|
||||
class ImportKeypairTestCase(KeypairAPITestCase, CreateImportSharedTestMixIn):
|
||||
func_name = 'import_key_pair'
|
||||
|
||||
def _check_success(self):
|
||||
@mock.patch('nova.compute.utils.notify_about_keypair_action')
|
||||
def _check_success(self, mock_notify):
|
||||
keypair = self.keypair_api.import_key_pair(self.ctxt,
|
||||
self.ctxt.user_id,
|
||||
'foo',
|
||||
@ -207,6 +208,11 @@ class ImportKeypairTestCase(KeypairAPITestCase, CreateImportSharedTestMixIn):
|
||||
self.assertEqual(self.fingerprint, keypair['fingerprint'])
|
||||
self.assertEqual(self.pub_key, keypair['public_key'])
|
||||
self.assertEqual(self.keypair_type, keypair['type'])
|
||||
mock_notify.assert_has_calls([
|
||||
mock.call(context=self.ctxt, keypair=keypair,
|
||||
action='import', phase='start'),
|
||||
mock.call(context=self.ctxt, keypair=keypair,
|
||||
action='import', phase='end')])
|
||||
self._check_notifications(action='import')
|
||||
|
||||
def test_success_ssh(self):
|
||||
|
@ -373,7 +373,7 @@ notification_object_data = {
|
||||
'AuditPeriodPayload': '1.0-2b429dd307b8374636703b843fa3f9cb',
|
||||
'BandwidthPayload': '1.0-ee2616a7690ab78406842a2b68e34130',
|
||||
'BlockDevicePayload': '1.0-29751e1b6d41b1454e36768a1e764df8',
|
||||
'EventType': '1.7-3a3b2d10c77bc2ad7c3a4dd7ff2d9d9b',
|
||||
'EventType': '1.8-0f8fb2dbc76f10c7c56d1680c65ad0cf',
|
||||
'ExceptionNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
'ExceptionPayload': '1.0-27db46ee34cd97e39f2643ed92ad0cc5',
|
||||
'FlavorNotification': '1.0-a73147b93b520ff0061865849d3dfa56',
|
||||
|
Loading…
Reference in New Issue
Block a user