Exemplo n.º 1
0
 def test__create_volume_mounts_no_volume_mounts(self):
     ssh_vol = {'name': 'fake_ssh_key2',
                'mountPath': kubernetes.ContainerObject.SSH_MOUNT_PATH,
                'readOnly': False}
     container_obj = kubernetes.ContainerObject('name', 'fake_ssh_key2')
     output = container_obj._create_volume_mounts()
     self.assertEqual([ssh_vol], output)
Exemplo n.º 2
0
 def test_get_container_item_image_pull_policy(self):
     container_obj = kubernetes.ContainerObject(
         'cname', ssh_key='fake_sshkey', imagePullPolicy='Always')
     expected = {'args': [],
                 'command': kubernetes.ContainerObject.COMMAND_DEFAULT,
                 'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
                 'name': 'cname-container',
                 'volumeMounts': container_obj._create_volume_mounts(),
                 'imagePullPolicy':'Always'}
     self.assertEqual(expected, container_obj.get_container_item())
Exemplo n.º 3
0
 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())
Exemplo n.º 4
0
 def test_get_container_item_with_ports_no_container_port(self):
     with self.assertRaises(exceptions.KubernetesContainerPortNotDefined):
         volume_mount = {'name': 'fake_name',
                         'mountPath': 'fake_path'}
         args = ['arg1', 'arg2']
         container_obj = kubernetes.ContainerObject(
                 'cname', ssh_key='fake_sshkey', volumeMount=[volume_mount],
                 args=args, ports=[{'hostPort': 'fake_host_port',
                                    'name': 'fake_name',
                                    'protocol': 'fake_protocol',
                                    'hostIP': 'fake_port_number'}])
         container_obj.get_container_item()
Exemplo n.º 5
0
 def test_get_container_item(self):
     volume_mount = {'name': 'fake_name',
                     'mountPath': 'fake_path'}
     args = ['arg1', 'arg2']
     container_obj = kubernetes.ContainerObject(
         'cname', ssh_key='fake_sshkey', volumeMount=[volume_mount],
         args=args)
     expected = {'args': args,
                 'command': kubernetes.ContainerObject.COMMAND_DEFAULT,
                 'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
                 'name': 'cname-container',
                 'volumeMounts': container_obj._create_volume_mounts()}
     self.assertEqual(expected, container_obj.get_container_item())
Exemplo n.º 6
0
 def test__create_volume_mounts(self):
     volume_mount = {'name': 'fake_name',
                     'mountPath': 'fake_path'}
     ssh_vol = {'name': 'fake_ssh_key',
                'mountPath': kubernetes.ContainerObject.SSH_MOUNT_PATH,
                'readOnly': False}
     expected = copy.deepcopy(volume_mount)
     expected['readOnly'] = False
     expected = [expected, ssh_vol]
     container_obj = kubernetes.ContainerObject(
         'cname', 'fake_ssh_key', volumeMounts=[volume_mount])
     output = container_obj._create_volume_mounts()
     self.assertEqual(expected, output)
Exemplo n.º 7
0
 def test_get_container_item_with_resources(self):
     volume_mount = {'name': 'fake_name',
                     'mountPath': 'fake_path'}
     args = ['arg1', 'arg2']
     resources = {'requests': {'key1': 'val1'},
                  'limits': {'key2': 'val2'},
                  'other_key': {'key3': 'val3'}}
     container_obj = kubernetes.ContainerObject(
         'cname', ssh_key='fake_sshkey', volumeMount=[volume_mount],
         args=args, resources=resources)
     expected = {'args': args,
                 'command': kubernetes.ContainerObject.COMMAND_DEFAULT,
                 'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
                 'name': 'cname-container',
                 'volumeMounts': container_obj._create_volume_mounts(),
                 'resources': {'requests': {'key1': 'val1'},
                               'limits': {'key2': 'val2'}}}
     self.assertEqual(expected, container_obj.get_container_item())
Exemplo n.º 8
0
 def test_get_container_item_with_ports_multi_parameter(self):
     volume_mount = {'name': 'fake_name',
                     'mountPath': 'fake_path'}
     args = ['arg1', 'arg2']
     container_obj = kubernetes.ContainerObject(
         'cname', ssh_key='fake_sshkey', volumeMount=[volume_mount],
         args=args, ports=[{'containerPort': 'fake_port_name',
                            'hostPort': 'fake_host_port',
                            'name': 'fake_name',
                            'protocol': 'fake_protocol',
                            'invalid_varible': 'fakeinvalid_varible',
                            'hostIP': 'fake_port_number'}])
     expected = {'args': args,
                 'command': kubernetes.ContainerObject.COMMAND_DEFAULT,
                 'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
                 'name': 'cname-container',
                 'volumeMounts': container_obj._create_volume_mounts(),
                 'ports': [{'containerPort': 'fake_port_name',
                            'hostPort': 'fake_host_port',
                            'name': 'fake_name',
                            'protocol': 'fake_protocol',
                            'hostIP': 'fake_port_number'}]}
     self.assertEqual(expected, container_obj.get_container_item())
Exemplo n.º 9
0
 def test__parse_commands_exception(self):
     container_obj = kubernetes.ContainerObject('cname', 'fake_sshkey')
     with self.assertRaises(exceptions.KubernetesContainerCommandType):
         container_obj._parse_commands({})
Exemplo n.º 10
0
 def test__parse_commands_list(self):
     container_obj = kubernetes.ContainerObject('cname', 'fake_sshkey')
     self.assertEqual(['cmd1', 'cmd2'],
                      container_obj._parse_commands(['cmd1', 'cmd2']))
Exemplo n.º 11
0
 def test__parse_commands_string(self):
     container_obj = kubernetes.ContainerObject('cname', 'fake_sshkey')
     self.assertEqual(['fake command'],
                      container_obj._parse_commands('fake command'))