1818from openstackclient .network .v2 import security_group_rule
1919from openstackclient .tests .compute .v2 import fakes as compute_fakes
2020from openstackclient .tests import fakes
21+ from openstackclient .tests .identity .v3 import fakes as identity_fakes
2122from openstackclient .tests .network .v2 import fakes as network_fakes
2223from openstackclient .tests import utils as tests_utils
2324
@@ -89,6 +90,30 @@ def setUp(self):
8990 self .network .find_security_group = mock .Mock (
9091 return_value = self ._security_group )
9192
93+ # Set identity client v3. And get a shortcut to Identity client.
94+ identity_client = identity_fakes .FakeIdentityv3Client (
95+ endpoint = fakes .AUTH_URL ,
96+ token = fakes .AUTH_TOKEN ,
97+ )
98+ self .app .client_manager .identity = identity_client
99+ self .identity = self .app .client_manager .identity
100+
101+ # Get a shortcut to the ProjectManager Mock
102+ self .projects_mock = self .identity .projects
103+ self .projects_mock .get .return_value = fakes .FakeResource (
104+ None ,
105+ copy .deepcopy (identity_fakes .PROJECT ),
106+ loaded = True ,
107+ )
108+
109+ # Get a shortcut to the DomainManager Mock
110+ self .domains_mock = self .identity .domains
111+ self .domains_mock .get .return_value = fakes .FakeResource (
112+ None ,
113+ copy .deepcopy (identity_fakes .DOMAIN ),
114+ loaded = True ,
115+ )
116+
92117 # Get the command object to test
93118 self .cmd = security_group_rule .CreateSecurityGroupRule (
94119 self .app , self .namespace )
@@ -231,13 +256,17 @@ def test_create_network_options(self):
231256 '--dst-port' , str (self ._security_group_rule .port_range_min ),
232257 '--egress' ,
233258 '--ethertype' , self ._security_group_rule .ethertype ,
259+ '--project' , identity_fakes .project_name ,
260+ '--project-domain' , identity_fakes .domain_name ,
234261 self ._security_group .id ,
235262 ]
236263 verifylist = [
237264 ('dst_port' , (self ._security_group_rule .port_range_min ,
238265 self ._security_group_rule .port_range_max )),
239266 ('egress' , True ),
240267 ('ethertype' , self ._security_group_rule .ethertype ),
268+ ('project' , identity_fakes .project_name ),
269+ ('project_domain' , identity_fakes .domain_name ),
241270 ('group' , self ._security_group .id ),
242271 ]
243272 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
@@ -251,6 +280,7 @@ def test_create_network_options(self):
251280 'port_range_min' : self ._security_group_rule .port_range_min ,
252281 'protocol' : self ._security_group_rule .protocol ,
253282 'security_group_id' : self ._security_group .id ,
283+ 'tenant_id' : identity_fakes .project_id ,
254284 })
255285 self .assertEqual (tuple (self .expected_columns ), columns )
256286 self .assertEqual (self .expected_data , data )
@@ -307,6 +337,17 @@ def test_create_bad_protocol(self):
307337 self .assertRaises (tests_utils .ParserException ,
308338 self .check_parser , self .cmd , arglist , [])
309339
340+ def test_create_network_options (self ):
341+ arglist = [
342+ '--ingress' ,
343+ '--ethertype' , 'IPv4' ,
344+ '--project' , identity_fakes .project_name ,
345+ '--project-domain' , identity_fakes .domain_name ,
346+ self ._security_group .id ,
347+ ]
348+ self .assertRaises (tests_utils .ParserException ,
349+ self .check_parser , self .cmd , arglist , [])
350+
310351 def test_create_default_rule (self ):
311352 expected_columns , expected_data = self ._setup_security_group_rule ()
312353 dst_port = str (self ._security_group_rule .from_port ) + ':' + \
0 commit comments