diff --git a/api-ref/source/hosts.inc b/api-ref/source/hosts.inc index 356f66a9b..4a5f5f1c9 100644 --- a/api-ref/source/hosts.inc +++ b/api-ref/source/hosts.inc @@ -45,6 +45,7 @@ Response Parameters - os_type: host-os_type - total_containers: host-total_containers - uuid: host-uuid + - enable_cpu_pinning: enable_cpu_pinning Response Example ---------------- @@ -98,6 +99,7 @@ Response - os_type: host-os_type - total_containers: host-total_containers - uuid: host-uuid + - enable_cpu_pinning: enable_cpu_pinning Response Example ---------------- diff --git a/api-ref/source/parameters.yaml b/api-ref/source/parameters.yaml index c0ecab1a4..f2b84bd7a 100644 --- a/api-ref/source/parameters.yaml +++ b/api-ref/source/parameters.yaml @@ -442,6 +442,12 @@ disk-response: required: true in: body type: object +enable_cpu_pinning: + description: | + Indicate whether this host has cpu pinning enabled. + in: body + required: true + type: object environment: description: | The environment variables. diff --git a/zun/api/controllers/v1/views/hosts_view.py b/zun/api/controllers/v1/views/hosts_view.py index c4ed515f9..267e622f7 100644 --- a/zun/api/controllers/v1/views/hosts_view.py +++ b/zun/api/controllers/v1/views/hosts_view.py @@ -33,6 +33,7 @@ _basic_keys = ( 'disk_total', 'disk_quota_supported', 'runtimes', + 'enable_cpu_pinning', ) diff --git a/zun/api/controllers/versions.py b/zun/api/controllers/versions.py index 14782321e..365aadada 100644 --- a/zun/api/controllers/versions.py +++ b/zun/api/controllers/versions.py @@ -61,10 +61,11 @@ REST_API_VERSION_HISTORY = """REST API Version History: * 1.26 - Introduce Quota support * 1.27 - Add support for deleting networks * 1.28 - Add support cpuset + * 1.29 - Add enable_cpu_pinning to compute_node """ BASE_VER = '1.1' -CURRENT_MAX_VER = '1.28' +CURRENT_MAX_VER = '1.29' class Version(object): diff --git a/zun/api/rest_api_version_history.rst b/zun/api/rest_api_version_history.rst index 930bf38ff..ec276b129 100644 --- a/zun/api/rest_api_version_history.rst +++ b/zun/api/rest_api_version_history.rst @@ -225,3 +225,8 @@ user documentation. Add a new attribute 'cpu_policy'. Users can use this attribute to determine which CPU policy the container uses. + +1.29 +---- + + Add a new attribute 'enable_cpu_pinning' to 'host' resource. diff --git a/zun/container/docker/driver.py b/zun/container/docker/driver.py index 5456003e2..ffa1c7946 100644 --- a/zun/container/docker/driver.py +++ b/zun/container/docker/driver.py @@ -1121,6 +1121,7 @@ class DockerDriver(driver.ContainerDriver): else: runtimes = ['runc'] docker_root_dir = info['DockerRootDir'] + enable_cpu_pinning = CONF.compute.enable_cpu_pinning return {'total_containers': total, 'running_containers': running, @@ -1133,7 +1134,8 @@ class DockerDriver(driver.ContainerDriver): 'kernel_version': kernel_version, 'labels': labels, 'runtimes': runtimes, - 'docker_root_dir': docker_root_dir} + 'docker_root_dir': docker_root_dir, + 'enable_cpu_pinning': enable_cpu_pinning} def get_total_disk_for_container(self): try: diff --git a/zun/container/driver.py b/zun/container/driver.py index 147177c47..3093f9b81 100644 --- a/zun/container/driver.py +++ b/zun/container/driver.py @@ -250,6 +250,7 @@ class ContainerDriver(object): disk_quota_supported = self.node_support_disk_quota() node.disk_quota_supported = disk_quota_supported node.runtimes = info['runtimes'] + node.enable_cpu_pinning = info['enable_cpu_pinning'] def node_is_available(self, nodename): """Return whether this compute service manages a particular node.""" diff --git a/zun/db/sqlalchemy/alembic/versions/21fa080c818a_add_enable_cpu_pinning_to_compute_node.py b/zun/db/sqlalchemy/alembic/versions/21fa080c818a_add_enable_cpu_pinning_to_compute_node.py new file mode 100644 index 000000000..9acf985cd --- /dev/null +++ b/zun/db/sqlalchemy/alembic/versions/21fa080c818a_add_enable_cpu_pinning_to_compute_node.py @@ -0,0 +1,35 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""add enable_cpu_pinning to compute_node + +Revision ID: 21fa080c818a +Revises: 2b129060baff +Create Date: 2018-12-12 03:09:40.316168 + +""" + +# revision identifiers, used by Alembic. +revision = '21fa080c818a' +down_revision = '2b129060baff' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('compute_node', + sa.Column('enable_cpu_pinning', sa.Boolean(), + nullable=False, default=sa.sql.false(), + server_default=sa.sql.false())) diff --git a/zun/db/sqlalchemy/models.py b/zun/db/sqlalchemy/models.py index 55a25ae2f..842858779 100644 --- a/zun/db/sqlalchemy/models.py +++ b/zun/db/sqlalchemy/models.py @@ -385,6 +385,8 @@ class ComputeNode(Base): disk_quota_supported = Column(Boolean, nullable=False, default=sql.false(), server_default=sql.false()) runtimes = Column(JSONEncodedList, nullable=True) + enable_cpu_pinning = Column(Boolean, nullable=False, default=sql.false(), + server_default=sql.false()) class Capsule(Base): diff --git a/zun/objects/compute_node.py b/zun/objects/compute_node.py index 4cc54427a..bc266c5e5 100644 --- a/zun/objects/compute_node.py +++ b/zun/objects/compute_node.py @@ -34,7 +34,8 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject): # Version 1.10: Add disk_total, disk_used columns # Version 1.11: Add disk_quota_supported field # Version 1.12: Add runtimes field - VERSION = '1.12' + # Version 1.13: Add enable_cpu_pinning field + VERSION = '1.13' fields = { 'uuid': fields.UUIDField(read_only=True, nullable=False), @@ -63,6 +64,7 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject): 'disk_used': fields.IntegerField(nullable=False), 'disk_quota_supported': fields.BooleanField(nullable=False), 'runtimes': fields.ListOfStringsField(nullable=True), + 'enable_cpu_pinning': fields.BooleanField(nullable=False), } @staticmethod diff --git a/zun/tests/unit/api/base.py b/zun/tests/unit/api/base.py index ea4260d6c..1a568a751 100644 --- a/zun/tests/unit/api/base.py +++ b/zun/tests/unit/api/base.py @@ -26,7 +26,7 @@ from zun.tests.unit.db import base PATH_PREFIX = '/v1' -CURRENT_VERSION = "container 1.27" +CURRENT_VERSION = "container 1.29" class FunctionalTest(base.DbTestCase): diff --git a/zun/tests/unit/api/controllers/test_root.py b/zun/tests/unit/api/controllers/test_root.py index a93d8ba88..43502b9ac 100644 --- a/zun/tests/unit/api/controllers/test_root.py +++ b/zun/tests/unit/api/controllers/test_root.py @@ -28,7 +28,7 @@ class TestRootController(api_base.FunctionalTest): 'default_version': {'id': 'v1', 'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}], - 'max_version': '1.28', + 'max_version': '1.29', 'min_version': '1.1', 'status': 'CURRENT'}, 'description': 'Zun is an OpenStack project which ' @@ -37,7 +37,7 @@ class TestRootController(api_base.FunctionalTest): 'versions': [{'id': 'v1', 'links': [{'href': 'http://localhost/v1/', 'rel': 'self'}], - 'max_version': '1.28', + 'max_version': '1.29', 'min_version': '1.1', 'status': 'CURRENT'}]} diff --git a/zun/tests/unit/container/docker/test_docker_driver.py b/zun/tests/unit/container/docker/test_docker_driver.py index 22a0ce84e..f2bd8392d 100644 --- a/zun/tests/unit/container/docker/test_docker_driver.py +++ b/zun/tests/unit/container/docker/test_docker_driver.py @@ -1026,6 +1026,7 @@ class TestDockerDriver(base.DriverTestCase): 'kernel_version': '3.10.0-123', 'labels': {'dev.type': 'product'}, 'runtimes': ['runc'], + 'enable_cpu_pinning': False, 'docker_root_dir': '/var/lib/docker'} mock_cpu_used.return_value = 1.0 mock_disk.return_value = 80 diff --git a/zun/tests/unit/db/utils.py b/zun/tests/unit/db/utils.py index 817a1e86f..d3b6aad9e 100644 --- a/zun/tests/unit/db/utils.py +++ b/zun/tests/unit/db/utils.py @@ -408,6 +408,7 @@ def get_test_compute_node(**kwargs): 'disk_used': kwargs.get('disk_used', 20), 'disk_quota_supported': kwargs.get('disk_quota_supported', False), 'runtimes': kwargs.get('runtimes', ['runc']), + 'enable_cpu_pinning': kwargs.get('enable_cpu_pinning', False), } diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index ae28499f4..ec893bf71 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -357,7 +357,7 @@ object_data = { 'ZunService': '1.2-deff2a74a9ce23baa231ae12f39a6189', 'Capsule': '1.7-4b895382ee5c44742a9fdc6be85437c7', 'PciDevice': '1.1-6e3f0851ad1cf12583e6af4df1883979', - 'ComputeNode': '1.12-12d7c4fdeb26d58e1988d8577c838512', + 'ComputeNode': '1.13-3c122f455c38d3665d327c05d2df6617', 'PciDevicePool': '1.0-3f5ddc3ff7bfa14da7f6c7e9904cc000', 'PciDevicePoolList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', 'Quota': '1.2-3a7d520d119fe1e886baad968ef7990a',