def publish_exists_event(self, context): """ Push this in Instance Tasks to fetch a report/collection :param context: currently None as specied in bin script """ mgmtmodels.publish_exist_events(self.exists_transformer, self.admin_context)
def test_public_exists_events(self): status = rd_instance.ServiceStatuses.BUILDING.api_status instance, service_status = self.build_db_instance( status, task_status=InstanceTasks.BUILDING) server = MagicMock(spec=Server) server.user_id = 'test_user_id' mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context, instance, server, service_status) flavor = MagicMock(spec=Flavor) flavor.name = 'db.small' notifier = MagicMock() with patch.object(rpc, 'get_notifier', return_value=notifier): with patch.object(mgmtmodels, 'load_mgmt_instances', return_value=[mgmt_instance]): with patch.object(self.flavor_mgr, 'get', return_value=flavor): self.assertThat(self.context.auth_token, Is('some_secret_password')) with patch.object(notifier, 'info', return_value=None): # invocation mgmtmodels.publish_exist_events( mgmtmodels.NovaNotificationTransformer( context=self.context), self.context) # assertion notifier.info.assert_any_call(self.context, 'trove.instance.exists', ANY) self.assertThat(self.context.auth_token, Is(None)) self.addCleanup(self.do_cleanup, instance, service_status)
def test_public_exists_events(self): status = rd_instance.ServiceStatuses.BUILDING.api_status instance, service_status = self.build_db_instance( status, task_status=InstanceTasks.BUILDING) server = MagicMock(spec=Server) server.user_id = 'test_user_id' mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context, instance, server, service_status) flavor = MagicMock(spec=Flavor) flavor.name = 'db.small' notifier = MagicMock() with patch.object(rpc, 'get_notifier', return_value=notifier): with patch.object(mgmtmodels, 'load_mgmt_instances', return_value=[mgmt_instance]): with patch.object(self.flavor_mgr, 'get', return_value=flavor): self.assertThat(self.context.auth_token, Is('some_secret_password')) with patch.object(notifier, 'info', return_value=None): # invocation mgmtmodels.publish_exist_events( mgmtmodels.NovaNotificationTransformer( context=self.context), self.context) # assertion notifier.info.assert_any_call( self.context, 'trove.instance.exists', ANY) self.assertThat(self.context.auth_token, Is(None)) self.addCleanup(self.do_cleanup, instance, service_status)
def test_public_exists_events(self): status = ServiceStatuses.BUILDING.api_status db_instance = DBInstance( InstanceTasks.BUILDING, created="xyz", name="test_name", id="1", flavor_id="flavor_1", compute_instance_id="compute_id_1", server_id="server_id_1", tenant_id="tenant_id_1", server_status=status, ) server = mock(Server) server.user_id = "test_user_id" mgmt_instance = SimpleMgmtInstance(self.context, db_instance, server, None) when(mgmtmodels).load_mgmt_instances(self.context, deleted=False, client=self.client).thenReturn( [mgmt_instance, mgmt_instance] ) flavor = mock(Flavor) flavor.name = "db.small" when(self.flavor_mgr).get("flavor_1").thenReturn(flavor) self.assertThat(self.context.auth_token, Is("some_secret_password")) when(notifier).notify(self.context, any(str), "trove.instance.exists", "INFO", any(dict)).thenReturn(None) # invocation mgmtmodels.publish_exist_events(NovaNotificationTransformer(context=self.context), self.context) # assertion verify(notifier, times=2).notify(self.context, any(str), "trove.instance.exists", "INFO", any(dict)) self.assertThat(self.context.auth_token, Is(None))
def test_public_exists_events(self): status = rd_instance.ServiceStatuses.BUILDING.api_status db_instance = MockMgmtInstanceTest.build_db_instance( status, task_status=InstanceTasks.BUILDING) server = mock(Server) server.user_id = 'test_user_id' mgmt_instance = mgmtmodels.SimpleMgmtInstance(self.context, db_instance, server, None) when(mgmtmodels).load_mgmt_instances(self.context, deleted=False, client=self.client).thenReturn([ mgmt_instance, mgmt_instance ]) flavor = mock(Flavor) flavor.name = 'db.small' when(self.flavor_mgr).get('flavor_1').thenReturn(flavor) self.assertThat(self.context.auth_token, Is('some_secret_password')) when(notifier).notify(self.context, any(str), 'trove.instance.exists', 'INFO', any(dict)).thenReturn(None) # invocation mgmtmodels.publish_exist_events( mgmtmodels.NovaNotificationTransformer(context=self.context), self.context) # assertion verify(notifier, times=2).notify(self.context, any(str), 'trove.instance.exists', 'INFO', any(dict)) self.assertThat(self.context.auth_token, Is(None))
def test_public_exists_events(self): status = rd_instance.ServiceStatuses.BUILDING.api_status db_instance = DBInstance(InstanceTasks.BUILDING, created='xyz', name='test_name', id='1', flavor_id='flavor_1', compute_instance_id='compute_id_1', server_id='server_id_1', tenant_id='tenant_id_1', server_status=status) server = mock(Server) server.user_id = 'test_user_id' mgmt_instance = SimpleMgmtInstance(self.context, db_instance, server, None) when(mgmtmodels).load_mgmt_instances( self.context, deleted=False, client=self.client).thenReturn( [mgmt_instance, mgmt_instance]) flavor = mock(Flavor) flavor.name = 'db.small' when(self.flavor_mgr).get('flavor_1').thenReturn(flavor) self.assertThat(self.context.auth_token, Is('some_secret_password')) when(notifier).notify(self.context, any(str), 'trove.instance.exists', 'INFO', any(dict)).thenReturn(None) # invocation mgmtmodels.publish_exist_events( NovaNotificationTransformer(context=self.context), self.context) # assertion verify(notifier, times=2).notify(self.context, any(str), 'trove.instance.exists', 'INFO', any(dict)) self.assertThat(self.context.auth_token, Is(None))