krkn-lib 5.1.12__py3-none-any.whl → 5.1.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,550 @@
1
+ """
2
+ Comprehensive tests for KrknOpenshift class.
3
+
4
+ This test suite includes both unit tests (mocked) and integration tests
5
+ (requiring actual testdata or clusters).
6
+
7
+ Unit tests use mocks to test all methods without requiring
8
+ actual OpenShift clusters or external services.
9
+
10
+ Integration tests use BaseTest and require actual testdata files
11
+ or cluster connections.
12
+
13
+ Assisted By: Claude Code
14
+ """
15
+
1
16
  import os
17
+ import tempfile
18
+ import unittest
2
19
  from datetime import datetime
20
+ from unittest.mock import Mock, PropertyMock, patch
3
21
 
22
+ from krkn_lib.ocp.krkn_openshift import KrknOpenshift
4
23
  from krkn_lib.tests import BaseTest
5
24
  from krkn_lib.utils import SafeLogger
6
25
 
7
26
 
8
- class KrknOpenshiftTest(BaseTest):
27
+ # ==============================================================================
28
+ # UNIT TESTS (Mocked - No external dependencies)
29
+ # ==============================================================================
30
+
31
+
32
+ class TestKrknOpenshiftInit(unittest.TestCase):
33
+ """Test KrknOpenshift initialization."""
34
+
35
+ @patch("krkn_lib.k8s.krkn_kubernetes.config")
36
+ def test_init_with_kubeconfig(self, mock_config):
37
+ """Test initialization with kubeconfig path."""
38
+ mock_config.load_kube_config = Mock()
39
+
40
+ with tempfile.NamedTemporaryFile(delete=False) as f:
41
+ temp_kubeconfig = f.name
42
+
43
+ try:
44
+ ocp = KrknOpenshift(kubeconfig_path=temp_kubeconfig)
45
+
46
+ self.assertIsNotNone(ocp)
47
+ # Should inherit from KrknKubernetes
48
+ self.assertTrue(hasattr(ocp, "api_client"))
49
+ finally:
50
+ if os.path.exists(temp_kubeconfig):
51
+ os.unlink(temp_kubeconfig)
52
+
53
+ @patch("krkn_lib.k8s.krkn_kubernetes.config")
54
+ def test_init_without_kubeconfig(self, mock_config):
55
+ """Test initialization without kubeconfig path."""
56
+ mock_config.load_kube_config = Mock()
57
+
58
+ ocp = KrknOpenshift()
59
+
60
+ self.assertIsNotNone(ocp)
61
+
62
+
63
+ class TestGetClusterversionString(unittest.TestCase):
64
+ """Test get_clusterversion_string method."""
65
+
66
+ def setUp(self):
67
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
68
+ self.ocp = KrknOpenshift()
69
+
70
+ @patch.object(KrknOpenshift, "_get_clusterversion_string")
71
+ def test_get_clusterversion_string_success(
72
+ self, mock_get_clusterversion_string
73
+ ):
74
+ """Test successful retrieval of clusterversion string."""
75
+ mock_get_clusterversion_string.return_value = "4.13.0"
76
+
77
+ result = self.ocp.get_clusterversion_string()
78
+
79
+ self.assertEqual(result, "4.13.0")
80
+ mock_get_clusterversion_string.assert_called_once()
81
+
82
+ @patch.object(KrknOpenshift, "_get_clusterversion_string")
83
+ def test_get_clusterversion_string_empty(
84
+ self, mock_get_clusterversion_string
85
+ ):
86
+ """Test when clusterversion string is empty."""
87
+ mock_get_clusterversion_string.return_value = ""
88
+
89
+ result = self.ocp.get_clusterversion_string()
90
+
91
+ self.assertEqual(result, "")
92
+
93
+
94
+ class TestIsOpenshift(unittest.TestCase):
95
+ """Test is_openshift method."""
96
+
97
+ def setUp(self):
98
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
99
+ self.ocp = KrknOpenshift()
100
+
101
+ @patch.object(KrknOpenshift, "_get_clusterversion_string")
102
+ def test_is_openshift_true(self, mock_get_clusterversion_string):
103
+ """Test is_openshift returns True for OpenShift cluster."""
104
+ mock_get_clusterversion_string.return_value = "4.13.0"
105
+
106
+ result = self.ocp.is_openshift()
107
+
108
+ self.assertTrue(result)
109
+
110
+ @patch.object(KrknOpenshift, "_get_clusterversion_string")
111
+ def test_is_openshift_false_empty(self, mock_get_clusterversion_string):
112
+ """Test is_openshift returns False when version is empty."""
113
+ mock_get_clusterversion_string.return_value = ""
114
+
115
+ result = self.ocp.is_openshift()
116
+
117
+ self.assertFalse(result)
118
+
119
+ @patch.object(KrknOpenshift, "_get_clusterversion_string")
120
+ def test_is_openshift_false_none(self, mock_get_clusterversion_string):
121
+ """Test is_openshift returns False when version is None."""
122
+ mock_get_clusterversion_string.return_value = None
123
+
124
+ result = self.ocp.is_openshift()
125
+
126
+ self.assertFalse(result)
127
+
128
+
129
+ class TestGetClusterType(unittest.TestCase):
130
+ """Test get_cluster_type method with PropertyMock."""
131
+
132
+ def setUp(self):
133
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
134
+ self.ocp = KrknOpenshift()
135
+
136
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
137
+ def test_get_cluster_type_rosa(self, mock_api_client_prop):
138
+ """Test getting ROSA cluster type from resource tags."""
139
+ mock_api_client = Mock()
140
+
141
+ mock_response = (
142
+ str(
143
+ {
144
+ "status": {
145
+ "platform": "AWS",
146
+ "platformStatus": {
147
+ "aws": {
148
+ "region": "us-west-2",
149
+ "resourceTags": [
150
+ {"key": "prowci", "value": "ci-rosa-123"},
151
+ {
152
+ "key": "red-hat-clustertype",
153
+ "value": "rosa",
154
+ },
155
+ ],
156
+ }
157
+ },
158
+ }
159
+ }
160
+ ),
161
+ )
162
+
163
+ mock_api_client.call_api.return_value = mock_response
164
+ mock_api_client.select_header_accept.return_value = "application/json"
165
+ mock_api_client_prop.return_value = mock_api_client
166
+
167
+ result = self.ocp.get_cluster_type()
168
+
169
+ self.assertEqual(result, "rosa")
170
+
171
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
172
+ def test_get_cluster_type_self_managed(self, mock_api_client_prop):
173
+ """Test getting self-managed cluster type (no resource tags)."""
174
+ mock_api_client = Mock()
175
+
176
+ mock_response = (
177
+ str(
178
+ {
179
+ "status": {
180
+ "platform": "AWS",
181
+ "platformStatus": {"aws": {"region": "us-west-2"}},
182
+ }
183
+ }
184
+ ),
185
+ )
186
+
187
+ mock_api_client.call_api.return_value = mock_response
188
+ mock_api_client.select_header_accept.return_value = "application/json"
189
+ mock_api_client_prop.return_value = mock_api_client
190
+
191
+ result = self.ocp.get_cluster_type()
192
+
193
+ self.assertEqual(result, "self-managed")
194
+
195
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
196
+ def test_get_cluster_type_exception(self, mock_api_client_prop):
197
+ """Test exception handling returns self-managed."""
198
+ mock_api_client = Mock()
199
+ mock_api_client.call_api.side_effect = Exception("API error")
200
+ mock_api_client_prop.return_value = mock_api_client
201
+
202
+ result = self.ocp.get_cluster_type()
203
+
204
+ self.assertEqual(result, "self-managed")
205
+
206
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
207
+ def test_get_cluster_type_no_api_client(self, mock_api_client_prop):
208
+ """Test when api_client is None."""
209
+ mock_api_client_prop.return_value = None
210
+
211
+ result = self.ocp.get_cluster_type()
212
+
213
+ self.assertIsNone(result)
214
+
215
+
216
+ class TestGetCloudInfrastructure(unittest.TestCase):
217
+ """Test get_cloud_infrastructure method."""
218
+
219
+ def setUp(self):
220
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
221
+ self.ocp = KrknOpenshift()
222
+
223
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
224
+ def test_get_cloud_infrastructure_aws(self, mock_api_client_prop):
225
+ """Test getting AWS infrastructure."""
226
+ mock_api_client = Mock()
227
+
228
+ mock_response = (
229
+ str(
230
+ {
231
+ "status": {
232
+ "platform": "AWS",
233
+ "platformStatus": {"aws": {"region": "us-west-2"}},
234
+ }
235
+ }
236
+ ),
237
+ )
238
+
239
+ mock_api_client.call_api.return_value = mock_response
240
+ mock_api_client.select_header_accept.return_value = "application/json"
241
+ mock_api_client_prop.return_value = mock_api_client
242
+
243
+ result = self.ocp.get_cloud_infrastructure()
244
+
245
+ self.assertEqual(result, "AWS")
246
+
247
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
248
+ def test_get_cloud_infrastructure_exception(self, mock_api_client_prop):
249
+ """Test exception handling returns Unknown."""
250
+ mock_api_client = Mock()
251
+ mock_api_client.call_api.side_effect = Exception("API error")
252
+ mock_api_client_prop.return_value = mock_api_client
253
+
254
+ result = self.ocp.get_cloud_infrastructure()
255
+
256
+ self.assertEqual(result, "Unknown")
257
+
258
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
259
+ def test_get_cloud_infrastructure_no_api_client(self, mock_api_client_prop):
260
+ """Test when api_client is None."""
261
+ mock_api_client_prop.return_value = None
262
+
263
+ result = self.ocp.get_cloud_infrastructure()
264
+
265
+ self.assertIsNone(result)
266
+
267
+
268
+ class TestGetClusterNetworkPlugins(unittest.TestCase):
269
+ """Test get_cluster_network_plugins method."""
270
+
271
+ def setUp(self):
272
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
273
+ self.ocp = KrknOpenshift()
274
+
275
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
276
+ def test_get_cluster_network_plugins_ovn(self, mock_api_client_prop):
277
+ """Test getting OVNKubernetes network plugin."""
278
+ mock_api_client = Mock()
279
+
280
+ mock_response = (
281
+ str(
282
+ {
283
+ "items": [
284
+ {
285
+ "metadata": {"name": "cluster"},
286
+ "status": {"networkType": "OVNKubernetes"},
287
+ }
288
+ ]
289
+ }
290
+ ),
291
+ )
292
+
293
+ mock_api_client.call_api.return_value = mock_response
294
+ mock_api_client.select_header_accept.return_value = "application/json"
295
+ mock_api_client_prop.return_value = mock_api_client
296
+
297
+ result = self.ocp.get_cluster_network_plugins()
298
+
299
+ self.assertEqual(result, ["OVNKubernetes"])
300
+
301
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
302
+ def test_get_cluster_network_plugins_exception(self, mock_api_client_prop):
303
+ """Test exception handling returns Unknown."""
304
+ mock_api_client = Mock()
305
+ mock_api_client.call_api.side_effect = Exception("API error")
306
+ mock_api_client_prop.return_value = mock_api_client
307
+
308
+ result = self.ocp.get_cluster_network_plugins()
309
+
310
+ self.assertEqual(result, ["Unknown"])
311
+
312
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
313
+ def test_get_cluster_network_plugins_no_api_client(
314
+ self, mock_api_client_prop
315
+ ):
316
+ """Test when api_client is None."""
317
+ mock_api_client_prop.return_value = None
318
+
319
+ result = self.ocp.get_cluster_network_plugins()
320
+
321
+ self.assertEqual(result, [])
322
+
323
+
324
+ class TestGetPrometheusApiConnectionData(unittest.TestCase):
325
+ """Test get_prometheus_api_connection_data method."""
326
+
327
+ def setUp(self):
328
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
329
+ self.ocp = KrknOpenshift()
330
+
331
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
332
+ @patch.object(KrknOpenshift, "create_token_for_sa")
333
+ def test_get_prometheus_api_connection_data_success(
334
+ self, mock_create_token, mock_api_client_prop
335
+ ):
336
+ """Test successful retrieval of Prometheus connection data."""
337
+ mock_create_token.return_value = "test-token-12345"
338
+
339
+ mock_api_client = Mock()
340
+ host = "prometheus-k8s-openshift-monitoring.apps.cluster.com"
341
+ mock_response = (
342
+ str(
343
+ {
344
+ "items": [
345
+ {
346
+ "metadata": {"name": "prometheus-k8s"},
347
+ "spec": {
348
+ "host": host
349
+ },
350
+ }
351
+ ]
352
+ }
353
+ ),
354
+ )
355
+
356
+ mock_api_client.call_api.return_value = mock_response
357
+ mock_api_client.select_header_accept.return_value = "application/json"
358
+ mock_api_client_prop.return_value = mock_api_client
359
+
360
+ result = self.ocp.get_prometheus_api_connection_data()
361
+
362
+ self.assertIsNotNone(result)
363
+ self.assertEqual(result.token, "test-token-12345")
364
+ self.assertEqual(
365
+ result.endpoint,
366
+ "https://prometheus-k8s-openshift-monitoring.apps.cluster.com",
367
+ )
368
+
369
+ @patch.object(KrknOpenshift, "create_token_for_sa")
370
+ def test_get_prometheus_api_connection_data_no_token(
371
+ self, mock_create_token
372
+ ):
373
+ """Test when token creation fails."""
374
+ mock_create_token.return_value = None
375
+
376
+ result = self.ocp.get_prometheus_api_connection_data()
377
+
378
+ self.assertIsNone(result)
379
+
380
+ @patch.object(KrknOpenshift, "api_client", new_callable=PropertyMock)
381
+ @patch.object(KrknOpenshift, "create_token_for_sa")
382
+ def test_get_prometheus_api_connection_data_route_not_found(
383
+ self, mock_create_token, mock_api_client_prop
384
+ ):
385
+ """Test when prometheus route is not found."""
386
+ mock_create_token.return_value = "test-token-12345"
387
+
388
+ mock_api_client = Mock()
389
+ mock_response = (str({"items": []}),)
390
+ mock_api_client.call_api.return_value = mock_response
391
+ mock_api_client.select_header_accept.return_value = "application/json"
392
+ mock_api_client_prop.return_value = mock_api_client
393
+
394
+ result = self.ocp.get_prometheus_api_connection_data()
395
+
396
+ self.assertIsNone(result)
397
+
398
+
399
+ class TestCollectFilterArchiveOcpLogs(unittest.TestCase):
400
+ """Test collect_filter_archive_ocp_logs method."""
401
+
402
+ def setUp(self):
403
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
404
+ self.ocp = KrknOpenshift()
405
+ self.safe_logger = Mock(spec=SafeLogger)
406
+
407
+ @patch("shutil.which")
408
+ def test_collect_filter_archive_ocp_logs_oc_not_found(self, mock_which):
409
+ """Test when oc command is not found."""
410
+ mock_which.return_value = None
411
+
412
+ result = self.ocp.collect_filter_archive_ocp_logs(
413
+ "/tmp/src",
414
+ "/tmp/dst",
415
+ "/tmp/kubeconfig",
416
+ 1234567890,
417
+ 1234567900,
418
+ [r"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z).+"],
419
+ 3,
420
+ self.safe_logger,
421
+ )
422
+
423
+ self.assertIsNone(result)
424
+ self.safe_logger.error.assert_called()
425
+
426
+ @patch("os.path.exists")
427
+ @patch("shutil.which")
428
+ def test_collect_filter_archive_ocp_logs_invalid_kubeconfig(
429
+ self, mock_which, mock_exists
430
+ ):
431
+ """Test with invalid kubeconfig path."""
432
+ mock_which.return_value = "/usr/bin/oc"
433
+
434
+ def exists_side_effect(path):
435
+ if "kubeconfig" in path:
436
+ return False
437
+ return True
438
+
439
+ mock_exists.side_effect = exists_side_effect
440
+
441
+ with self.assertRaises(Exception) as context:
442
+ self.ocp.collect_filter_archive_ocp_logs(
443
+ "/tmp/src",
444
+ "/tmp/dst",
445
+ "/tmp/kubeconfig",
446
+ 1234567890,
447
+ 1234567900,
448
+ [r"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z).+"],
449
+ 3,
450
+ self.safe_logger,
451
+ )
452
+
453
+ self.assertIn("kubeconfig path", str(context.exception))
454
+
455
+ @patch("os.path.expanduser")
456
+ @patch("os.path.exists")
457
+ @patch("shutil.which")
458
+ def test_collect_filter_archive_ocp_logs_expands_tilde(
459
+ self, mock_which, mock_exists, mock_expanduser
460
+ ):
461
+ """Test tilde expansion in paths."""
462
+ mock_which.return_value = "/usr/bin/oc"
463
+ mock_exists.return_value = False
464
+
465
+ def expanduser_side_effect(path):
466
+ return path.replace("~", "/home/user")
467
+
468
+ mock_expanduser.side_effect = expanduser_side_effect
469
+
470
+ with self.assertRaises(Exception):
471
+ self.ocp.collect_filter_archive_ocp_logs(
472
+ "~/src",
473
+ "~/dst",
474
+ "~/kubeconfig",
475
+ 1234567890,
476
+ 1234567900,
477
+ [r"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z).+"],
478
+ 3,
479
+ self.safe_logger,
480
+ )
481
+
482
+ # Should have expanded paths
483
+ self.assertTrue(mock_expanduser.called)
484
+
485
+
486
+ class TestFilterMustGatherOcpLogFolder(unittest.TestCase):
487
+ """Test filter_must_gather_ocp_log_folder method."""
488
+
489
+ def setUp(self):
490
+ with patch("krkn_lib.k8s.krkn_kubernetes.config"):
491
+ self.ocp = KrknOpenshift()
492
+
493
+ def test_filter_must_gather_ocp_log_folder_dst_not_exists(self):
494
+ """Test when destination directory doesn't exist."""
495
+ with self.assertRaises(Exception) as context:
496
+ self.ocp.filter_must_gather_ocp_log_folder(
497
+ "src/testdata/must-gather",
498
+ "/nonexistent/dir",
499
+ 1234567890,
500
+ 1234567900,
501
+ "*.log",
502
+ 3,
503
+ [r"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z).+"],
504
+ )
505
+
506
+ self.assertIn("Log destination dir do not exist", str(context.exception))
507
+
508
+
509
+ # ==============================================================================
510
+ # INTEGRATION TESTS (Require actual testdata or kind cluster connections)
511
+ # ==============================================================================
512
+
513
+
514
+ class KrknOpenshiftIntegrationTest(BaseTest):
515
+ """Integration tests requiring actual cluster connections."""
516
+
9
517
  def test_get_cluster_version_string(self):
10
- # TODO
518
+ """Test cluster version string retrieval on real cluster."""
11
519
  result = self.lib_ocp.get_clusterversion_string()
12
520
  self.assertIsNotNone(result)
13
521
 
14
522
  def test_get_cluster_network_plugins(self):
523
+ """Test network plugin detection on real cluster."""
15
524
  resp = self.lib_ocp.get_cluster_network_plugins()
16
525
  self.assertTrue(len(resp) > 0)
17
526
  self.assertEqual(resp[0], "Unknown")
18
527
 
19
528
  def test_get_cluster_type(self):
529
+ """Test cluster type detection on real cluster."""
20
530
  resp = self.lib_ocp.get_cluster_type()
21
531
  self.assertTrue(resp)
22
532
  self.assertEqual(resp, "self-managed")
23
533
 
24
534
  def test_get_cloud_infrastructure(self):
535
+ """Test cloud infrastructure detection on real cluster."""
25
536
  resp = self.lib_ocp.get_cloud_infrastructure()
26
537
  self.assertTrue(resp)
27
538
  self.assertEqual(resp, "Unknown")
28
539
 
540
+ def test_is_openshift(self):
541
+ """Test OpenShift detection on real cluster."""
542
+ self.assertFalse(self.lib_ocp.is_openshift())
543
+
29
544
  def test_filter_must_gather_ocp_log_folder(self):
30
- # 1694473200 12 Sep 2023 01:00 AM GMT+2
31
- # 1694476200 12 Sep 2023 01:50 AM GMT+2
545
+ """Test log filtering with actual testdata files."""
546
+ # 1694473200 = 12 Sep 2023 01:00 AM GMT+2
547
+ # 1694476200 = 12 Sep 2023 01:50 AM GMT+2
32
548
  filter_patterns = [
33
549
  # Sep 9 11:20:36.123425532
34
550
  r"(\w{3}\s\d{1,2}\s\d{2}:\d{2}:\d{2}\.\d+).+",
@@ -39,60 +555,62 @@ class KrknOpenshiftTest(BaseTest):
39
555
  ]
40
556
  dst_dir = f"/tmp/filtered_logs.{datetime.now().timestamp()}"
41
557
  os.mkdir(dst_dir)
42
- self.lib_ocp.filter_must_gather_ocp_log_folder(
43
- "src/testdata/must-gather",
44
- dst_dir,
45
- 1694473200,
46
- 1694476200,
47
- "*.log",
48
- 3,
49
- filter_patterns,
50
- )
51
558
 
52
- test_file_1 = os.path.join(
53
- dst_dir,
54
- "namespaces.openshift-monitoring.pods."
55
- "openshift-state-metrics-"
56
- "78df59b4d5-mjvhd.openshift-state-metrics."
57
- "openshift-state-metrics.logs.current.log",
58
- )
559
+ try:
560
+ self.lib_ocp.filter_must_gather_ocp_log_folder(
561
+ "src/testdata/must-gather",
562
+ dst_dir,
563
+ 1694473200,
564
+ 1694476200,
565
+ "*.log",
566
+ 3,
567
+ filter_patterns,
568
+ )
59
569
 
60
- test_file_2 = os.path.join(
61
- dst_dir,
62
- "namespaces.openshift-monitoring.pods.prometheus-"
63
- "k8s-0.prometheus.prometheus.logs.current.log",
64
- )
65
- self.assertTrue(os.path.exists(test_file_1))
66
- self.assertTrue(os.path.exists(test_file_2))
570
+ test_file_1 = os.path.join(
571
+ dst_dir,
572
+ "namespaces.openshift-monitoring.pods."
573
+ "openshift-state-metrics-"
574
+ "78df59b4d5-mjvhd.openshift-state-metrics."
575
+ "openshift-state-metrics.logs.current.log",
576
+ )
67
577
 
68
- test_file_1_lines = 0
69
- test_file_2_lines = 0
578
+ test_file_2 = os.path.join(
579
+ dst_dir,
580
+ "namespaces.openshift-monitoring.pods.prometheus-"
581
+ "k8s-0.prometheus.prometheus.logs.current.log",
582
+ )
70
583
 
71
- with open(test_file_1) as file:
72
- for _ in file:
73
- test_file_1_lines += 1
584
+ self.assertTrue(os.path.exists(test_file_1))
585
+ self.assertTrue(os.path.exists(test_file_2))
74
586
 
75
- with open(test_file_2) as file:
76
- for _ in file:
77
- test_file_2_lines += 1
587
+ test_file_1_lines = 0
588
+ test_file_2_lines = 0
78
589
 
79
- self.assertEqual(test_file_1_lines, 7)
80
- self.assertEqual(test_file_2_lines, 4)
590
+ with open(test_file_1) as file:
591
+ for _ in file:
592
+ test_file_1_lines += 1
81
593
 
82
- def test_is_openshift(self):
83
- self.assertFalse(self.lib_ocp.is_openshift())
594
+ with open(test_file_2) as file:
595
+ for _ in file:
596
+ test_file_2_lines += 1
84
597
 
85
- def test_get_cluster_version(self):
86
- # TODO
87
- result = self.lib_ocp.get_clusterversion_string()
88
- self.assertIsNotNone(result)
598
+ self.assertEqual(test_file_1_lines, 7)
599
+ self.assertEqual(test_file_2_lines, 4)
600
+ finally:
601
+ # Cleanup temporary directory
602
+ if os.path.exists(dst_dir):
603
+ import shutil
604
+
605
+ shutil.rmtree(dst_dir)
89
606
 
90
607
  def _test_collect_filter_archive_ocp_logs(self):
91
- ##################################################
92
- # This test is incomplete and inactive because #
93
- # we don't have an OCP Integration env yet. #
94
- ##################################################
608
+ """
609
+ Test full log collection, filtering, and archiving.
95
610
 
611
+ Note: This test is incomplete and inactive because
612
+ we don't have an OCP integration env yet.
613
+ """
96
614
  base_dir = os.path.join(
97
615
  "/tmp", f"log-filter-test.{datetime.now().timestamp()}"
98
616
  )
@@ -114,10 +632,14 @@ class KrknOpenshiftTest(BaseTest):
114
632
  self.lib_ocp.collect_filter_archive_ocp_logs(
115
633
  work_dir,
116
634
  dst_dir,
117
- "/home/tsebasti/OCP/auth/kubeconfig",
635
+ "/path/to/kubeconfig", # Update with actual path
118
636
  start,
119
637
  end,
120
638
  filter_patterns,
121
639
  5,
122
640
  SafeLogger(),
123
641
  )
642
+
643
+
644
+ if __name__ == "__main__":
645
+ unittest.main()