Page MenuHomePhabricator

Scap fails to force-deploy the config
Closed, ResolvedPublic

Description

As part of T144542: Enable config deploys for service::node services, there is a script that forces a local Scap3 config deploy if the file containing the Puppet-controlled variables changes. Trying it out in BetaCluster as part of T144755: Enable Scap3 config deploys for Mathoid revealed a failure due to an already-existing directory:

12:26:12 Unhandled error:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/scap/cli.py", line 256, in run
    exit_status = app.main(app.extra_arguments)
  File "/usr/lib/python2.7/dist-packages/scap/deploy.py", line 89, in main
    getattr(self, stage)()
  File "/usr/lib/python2.7/dist-packages/scap/deploy.py", line 124, in config_deploy
    utils.mkdir_p(source_basepath)
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 640, in mkdir_p
    sudo_check_call(user, "mkdir -p '{}'".format(path))
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 319, in context_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 421, in sudo_check_call
    raise subprocess.CalledProcessError(proc.returncode, cmd)
CalledProcessError: Command 'mkdir -p '/srv/deployment/mathoid/deploy-cache/revs/9937e0fec4a26641b74be6709f17f21e236b193f/.git/config-files'' returned non-zero exit status 1

Since this is only a config deploy, and a forced one at that, I would not expect Scap3 to fail because the directory already exists (and it will in most instances).

Revisions and Commits

rMSCA Scap
Restricted Differential Revision

Event Timeline

The problem seems to be the fact that Scap3 tries to sudo into the deployment user, which is the same as the one running the script. Alas, the deployment user cannot do sudo -i ${deployment_user}. Here's what I get when manually running the script as the deployment user:

deploy-service@deployment-mathoid:~$ /usr/bin/scap deploy-local -D 'log_json:False' --repo mathoid/deploy --force config_deploy;
15:55:14 Last output:
sudo: a password is required
15:55:14 Unhandled error:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/scap/cli.py", line 256, in run
    exit_status = app.main(app.extra_arguments)
  File "/usr/lib/python2.7/dist-packages/scap/deploy.py", line 89, in main
    getattr(self, stage)()
  File "/usr/lib/python2.7/dist-packages/scap/deploy.py", line 124, in config_deploy
    utils.mkdir_p(source_basepath)
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 640, in mkdir_p
    sudo_check_call(user, "mkdir -p '{}'".format(path))
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 319, in context_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/scap/utils.py", line 421, in sudo_check_call
    raise subprocess.CalledProcessError(proc.returncode, cmd)
CalledProcessError: Command 'mkdir -p '/srv/deployment/mathoid/deploy-cache/revs/9937e0fec4a26641b74be6709f17f21e236b193f/.git/config-files'' returned non-zero exit status 1
15:55:14 deploy-local failed: <CalledProcessError> Command 'mkdir -p '/srv/deployment/mathoid/deploy-cache/revs/9937e0fec4a26641b74be6709f17f21e236b193f/.git/config-files'' returned non-zero exit status 1

Confirmation of the above:

deploy-service@deployment-mathoid:~$ sudo -i deploy-service scap deploy-local --help

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for deploy-service:
mobrovac assigned this task to thcipriani.

Fixed in v3.2.5-1. Thnx @thcipriani !