1010# License for the specific language governing permissions and limitations
1111# under the License.
1212
13+ import json
1314import uuid
1415
1516from openstackclient .tests .functional .network .v2 import common
@@ -22,69 +23,51 @@ class NetworkRBACTests(common.NetworkTests):
2223 HEADERS = ['ID' ]
2324 FIELDS = ['id' ]
2425
25- @classmethod
26- def setUpClass (cls ):
27- common .NetworkTests .setUpClass ()
28- if cls .haz_network :
29- cls .NET_NAME = uuid .uuid4 ().hex
30- cls .PROJECT_NAME = uuid .uuid4 ().hex
31-
32- opts = cls .get_opts (cls .FIELDS )
33- raw_output = cls .openstack (
34- 'network create ' + cls .NET_NAME + opts
35- )
36- cls .OBJECT_ID = raw_output .strip ('\n ' )
37- opts = cls .get_opts (['id' , 'object_id' ])
38- raw_output = cls .openstack (
39- 'network rbac create ' +
40- cls .OBJECT_ID +
41- ' --action access_as_shared' +
42- ' --target-project admin' +
43- ' --type network' + opts
44- )
45- cls .ID , object_id , rol = tuple (raw_output .split ('\n ' ))
46- cls .assertOutput (cls .OBJECT_ID , object_id )
47-
48- @classmethod
49- def tearDownClass (cls ):
50- try :
51- if cls .haz_network :
52- raw_output_rbac = cls .openstack (
53- 'network rbac delete ' + cls .ID
54- )
55- raw_output_network = cls .openstack (
56- 'network delete ' + cls .OBJECT_ID
57- )
58- cls .assertOutput ('' , raw_output_rbac )
59- cls .assertOutput ('' , raw_output_network )
60- finally :
61- super (NetworkRBACTests , cls ).tearDownClass ()
62-
6326 def setUp (self ):
6427 super (NetworkRBACTests , self ).setUp ()
6528 # Nothing in this class works with Nova Network
6629 if not self .haz_network :
6730 self .skipTest ("No Network service present" )
6831
32+ self .NET_NAME = uuid .uuid4 ().hex
33+ self .PROJECT_NAME = uuid .uuid4 ().hex
34+
35+ cmd_output = json .loads (self .openstack (
36+ 'network create -f json ' + self .NET_NAME
37+ ))
38+ self .addCleanup (self .openstack ,
39+ 'network delete ' + cmd_output ['id' ])
40+ self .OBJECT_ID = cmd_output ['id' ]
41+
42+ cmd_output = json .loads (self .openstack (
43+ 'network rbac create -f json ' +
44+ self .OBJECT_ID +
45+ ' --action access_as_shared' +
46+ ' --target-project admin' +
47+ ' --type network'
48+ ))
49+ self .addCleanup (self .openstack ,
50+ 'network rbac delete ' + cmd_output ['id' ])
51+ self .ID = cmd_output ['id' ]
52+ self .assertEqual (self .OBJECT_ID , cmd_output ['object_id' ])
53+
6954 def test_network_rbac_list (self ):
70- opts = self .get_opts (self .HEADERS )
71- raw_output = self .openstack ('network rbac list' + opts )
72- self .assertIn (self .ID , raw_output )
55+ cmd_output = json .loads (self .openstack ('network rbac list -f json' ))
56+ self .assertIn (self .ID , [rbac ['ID' ] for rbac in cmd_output ])
7357
7458 def test_network_rbac_show (self ):
75- opts = self . get_opts (self .FIELDS )
76- raw_output = self . openstack ( 'network rbac show ' + self .ID + opts )
77- self .assertEqual (self .ID + " \n " , raw_output )
59+ cmd_output = json . loads (self .openstack (
60+ 'network rbac show -f json ' + self .ID ) )
61+ self .assertEqual (self .ID , cmd_output [ 'id' ] )
7862
7963 def test_network_rbac_set (self ):
80- opts = self .get_opts (self .FIELDS )
81- project_id = self .openstack (
82- 'project create ' + self .PROJECT_NAME + opts )
64+ project_id = json .loads (self .openstack (
65+ 'project create -f json ' + self .PROJECT_NAME ))['id' ]
8366 self .openstack ('network rbac set ' + self .ID +
8467 ' --target-project ' + self .PROJECT_NAME )
85- opts = self .get_opts (['target_project_id' ])
86- raw_output_rbac = self .openstack ('network rbac show ' + self .ID + opts )
68+ cmd_output_rbac = json .loads (self .openstack (
69+ 'network rbac show -f json ' + self .ID ))
70+ self .assertEqual (project_id , cmd_output_rbac ['target_project_id' ])
8771 raw_output_project = self .openstack (
8872 'project delete ' + self .PROJECT_NAME )
89- self .assertEqual (project_id , raw_output_rbac )
90- self .assertOutput ('' , raw_output_project )
73+ self .assertEqual ('' , raw_output_project )
0 commit comments