2323import json
2424import random
2525import datetime
26+ from envassert import file , process , package , user , group , port , cron , detect , ip
27+ import copy
2628
2729try :
2830 from . import SystemVMTestCase , has_line , print_doc
@@ -47,7 +49,8 @@ class UpdateConfigTestCase(SystemVMTestCase):
4749 "netmask" : "255.255.255.0" ,
4850 "vif_mac_address" : "06:cb:aa:00:00:03" ,
4951 "nic_dev_id" : 1 ,
50- "new_nic" : False
52+ "new_nic" : False ,
53+ "nw_type" : "public"
5154 }
5255 ],
5356 "type" : "ips"
@@ -60,7 +63,6 @@ def update_config(self, config):
6063 with hide ("everything" ):
6164 result = run ("python /opt/cloud/bin/update_config.py update_config_test.json" ,
6265 timeout = 600 , warn_only = True )
63- print result
6466 assert result .succeeded , 'update_config.py ran without errors'
6567 assert result .find ("Convergence is achieved" ) >= 0 , 'update_config.py should report convergence'
6668
@@ -90,30 +92,58 @@ def test_basic_config(self):
9092
9193 @attr (tags = ["systemvm" ], required_hardware = "true" )
9294 def test_various_random_ip_addresses (self ):
95+ buffer = []
9396 r = random .Random ()
9497 r .seed ()
9598 for i in range (0 , 10 ):
99+ ip_address = {}
96100 # todo need to know what kind of configurations are valid!
97101 config = deep_copy (self .basic_config )
98102 ip_address = deep_copy (self .basic_config ["ip_address" ][0 ])
99- ip_address ["public_ip" ] = "10.0.2.%d" % (i + 103 , )
103+ ip_address ["public_ip" ] = "10.0.2.%d" % (i + 103 )
100104 ip_address ["source_nat" ] = r .choice ((True , False ))
101- ip_address ["add" ] = r . choice (( True , False ))
105+ ip_address ["add" ] = True
102106 ip_address ["one_to_one_nat" ] = r .choice ((True , False ))
103107 ip_address ["first_i_p" ] = r .choice ((True , False ))
104- ip_address ["nic_dev_id" ] = r .choice ((2 , 3 ))
105- if ip_address ["nic_dev_id" ] > 0 :
106- ip_address ["new_nic" ] = True
107- else :
108- ip_address ["new_nic" ] = False
108+ ip_address ["nic_dev_id" ] = 3
109109 config ["ip_address" ].append (ip_address )
110110 # runs a bunch of times adding an IP address each time
111111 self .update_config (config )
112+ ip_address ["add" ] = False
113+ buffer .append (copy .deepcopy (ip_address ))
112114 self .check_no_errors ()
113115 self .clear_log ()
114- # run again with just the basic config; this should remove the IP addresses?
115- self .update_config (self .basic_config )
116+ assert ip .has_ip ("%s/24" % ip_address ["public_ip" ], "eth%s" % ip_address ["nic_dev_id" ])
117+ # Now delete all the IPs we just made
118+ for ips in buffer :
119+ config = copy .deepcopy (self .basic_config )
120+ config ["ip_address" ].append (ips )
121+ self .update_config (config )
122+ assert ip .has_ip ("%s/24" % ips ["public_ip" ], "eth%s" % ips ["nic_dev_id" ]) is False
116123
124+ def test_create_guest_network (self ):
125+ config = { "add" :True ,
126+ "mac_address" :"02:00:56:36:00:02" ,
127+ "device" :"eth4" ,
128+ "router_guest_ip" :"172.16.1.1" ,
129+ "router_guest_gateway" :"172.16.1.0" ,
130+ "router_guest_netmask" :"255.255.255.0" ,
131+ "cidr" :"24" ,
132+ "dns" :"8.8.8.8,8.8.8.4" ,
133+ "domain_name" :"devcloud.local" ,
134+ "type" :"guestnetwork"
135+ }
136+ self .update_config (config )
137+ assert ip .has_ip ("172.16.1.1/24" , "eth4" )
138+ assert process .is_up ("apache2" ) is True
139+ assert process .is_up ("dnsmasq" ) is True
140+ assert port .is_listening (80 )
141+ assert port .is_listening (53 )
142+ assert port .is_listening (53 )
143+ assert port .is_listening (67 )
144+ config ['add' ] = False
145+ self .update_config (config )
146+ assert ip .has_ip ("172.16.1.1/24" , "eth4" ) is False
117147
118148if __name__ == '__main__' :
119149 import unittest
0 commit comments