1717
1818from marvin .codes import FAILED
1919from marvin .cloudstackTestCase import cloudstackTestCase
20- from marvin .cloudstackAPI import (uploadSslCert ,
21- deleteSslCert )
2220from marvin .lib .utils import wait_until
2321from marvin .lib .base import (Account ,
22+ Project ,
2423 UserData ,
2524 SslCertificate ,
2625 Template ,
2726 NetworkOffering ,
2827 ServiceOffering ,
2928 VirtualMachine ,
3029 Network ,
30+ VPC ,
31+ VpcOffering ,
3132 PublicIPAddress ,
3233 LoadBalancerRule )
3334from marvin .lib .common import (get_domain , get_zone , get_test_template )
@@ -199,21 +200,10 @@ def setUpClass(cls):
199200 admin = True ,
200201 domainid = cls .domain .id
201202 )
202- # Register Userdata
203- cls .userdata = UserData .register (cls .apiclient ,
204- name = "test-userdata" ,
205- userdata = USER_DATA ,
206- account = cls .account .name ,
207- domainid = cls .account .domainid
208- )
209-
210- # Upload SSL Certificate, save chain as a file
211- cls .sslcert = SslCertificate .create (cls .apiclient ,
212- CERT ,
213- name = "test-ssl-certificate" ,
214- account = cls .account .name ,
215- domainid = cls .account .domainid )
203+ cls .user = cls .account .user [0 ]
204+ cls .userapiclient = cls .testClient .getUserApiClient (cls .user .username , cls .domain .name )
216205
206+ # Save full chain as a file
217207 with open (FULL_CHAIN , "w" , encoding = "utf-8" ) as f :
218208 f .write (CERT ["certchain" ])
219209
@@ -259,12 +249,12 @@ def setUp(self):
259249
260250 def tearDown (self ):
261251 super (TestSslOffloading , self ).tearDown ()
262- if os .path .exists (FULL_CHAIN ):
263- os .remove (FULL_CHAIN )
264252
265253 @classmethod
266254 def tearDownClass (cls ):
267255 super (TestSslOffloading , cls ).tearDownClass ()
256+ if os .path .exists (FULL_CHAIN ):
257+ os .remove (FULL_CHAIN )
268258
269259 def wait_for_service_ready (self , command , expected , retries = 60 ):
270260 output = None
@@ -289,7 +279,7 @@ def check_output():
289279 return res
290280
291281 @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
292- def test_01_ssl_offloading (self ):
282+ def test_01_ssl_offloading_isolated_network (self ):
293283 """Test to create Load balancing rule with SSL offloading"""
294284
295285 # Validate:
@@ -301,13 +291,29 @@ def test_01_ssl_offloading(self):
301291 # 6. remove cert from LB with port 443
302292 # 7. delete SSL certificate
303293
294+ # Register Userdata
295+ self .userdata = UserData .register (self .apiclient ,
296+ name = "test-userdata" ,
297+ userdata = USER_DATA ,
298+ account = self .account .name ,
299+ domainid = self .account .domainid
300+ )
301+
302+ # Upload SSL Certificate
303+ self .sslcert = SslCertificate .create (self .apiclient ,
304+ CERT ,
305+ name = "test-ssl-certificate" ,
306+ account = self .account .name ,
307+ domainid = self .account .domainid )
308+
304309 # 1. Create network
305310 self .network = Network .create (self .apiclient ,
306311 zoneid = self .zone .id ,
307312 services = self .services ["network" ],
308313 domainid = self .domain .id ,
309314 account = self .account .name ,
310315 networkofferingid = self .network_offering .id )
316+ self .cleanup .append (self .network )
311317
312318 self .services ["virtual_machine" ]["networkids" ] = [str (self .network .id )]
313319
@@ -321,6 +327,8 @@ def test_01_ssl_offloading(self):
321327 userdataid = self .userdata .userdata .id ,
322328 serviceofferingid = self .service_offering .id
323329 )
330+ self .cleanup .append (self .vm_1 )
331+
324332 self .public_ip = PublicIPAddress .create (
325333 self .apiclient ,
326334 self .account .name ,
@@ -394,3 +402,152 @@ def test_01_ssl_offloading(self):
394402
395403 # 7. delete SSL certificate
396404 self .sslcert .delete (self .apiclient )
405+
406+ @attr (tags = ["advanced" , "advancedns" , "smoke" ], required_hardware = "true" )
407+ def test_02_ssl_offloading_project_vpc (self ):
408+ """Test to create Load balancing rule with SSL offloading in VPC in user project"""
409+
410+ # Validate:
411+ # 1. Create VPC, VPC tier and vm instance
412+ # 2. create LB with port 80 -> 80, verify the website (should get expected content)
413+ # 3. create LB with port 443 -> 80, verify the website (should not work)
414+ # 4. add cert to LB with port 443
415+ # 5. verify the website (should get expected content)
416+ # 6. remove cert from LB with port 443
417+ # 7. delete SSL certificate
418+
419+ # Create project by user
420+ self .project = Project .create (
421+ self .userapiclient ,
422+ self .services ["project" ]
423+ )
424+ self .cleanup .append (self .project )
425+
426+ # Register Userdata by user
427+ self .userdata = UserData .register (self .userapiclient ,
428+ name = "test-user-userdata" ,
429+ userdata = USER_DATA ,
430+ projectid = self .project .id
431+ )
432+
433+ # Upload SSL Certificate by user
434+ self .sslcert = SslCertificate .create (self .userapiclient ,
435+ CERT ,
436+ name = "test-user-ssl-certificate" ,
437+ projectid = self .project .id
438+ )
439+
440+ # 1. Create VPC and VPC tier
441+ vpcOffering = VpcOffering .list (self .userapiclient , name = "Default VPC offering" )
442+ self .assertTrue (vpcOffering is not None and len (
443+ vpcOffering ) > 0 , "No VPC offerings found" )
444+
445+ self .vpc = VPC .create (
446+ apiclient = self .userapiclient ,
447+ services = self .services ["vpc_vpn" ]["vpc" ],
448+ vpcofferingid = vpcOffering [0 ].id ,
449+ zoneid = self .zone .id ,
450+ projectid = self .project .id
451+ )
452+ self .cleanup .append (self .vpc )
453+
454+ networkOffering = NetworkOffering .list (
455+ self .userapiclient , name = "DefaultIsolatedNetworkOfferingForVpcNetworks" )
456+ self .assertTrue (networkOffering is not None and len (
457+ networkOffering ) > 0 , "No VPC based network offering" )
458+
459+ self .network = Network .create (
460+ apiclient = self .userapiclient ,
461+ services = self .services ["vpc_vpn" ]["network_1" ],
462+ networkofferingid = networkOffering [0 ].id ,
463+ zoneid = self .zone .id ,
464+ vpcid = self .vpc .id ,
465+ projectid = self .project .id
466+ )
467+ self .cleanup .append (self .network )
468+
469+ self .services ["virtual_machine" ]["networkids" ] = [str (self .network .id )]
470+
471+ # Create vm instance
472+ self .vm_2 = VirtualMachine .create (
473+ self .userapiclient ,
474+ self .services ["virtual_machine" ],
475+ templateid = self .template .id ,
476+ userdataid = self .userdata .userdata .id ,
477+ serviceofferingid = self .service_offering .id ,
478+ projectid = self .project .id
479+ )
480+ self .cleanup .append (self .vm_2 )
481+
482+ self .public_ip = PublicIPAddress .create (
483+ self .userapiclient ,
484+ zoneid = self .zone .id ,
485+ services = self .services ["virtual_machine" ],
486+ networkid = self .network .id ,
487+ vpcid = self .vpc .id ,
488+ projectid = self .project .id
489+ )
490+
491+ # 2. create LB with port 80 -> 80, verify the website (should get expected content).
492+ # firewall is open by default
493+ lb_http = {
494+ "name" : "http" ,
495+ "alg" : "roundrobin" ,
496+ "privateport" : 80 ,
497+ "publicport" : 80 ,
498+ "protocol" : "tcp"
499+ }
500+ lb_rule_http = LoadBalancerRule .create (
501+ self .userapiclient ,
502+ lb_http ,
503+ self .public_ip .ipaddress .id ,
504+ networkid = self .network .id ,
505+ projectid = self .project .id
506+ )
507+ lb_rule_http .assign (self .userapiclient , [self .vm_2 ])
508+ command = "curl -L --connect-timeout 3 http://%s/" % self .public_ip .ipaddress .ipaddress
509+ # wait 10 minutes until the webpage is available. it returns "503 Service Unavailable" if not available
510+ self .wait_for_service_ready (command , CONTENT , 60 )
511+
512+ # 3. create LB with port 443 -> 80, verify the website (should not work)
513+ # firewall is open by default
514+ lb_https = {
515+ "name" : "https" ,
516+ "alg" : "roundrobin" ,
517+ "privateport" : 80 ,
518+ "publicport" : 443 ,
519+ "protocol" : "ssl"
520+ }
521+ lb_rule_https = LoadBalancerRule .create (
522+ self .userapiclient ,
523+ lb_https ,
524+ self .public_ip .ipaddress .id ,
525+ networkid = self .network .id ,
526+ projectid = self .project .id
527+ )
528+ lb_rule_https .assign (self .userapiclient , [self .vm_2 ])
529+
530+ command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
531+ self .wait_for_service_ready (command , None , 1 )
532+
533+ command = "curl -L --connect-timeout 3 --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
534+ self .wait_for_service_ready (command , None , 1 )
535+
536+ # 4. add cert to LB with port 443
537+ lb_rule_https .assignCert (self .userapiclient , self .sslcert .id )
538+
539+ # 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 )
542+
543+ command = "curl -L --connect-timeout 3 -k --resolve %s:443:%s https://%s/" % (DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
544+ self .wait_for_service_ready (command , CONTENT , 1 )
545+
546+ command = "curl -L --connect-timeout 3 --cacert %s --resolve %s:443:%s https://%s/" % (FULL_CHAIN , DOMAIN , self .public_ip .ipaddress .ipaddress , DOMAIN )
547+ self .wait_for_service_ready (command , CONTENT , 1 )
548+
549+ # 6. remove cert from LB with port 443
550+ lb_rule_https .removeCert (self .userapiclient )
551+
552+ # 7. delete SSL certificate
553+ self .sslcert .delete (self .userapiclient )
0 commit comments