Skip to content

Commit

Permalink
WIP test cleanRootfs
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Oct 16, 2023
1 parent 1c92a87 commit 84d1fb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions internal/statemachine/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2350,11 +2350,12 @@ func TestSuccessfulClassicRun(t *testing.T) {
}

// Check cleaned files were removed
cleaned := []string{filepath.Join("etc", "machine-id"),
filepath.Join("var", "lib", "dbus", "machine-id"),
cleaned := []string{
filepath.Join(mountDir, "etc", "machine-id"),
filepath.Join(mountDir, "var", "lib", "dbus", "machine-id"),
}
for _, file := range cleaned {
_, err := os.Stat(filepath.Join(mountDir, file))
_, err := os.Stat(file)
if !os.IsNotExist(err) {
t.Errorf("File %s should not exist, but does", file)
}
Expand Down
13 changes: 6 additions & 7 deletions internal/statemachine/common_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,34 +330,33 @@ func (stateMachine *StateMachine) populatePreparePartitions() error {
func (stateMachine *StateMachine) cleanRootfs() error {
toClean := []string{
// machine-id
filepath.Join("etc", "machine-id"),
filepath.Join("var", "lib", "dbus", "machine-id"),
filepath.Join(stateMachine.tempDirs.rootfs, "etc", "machine-id"),
filepath.Join(stateMachine.tempDirs.rootfs, "var", "lib", "dbus", "machine-id"),
}

// openssh default keys
sshPubKeys, err := filepath.Glob(filepath.Join("etc", "ssh", "ssh_host_*_key.pub"))
sshPubKeys, err := filepath.Glob(filepath.Join(stateMachine.tempDirs.rootfs, "etc", "ssh", "ssh_host_*_key.pub"))
if err != nil {
return fmt.Errorf("unable to list sshd pub keys: %s", err.Error())
}

toClean = append(toClean, sshPubKeys...)

sshPrivKeys, err := filepath.Glob(filepath.Join("etc", "ssh", "ssh_host_*_key"))
sshPrivKeys, err := filepath.Glob(filepath.Join(stateMachine.tempDirs.rootfs, "etc", "ssh", "ssh_host_*_key"))
if err != nil {
return fmt.Errorf("unable to list sshd pub keys: %s", err.Error())
}

toClean = append(toClean, sshPrivKeys...)

for _, f := range toClean {
path := filepath.Join(stateMachine.tempDirs.rootfs, f)
err = osRemove(path)
err = osRemove(f)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("Error removing %s: %s", f, err.Error())
}
}

udevRules, err := filepath.Glob(filepath.Join("etc", "udev", "rules.d", "*persistent-net.rules"))
udevRules, err := filepath.Glob(filepath.Join(stateMachine.tempDirs.rootfs, "etc", "udev", "rules.d", "*persistent-net.rules"))
if err != nil {
return fmt.Errorf("unable to list udev persistent rules: %s", err.Error())
}
Expand Down

0 comments on commit 84d1fb8

Please sign in to comment.