1515from unittest .mock import call
1616import uuid
1717
18- from openstack .network .v2 import _proxy
1918from openstack .network .v2 import (
2019 default_security_group_rule as _default_security_group_rule ,
2120)
2827from openstackclient .tests .unit import utils as tests_utils
2928
3029
31- class TestDefaultSecurityGroupRule (network_fakes .TestNetworkV2 ):
32- def setUp (self ):
33- super ().setUp ()
34-
35- self .app .client_manager .sdk_connection = mock .Mock ()
36- self .app .client_manager .sdk_connection .network = mock .Mock (
37- spec = _proxy .Proxy ,
38- )
39- self .sdk_client = self .app .client_manager .sdk_connection .network
40-
41-
42- class TestCreateDefaultSecurityGroupRule (TestDefaultSecurityGroupRule ):
30+ class TestCreateDefaultSecurityGroupRule (network_fakes .TestNetworkV2 ):
4331 expected_columns = (
4432 'description' ,
4533 'direction' ,
@@ -82,7 +70,7 @@ def _setup_default_security_group_rule(self, attrs=None):
8270 ** default_security_group_rule_attrs ,
8371 )
8472
85- self .sdk_client .create_default_security_group_rule .return_value = (
73+ self .network_client .create_default_security_group_rule .return_value = (
8674 self ._default_sg_rule
8775 )
8876 self .expected_data = (
@@ -208,7 +196,7 @@ def test_create_default_rule(self):
208196
209197 columns , data = self .cmd .take_action (parsed_args )
210198
211- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
199+ self .network_client .create_default_security_group_rule .assert_called_once_with (
212200 ** {
213201 'direction' : self ._default_sg_rule .direction ,
214202 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -252,7 +240,7 @@ def _test_create_protocol_any_helper(
252240
253241 columns , data = self .cmd .take_action (parsed_args )
254242
255- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
243+ self .network_client .create_default_security_group_rule .assert_called_once_with (
256244 ** {
257245 'direction' : self ._default_sg_rule .direction ,
258246 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -302,7 +290,7 @@ def test_create_remote_address_group(self):
302290
303291 columns , data = self .cmd .take_action (parsed_args )
304292
305- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
293+ self .network_client .create_default_security_group_rule .assert_called_once_with (
306294 ** {
307295 'direction' : self ._default_sg_rule .direction ,
308296 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -347,7 +335,7 @@ def test_create_remote_group(self):
347335
348336 columns , data = self .cmd .take_action (parsed_args )
349337
350- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
338+ self .network_client .create_default_security_group_rule .assert_called_once_with (
351339 ** {
352340 'direction' : self ._default_sg_rule .direction ,
353341 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -381,7 +369,7 @@ def test_create_source_group(self):
381369
382370 columns , data = self .cmd .take_action (parsed_args )
383371
384- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
372+ self .network_client .create_default_security_group_rule .assert_called_once_with (
385373 ** {
386374 'direction' : self ._default_sg_rule .direction ,
387375 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -415,7 +403,7 @@ def test_create_source_ip(self):
415403
416404 columns , data = self .cmd .take_action (parsed_args )
417405
418- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
406+ self .network_client .create_default_security_group_rule .assert_called_once_with (
419407 ** {
420408 'direction' : self ._default_sg_rule .direction ,
421409 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -449,7 +437,7 @@ def test_create_remote_ip(self):
449437
450438 columns , data = self .cmd .take_action (parsed_args )
451439
452- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
440+ self .network_client .create_default_security_group_rule .assert_called_once_with (
453441 ** {
454442 'direction' : self ._default_sg_rule .direction ,
455443 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -599,7 +587,7 @@ def test_create_icmp_type(self):
599587
600588 columns , data = self .cmd .take_action (parsed_args )
601589
602- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
590+ self .network_client .create_default_security_group_rule .assert_called_once_with (
603591 ** {
604592 'direction' : self ._default_sg_rule .direction ,
605593 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -637,7 +625,7 @@ def test_create_icmp_type_zero(self):
637625
638626 columns , data = self .cmd .take_action (parsed_args )
639627
640- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
628+ self .network_client .create_default_security_group_rule .assert_called_once_with (
641629 ** {
642630 'direction' : self ._default_sg_rule .direction ,
643631 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -675,7 +663,7 @@ def test_create_icmp_type_greater_than_zero(self):
675663
676664 columns , data = self .cmd .take_action (parsed_args )
677665
678- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
666+ self .network_client .create_default_security_group_rule .assert_called_once_with (
679667 ** {
680668 'direction' : self ._default_sg_rule .direction ,
681669 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -713,7 +701,7 @@ def test_create_icmp_type_negative_value(self):
713701
714702 columns , data = self .cmd .take_action (parsed_args )
715703
716- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
704+ self .network_client .create_default_security_group_rule .assert_called_once_with (
717705 ** {
718706 'direction' : self ._default_sg_rule .direction ,
719707 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -754,7 +742,7 @@ def test_create_ipv6_icmp_type_code(self):
754742
755743 columns , data = self .cmd .take_action (parsed_args )
756744
757- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
745+ self .network_client .create_default_security_group_rule .assert_called_once_with (
758746 ** {
759747 'direction' : self ._default_sg_rule .direction ,
760748 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -794,7 +782,7 @@ def test_create_icmpv6_type(self):
794782
795783 columns , data = self .cmd .take_action (parsed_args )
796784
797- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
785+ self .network_client .create_default_security_group_rule .assert_called_once_with (
798786 ** {
799787 'direction' : self ._default_sg_rule .direction ,
800788 'ethertype' : self ._default_sg_rule .ether_type ,
@@ -825,7 +813,7 @@ def test_create_with_description(self):
825813
826814 columns , data = self .cmd .take_action (parsed_args )
827815
828- self .sdk_client .create_default_security_group_rule .assert_called_once_with (
816+ self .network_client .create_default_security_group_rule .assert_called_once_with (
829817 ** {
830818 'description' : self ._default_sg_rule .description ,
831819 'direction' : self ._default_sg_rule .direction ,
@@ -840,7 +828,7 @@ def test_create_with_description(self):
840828 self .assertEqual (self .expected_data , data )
841829
842830
843- class TestDeleteDefaultSecurityGroupRule (TestDefaultSecurityGroupRule ):
831+ class TestDeleteDefaultSecurityGroupRule (network_fakes . TestNetworkV2 ):
844832 # The default security group rules to be deleted.
845833 default_security_group_rule_attrs = {
846834 'direction' : 'ingress' ,
@@ -866,7 +854,9 @@ class TestDeleteDefaultSecurityGroupRule(TestDefaultSecurityGroupRule):
866854 def setUp (self ):
867855 super ().setUp ()
868856
869- self .sdk_client .delete_default_security_group_rule .return_value = None
857+ self .network_client .delete_default_security_group_rule .return_value = (
858+ None
859+ )
870860
871861 # Get the command object to test
872862 self .cmd = default_security_group_rule .DeleteDefaultSecurityGroupRule (
@@ -880,15 +870,15 @@ def test_default_security_group_rule_delete(self):
880870 verifylist = [
881871 ('rule' , [self ._default_sg_rules [0 ].id ]),
882872 ]
883- self .sdk_client .find_default_security_group_rule .return_value = (
873+ self .network_client .find_default_security_group_rule .return_value = (
884874 self ._default_sg_rules [0 ]
885875 )
886876
887877 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
888878
889879 result = self .cmd .take_action (parsed_args )
890880
891- self .sdk_client .delete_default_security_group_rule .assert_called_once_with (
881+ self .network_client .delete_default_security_group_rule .assert_called_once_with (
892882 self ._default_sg_rules [0 ]
893883 )
894884 self .assertIsNone (result )
@@ -902,7 +892,7 @@ def test_multi_default_security_group_rules_delete(self):
902892 verifylist = [
903893 ('rule' , arglist ),
904894 ]
905- self .sdk_client .find_default_security_group_rule .side_effect = (
895+ self .network_client .find_default_security_group_rule .side_effect = (
906896 self ._default_sg_rules
907897 )
908898 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
@@ -912,7 +902,7 @@ def test_multi_default_security_group_rules_delete(self):
912902 calls = []
913903 for s in self ._default_sg_rules :
914904 calls .append (call (s ))
915- self .sdk_client .delete_default_security_group_rule .assert_has_calls (
905+ self .network_client .delete_default_security_group_rule .assert_has_calls (
916906 calls
917907 )
918908 self .assertIsNone (result )
@@ -931,7 +921,7 @@ def test_multi_default_security_group_rules_delete_with_exception(self):
931921 self ._default_sg_rules [0 ],
932922 exceptions .CommandError ,
933923 ]
934- self .sdk_client .find_default_security_group_rule = mock .Mock (
924+ self .network_client .find_default_security_group_rule = mock .Mock (
935925 side_effect = find_mock_result
936926 )
937927
@@ -941,18 +931,18 @@ def test_multi_default_security_group_rules_delete_with_exception(self):
941931 except exceptions .CommandError as e :
942932 self .assertEqual ('1 of 2 default rules failed to delete.' , str (e ))
943933
944- self .sdk_client .find_default_security_group_rule .assert_any_call (
934+ self .network_client .find_default_security_group_rule .assert_any_call (
945935 self ._default_sg_rules [0 ].id , ignore_missing = False
946936 )
947- self .sdk_client .find_default_security_group_rule .assert_any_call (
937+ self .network_client .find_default_security_group_rule .assert_any_call (
948938 'unexist_rule' , ignore_missing = False
949939 )
950- self .sdk_client .delete_default_security_group_rule .assert_called_once_with (
940+ self .network_client .delete_default_security_group_rule .assert_called_once_with (
951941 self ._default_sg_rules [0 ]
952942 )
953943
954944
955- class TestListDefaultSecurityGroupRule (TestDefaultSecurityGroupRule ):
945+ class TestListDefaultSecurityGroupRule (network_fakes . TestNetworkV2 ):
956946 # The security group rule to be listed.
957947 _default_sg_rule_tcp = sdk_fakes .generate_fake_resource (
958948 _default_security_group_rule .DefaultSecurityGroupRule ,
@@ -1001,7 +991,7 @@ class TestListDefaultSecurityGroupRule(TestDefaultSecurityGroupRule):
1001991 def setUp (self ):
1002992 super ().setUp ()
1003993
1004- self .sdk_client .default_security_group_rules .return_value = (
994+ self .network_client .default_security_group_rules .return_value = (
1005995 self ._default_sg_rules
1006996 )
1007997
@@ -1016,7 +1006,7 @@ def test_list_default(self):
10161006
10171007 columns , data = self .cmd .take_action (parsed_args )
10181008
1019- self .sdk_client .default_security_group_rules .assert_called_once_with (
1009+ self .network_client .default_security_group_rules .assert_called_once_with (
10201010 ** {}
10211011 )
10221012 self .assertEqual (self .expected_columns , columns )
@@ -1035,7 +1025,7 @@ def test_list_with_protocol(self):
10351025
10361026 columns , data = self .cmd .take_action (parsed_args )
10371027
1038- self .sdk_client .default_security_group_rules .assert_called_once_with (
1028+ self .network_client .default_security_group_rules .assert_called_once_with (
10391029 ** {
10401030 'protocol' : 'tcp' ,
10411031 }
@@ -1055,7 +1045,7 @@ def test_list_with_ingress(self):
10551045
10561046 columns , data = self .cmd .take_action (parsed_args )
10571047
1058- self .sdk_client .default_security_group_rules .assert_called_once_with (
1048+ self .network_client .default_security_group_rules .assert_called_once_with (
10591049 ** {
10601050 'direction' : 'ingress' ,
10611051 }
@@ -1075,7 +1065,7 @@ def test_list_with_wrong_egress(self):
10751065
10761066 columns , data = self .cmd .take_action (parsed_args )
10771067
1078- self .sdk_client .default_security_group_rules .assert_called_once_with (
1068+ self .network_client .default_security_group_rules .assert_called_once_with (
10791069 ** {
10801070 'direction' : 'egress' ,
10811071 }
@@ -1084,7 +1074,7 @@ def test_list_with_wrong_egress(self):
10841074 self .assertEqual (self .expected_data , list (data ))
10851075
10861076
1087- class TestShowDefaultSecurityGroupRule (TestDefaultSecurityGroupRule ):
1077+ class TestShowDefaultSecurityGroupRule (network_fakes . TestNetworkV2 ):
10881078 # The default security group rule to be shown.
10891079 _default_sg_rule = sdk_fakes .generate_fake_resource (
10901080 _default_security_group_rule .DefaultSecurityGroupRule
@@ -1123,7 +1113,7 @@ class TestShowDefaultSecurityGroupRule(TestDefaultSecurityGroupRule):
11231113 def setUp (self ):
11241114 super ().setUp ()
11251115
1126- self .sdk_client .find_default_security_group_rule .return_value = (
1116+ self .network_client .find_default_security_group_rule .return_value = (
11271117 self ._default_sg_rule
11281118 )
11291119
@@ -1148,7 +1138,7 @@ def test_show_all_options(self):
11481138
11491139 columns , data = self .cmd .take_action (parsed_args )
11501140
1151- self .sdk_client .find_default_security_group_rule .assert_called_once_with (
1141+ self .network_client .find_default_security_group_rule .assert_called_once_with (
11521142 self ._default_sg_rule .id , ignore_missing = False
11531143 )
11541144 self .assertEqual (self .columns , columns )
0 commit comments