@@ -407,6 +407,78 @@ def test_create_icmp_code(self):
407407 self .assertRaises (exceptions .CommandError , self .cmd .take_action ,
408408 parsed_args )
409409
410+ def test_create_icmp_code_zero (self ):
411+ self ._setup_security_group_rule ({
412+ 'port_range_min' : 15 ,
413+ 'port_range_max' : 0 ,
414+ 'protocol' : 'icmp' ,
415+ 'remote_ip_prefix' : '0.0.0.0/0' ,
416+ })
417+ arglist = [
418+ '--protocol' , self ._security_group_rule .protocol ,
419+ '--icmp-type' , str (self ._security_group_rule .port_range_min ),
420+ '--icmp-code' , str (self ._security_group_rule .port_range_max ),
421+ self ._security_group .id ,
422+ ]
423+ verifylist = [
424+ ('protocol' , self ._security_group_rule .protocol ),
425+ ('icmp_code' , self ._security_group_rule .port_range_max ),
426+ ('icmp_type' , self ._security_group_rule .port_range_min ),
427+ ('group' , self ._security_group .id ),
428+ ]
429+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
430+ columns , data = self .cmd .take_action (parsed_args )
431+ self .assertEqual (self .expected_columns , columns )
432+ self .assertEqual (self .expected_data , data )
433+
434+ def test_create_icmp_code_greater_than_zero (self ):
435+ self ._setup_security_group_rule ({
436+ 'port_range_min' : 15 ,
437+ 'port_range_max' : 18 ,
438+ 'protocol' : 'icmp' ,
439+ 'remote_ip_prefix' : '0.0.0.0/0' ,
440+ })
441+ arglist = [
442+ '--protocol' , self ._security_group_rule .protocol ,
443+ '--icmp-type' , str (self ._security_group_rule .port_range_min ),
444+ '--icmp-code' , str (self ._security_group_rule .port_range_max ),
445+ self ._security_group .id ,
446+ ]
447+ verifylist = [
448+ ('protocol' , self ._security_group_rule .protocol ),
449+ ('icmp_type' , self ._security_group_rule .port_range_min ),
450+ ('icmp_code' , self ._security_group_rule .port_range_max ),
451+ ('group' , self ._security_group .id ),
452+ ]
453+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
454+ columns , data = self .cmd .take_action (parsed_args )
455+ self .assertEqual (self .expected_columns , columns )
456+ self .assertEqual (self .expected_data , data )
457+
458+ def test_create_icmp_code_negative_value (self ):
459+ self ._setup_security_group_rule ({
460+ 'port_range_min' : 15 ,
461+ 'port_range_max' : None ,
462+ 'protocol' : 'icmp' ,
463+ 'remote_ip_prefix' : '0.0.0.0/0' ,
464+ })
465+ arglist = [
466+ '--protocol' , self ._security_group_rule .protocol ,
467+ '--icmp-type' , str (self ._security_group_rule .port_range_min ),
468+ '--icmp-code' , '-2' ,
469+ self ._security_group .id ,
470+ ]
471+ verifylist = [
472+ ('protocol' , self ._security_group_rule .protocol ),
473+ ('icmp_type' , self ._security_group_rule .port_range_min ),
474+ ('icmp_code' , - 2 ),
475+ ('group' , self ._security_group .id ),
476+ ]
477+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
478+ columns , data = self .cmd .take_action (parsed_args )
479+ self .assertEqual (self .expected_columns , columns )
480+ self .assertEqual (self .expected_data , data )
481+
410482 def test_create_icmp_type (self ):
411483 self ._setup_security_group_rule ({
412484 'port_range_min' : 15 ,
@@ -440,6 +512,104 @@ def test_create_icmp_type(self):
440512 self .assertEqual (self .expected_columns , columns )
441513 self .assertEqual (self .expected_data , data )
442514
515+ def test_create_icmp_type_zero (self ):
516+ self ._setup_security_group_rule ({
517+ 'port_range_min' : 0 ,
518+ 'protocol' : 'icmp' ,
519+ 'remote_ip_prefix' : '0.0.0.0/0' ,
520+ })
521+ arglist = [
522+ '--icmp-type' , str (self ._security_group_rule .port_range_min ),
523+ '--protocol' , self ._security_group_rule .protocol ,
524+ self ._security_group .id ,
525+ ]
526+ verifylist = [
527+ ('dst_port' , None ),
528+ ('icmp_type' , self ._security_group_rule .port_range_min ),
529+ ('icmp_code' , None ),
530+ ('protocol' , self ._security_group_rule .protocol ),
531+ ('group' , self ._security_group .id ),
532+ ]
533+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
534+
535+ columns , data = self .cmd .take_action (parsed_args )
536+
537+ self .network .create_security_group_rule .assert_called_once_with (** {
538+ 'direction' : self ._security_group_rule .direction ,
539+ 'ethertype' : self ._security_group_rule .ether_type ,
540+ 'port_range_min' : self ._security_group_rule .port_range_min ,
541+ 'protocol' : self ._security_group_rule .protocol ,
542+ 'remote_ip_prefix' : self ._security_group_rule .remote_ip_prefix ,
543+ 'security_group_id' : self ._security_group .id ,
544+ })
545+ self .assertEqual (self .expected_columns , columns )
546+ self .assertEqual (self .expected_data , data )
547+
548+ def test_create_icmp_type_greater_than_zero (self ):
549+ self ._setup_security_group_rule ({
550+ 'port_range_min' : 13 , # timestamp
551+ 'protocol' : 'icmp' ,
552+ 'remote_ip_prefix' : '0.0.0.0/0' ,
553+ })
554+ arglist = [
555+ '--icmp-type' , str (self ._security_group_rule .port_range_min ),
556+ '--protocol' , self ._security_group_rule .protocol ,
557+ self ._security_group .id ,
558+ ]
559+ verifylist = [
560+ ('dst_port' , None ),
561+ ('icmp_type' , self ._security_group_rule .port_range_min ),
562+ ('icmp_code' , None ),
563+ ('protocol' , self ._security_group_rule .protocol ),
564+ ('group' , self ._security_group .id ),
565+ ]
566+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
567+
568+ columns , data = self .cmd .take_action (parsed_args )
569+
570+ self .network .create_security_group_rule .assert_called_once_with (** {
571+ 'direction' : self ._security_group_rule .direction ,
572+ 'ethertype' : self ._security_group_rule .ether_type ,
573+ 'port_range_min' : self ._security_group_rule .port_range_min ,
574+ 'protocol' : self ._security_group_rule .protocol ,
575+ 'remote_ip_prefix' : self ._security_group_rule .remote_ip_prefix ,
576+ 'security_group_id' : self ._security_group .id ,
577+ })
578+ self .assertEqual (self .expected_columns , columns )
579+ self .assertEqual (self .expected_data , data )
580+
581+ def test_create_icmp_type_negative_value (self ):
582+ self ._setup_security_group_rule ({
583+ 'port_range_min' : None , # timestamp
584+ 'protocol' : 'icmp' ,
585+ 'remote_ip_prefix' : '0.0.0.0/0' ,
586+ })
587+ arglist = [
588+ '--icmp-type' , '-13' ,
589+ '--protocol' , self ._security_group_rule .protocol ,
590+ self ._security_group .id ,
591+ ]
592+ verifylist = [
593+ ('dst_port' , None ),
594+ ('icmp_type' , - 13 ),
595+ ('icmp_code' , None ),
596+ ('protocol' , self ._security_group_rule .protocol ),
597+ ('group' , self ._security_group .id ),
598+ ]
599+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
600+
601+ columns , data = self .cmd .take_action (parsed_args )
602+
603+ self .network .create_security_group_rule .assert_called_once_with (** {
604+ 'direction' : self ._security_group_rule .direction ,
605+ 'ethertype' : self ._security_group_rule .ether_type ,
606+ 'protocol' : self ._security_group_rule .protocol ,
607+ 'remote_ip_prefix' : self ._security_group_rule .remote_ip_prefix ,
608+ 'security_group_id' : self ._security_group .id ,
609+ })
610+ self .assertEqual (self .expected_columns , columns )
611+ self .assertEqual (self .expected_data , data )
612+
443613 def test_create_ipv6_icmp_type_code (self ):
444614 self ._setup_security_group_rule ({
445615 'ether_type' : 'IPv6' ,
0 commit comments