2323import json
2424import random
2525import datetime
26+ import subprocess
2627from envassert import file , process , package , user , group , port , cron , detect , ip
2728import copy
29+ from fabric import state
2830
2931try :
3032 from . import SystemVMTestCase , has_line , print_doc
@@ -144,7 +146,7 @@ class UpdateConfigTestCase(SystemVMTestCase):
144146
145147 def update_config (self , config ):
146148 config_json = json .dumps (config , indent = 2 )
147- print_doc ('config.json' , config_json )
149+ # print_doc('config.json', config_json)
148150 file_write ('/var/cache/cloud/update_config_test.json' , config_json )
149151 with hide ("everything" ):
150152 result = run ("python /opt/cloud/bin/update_config.py update_config_test.json" ,
@@ -164,7 +166,8 @@ def check_no_errors(self):
164166 # todo config update should exit 1 on convergence errors!
165167 found , context = has_line ('/var/log/cloud.log' , 'cannot be configured' )
166168 if found :
167- print_doc ('/var/log/cloud.log' , context )
169+ #print_doc('/var/log/cloud.log', context)
170+ pass
168171 assert not found , 'cloud.log should not contain "cannot be configured"'
169172
170173 @attr (tags = ["systemvm" ], required_hardware = "true" )
@@ -252,7 +255,21 @@ def test_create_guest_network(self):
252255 self .guest_network (config )
253256
254257 def check_acl (self , list ):
255- # clear all acls
258+ clear1 = self .clear_all_acls ()
259+ clear2 = self .clear_all_acls ()
260+ assert clear1 == clear2 , "Clear all acls called twice and produced different results"
261+ unique = {}
262+
263+ # How many unique devices
264+ for ips in list :
265+ unique ["eth%s" % ips ["nic_dev_id" ]] = 1
266+
267+ # If this is the first run, the drops will not be there yet
268+ # this is so I can get get a true count of what is explicitly added
269+ drops = len (unique )
270+ for dev in unique :
271+ drops -= ip .count_fw_rules ('ACL_INBOUND_%s -j DROP' % dev )
272+
256273 for ips in list :
257274 config = copy .deepcopy (self .basic_network_acl )
258275 config ['device' ] = "eth%s" % ips ["nic_dev_id" ]
@@ -262,11 +279,29 @@ def check_acl(self, list):
262279 config ['egress_rules' ].append (rule )
263280 self .update_config (config )
264281
265- #def count_acls(self):
266- #p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
267- #result = p.communicate()[0]
268- #for i in result.splitlines():
282+ # Check the default drop rules are there
283+ for dev in unique :
284+ drop = ip . count_fw_rules ( 'ACL_INBOUND_%s -j DROP' % dev )
285+ assert drop == 1 , "ACL_INBOUND_%s does not have a default drop rule" % dev
269286
287+ after = ip .count_fw_rules ()
288+ # How many new acls should we get?
289+ # The number of rules * the number of devices * 2 (in and out)
290+ expected = len (unique ) * 2 * len (self .basic_acl_rules ) + clear2 + drops
291+ assert expected == after , "Number of acl rules does not match what I expected to see"
292+ for dev in range (6 ):
293+ config = copy .deepcopy (self .basic_network_acl )
294+ config ['device' ] = "eth%s" % dev
295+ self .update_config (config )
296+ clear2 = self .clear_all_acls () - drops
297+ assert clear1 == clear2 , "Clear all acls appears to have failed"
298+
299+ def clear_all_acls (self ):
300+ for dev in range (6 ):
301+ config = copy .deepcopy (self .basic_network_acl )
302+ config ['device' ] = "eth%s" % dev
303+ self .update_config (config )
304+ return ip .count_fw_rules ()
270305
271306 def check_password (self ,passw ):
272307 for val in passw :
@@ -318,5 +353,4 @@ def guest_network(self,config):
318353 assert file .has_line ("/etc/dhcphosts.txt" , line ) is False
319354
320355if __name__ == '__main__' :
321- import unittest
322356 unittest .main ()
0 commit comments