3636
3737import os
3838import subprocess
39+ import logging
3940
4041
4142_multiprocess_shared_ = True
170171 "enabledrevocationcheck" : False
171172}
172173
173- USER_DATA = """I2Nsb3VkLWNvbmZpZwoKcnVuY21kOgogIC0gc3VkbyBhcHQtZ2V0IHVwZGF0Z
174- QogIC0gc3VkbyBhcHQtZ2V0IGluc3RhbGwgLXkgYXBhY2hlMgogIC0gc3Vkby
175- BzeXN0ZW1jdGwgZW5hYmxlIGFwYWNoZTIKICAtIHN1ZG8gc3lzdGVtY3RsIHN0
176- YXJ0IGFwYWNoZTIKICAtIGVjaG8gIlRlc3QgcGFnZSIgfHN1ZG8gdGVlIC92YX
177- Ivd3d3L2h0bWwvaW5kZXguaHRtbAoKCg=="""
174+ # Install apache2 via userdata
175+ USER_DATA = """I2Nsb3VkLWNvbmZpZwpydW5jbWQ6CiAgLSBzdWRvIGFwdC1nZXQgdXBkYXRlCiAgLSBzdWRvIGFw
176+ dC1nZXQgaW5zdGFsbCAteSBhcGFjaGUyCiAgLSBzdWRvIHN5c3RlbWN0bCBlbmFibGUgYXBhY2hl
177+ MgogIC0gc3VkbyBzeXN0ZW1jdGwgc3RhcnQgYXBhY2hlMgogIC0gZWNobyAiVGVzdCBwYWdlIiB8
178+ c3VkbyB0ZWUgL3Zhci93d3cvaHRtbC90ZXN0Lmh0bWwK"""
179+ # #cloud-config
180+ # runcmd:
181+ # - sudo apt-get update
182+ # - sudo apt-get install -y apache2
183+ # - sudo systemctl enable apache2
184+ # - sudo systemctl start apache2
185+ # - echo "Test page" |sudo tee /var/www/html/test.html
178186
179187class TestSslOffloading (cloudstackTestCase ):
180188
@@ -243,6 +251,11 @@ def setUpClass(cls):
243251 cls .user = cls .account .user [0 ]
244252 cls .userapiclient = cls .testClient .getUserApiClient (cls .user .username , cls .domain .name )
245253
254+ cls .logger = logging .getLogger ("TestSslOffloading" )
255+ cls .stream_handler = logging .StreamHandler ()
256+ cls .logger .setLevel (logging .DEBUG )
257+ cls .logger .addHandler (cls .stream_handler )
258+
246259 def setUp (self ):
247260 self .apiclient = self .testClient .getApiClient ()
248261 self .cleanup = []
@@ -253,30 +266,32 @@ def tearDown(self):
253266 @classmethod
254267 def tearDownClass (cls ):
255268 super (TestSslOffloading , cls ).tearDownClass ()
269+ # Remove full chain file
256270 if os .path .exists (FULL_CHAIN ):
257271 os .remove (FULL_CHAIN )
258272
259273 def wait_for_service_ready (self , command , expected , retries = 60 ):
260274 output = None
275+ self .logger .debug ("======================================" )
276+ self .logger .debug ("Checking output of command '%s', expected result: '%s'" % (command , expected ))
261277 def check_output ():
262278 try :
263- output = subprocess .check_output (command , shell = True ).strip ().decode ('utf-8' )
279+ output = subprocess .check_output (command + ' 2>&1' , shell = True ).strip ().decode ('utf-8' )
264280 except Exception as e :
265- print ("Failed to get output of command %s: %s " % (command , e ))
281+ self . logger . debug ("Failed to get output of command '%s': '%s' " % (command , e ))
266282 if expected is None :
267- print ("But it is expected" )
283+ self . logger . debug ("But it is expected" )
268284 return True , None
269285 return False , None
270- print ("Output of command %s: \n %s " % (command , output ))
286+ self . logger . debug ("Output of command '%s' is '%s' " % (command , output ))
271287 if expected is None :
272- print ("But it is expected to be None" )
288+ self . logger . debug ("But it is expected to be None" )
273289 return False , None
274290 return (expected in output ), None
275291
276- res = wait_until (10 , retries , check_output )
292+ res , _ = wait_until (10 , retries , check_output )
277293 if not res :
278294 self .fail ("Failed to wait for http server to show content '%s'. The output is '%s'" % (expected , output ))
279- return res
280295
281296 @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
282297 def test_01_ssl_offloading_isolated_network (self ):
@@ -355,7 +370,7 @@ def test_01_ssl_offloading_isolated_network(self):
355370 networkid = self .network .id
356371 )
357372 lb_rule_http .assign (self .apiclient , [self .vm_1 ])
358- command = "curl -L --connect-timeout 3 http://%s/" % self .public_ip .ipaddress .ipaddress
373+ command = "curl -sL --connect-timeout 3 http://%s/test.html " % self .public_ip .ipaddress .ipaddress
359374 # wait 10 minutes until the webpage is available. it returns "503 Service Unavailable" if not available
360375 self .wait_for_service_ready (command , CONTENT , 60 )
361376
@@ -378,23 +393,23 @@ def test_01_ssl_offloading_isolated_network(self):
378393 )
379394 lb_rule_https .assign (self .apiclient , [self .vm_1 ])
380395
381- command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
396+ command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
382397 self .wait_for_service_ready (command , None , 1 )
383398
384- command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
399+ command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
385400 self .wait_for_service_ready (command , None , 1 )
386401
387402 # 4. add cert to LB with port 443
388403 lb_rule_https .assignCert (self .apiclient , self .sslcert .id )
389404
390405 # 5. verify the website (should get expected content)
391- command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
392- self .wait_for_service_ready (command , "SSL certificate problem" , 1 )
406+ command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
407+ self .wait_for_service_ready (command , None , 1 )
393408
394- command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
409+ command = "curl -sL --connect-timeout 3 -k --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
395410 self .wait_for_service_ready (command , CONTENT , 1 )
396411
397- command = "curl -L --connect-timeout 3 --cacert %s --resolve %s:443:%s https://%s/" % (FULL_CHAIN , DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
412+ command = "curl -sL --connect-timeout 3 --cacert %s --resolve %s:443:%s https://%s/test.html " % (FULL_CHAIN , DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
398413 self .wait_for_service_ready (command , CONTENT , 1 )
399414
400415 # 6. remove cert from LB with port 443
@@ -505,7 +520,7 @@ def test_02_ssl_offloading_project_vpc(self):
505520 projectid = self .project .id
506521 )
507522 lb_rule_http .assign (self .userapiclient , [self .vm_2 ])
508- command = "curl -L --connect-timeout 3 http://%s/" % self .public_ip .ipaddress .ipaddress
523+ command = "curl -sL --connect-timeout 3 http://%s/test.html " % self .public_ip .ipaddress .ipaddress
509524 # wait 10 minutes until the webpage is available. it returns "503 Service Unavailable" if not available
510525 self .wait_for_service_ready (command , CONTENT , 60 )
511526
@@ -527,23 +542,23 @@ def test_02_ssl_offloading_project_vpc(self):
527542 )
528543 lb_rule_https .assign (self .userapiclient , [self .vm_2 ])
529544
530- command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
545+ command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
531546 self .wait_for_service_ready (command , None , 1 )
532547
533- command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
548+ command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
534549 self .wait_for_service_ready (command , None , 1 )
535550
536551 # 4. add cert to LB with port 443
537552 lb_rule_https .assignCert (self .userapiclient , self .sslcert .id )
538553
539554 # 5. verify the website (should get expected content)
540- command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
541- self .wait_for_service_ready (command , "SSL certificate problem" , 1 )
555+ command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
556+ self .wait_for_service_ready (command , None , 1 )
542557
543- command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
558+ command = "curl -sL --connect-timeout 3 -k --resolve %s:443:%s https://%s/test.html " % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
544559 self .wait_for_service_ready (command , CONTENT , 1 )
545560
546- command = "curl -L --connect-timeout 3 --cacert %s --resolve %s:443:%s https://%s/" % (FULL_CHAIN , DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
561+ command = "curl -sL --connect-timeout 3 --cacert %s --resolve %s:443:%s https://%s/test.html " % (FULL_CHAIN , DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
547562 self .wait_for_service_ready (command , CONTENT , 1 )
548563
549564 # 6. remove cert from LB with port 443
0 commit comments