1111# under the License.
1212
1313import json
14- import time
1514import uuid
1615
1716from openstackclient .tests .functional import base
2019class AggregateTests (base .TestCase ):
2120 """Functional tests for aggregate"""
2221
23- def test_aggregate_create_and_delete (self ):
22+ def test_aggregate_crud (self ):
2423 """Test create, delete multiple"""
2524 name1 = uuid .uuid4 ().hex
2625 cmd_output = json .loads (self .openstack (
2726 'aggregate create -f json ' +
2827 '--zone nova ' +
28+ '--property a=b ' +
2929 name1
3030 ))
3131 self .assertEqual (
@@ -36,114 +36,33 @@ def test_aggregate_create_and_delete(self):
3636 'nova' ,
3737 cmd_output ['availability_zone' ]
3838 )
39+ # TODO(dtroyer): enable the following once the properties field
40+ # is correctly formatted in the create output
41+ # self.assertIn(
42+ # "a='b'",
43+ # cmd_output['properties']
44+ # )
3945
4046 name2 = uuid .uuid4 ().hex
4147 cmd_output = json .loads (self .openstack (
4248 'aggregate create -f json ' +
43- '--zone nova ' +
49+ '--zone external ' +
4450 name2
4551 ))
4652 self .assertEqual (
4753 name2 ,
4854 cmd_output ['name' ]
4955 )
5056 self .assertEqual (
51- 'nova ' ,
57+ 'external ' ,
5258 cmd_output ['availability_zone' ]
5359 )
5460
55- # Loop a few times since this is timing-sensitive
56- # Just hard-code it for now, since there is no pause and it is
57- # racy we shouldn't have to wait too long, a minute or two
58- # seems reasonable
59- wait_time = 0
60- while wait_time <= 120 :
61- cmd_output = json .loads (self .openstack (
62- 'aggregate show -f json ' +
63- name2
64- ))
65- if cmd_output ['name' ] != name2 :
66- # Hang out for a bit and try again
67- print ('retrying aggregate check' )
68- wait_time += 10
69- time .sleep (10 )
70- else :
71- break
72-
73- del_output = self .openstack (
74- 'aggregate delete ' +
75- name1 + ' ' +
76- name2
77- )
78- self .assertOutput ('' , del_output )
79-
80- def test_aggregate_list (self ):
81- """Test aggregate list"""
82- name1 = uuid .uuid4 ().hex
83- self .openstack (
84- 'aggregate create ' +
85- '--zone nova ' +
86- '--property a=b ' +
87- name1
88- )
89- self .addCleanup (
90- self .openstack ,
91- 'aggregate delete ' + name1 ,
92- fail_ok = True ,
93- )
94-
95- name2 = uuid .uuid4 ().hex
96- self .openstack (
97- 'aggregate create ' +
98- '--zone internal ' +
99- '--property c=d ' +
100- name2
101- )
102- self .addCleanup (
103- self .openstack ,
104- 'aggregate delete ' + name2 ,
105- fail_ok = True ,
106- )
107-
108- cmd_output = json .loads (self .openstack (
109- 'aggregate list -f json'
110- ))
111- names = [x ['Name' ] for x in cmd_output ]
112- self .assertIn (name1 , names )
113- self .assertIn (name2 , names )
114- zones = [x ['Availability Zone' ] for x in cmd_output ]
115- self .assertIn ('nova' , zones )
116- self .assertIn ('internal' , zones )
117-
118- # Test aggregate list --long
119- cmd_output = json .loads (self .openstack (
120- 'aggregate list --long -f json'
121- ))
122- names = [x ['Name' ] for x in cmd_output ]
123- self .assertIn (name1 , names )
124- self .assertIn (name2 , names )
125- zones = [x ['Availability Zone' ] for x in cmd_output ]
126- self .assertIn ('nova' , zones )
127- self .assertIn ('internal' , zones )
128- properties = [x ['Properties' ] for x in cmd_output ]
129- self .assertIn ({'a' : 'b' }, properties )
130- self .assertIn ({'c' : 'd' }, properties )
131-
132- def test_aggregate_set_and_unset (self ):
133- """Test aggregate set, show and unset"""
134- name1 = uuid .uuid4 ().hex
135- name2 = uuid .uuid4 ().hex
136- self .openstack (
137- 'aggregate create ' +
138- '--zone nova ' +
139- '--property a=b ' +
140- name1
141- )
142- self .addCleanup (self .openstack , 'aggregate delete ' + name2 )
143-
61+ # Test aggregate set
62+ name3 = uuid .uuid4 ().hex
14463 raw_output = self .openstack (
14564 'aggregate set ' +
146- '--name ' + name2 + ' ' +
65+ '--name ' + name3 + ' ' +
14766 '--zone internal ' +
14867 '--no-property ' +
14968 '--property c=d ' +
@@ -153,10 +72,10 @@ def test_aggregate_set_and_unset(self):
15372
15473 cmd_output = json .loads (self .openstack (
15574 'aggregate show -f json ' +
156- name2
75+ name3
15776 ))
15877 self .assertEqual (
159- name2 ,
78+ name3 ,
16079 cmd_output ['name' ]
16180 )
16281 self .assertEqual (
@@ -172,23 +91,56 @@ def test_aggregate_set_and_unset(self):
17291 cmd_output ['properties' ]
17392 )
17493
94+ # Test aggregate list
95+ cmd_output = json .loads (self .openstack (
96+ 'aggregate list -f json'
97+ ))
98+ names = [x ['Name' ] for x in cmd_output ]
99+ self .assertIn (name3 , names )
100+ self .assertIn (name2 , names )
101+ zones = [x ['Availability Zone' ] for x in cmd_output ]
102+ self .assertIn ('external' , zones )
103+ self .assertIn ('internal' , zones )
104+
105+ # Test aggregate list --long
106+ cmd_output = json .loads (self .openstack (
107+ 'aggregate list --long -f json'
108+ ))
109+ names = [x ['Name' ] for x in cmd_output ]
110+ self .assertIn (name3 , names )
111+ self .assertIn (name2 , names )
112+ zones = [x ['Availability Zone' ] for x in cmd_output ]
113+ self .assertIn ('external' , zones )
114+ self .assertIn ('internal' , zones )
115+ properties = [x ['Properties' ] for x in cmd_output ]
116+ self .assertNotIn ({'a' : 'b' }, properties )
117+ self .assertIn ({'c' : 'd' }, properties )
118+
175119 # Test unset
176120 raw_output = self .openstack (
177121 'aggregate unset ' +
178122 '--property c ' +
179- name2
123+ name3
180124 )
181125 self .assertOutput ('' , raw_output )
182126
183127 cmd_output = json .loads (self .openstack (
184128 'aggregate show -f json ' +
185- name2
129+ name3
186130 ))
187131 self .assertNotIn (
188132 "c='d'" ,
189133 cmd_output ['properties' ]
190134 )
191135
136+ # test aggregate delete
137+ del_output = self .openstack (
138+ 'aggregate delete ' +
139+ name3 + ' ' +
140+ name2
141+ )
142+ self .assertOutput ('' , del_output )
143+
192144 def test_aggregate_add_and_remove_host (self ):
193145 """Test aggregate add and remove host"""
194146 # Get a host
0 commit comments