Bug 1263609 - oc rsh take command option as command argument wrongly
oc rsh take command option as command argument wrongly
Status: CLOSED CURRENTRELEASE
Product: OpenShift Origin
Classification: Red Hat
Component: Command Line Interface (Show other bugs)
3.x
Unspecified Unspecified
medium Severity low
: ---
: ---
Assigned To: Fabiano Franz
Wei Sun
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-09-16 05:50 EDT by yapei
Modified: 2016-05-12 13:16 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-05-12 13:16:02 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description yapei 2015-09-16 05:50:46 EDT
Description of problem:
'oc rsh -h' gives the help information about command, when follow the instruction to execute some commands in format 'oc rsh POD [command] -t/-T/-c',-t/-T/-c is regarded as argument of [command] passed in oc rsh

Version-Release number of selected component (if applicable):
oc v1.0.6-37-gaece681
kubernetes v1.1.0-alpha.0-1605-g44c91b1
devenv-fedora_2348

How reproducible:
Always

Steps to Reproduce:
1. Create a pod with two containers, wait the pod to be Running
$ oc create -f https://raw.githubusercontent.com/openshift-qe/v3-testfiles/master/pods/pod_with_two_containers.json
2. Check 'oc rsh' help info
$ oc rsh -h
Usage:
  oc rsh POD [command] [options]
Examples:
  // Open a shell session on the first container in pod 'foo'
  $ oc rsh foo
  // Run the command 'cat /etc/resolv.conf' inside pod 'foo'
  $ oc rsh foo cat /etc/resolv.conf
Options:
  -c, --container='': Container name; defaults to first container
  -T, --no-tty=false: Disable pseudo-terminal allocation
      --shell='/bin/bash': Path to shell command
  -t, --tty=false: Force a pseudo-terminal to be allocated
3. Use 'oc rsh' behaviour to execute command in container
(a)$ oc rsh doublecontainers ls -T
(b)$ oc rsh -T doublecontainers ls
bin
dev
etc
hello-openshift
......
(c)$ oc rsh doublecontainers date -c hello-openshift-fedora
4. Check -t and -T options for ssh commmand
$ man ssh
ssh [-1246AaCfGgKkMNnqsTtVvXxYy]...... [user@]hostname [command]
[-t] and [-T] options are before the [command] option

Actual results:
step2:
$ oc rsh -h
Usage:
  oc rsh POD [command] [options]
Examples:
  // Open a shell session on the first container in pod 'foo'
  $ oc rsh foo
  // Run the command 'cat /etc/resolv.conf' inside pod 'foo'
  $ oc rsh foo cat /etc/resolv.conf
Options:
  -c, --container='': Container name; defaults to first container
  -T, --no-tty=false: Disable pseudo-terminal allocation
      --shell='/bin/bash': Path to shell command
  -t, --tty=false: Force a pseudo-terminal to be allocated
step3:
(a)$ oc rsh doublecontainers ls -T
ls: option requires an argument -- 'T'
Try 'ls --help' for more information.
error: error executing remote command: Error executing command in container: Error executing in Docker Container: 2
(c)$ oc rsh doublecontainers date -c hello-openshift-fedora
date: invalid option -- 'c'
Try 'date --help' for more information.
error: error executing remote command: Error executing command in container: Error executing in Docker Container: 1

Expected results:
In the help info, [command] should behind the [option], like 
oc rsh POD [options] [command] 
only in this way, -t and -T option will not be treated as a argument of command.
otherwise, it will give wrong direction for users to use 'oc rsh'command
step3(a)
'ls' command is executed and result is returned
step3(c)
`date` command should be executed in container 'hello-openshift-fedora'

Additional info:
If we specify -T option for interactive command, it will hang 
$ oc rsh -c hello-openshift-fedora -T doublecontainers bash
$ oc rsh -c hello-openshift-fedora -T doublecontainers /usr/bin/python
Comment 1 Fabiano Franz 2016-01-12 13:53:26 EST
Fixed in https://github.com/openshift/origin/pull/6619. Note that we still have [options] in the end for the command options, but added [options] for the rsh command.
Comment 2 openshift-github-bot 2016-01-12 14:55:57 EST
Commit pushed to master at https://github.com/openshift/origin

https://github.com/openshift/origin/commit/0741048c36a2fdc7fbd70dba72ccb960ca5bab78
Bug 1263609 - fix oc rsh usage
Comment 3 yapei 2016-01-14 04:32:53 EST
checked on devenv-rhel7_3145,

when -c option is carried, 
'oc rsh doublecontainers --container=hello-openshift-fedora‘

There is still error info printed,
exec: "--container=hello-openshift-fedora": executable file not found in $PATH
error: error executing remote command: Error executing command in container: Error executing in Docker Container: -1

when other option (-T/-t) is carried, same problem happens
Comment 4 Fabiano Franz 2016-03-10 08:41:43 EST
Fixed the usage in https://github.com/openshift/origin/pull/7895.
Comment 5 yapei 2016-03-11 00:10:11 EST
checked against devenv-rhel7_3688, 

1. Check 'oc rsh' usage
Usage:
  oc rsh POD [options] [COMMAND]

2. [options] are placed behind POD
# oc rsh doublecontainers -c hello-openshift-fedora  cat /etc/system-release
exec: "-c": executable file not found in $PATH

3. [options] are placed before POD
# oc rsh -c hello-openshift-fedora doublecontainers  cat /etc/system-release
Fedora release 21 (Twenty One)

4. Compared with 'oc exec'
# oc exec doublecontainers -c hello-openshift-fedora  cat /etc/system-release
Fedora release 21 (Twenty One)

From step2, when [options] comes after POD, it gives error info. I think this is wrong behaviour because help info says [options] comes after POD, current solution didn't match help info.

Another issue,
In the help info, it says "will attempt to use '/bin/bash' as the default shell", please see this command

# oc rsh doublecontainers
sh-4.2$ echo $BASH
/bin/sh
sh-4.2$ ps
  PID TTY          TIME CMD
   55 ?        00:00:00 sh
   59 ?        00:00:00 ps

it seems that /bin/sh is used instead of /bin/bash.

Please check these problems
Comment 6 Fabiano Franz 2016-03-11 11:27:10 EST
Good catch, rsh usage is fixed in https://github.com/openshift/origin/pull/7946.
Comment 7 yapei 2016-03-13 21:40:29 EDT
checked against devenv-rhel7_3705

Now the command works well

# oc rsh -c hello-openshift-fedora doublecontainers
sh-4.3$ cat /etc/system-release
Fedora release 21 (Twenty One)
sh-4.3$ exit
exit
# oc rsh --container=hello-openshift-fedora doublecontainers
sh-4.3$ cat /etc/system-release
Fedora release 21 (Twenty One)
sh-4.3$ exit
exit
# oc rsh --container=hello-openshift-fedora doublecontainers cat /etc/system-release
Fedora release 21 (Twenty One)
# oc rsh --container=hello-openshift-fedora --shell=/bin/bash doublecontainers
bash-4.3$ exit

Move to VERIFIED

Note You need to log in before you can comment on or make changes to this bug.