|
| 1 | +import functools |
| 2 | +import itertools |
1 | 3 | import json
|
2 | 4 | import os
|
3 | 5 | from unittest import mock
|
@@ -165,7 +167,9 @@ def mock_paasta_volumes(self, monkeypatch, tmpdir):
|
165 | 167 |
|
166 | 168 | @pytest.fixture
|
167 | 169 | def mock_existed_files(self, mock_paasta_volumes):
|
168 |
| - existed_files = [v.split(':')[0] for v in mock_paasta_volumes] + ['/host/file1', '/host/file2', '/host/file3'] |
| 170 | + existed_files = [v.split(':')[0] for v in mock_paasta_volumes] + [ |
| 171 | + '/host/file1', '/host/file2', '/host/file3', '/etc/pki/spark', '/etc/group', '/etc/passwd', |
| 172 | + ] |
169 | 173 | with mock.patch('os.path.exists', side_effect=lambda f: f in existed_files):
|
170 | 174 | yield existed_files
|
171 | 175 |
|
@@ -220,6 +224,45 @@ def test_get_mesos_docker_volumes_conf(
|
220 | 224 | )
|
221 | 225 | assert sorted(output[validate_key].split(',')) == sorted(set(expected_volumes))
|
222 | 226 |
|
| 227 | + def test_get_k8s_volume_hostpath_dict(self): |
| 228 | + assert spark_config._get_k8s_volume_hostpath_dict( |
| 229 | + '/host/file1', '/container/file1', 'RO', itertools.count(), |
| 230 | + ) == { |
| 231 | + 'spark.kubernetes.executor.volumes.hostPath.0.mount.path': '/container/file1', |
| 232 | + 'spark.kubernetes.executor.volumes.hostPath.0.options.path': '/host/file1', |
| 233 | + 'spark.kubernetes.executor.volumes.hostPath.0.mount.readOnly': 'true', |
| 234 | + } |
| 235 | + |
| 236 | + @pytest.mark.parametrize( |
| 237 | + 'volumes', [ |
| 238 | + None, |
| 239 | + [ |
| 240 | + {'hostPath': '/host/file1', 'containerPath': '/containter/file1', 'mode': 'RO'}, |
| 241 | + {'hostPath': '/host/file2', 'containerPath': '/containter/file2', 'mode': 'RO'}, |
| 242 | + {'hostPath': '/host/paasta1', 'containerPath': '/container/paasta1', 'mode': 'RO'}, |
| 243 | + ], |
| 244 | + ], |
| 245 | + ) |
| 246 | + @pytest.mark.usefixtures('mock_existed_files') |
| 247 | + def test_get_k8s_docker_volumes_conf(self, volumes): |
| 248 | + expected_volumes = {} |
| 249 | + |
| 250 | + _get_k8s_volume = functools.partial(spark_config._get_k8s_volume_hostpath_dict, count=itertools.count()) |
| 251 | + if volumes: |
| 252 | + for volume in volumes: |
| 253 | + expected_volumes.update( |
| 254 | + _get_k8s_volume(volume['hostPath'], volume['containerPath'], volume['mode']), |
| 255 | + ) |
| 256 | + |
| 257 | + expected_volumes.update({ |
| 258 | + **_get_k8s_volume('/etc/pki/spark', '/etc/pki/spark', 'ro'), |
| 259 | + **_get_k8s_volume('/etc/passwd', '/etc/passwd', 'ro'), |
| 260 | + **_get_k8s_volume('/etc/group', '/etc/group', 'ro'), |
| 261 | + }) |
| 262 | + |
| 263 | + output = spark_config._get_k8s_docker_volumes_conf(volumes) |
| 264 | + assert output == expected_volumes |
| 265 | + |
223 | 266 | @pytest.fixture
|
224 | 267 | def mock_account_id(self, tmpdir, monkeypatch):
|
225 | 268 | def get_client(service_name, **kwargs):
|
@@ -744,7 +787,7 @@ def test_get_spark_conf_mesos(
|
744 | 787 | @pytest.fixture
|
745 | 788 | def assert_kubernetes_conf(self):
|
746 | 789 | expected_output = {
|
747 |
| - 'spark.master': f'k8s://https://k8s.paasta-{self.cluster}.yelp:16443', |
| 790 | + 'spark.master': f'k8s://https://k8s.{self.cluster}.paasta:6443', |
748 | 791 | 'spark.executorEnv.PAASTA_SERVICE': self.service,
|
749 | 792 | 'spark.executorEnv.PAASTA_INSTANCE': self.instance,
|
750 | 793 | 'spark.executorEnv.PAASTA_CLUSTER': self.cluster,
|
|
0 commit comments