Add "stdin" and "tty" parameters to Kubernetes container 53/59953/5
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 18 Jul 2018 16:14:24 +0000 (17:14 +0100)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Thu, 19 Jul 2018 13:42:54 +0000 (13:42 +0000)
JIRA: YARDSTICK-1330

Change-Id: I05303a1d0783421472883806f97441dd63f7f740
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
yardstick/orchestrator/kubernetes.py
yardstick/tests/unit/orchestrator/test_kubernetes.py

index 3e2572f..8d9fc41 100644 (file)
@@ -41,6 +41,8 @@ class ContainerObject(object):
         self._resources = kwargs.get('resources', {})
         self._ports = kwargs.get('ports', [])
         self._image_pull_policy = kwargs.get('imagePullPolicy')
         self._resources = kwargs.get('resources', {})
         self._ports = kwargs.get('ports', [])
         self._image_pull_policy = kwargs.get('imagePullPolicy')
+        self._tty = kwargs.get('tty')
+        self._stdin = kwargs.get('stdin')
 
     @staticmethod
     def _parse_commands(command):
 
     @staticmethod
     def _parse_commands(command):
@@ -99,6 +101,10 @@ class ContainerObject(object):
             if self._image_pull_policy not in self.IMAGE_PULL_POLICY:
                 raise exceptions.KubernetesContainerWrongImagePullPolicy()
             container['imagePullPolicy'] = self._image_pull_policy
             if self._image_pull_policy not in self.IMAGE_PULL_POLICY:
                 raise exceptions.KubernetesContainerWrongImagePullPolicy()
             container['imagePullPolicy'] = self._image_pull_policy
+        if self._stdin is not None:
+            container['stdin'] = self._stdin
+        if self._tty is not None:
+            container['tty'] = self._tty
         return container
 
 
         return container
 
 
index be9c2ae..a73a4a1 100644 (file)
@@ -405,6 +405,19 @@ class ContainerObjectTestCase(base.BaseUnitTestCase):
                     'imagePullPolicy':'Always'}
         self.assertEqual(expected, container_obj.get_container_item())
 
                     'imagePullPolicy':'Always'}
         self.assertEqual(expected, container_obj.get_container_item())
 
+    def test_get_container_item_with_tty_stdin(self):
+        args = ['arg1', 'arg2']
+        container_obj = kubernetes.ContainerObject(
+            'cname', 'fake_sshkey', args=args, tty=False, stdin=True)
+        expected = {'args': args,
+                    'command': kubernetes.ContainerObject.COMMAND_DEFAULT,
+                    'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
+                    'name': 'cname-container',
+                    'volumeMounts': container_obj._create_volume_mounts(),
+                    'tty': False,
+                    'stdin': True}
+        self.assertEqual(expected, container_obj.get_container_item())
+
     def test__parse_commands_string(self):
         container_obj = kubernetes.ContainerObject('cname', 'fake_sshkey')
         self.assertEqual(['fake command'],
     def test__parse_commands_string(self):
         container_obj = kubernetes.ContainerObject('cname', 'fake_sshkey')
         self.assertEqual(['fake command'],