@@ -28,6 +28,138 @@ def setUp(self):
2828 self .app .client_manager .volume .consistencygroups )
2929 self .consistencygroups_mock .reset_mock ()
3030
31+ self .types_mock = self .app .client_manager .volume .volume_types
32+ self .types_mock .reset_mock ()
33+
34+
35+ class TestConsistencyGroupCreate (TestConsistencyGroup ):
36+
37+ volume_type = volume_fakes .FakeType .create_one_type ()
38+ new_consistency_group = (
39+ volume_fakes .FakeConsistencyGroup .create_one_consistency_group ())
40+
41+ columns = (
42+ 'availability_zone' ,
43+ 'created_at' ,
44+ 'description' ,
45+ 'id' ,
46+ 'name' ,
47+ 'status' ,
48+ 'volume_types' ,
49+ )
50+ data = (
51+ new_consistency_group .availability_zone ,
52+ new_consistency_group .created_at ,
53+ new_consistency_group .description ,
54+ new_consistency_group .id ,
55+ new_consistency_group .name ,
56+ new_consistency_group .status ,
57+ new_consistency_group .volume_types ,
58+ )
59+
60+ def setUp (self ):
61+ super (TestConsistencyGroupCreate , self ).setUp ()
62+ self .consistencygroups_mock .create .return_value = (
63+ self .new_consistency_group )
64+ self .consistencygroups_mock .create_from_src .return_value = (
65+ self .new_consistency_group )
66+ self .consistencygroups_mock .get .return_value = (
67+ self .new_consistency_group )
68+ self .types_mock .get .return_value = self .volume_type
69+
70+ # Get the command object to test
71+ self .cmd = consistency_group .CreateConsistencyGroup (self .app , None )
72+
73+ def test_consistency_group_create (self ):
74+ arglist = [
75+ '--volume-type' , self .volume_type .id ,
76+ '--description' , self .new_consistency_group .description ,
77+ '--availability-zone' ,
78+ self .new_consistency_group .availability_zone ,
79+ self .new_consistency_group .name ,
80+ ]
81+ verifylist = [
82+ ('volume_type' , self .volume_type .id ),
83+ ('description' , self .new_consistency_group .description ),
84+ ('availability_zone' ,
85+ self .new_consistency_group .availability_zone ),
86+ ('name' , self .new_consistency_group .name ),
87+ ]
88+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
89+
90+ columns , data = self .cmd .take_action (parsed_args )
91+
92+ self .types_mock .get .assert_called_once_with (
93+ self .volume_type .id )
94+ self .consistencygroups_mock .get .assert_not_called ()
95+ self .consistencygroups_mock .create .assert_called_once_with (
96+ self .volume_type .id ,
97+ name = self .new_consistency_group .name ,
98+ description = self .new_consistency_group .description ,
99+ availability_zone = self .new_consistency_group .availability_zone ,
100+ )
101+
102+ self .assertEqual (self .columns , columns )
103+ self .assertEqual (self .data , data )
104+
105+ def test_consistency_group_create_without_name (self ):
106+ arglist = [
107+ '--volume-type' , self .volume_type .id ,
108+ '--description' , self .new_consistency_group .description ,
109+ '--availability-zone' ,
110+ self .new_consistency_group .availability_zone ,
111+ ]
112+ verifylist = [
113+ ('volume_type' , self .volume_type .id ),
114+ ('description' , self .new_consistency_group .description ),
115+ ('availability_zone' ,
116+ self .new_consistency_group .availability_zone ),
117+ ]
118+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
119+
120+ columns , data = self .cmd .take_action (parsed_args )
121+
122+ self .types_mock .get .assert_called_once_with (
123+ self .volume_type .id )
124+ self .consistencygroups_mock .get .assert_not_called ()
125+ self .consistencygroups_mock .create .assert_called_once_with (
126+ self .volume_type .id ,
127+ name = None ,
128+ description = self .new_consistency_group .description ,
129+ availability_zone = self .new_consistency_group .availability_zone ,
130+ )
131+
132+ self .assertEqual (self .columns , columns )
133+ self .assertEqual (self .data , data )
134+
135+ def test_consistency_group_create_from_source (self ):
136+ arglist = [
137+ '--consistency-group-source' , self .new_consistency_group .id ,
138+ '--description' , self .new_consistency_group .description ,
139+ self .new_consistency_group .name ,
140+ ]
141+ verifylist = [
142+ ('consistency_group_source' , self .new_consistency_group .id ),
143+ ('description' , self .new_consistency_group .description ),
144+ ('name' , self .new_consistency_group .name ),
145+ ]
146+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
147+
148+ columns , data = self .cmd .take_action (parsed_args )
149+
150+ self .types_mock .get .assert_not_called ()
151+ self .consistencygroups_mock .get .assert_called_once_with (
152+ self .new_consistency_group .id )
153+ self .consistencygroups_mock .create_from_src .assert_called_with (
154+ None ,
155+ self .new_consistency_group .id ,
156+ name = self .new_consistency_group .name ,
157+ description = self .new_consistency_group .description ,
158+ )
159+
160+ self .assertEqual (self .columns , columns )
161+ self .assertEqual (self .data , data )
162+
31163
32164class TestConsistencyGroupList (TestConsistencyGroup ):
33165
0 commit comments