Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmd.run with cwd and runas on macOS #51012

Merged

Conversation

cdalvaro
Copy link
Contributor

@cdalvaro cdalvaro commented Dec 31, 2018

What does this PR do?

When calling cmd.run with cwd in combination with runas the working directory was not set on macOS

SLS test recipe

test 1 - cmd.run as root:
  cmd.run:
    - name: pwd | grep '/Users/Carlos/Desktop'
    - cwd: /Users/Carlos/Desktop

test 2 - cmd.run as user:
  cmd.run:
    - name: pwd | grep '/Users/Carlos/Desktop'
    - cwd: /Users/Carlos/Desktop
    - runas: Carlos

test 3 - git.cloned (uses cmd.run):
  git.cloned:
    - name: https://github.com/robbyrussell/oh-my-zsh.git
    - target: /Users/Carlos/.oh-my-zsh
    - user: Carlos

test 4 - git.latest (uses cmd.run):
  git.latest:
    - name: https://github.com/bhilburn/powerlevel9k.git
    - target: /Users/Carlos/.oh-my-zsh/custom/themes/powerlevel9k
    - user: Carlos

What issues does this PR fix or reference?

#51008

Previous Behavior

local:
----------
          ID: test 1 - cmd.run as root
    Function: cmd.run
        Name: pwd | grep '/Users/Carlos/Desktop'
      Result: True
     Comment: Command "pwd | grep '/Users/Carlos/Desktop'" run
     Started: 14:25:37.286952
    Duration: 13.423 ms
     Changes:
              ----------
              pid:
                  21164
              retcode:
                  0
              stderr:
              stdout:
                  /Users/Carlos/Desktop
----------
          ID: test 2 - cmd.run as user
    Function: cmd.run
        Name: pwd | grep '/Users/Carlos/Desktop'
      Result: False
     Comment: Command "pwd | grep '/Users/Carlos/Desktop'" run
     Started: 14:25:37.300748
    Duration: 58.866 ms
     Changes:
              ----------
              pid:
                  21167
              retcode:
                  1
              stderr:
              stdout:
----------
          ID: test 3 - git.cloned (uses cmd.run)
    Function: git.cloned
        Name: https://github.com/robbyrussell/oh-my-zsh.git
      Result: False
     Comment: Command 'git status -z --porcelain' failed: fatal: not a git repository (or any of the parent directories): .git
     Started: 14:25:37.374095
    Duration: 59.353 ms
     Changes:
----------
          ID: test 4 - git.latest (uses cmd.run)
    Function: git.latest
        Name: https://github.com/bhilburn/powerlevel9k.git
      Result: False
     Comment: fatal: not a git repository (or any of the parent directories): .git
     Started: 14:25:37.433847
    Duration: 1953.688 ms
     Changes:

Summary for local
------------
Succeeded: 1 (changed=2)
Failed:    3
------------
Total states run:     4
Total run time:   2.085 s

New Behavior

local:
----------
          ID: test 1 - cmd.run as root
    Function: cmd.run
        Name: pwd | grep '/Users/Carlos/Desktop'
      Result: True
     Comment: Command "pwd | grep '/Users/Carlos/Desktop'" run
     Started: 14:27:03.927846
    Duration: 26.604 ms
     Changes:
              ----------
              pid:
                  21433
              retcode:
                  0
              stderr:
              stdout:
                  /Users/Carlos/Desktop
----------
          ID: test 2 - cmd.run as user
    Function: cmd.run
        Name: pwd | grep '/Users/Carlos/Desktop'
      Result: True
     Comment: Command "pwd | grep '/Users/Carlos/Desktop'" run
     Started: 14:27:03.954871
    Duration: 58.845 ms
     Changes:
              ----------
              pid:
                  21436
              retcode:
                  0
              stderr:
              stdout:
                  /Users/Carlos/Desktop
----------
          ID: test 3 - git.cloned (uses cmd.run)
    Function: git.cloned
        Name: https://github.com/robbyrussell/oh-my-zsh.git
      Result: True
     Comment: Repository already exists at /Users/Carlos/.oh-my-zsh
     Started: 14:27:04.028293
    Duration: 106.831 ms
     Changes:
----------
          ID: test 4 - git.latest (uses cmd.run)
    Function: git.latest
        Name: https://github.com/bhilburn/powerlevel9k.git
      Result: True
     Comment: Repository /Users/Carlos/.oh-my-zsh/custom/themes/powerlevel9k is up-to-date
     Started: 14:27:04.135623
    Duration: 4391.238 ms
     Changes:

Summary for local
------------
Succeeded: 4 (changed=2)
Failed:    0
------------
Total states run:     4
Total run time:   4.584 s

Tests written?

Yes

Commits signed with GPG?

Yes

When calling cmd.run with cwd in combination
with runas the working directory was not set on macOS

This commit also adds a test to check the expected behaviour
@cdalvaro cdalvaro changed the title Fix issue #51008 Fix cmd.run with cwd and runas on macOS Dec 31, 2018
@dwoz dwoz merged commit 5f8eae7 into saltstack:develop Dec 31, 2018
@cdalvaro cdalvaro deleted the bugifx/cwd_in_combination_with_runas_cmd.run branch February 23, 2019 16:47
waynew added a commit to waynew/salt that referenced this pull request Apr 21, 2020
When calling cmd.run with cwd in combination
with runas the working directory was not set on macOS

This commit also adds a test to check the expected behaviour

Co-authored-by: Wayne Werner <wwerner@saltstack.com>
@waynew waynew mentioned this pull request Apr 21, 2020
3 tasks
@sagetherage sagetherage added code-jam has master-port port to master has been created labels Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-jam has master-port port to master has been created
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants