diff --git a/heat/engine/clients/os/zun.py b/heat/engine/clients/os/zun.py index 1e1f2ca968..794cea9b83 100644 --- a/heat/engine/clients/os/zun.py +++ b/heat/engine/clients/os/zun.py @@ -28,9 +28,9 @@ class ZunClientPlugin(client_plugin.ClientPlugin): default_version = '1.12' supported_versions = [ - V1_12, V1_18 + V1_12, V1_18, V1_36, ] = [ - '1.12', '1.18' + '1.12', '1.18', '1.36', ] def _create(self, version=None): diff --git a/heat/engine/resources/openstack/zun/container.py b/heat/engine/resources/openstack/zun/container.py index 9dd8842e11..d87dfcfc2c 100644 --- a/heat/engine/resources/openstack/zun/container.py +++ b/heat/engine/resources/openstack/zun/container.py @@ -39,12 +39,12 @@ class Container(resource.Resource, NAME, IMAGE, COMMAND, CPU, MEMORY, ENVIRONMENT, WORKDIR, LABELS, IMAGE_PULL_POLICY, RESTART_POLICY, INTERACTIVE, IMAGE_DRIVER, HINTS, - HOSTNAME, SECURITY_GROUPS, MOUNTS, NETWORKS, + HOSTNAME, SECURITY_GROUPS, MOUNTS, NETWORKS, TTY, ) = ( 'name', 'image', 'command', 'cpu', 'memory', 'environment', 'workdir', 'labels', 'image_pull_policy', 'restart_policy', 'interactive', 'image_driver', 'hints', - 'hostname', 'security_groups', 'mounts', 'networks', + 'hostname', 'security_groups', 'mounts', 'networks', 'tty', ) _NETWORK_KEYS = ( @@ -129,6 +129,11 @@ class Container(resource.Resource, properties.Schema.BOOLEAN, _('Keep STDIN open even if not attached.'), ), + TTY: properties.Schema( + properties.Schema.BOOLEAN, + _('Whether the container allocates a TTY for itself.'), + support_status=support.SupportStatus(version='14.0.0'), + ), IMAGE_DRIVER: properties.Schema( properties.Schema.STRING, _('The image driver to use to pull container image.'), @@ -320,7 +325,12 @@ class Container(resource.Resource, command = args.pop(self.COMMAND, None) if command: args['command'] = shlex.split(command) - container = self.client().containers.run(**args) + + if self.TTY in args: + container = self.client( + version=self.client_plugin().V1_36).containers.run(**args) + else: + container = self.client().containers.run(**args) self.resource_id_set(container.uuid) return container.uuid diff --git a/heat/tests/openstack/zun/test_container.py b/heat/tests/openstack/zun/test_container.py index 3588334550..f98ddfc2d0 100644 --- a/heat/tests/openstack/zun/test_container.py +++ b/heat/tests/openstack/zun/test_container.py @@ -48,6 +48,7 @@ resources: image_pull_policy: always restart_policy: on-failure:2 interactive: false + tty: false image_driver: docker hints: hintkey: hintval @@ -108,6 +109,7 @@ class ZunContainerTest(common.HeatTestCase): self.fake_restart_policy = {'MaximumRetryCount': '2', 'Name': 'on-failure'} self.fake_interactive = False + self.fake_tty = False self.fake_image_driver = 'docker' self.fake_hints = {'hintkey': 'hintval'} self.fake_hostname = 'myhost' @@ -194,6 +196,7 @@ class ZunContainerTest(common.HeatTestCase): value.image_pull_policy = self.fake_image_policy value.restart_policy = self.fake_restart_policy value.interactive = self.fake_interactive + value.tty = self.fake_tty value.image_driver = self.fake_image_driver value.hints = self.fake_hints value.hostname = self.fake_hostname @@ -248,6 +251,9 @@ class ZunContainerTest(common.HeatTestCase): self.assertEqual( self.fake_interactive, c.properties.get(container.Container.INTERACTIVE)) + self.assertEqual( + self.fake_tty, + c.properties.get(container.Container.TTY)) self.assertEqual( self.fake_image_driver, c.properties.get(container.Container.IMAGE_DRIVER)) @@ -283,6 +289,7 @@ class ZunContainerTest(common.HeatTestCase): image_pull_policy=self.fake_image_policy, restart_policy=self.fake_restart_policy, interactive=self.fake_interactive, + tty=self.fake_tty, image_driver=self.fake_image_driver, hints=self.fake_hints, hostname=self.fake_hostname, diff --git a/releasenotes/notes/add-tty-property-to-container-1b8bf92f0f47deca.yaml b/releasenotes/notes/add-tty-property-to-container-1b8bf92f0f47deca.yaml new file mode 100644 index 0000000000..6bc47a0af2 --- /dev/null +++ b/releasenotes/notes/add-tty-property-to-container-1b8bf92f0f47deca.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``tty`` property to ``OS::Zun::Container``. + This property allows users to open the TTY of the container.