Exemplo n.º 1
0
    def test_event_grid_mode_creates_advanced_filtered_subscription_with_multiple_events(self):
        p = self.load_policy({
            'name': 'test-azure-event',
            'resource': 'azure.vm',
            'mode':
                {'type': FUNCTION_EVENT_TRIGGER_MODE,
                 'events':
                     ['VmWrite',
                        {
                            'resourceProvider': 'Microsoft.Resources/subscriptions/resourceGroups',
                            'event': 'write'
                        }]},
        })

        with mock.patch('c7n_azure.azure_events.AzureEventSubscription.create') as mock_create:
            storage_account = StorageAccount(id=1, location='westus')
            event_mode = AzureEventGridMode(p)
            event_mode._create_event_subscription(storage_account, 'some_queue', None)

            name, args, kwargs = mock_create.mock_calls[0]

            # verify the advanced filter created
            event_filter = args[3].advanced_filters[0]
            self.assertEqual(event_filter.key, 'Data.OperationName')
            self.assertEqual(event_filter.values,
                             ['Microsoft.Compute/virtualMachines/write',
                              'Microsoft.Resources/subscriptions/resourceGroups/write'])
            self.assertEqual(event_filter.operator_type, 'StringIn')
Exemplo n.º 2
0
    def test_event_grid_mode_creates_advanced_filtered_subscription_with_multiple_events(self):
        p = self.load_policy({
            'name': 'test-azure-event',
            'resource': 'azure.vm',
            'mode':
                {'type': FUNCTION_EVENT_TRIGGER_MODE,
                 'events':
                     ['VmWrite',
                        {
                            'resourceProvider': 'Microsoft.Resources/subscriptions/resourceGroups',
                            'event': 'write'
                        }]},
        })

        with mock.patch('c7n_azure.azure_events.AzureEventSubscription.create') as mock_create:
            storage_account = StorageAccount(id=1, location='westus')
            event_mode = AzureEventGridMode(p)
            event_mode.target_subscription_ids = [DEFAULT_SUBSCRIPTION_ID]
            event_mode._create_event_subscription(storage_account, 'some_queue', None)

            name, args, kwargs = mock_create.mock_calls[0]

            # verify the advanced filter created
            event_filter = args[4].advanced_filters[0]
            self.assertEqual(event_filter.key, 'Data.OperationName')
            self.assertEqual(event_filter.values,
                             ['Microsoft.Compute/virtualMachines/write',
                              'Microsoft.Resources/subscriptions/resourceGroups/write'])
            self.assertEqual(event_filter.operator_type, 'StringIn')
Exemplo n.º 3
0
    def test_event_grid_mode_creates_advanced_filtered_subscription(self):
        p = self.load_policy({
            'name': 'test-azure-event',
            'resource': 'azure.vm',
            'mode': {
                'type': FUNCTION_EVENT_TRIGGER_MODE,
                'events': ['VmWrite']
            },
        })

        with mock.patch('c7n_azure.azure_events.AzureEventSubscription.create'
                        ) as mock_create:
            storage_account = MockStorageAccount()
            event_mode = AzureEventGridMode(p)
            event_mode._create_event_subscription(storage_account,
                                                  'some_queue', None)

            name, args, kwargs = mock_create.mock_calls[0]

            # verify the advanced filter created
            event_filter = args[3].advanced_filters[0]
            self.assertEqual(event_filter.key, 'Data.OperationName')
            self.assertEqual(event_filter.values,
                             ['Microsoft.Compute/virtualMachines/write'])
            self.assertEqual(event_filter.operator_type, 'StringIn')