diff --git a/ansible/module_utils/kolla_docker_worker.py b/ansible/module_utils/kolla_docker_worker.py index 8c365ca450..9ac6cff852 100644 --- a/ansible/module_utils/kolla_docker_worker.py +++ b/ansible/module_utils/kolla_docker_worker.py @@ -50,6 +50,8 @@ class DockerWorker(object): self._cgroupns_mode_supported = ( StrictVersion(self.dc._version) >= StrictVersion('1.41')) + self._dimensions_kernel_memory_removed = ( + StrictVersion(self.dc._version) >= StrictVersion('1.42')) self.systemd = SystemdWorker(self.params) @@ -310,8 +312,11 @@ class DockerWorker(object): 'memswap_limit': 'MemorySwap', 'cpu_period': 'CpuPeriod', 'cpu_quota': 'CpuQuota', 'cpu_shares': 'CpuShares', 'cpuset_cpus': 'CpusetCpus', 'cpuset_mems': 'CpusetMems', - 'kernel_memory': 'KernelMemory', 'blkio_weight': 'BlkioWeight', - 'ulimits': 'Ulimits'} + 'blkio_weight': 'BlkioWeight', 'ulimits': 'Ulimits'} + + if not self._dimensions_kernel_memory_removed: + dimension_map['kernel_memory'] = 'KernelMemory' + unsupported = set(new_dimensions.keys()) - \ set(dimension_map.keys()) if unsupported: diff --git a/tests/pre.yml b/tests/pre.yml index aba2cff360..2deead9f64 100644 --- a/tests/pre.yml +++ b/tests/pre.yml @@ -49,6 +49,14 @@ - python3-pip - python3-setuptools + # TODO(mnasiadka): Remove this once ansible-collection-kolla + # installs apparmor + - name: Install apparmor on Debian/Ubuntu + become: true + package: + name: apparmor + when: ansible_os_family == 'Debian' + - name: Ensure /tmp/logs/ dir file: path: "{{ logs_dir }}" diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index 727caf9f5a..646f809c52 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -269,6 +269,15 @@ class TestMainModule(base.BaseTestCase): docker_api_version='1.41') self.assertTrue(self.dw._cgroupns_mode_supported) + def test_sets_dimensions_kernelmemory_supported_true(self): + self.dw = get_DockerWorker(self.fake_data['params']) + self.assertFalse(self.dw._dimensions_kernel_memory_removed) + + def test_sets_dimensions_kernelmemory_supported_false(self): + self.dw = get_DockerWorker(self.fake_data['params'], + docker_api_version='1.42') + self.assertTrue(self.dw._dimensions_kernel_memory_removed) + class TestContainer(base.BaseTestCase): @@ -1396,6 +1405,22 @@ class TestAttrComp(base.BaseTestCase): self.dw = get_DockerWorker(self.fake_data['params']) self.assertFalse(self.dw.compare_dimensions(container_info)) + def test_compare_dimensions_kernel_memory_1_42(self): + self.fake_data['params']['dimensions'] = { + 'kernel_memory': '1024'} + container_info = dict() + container_info['HostConfig'] = { + 'CpuPeriod': 0, 'Memory': 0, 'CpuQuota': 0, + 'CpusetCpus': '', 'CpuShares': 0, 'BlkioWeight': 0, + 'CpusetMems': '', 'MemorySwap': 0, 'MemoryReservation': 0, + 'Ulimits': []} + self.dw = get_DockerWorker(self.fake_data['params'], + docker_api_version='1.42') + self.dw.compare_dimensions(container_info) + self.dw.module.exit_json.assert_called_once_with( + failed=True, msg=repr("Unsupported dimensions"), + unsupported_dimensions=set(['kernel_memory'])) + def test_compare_container_state_pos(self): container_info = {'State': dict(Status='running')} self.dw = get_DockerWorker({'state': 'exited'})