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

Copy in additional files before postprocessing #997

Closed
wants to merge 4 commits into from

Conversation

jdieter
Copy link

@jdieter jdieter commented Sep 18, 2017

Sometimes it's useful to have access to the additional files when running the post script, so this re-orders the compose process to copy the additional files in before the post script runs.

I'm not sure how to create a test for this patch, but if you give me some pointers, I'll put something together.

@rh-atomic-bot
Copy link

Can one of the admins verify this patch?
I understand the following commands:

  • bot, add author to whitelist
  • bot, test pull request
  • bot, test pull request once

@jdieter
Copy link
Author

jdieter commented Sep 18, 2017

While I'm thinking about this, I did backport this patch to the 2017.8 release and tested locally, and it works as advertised.

@cgwalters
Copy link
Member

Hi, thanks for the patch! There's a bigger picture issue here; see
#471

I swear there was another issue filed about this; I found #779 but that's not quite the same.

Anyways I have a vague concern about compatibility here - could someone have been using add-files in such a way that they expected it to happen before postprocessing? I can't think offhand of how this would break something though.

@cgwalters
Copy link
Member

There are tests in tests/compose - I can take care of updating them for this though.

@jdieter
Copy link
Author

jdieter commented Sep 19, 2017

Well, you've read my mind. As I think I mentioned to you at Flock, I'm really interested in using this to run ansible locally. In my testing, I've managed to tar up my ansible playbooks, copy them across using add-files, and run them. I'm hitting some roadblocks in ansible (apparently the service and systemd modules don't like being unable to connect to systemd when enabling and disabling services), so I haven't actually managed to complete a compose yet, but, assuming rpm-ostree will commit after running the post script, it's working perfectly.

The only situation that I thought of where add-files might need to happen after post was if it doesn't create any intermediate directories and the user needs to be manually do that in post.

@jdieter
Copy link
Author

jdieter commented Sep 19, 2017

Just to clarify, for what I'm doing, I don't actually need network access when running the ansible scripts.

@cgwalters
Copy link
Member

Will look at this and tests for it after the next release.

@cgwalters
Copy link
Member

bot, add author to whitelist

@cgwalters
Copy link
Member

This breaks at least the current test-misc-tweaks.sh in the compose tests - the issue seems to be we're basically creating /usr/etc and /etc in the tree. Fixing this seems like it's going to require some plumbing to ensure that we do the /etc/usr/etc rename before we do add-files. This actually overlaps a bit with work in #940 - I'm going to look at extracting that as a separate PR, then will rework this on top.

cgwalters added a commit to cgwalters/rpm-ostree that referenced this pull request Sep 25, 2017
Hooray, it's dead (here, but not in ostree). Noticed this while working on
<coreos#997>
cgwalters added a commit to jdieter/rpm-ostree that referenced this pull request Sep 26, 2017
Lots of confusion in the codebase about this. The basic problem is that in
*most* cases, our code doesn't care; it's conceptually operating on `/usr/etc`,
which we could maintain as `/etc` and just rename it back at the very end.

The exceptions though are the `/etc/passwd` handling and livefs. And of course
libostree needs to handle `/usr/etc` vs `/etc` for config merging.

I considered trying to keep things the other way, but while I think we have some
ugly added here in this patch for things where we need to maintain an external
view (`remove-files` and `remove-from-packages`, and boy am I glad we had tests
for those), this ends up being mostly more consistent elsewhere.

One thing that might help is to maintain a fd for it; but that'd be an even more
invasive change.

This also ends up rolling in some unified core prep from
coreos#940 in the form of
`rename_if_exists()` - basically for some minimal rootfs we may not have
`/boot`, or for that matter potentially even `etc`.

Prep for coreos#997
@cgwalters cgwalters removed the WIP label Sep 26, 2017
@cgwalters
Copy link
Member

OK, reworked this with a prep patch. Lifting WIP.

rh-atomic-bot pushed a commit that referenced this pull request Sep 26, 2017
Hooray, it's dead (here, but not in ostree). Noticed this while working on
<#997>

Closes: #1012
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Sep 26, 2017
Hooray, it's dead (here, but not in ostree). Noticed this while working on
<#997>

Closes: #1012
Approved by: jlebon
@cgwalters cgwalters requested a review from jlebon September 26, 2017 19:17
@@ -1442,6 +1450,12 @@ rpmostree_treefile_postprocessing (int rootfs_fd,
if (!glnx_shutil_rm_rf_at (rootfs_fd, val, cancellable, error))
return FALSE;
}
if (len > 0)
Copy link
Member

Choose a reason for hiding this comment

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

But the array could be specified but empty, right? I'd just shove this whole loop with the pre and post /etc moves in the if statement itself.

if (!glnx_fstatat_allow_noent (rootfs_dfd, "usr/etc", &stbuf, 0, error))
return FALSE;
if (errno == ENOENT)
etc_path = "etc";
Copy link
Member

Choose a reason for hiding this comment

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

But this should never happen, right? We've already moved /etc to /usr/etc, so it'd be an error to not find it there, no?

Copy link
Member

Choose a reason for hiding this comment

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

Updated for everything except this...I still need to investigate this bit more.

Copy link
Member

Choose a reason for hiding this comment

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

OK, upon further investigation I think you're right. I haven't yet rebased unified core on top of this to verify but if there's an issue with that we can fix it later.

@@ -1559,6 +1556,10 @@ rpmostree_treefile_postprocessing (int rootfs_fd,
}
}

/* Copy in additional files before postprocessing */
if (!copy_additional_files (rootfs_fd, context_directory, treefile, cancellable, error))
Copy link
Member

Choose a reason for hiding this comment

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

I just realized now that we handle add-files after the /etc to /usr/etc move. What this patch does is correct since it maintains that, though are we sure that's what we want to begin with? Seems like users would expect to dump things in e.g. /etc, not /usr/etc, right?

Copy link
Author

Choose a reason for hiding this comment

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

FWIW, I'd prefer the /etc to /usr/etc move happen after both add-files and the post script, but it's easy enough to work around if that's not possible.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not totally opposed to changing it but on the other hand we had a test case that did it, and I've definitely seen people talk about using add-files here and I'd like not to break them.

Perhaps the simplest thing is to support both; we could do that by dropping a temporary symlink, or translating paths.

Copy link
Member

Choose a reason for hiding this comment

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

Translating paths seems reasonable, yeah.

cgwalters and others added 3 commits September 27, 2017 21:56
Lots of confusion in the codebase about this. The basic problem is that in
*most* cases, our code doesn't care; it's conceptually operating on `/usr/etc`,
which we could maintain as `/etc` and just rename it back at the very end.

The exceptions though are the `/etc/passwd` handling and livefs. And of course
libostree needs to handle `/usr/etc` vs `/etc` for config merging.

I considered trying to keep things the other way, but while I think we have some
ugly added here in this patch for things where we need to maintain an external
view (`remove-files` and `remove-from-packages`, and boy am I glad we had tests
for those), this ends up being mostly more consistent elsewhere.

One thing that might help is to maintain a fd for it; but that'd be an even more
invasive change.

This also ends up rolling in some unified core prep from
coreos#940 in the form of
`rename_if_exists()` - basically for some minimal rootfs we may not have
`/boot`, or for that matter potentially even `etc`.

Prep for coreos#997
Even though it's really `/usr/etc`. This is for greater consistency with
`postprocess-script` where it appears as `/etc`.
Sometimes it's useful to have access to the additional files when running
the post script, so this re-orders the compose process to copy the
additional files in before the post script runs

Signed-off-by: Jonathan Dieter <[email protected]>
@jlebon
Copy link
Member

jlebon commented Sep 28, 2017

Looks good! @rh-atomic-bot r+ 3596d11

@rh-atomic-bot
Copy link

⌛ Testing commit 3596d11 with merge fd6109a...

rh-atomic-bot pushed a commit that referenced this pull request Sep 28, 2017
Even though it's really `/usr/etc`. This is for greater consistency with
`postprocess-script` where it appears as `/etc`.

Closes: #997
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Sep 28, 2017
Sometimes it's useful to have access to the additional files when running
the post script, so this re-orders the compose process to copy the
additional files in before the post script runs

Signed-off-by: Jonathan Dieter <[email protected]>

Closes: #997
Approved by: jlebon
@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing fd6109a to master...

@tjim
Copy link

tjim commented Oct 1, 2017

Just got burned by this (add-files to /etc, ostree fails due to existence of both /etc and /usr/etc). I realize this pull will address this but what happens now if I add-files to /usr/etc (my workaround for the current release)? Will there be a similar error?

Consider this a request for documentation and a check/error message at rpm-ostree compose time.

@cgwalters
Copy link
Member

Hi @tjim - it should work in both cases now in git master.

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