|
10 | 10 | docker_cleanup, |
11 | 11 | get_all_ima_containers, |
12 | 12 | get_all_skaled_containers, |
| 13 | + rm_legacy_containers, |
13 | 14 | save_container_logs, |
14 | 15 | safe_rm, |
15 | 16 | ) |
@@ -111,6 +112,27 @@ def _make_container(name: str) -> MagicMock: |
111 | 112 | return c |
112 | 113 |
|
113 | 114 |
|
| 115 | +def test_get_all_skaled_containers_real(dclient): |
| 116 | + containers = [] |
| 117 | + names = ['sk_skaled_test_chain', 'skale_schain_test_chain'] |
| 118 | + try: |
| 119 | + for name in names: |
| 120 | + c = dclient.containers.run('alpine', 'true', name=name, detach=True) |
| 121 | + containers.append(c) |
| 122 | + for c in containers: |
| 123 | + c.wait() |
| 124 | + result = get_all_skaled_containers() |
| 125 | + result_names = {c.name for c in result} |
| 126 | + for name in names: |
| 127 | + assert name in result_names |
| 128 | + finally: |
| 129 | + for c in containers: |
| 130 | + try: |
| 131 | + c.remove(force=True) |
| 132 | + except Exception: |
| 133 | + pass |
| 134 | + |
| 135 | + |
114 | 136 | def test_get_all_skaled_containers_both_prefixes(): |
115 | 137 | new_container = _make_container('sk_skaled_chain1') |
116 | 138 | legacy_container = _make_container('skale_schain_chain2') |
@@ -155,3 +177,27 @@ def fake_list(all=True, filters=None): |
155 | 177 | assert len(result) == 2 |
156 | 178 | names = {c.name for c in result} |
157 | 179 | assert names == {'sk_ima_chain1', 'skale_ima_chain2'} |
| 180 | + |
| 181 | + |
| 182 | +def test_rm_legacy_containers(dclient): |
| 183 | + names = ['skale_sync_admin', 'skale_api', 'skale_schain_old'] |
| 184 | + containers = [] |
| 185 | + try: |
| 186 | + for name in names: |
| 187 | + c = dclient.containers.run('alpine', 'true', name=name, detach=True) |
| 188 | + containers.append(c) |
| 189 | + for c in containers: |
| 190 | + c.wait() |
| 191 | + |
| 192 | + rm_legacy_containers() |
| 193 | + |
| 194 | + remaining = dclient.containers.list(all=True, filters={'name': 'skale_'}) |
| 195 | + remaining_names = {c.name for c in remaining} |
| 196 | + for name in names: |
| 197 | + assert name not in remaining_names |
| 198 | + finally: |
| 199 | + for c in containers: |
| 200 | + try: |
| 201 | + c.remove(force=True) |
| 202 | + except Exception: |
| 203 | + pass |
0 commit comments