Skip to content

Commit 1ec9658

Browse files
author
Riddhi Nilawar
committed
added UT
1 parent a8f5e11 commit 1ec9658

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/azure-cli/azure/cli/command_modules/network/tests/latest/test_nw_flow_log.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,63 @@ def test_nw_flow_log_create_vnetfl_with_filtering(self, resource_group, resource
163163
self.check('retentionPolicy.enabled', False),
164164
])
165165

166+
@ResourceGroupPreparer(name_prefix='test_nw_flow_log_', location='centraluseuap')
167+
@StorageAccountPreparer(name_prefix='testflowlog', location='centraluseuap', kind='StorageV2')
168+
def test_nw_flow_log_create_vnetfl_with_filtering(self, resource_group, resource_group_location, storage_account):
169+
self.kwargs.update({
170+
'rg': resource_group,
171+
'location': resource_group_location,
172+
'storage_account': storage_account,
173+
'vnet': 'vnet1',
174+
'subnet': 'subnet1',
175+
'nic': 'nic1',
176+
'watcher_rg': 'NetworkWatcherRG',
177+
'watcher_name': 'NetworkWatcher_{}'.format(resource_group_location),
178+
'flow_log': 'flow_log_test',
179+
'record_types': 'B,E',
180+
'workspace': self.create_random_name('clitest', 20),
181+
})
182+
183+
# enable network watcher
184+
# self.cmd('network watcher configure -g {rg} --locations {location} --enabled')
185+
186+
# prepare the target resource
187+
self.cmd('network vnet create -g {rg} -n {vnet}')
188+
self.cmd('network vnet subnet create -g {rg} --vnet-name {vnet} -n {subnet} --address-prefix 10.0.0.0/24')
189+
self.cmd('network nic create -g {rg} -n {nic} --vnet-name {vnet} --subnet {subnet}')
190+
191+
# prepare workspace
192+
workspace = self.cmd('monitor log-analytics workspace create '
193+
'--resource-group {rg} '
194+
'--location eastus '
195+
'--workspace-name {workspace} ').get_output_in_json()
196+
self.kwargs.update({
197+
'workspace_id': workspace['id']
198+
})
199+
200+
#targetId as vnet
201+
self.cmd('network watcher flow-log create '
202+
'--location {location} '
203+
'--resource-group {rg} '
204+
'--vnet {vnet} '
205+
'--storage-account {storage_account} '
206+
'--record-types {record_types} '
207+
'--workspace {workspace_id} '
208+
'--name {flow_log} ')
209+
210+
self.cmd('network watcher flow-log list --location {location}')
211+
212+
# This output is Azure Management Resource formatted.
213+
self.cmd('network watcher flow-log show --location {location} --name {flow_log}', checks=[
214+
self.check('name', self.kwargs['flow_log']),
215+
self.check('recordTypes', '.*/{record_types}$'),
216+
self.check('flowAnalyticsConfiguration.networkWatcherFlowAnalyticsConfiguration.workspaceResourceId',
217+
self.kwargs['workspace_id']),
218+
self.check_pattern('targetResourceId', '.*/{vnet}$'),
219+
self.check('retentionPolicy.days', 0),
220+
self.check('retentionPolicy.enabled', False),
221+
])
222+
166223
@ResourceGroupPreparer(name_prefix='test_nw_flow_log_', location='centraluseuap')
167224
@StorageAccountPreparer(name_prefix='testflowlog', location='centraluseuap', kind='StorageV2')
168225
def test_nw_flow_log_create_vnetflWithManagedIdentity(self, resource_group, resource_group_location, storage_account):

0 commit comments

Comments
 (0)