Docker plugin add cpu set property

Change-Id: I96763d0bc293baee044f79d0bc3123adf40c0728
Closes-bug: #1439042
This commit is contained in:
LiangChen 2015-04-15 10:16:22 +08:00
parent 0d42350150
commit 519efffdb0
2 changed files with 34 additions and 4 deletions

View File

@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
DOCKER_INSTALLED = False
MIN_API_VERSION_MAP = {'read_only': '1.17', 'cpu_shares': '1.8',
'devices': '1.14'}
'devices': '1.14', 'cpu_set': '1.12'}
DEVICE_PATH_REGEX = r"^/dev/[/_\-a-zA-Z0-9]+$"
# conditionally import so tests can work without having the dependency
# satisfied
@ -49,13 +49,14 @@ class DockerContainer(resource.Resource):
DOCKER_ENDPOINT, HOSTNAME, USER, MEMORY, PORT_SPECS,
PRIVILEGED, TTY, OPEN_STDIN, STDIN_ONCE, ENV, CMD, DNS,
IMAGE, VOLUMES, VOLUMES_FROM, PORT_BINDINGS, LINKS, NAME,
RESTART_POLICY, CAP_ADD, CAP_DROP, READ_ONLY, CPU_SHARES, DEVICES,
RESTART_POLICY, CAP_ADD, CAP_DROP, READ_ONLY, CPU_SHARES,
DEVICES, CPU_SET
) = (
'docker_endpoint', 'hostname', 'user', 'memory', 'port_specs',
'privileged', 'tty', 'open_stdin', 'stdin_once', 'env', 'cmd', 'dns',
'image', 'volumes', 'volumes_from', 'port_bindings', 'links', 'name',
'restart_policy', 'cap_add', 'cap_drop', 'read_only', 'cpu_shares',
'devices'
'devices', 'cpu_set'
)
ATTRIBUTES = (
@ -285,6 +286,13 @@ class DockerContainer(resource.Resource):
default=[],
support_status=support.SupportStatus(version='2015.2'),
),
CPU_SET: properties.Schema(
properties.Schema.STRING,
_('The CPUs in which to allow execution '
'(only supported for API version >= %s).') %
MIN_API_VERSION_MAP['cpu_set'],
support_status=support.SupportStatus(version='2015.2'),
)
}
attributes_schema = {
@ -402,7 +410,8 @@ class DockerContainer(resource.Resource):
'dns': self.properties[self.DNS],
'volumes': self.properties[self.VOLUMES],
'name': self.properties[self.NAME],
'cpu_shares': self.properties[self.CPU_SHARES]
'cpu_shares': self.properties[self.CPU_SHARES],
'cpuset': self.properties[self.CPU_SET]
}
client = self.get_client()
client.pull(self.properties[self.IMAGE])

View File

@ -432,3 +432,24 @@ class DockerContainerTest(common.HeatTestCase):
self.assertEqual(['samalba/wordpress'], client.pulled_images)
self.assertEqual(['/dev/sda:/dev/sda:rwm'],
client.container_start[0]['devices'])
def test_create_with_cpu_set(self):
t = template_format.parse(template)
stack = utils.parse_stack(t)
definition = stack.t.resource_definitions(stack)['Blog']
definition['Properties']['cpu_set'] = '0-8,16-24,28'
my_resource = docker_container.DockerContainer(
'Blog', definition, stack)
get_client_mock = self.patchobject(my_resource, 'get_client')
get_client_mock.return_value = fakeclient.FakeDockerClient()
self.assertIsNone(my_resource.validate())
scheduler.TaskRunner(my_resource.create)()
self.assertEqual((my_resource.CREATE, my_resource.COMPLETE),
my_resource.state)
client = my_resource.get_client()
self.assertEqual(['samalba/wordpress'], client.pulled_images)
self.assertEqual('0-8,16-24,28',
client.container_create[0]['cpuset'])
def test_create_with_cpu_set_for_low_api_version(self):
self.arg_for_low_api_version('cpu_set', '0-8,^2', '1.11')