Skip to content

cephadm: Make path to cephadm binary unique - #39141

Closed
sebastian-philipp wants to merge 4 commits into
ceph:masterfrom
sebastian-philipp:cephadmd-fix-unsafe-path
Closed

sebastian-philipp wants to merge 4 commits into
ceph:masterfrom
sebastian-philipp:cephadmd-fix-unsafe-path

Conversation

@sebastian-philipp

@sebastian-philipp sebastian-philipp commented Jan 28, 2021 •

Copy link
Copy Markdown
Contributor

right now, an upgrade might overwrite the existing
binary which would force us to have the CLI stable. Thus the path to cephadm is not safe for us.

This PR changes the path to a location that depends on the content of cephadm and thus is safe for up and downgrades.

Required for #37495

Signed-off-by: Sebastian Wagner [email protected]

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

Comment thread src/pybind/mgr/cephadm/module.py Resolved
right now, an upgrade might overwrite the existing
binary which would force us to have the CLI stable.

Signed-off-by: Sebastian Wagner <[email protected]>
@sebastian-philipp sebastian-philipp added the wip-swagner-testing My Teuthology tests label Feb 16, 2021
@sebastian-philipp

Copy link
Copy Markdown
Contributor Author
    @pytest.fixture
    def exporter():
        with mock.patch('cephadm.CephadmDaemon.daemon_path', _daemon_path()), \
           mock.patch('cephadm.CephadmDaemon.can_run', return_value=True), \
           mock.patch('cephadm.CephadmDaemon.run', _mock_run), \
           mock.patch('cephadm.CephadmDaemon._scrape_host_facts', _mock_scrape_host):
    
            ctx = cd.CephadmContext()
>           exporter = cd.CephadmDaemon(ctx, fsid='foobar', daemon_id='test')
E           TypeError: __init__() missing 1 required positional argument: 'binary'

@sebastian-philipp sebastian-philipp removed the wip-swagner-testing My Teuthology tests label Feb 18, 2021
Comment thread src/cephadm/cephadm Resolved

@jmolmo jmolmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check that cephadm binary exists when we create a Cephadmdaemon

Also:

* Enable the `test_can_run` unit test

Signed-off-by: Sebastian Wagner <[email protected]>
@sebastian-philipp

Copy link
Copy Markdown
Contributor Author

ping @jmolmo

@adk3798 adk3798 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code generally looks good to me. I haven't looked much at the exporter code so these are more questions on things I'm unsure about than suggestions.

Comment thread src/cephadm/cephadm
parser_exporter.add_argument(
'--binary',
type=str,
help='path to the cephadm binary')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this arg? If we're calling the exporter command directly from the command line then the binary to use would just be the one we're calling with, and in a call from the mgr to setup an exporter the only place the binary location is being used is in the CephadmDaemon unit_run function

ceph/src/cephadm/cephadm

Lines 6829 to 6838 in 4166eca

def unit_run(self):
return """set -e
{py3} {bin_path} exporter --fsid {fsid} --id {daemon_id} --port {port} &""".format(
py3 = shutil.which('python3'),
bin_path=self.binary_path,
fsid=self.fsid,
daemon_id=self.daemon_id,
port=self.port
)
which we aren't adjusting to use this arg.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this arg? If we're calling the exporter command directly from the command line then the binary to use would just be the one we're calling with.

There is no binary at this point. At least not when calling from cephadm. At least not until we have merged #39619 which depends on this very PR.

but we can probably avoid adding the --binary command argument indeed.

"key": cfg.key,
"token": cfg.token
"token": cfg.token,
'binary': self.mgr.cephadm_binary_path,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be off, but it looks like we pass the config dict into the CephadmDaemon deploy_daemon_unit function

ceph/src/cephadm/cephadm

Lines 2497 to 2504 in 4166eca

if ctx.config_json == '-':
config_js = get_parm('-')
else:
config_js = get_parm(ctx.config_json)
assert isinstance(config_js, dict)
cephadm_exporter = CephadmDaemon(ctx, fsid, config_js['binary'], daemon_id, port)
cephadm_exporter.deploy_daemon_unit(config_js)

which then writes all these files out

ceph/src/cephadm/cephadm

Lines 6876 to 6879 in 4166eca

# Create the required config files in the daemons dir, with restricted permissions
for filename in config:
with open(os.open(os.path.join(self.daemon_path, filename), os.O_CREAT | os.O_WRONLY, mode=0o600), "w") as f:
f.write(config[filename])

should we avoid having it do so for the binary since we're already deploying it beforehand with _deploy_cephadm_binary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if it makes sense to combine this PR with #39619 and avoid this complication

Comment thread src/pybind/mgr/cephadm/module.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants