@@ -132,11 +132,28 @@ def test_handle_project_created_no_svm_tag(
132
132
):
133
133
"""Test handling project creation without SVM tag."""
134
134
mock_tags .return_value = ["tag1" , "tag2" ]
135
+ mock_file = MagicMock ()
136
+ mock_open .return_value .__enter__ .return_value = mock_file
135
137
136
138
result = handle_project_created (mock_conn , mock_nautobot , valid_event_data )
137
139
assert result == 0
138
140
mock_tags .assert_called_once_with (mock_conn , "test-project-123" )
139
- mock_open .assert_called_with ("/var/run/argo/output.svm_enabled" , "w" )
141
+
142
+ # Verify both project_tags and svm_enabled files are written
143
+ expected_calls = [
144
+ call ("/var/run/argo/output.project_tags" , "w" ),
145
+ call ("/var/run/argo/output.svm_enabled" , "w" ),
146
+ ]
147
+ mock_open .assert_has_calls (expected_calls , any_order = True )
148
+
149
+ # Check that JSON-encoded tags were written
150
+ write_calls = mock_file .write .call_args_list
151
+ json_tags_written = False
152
+ for call_args in write_calls :
153
+ if call_args [0 ][0 ] == '["tag1", "tag2"]' :
154
+ json_tags_written = True
155
+ break
156
+ assert json_tags_written , "Project tags should be written as JSON"
140
157
141
158
@patch ("understack_workflows.oslo_event.keystone_project.NetAppManager" )
142
159
@patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
@@ -154,6 +171,8 @@ def test_handle_project_created_with_svm_tag(
154
171
mock_tags .return_value = ["tag1" , SVM_PROJECT_TAG , "tag2" ]
155
172
mock_netapp_manager = MagicMock ()
156
173
mock_netapp_class .return_value = mock_netapp_manager
174
+ mock_file = MagicMock ()
175
+ mock_open .return_value .__enter__ .return_value = mock_file
157
176
158
177
result = handle_project_created (mock_conn , mock_nautobot , valid_event_data )
159
178
@@ -168,7 +187,24 @@ def test_handle_project_created_with_svm_tag(
168
187
volume_size = VOLUME_SIZE ,
169
188
aggregate_name = AGGREGATE_NAME ,
170
189
)
171
- mock_open .assert_called ()
190
+
191
+ # Verify project tags are written as JSON
192
+ expected_calls = [
193
+ call ("/var/run/argo/output.project_tags" , "w" ),
194
+ call ("/var/run/argo/output.svm_enabled" , "w" ),
195
+ call ("/var/run/argo/output.svm_created" , "w" ),
196
+ call ("/var/run/argo/output.svm_name" , "w" ),
197
+ ]
198
+ mock_open .assert_has_calls (expected_calls , any_order = True )
199
+
200
+ # Check that JSON-encoded tags were written
201
+ write_calls = mock_file .write .call_args_list
202
+ json_tags_written = False
203
+ for call_args in write_calls :
204
+ if call_args [0 ][0 ] == '["tag1", "UNDERSTACK_SVM", "tag2"]' :
205
+ json_tags_written = True
206
+ break
207
+ assert json_tags_written , "Project tags should be written as JSON"
172
208
173
209
@patch ("understack_workflows.oslo_event.keystone_project.NetAppManager" )
174
210
@patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
@@ -292,6 +328,36 @@ def test_handle_project_created_constants_used(
292
328
)
293
329
mock_open .assert_called ()
294
330
331
+ @patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
332
+ @patch ("builtins.open" )
333
+ def test_handle_project_created_json_tags_output (
334
+ self , mock_open , mock_tags , mock_conn , mock_nautobot , valid_event_data
335
+ ):
336
+ """Test that project tags are written as JSON to output file."""
337
+ test_tags = ["custom_tag" , "another_tag" , SVM_PROJECT_TAG ]
338
+ mock_tags .return_value = test_tags
339
+ mock_file = MagicMock ()
340
+ mock_open .return_value .__enter__ .return_value = mock_file
341
+
342
+ with patch (
343
+ "understack_workflows.oslo_event.keystone_project.NetAppManager"
344
+ ) as mock_netapp_class :
345
+ mock_netapp_manager = MagicMock ()
346
+ mock_netapp_class .return_value = mock_netapp_manager
347
+
348
+ result = handle_project_created (mock_conn , mock_nautobot , valid_event_data )
349
+
350
+ assert result == 0
351
+
352
+ # Verify project_tags file is written
353
+ mock_open .assert_any_call ("/var/run/argo/output.project_tags" , "w" )
354
+
355
+ # Check that the exact JSON representation of tags was written
356
+ import json
357
+
358
+ expected_json = json .dumps (test_tags )
359
+ mock_file .write .assert_any_call (expected_json )
360
+
295
361
296
362
class TestHandleProjectUpdated :
297
363
"""Test cases for handle_project_updated function."""
@@ -338,7 +404,10 @@ def test_handle_project_updated_svm_tag_added(
338
404
):
339
405
"""Test project update when SVM_UNDERSTACK tag is added."""
340
406
# Project now has SVM tag
341
- mock_tags .return_value = ["tag1" , SVM_PROJECT_TAG , "tag2" ]
407
+ test_tags = ["tag1" , SVM_PROJECT_TAG , "tag2" ]
408
+ mock_tags .return_value = test_tags
409
+ mock_file = MagicMock ()
410
+ mock_open .return_value .__enter__ .return_value = mock_file
342
411
343
412
mock_netapp_manager = MagicMock ()
344
413
mock_netapp_manager .check_if_svm_exists .return_value = (
@@ -365,6 +434,13 @@ def test_handle_project_updated_svm_tag_added(
365
434
aggregate_name = AGGREGATE_NAME ,
366
435
)
367
436
437
+ # Verify project tags are written as JSON
438
+ mock_open .assert_any_call ("/var/run/argo/output.project_tags" , "w" )
439
+ import json
440
+
441
+ expected_json = json .dumps (test_tags )
442
+ mock_file .write .assert_any_call (expected_json )
443
+
368
444
@patch ("understack_workflows.oslo_event.keystone_project.NetAppManager" )
369
445
@patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
370
446
@patch ("builtins.open" )
@@ -588,13 +664,46 @@ def test_handle_project_updated_output_files_written(
588
664
)
589
665
590
666
assert result == 0
591
- # Verify output files are written
667
+ # Verify output files are written including project_tags
592
668
expected_calls = [
669
+ call ("/var/run/argo/output.project_tags" , "w" ),
593
670
call ("/var/run/argo/output.svm_enabled" , "w" ),
594
671
call ("/var/run/argo/output.svm_name" , "w" ),
595
672
]
596
673
mock_open .assert_has_calls (expected_calls , any_order = True )
597
674
675
+ @patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
676
+ @patch ("builtins.open" )
677
+ def test_handle_project_updated_json_tags_empty_list (
678
+ self , mock_open , mock_tags , mock_conn , mock_nautobot , valid_update_event_data
679
+ ):
680
+ """Test that empty project tags are written as JSON empty list."""
681
+ mock_tags .return_value = []
682
+ mock_file = MagicMock ()
683
+ mock_open .return_value .__enter__ .return_value = mock_file
684
+
685
+ with patch (
686
+ "understack_workflows.oslo_event.keystone_project.NetAppManager"
687
+ ) as mock_netapp_class :
688
+ mock_netapp_manager = MagicMock ()
689
+ mock_netapp_manager .check_if_svm_exists .return_value = False
690
+ mock_netapp_class .return_value = mock_netapp_manager
691
+
692
+ result = handle_project_updated (
693
+ mock_conn , mock_nautobot , valid_update_event_data
694
+ )
695
+
696
+ assert result == 0
697
+
698
+ # Verify project_tags file is written
699
+ mock_open .assert_any_call ("/var/run/argo/output.project_tags" , "w" )
700
+
701
+ # Check that empty list JSON was written
702
+ import json
703
+
704
+ expected_json = json .dumps ([])
705
+ mock_file .write .assert_any_call (expected_json )
706
+
598
707
599
708
class TestHandleProjectDeleted :
600
709
"""Test cases for handle_project_deleted function."""
0 commit comments