-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spore-drive] domain key and tau binary issue #268
- Loading branch information
Showing
4 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ func (d *sporedrive) writeDomainPrivKeyToTmp(h remoteHost) error { | |
} | ||
|
||
func (d *sporedrive) writeDomainPubKeyToTmp(h remoteHost) error { | ||
pkr, err := d.parser.Cloud().Domain().Validation().OpenPrivateKey() | ||
pkr, err := d.parser.Cloud().Domain().Validation().OpenPublicKey() | ||
if err != nil { | ||
return fmt.Errorf("failed to open private domain key: %w", err) | ||
} | ||
|
@@ -381,6 +381,17 @@ func listTauInstances(ctx context.Context, h remoteHost) ([]string, error) { | |
return instances, nil | ||
} | ||
|
||
func (d *sporedrive) isSameTau(ctx context.Context, h remoteHost) bool { | ||
output, err := h.Execute(ctx, "md5sum", "-bz", "/tb/bin/tau") | ||
if err == nil && output != nil { | ||
fields := strings.Fields(string(output)) | ||
if len(fields) > 1 && fields[0] == d.tauBinaryHash { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (d *sporedrive) displaceHandler(hypha *course.Hypha, progressCh chan<- Progress) func(context.Context, host.Host) error { | ||
updatingTau := (d.tauBinary != nil) | ||
return func(ctx context.Context, h host.Host) error { | ||
|
@@ -495,6 +506,14 @@ func (d *sporedrive) displaceHandler(hypha *course.Hypha, progressCh chan<- Prog | |
} | ||
pushProgress("dependencies", 100) | ||
|
||
pushProgress("checking state", 0) | ||
updatingTau = updatingTau && !d.isSameTau(ctx, r) | ||
pushProgress("checking state", 50) | ||
|
||
// TODO: check config changes | ||
|
||
pushProgress("checking state", 100) | ||
|
||
// Upload to /tmp | ||
if updatingTau { | ||
pushProgress("upload tau", 0) | ||
|
@@ -560,7 +579,11 @@ func (d *sporedrive) displaceHandler(hypha *course.Hypha, progressCh chan<- Prog | |
} | ||
|
||
if _, err = r.Sudo(ctx, "cp", "-f", "/tmp/[email protected]", "/lib/systemd/system/[email protected]"); err != nil { | ||
return pushError("upload tau files", fmt.Errorf("failed to copy [email protected]: %w", err)) | ||
return pushError("upload tau files", fmt.Errorf("failed to copy [email protected]: %w", err)) | ||
} | ||
|
||
if _, err = r.Sudo(ctx, "systemctl", "daemon-reload"); err != nil { | ||
return pushError("upload tau files", fmt.Errorf("failed to daemon-reload: %w", err)) | ||
} | ||
} | ||
|
||
|
@@ -598,8 +621,10 @@ func (d *sporedrive) displaceHandler(hypha *course.Hypha, progressCh chan<- Prog | |
} | ||
pushProgress("setup tau", 30) | ||
|
||
if _, err = r.Sudo(ctx, "cp", "-f", "/tmp/tau", "/tb/bin/"); err != nil { | ||
return pushError("setup tau", fmt.Errorf("failed to copy tau: %w", err)) | ||
if updatingTau { | ||
if _, err = r.Sudo(ctx, "cp", "-f", "/tmp/tau", "/tb/bin/"); err != nil { | ||
return pushError("setup tau", fmt.Errorf("failed to copy tau: %w", err)) | ||
} | ||
} | ||
|
||
pushProgress("setup plugins", 0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,10 @@ func testDisplace(t *testing.T, sd Spore) { | |
142.250.115.139 | ||
`), nil) | ||
|
||
if updatingTau { | ||
rh.On("Execute", ctx, "md5sum", "-bz", "/tb/bin/tau").Once().Return(nil, nil) | ||
} | ||
|
||
// upload tau | ||
if updatingTau { | ||
tauf, _ := fses[h].OpenFile("/tmp/tau", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0750) | ||
|
@@ -83,6 +87,7 @@ func testDisplace(t *testing.T, sd Spore) { | |
sdcf, _ := fses[h].OpenFile("/tmp/[email protected]", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) | ||
rh.On("OpenFile", "/tmp/[email protected]", os.O_CREATE|os.O_RDWR|os.O_TRUNC, fs.FileMode(0644)).Once().Return(sdcf, nil) | ||
rh.On("Sudo", ctx, "cp", "-f", "/tmp/[email protected]", "/lib/systemd/system/[email protected]").Return(nil, nil) | ||
rh.On("Sudo", ctx, "systemctl", "daemon-reload").Return(nil, nil) | ||
} | ||
|
||
rh.On("Sudo", ctx, "bash", "-c", "mkdir -p /tb/{bin,scripts,priv,cache,logs,storage,config/keys,plugins}").Return(nil, nil) | ||
|
@@ -104,7 +109,9 @@ func testDisplace(t *testing.T, sd Spore) { | |
sh1cf, _ := fses[h].OpenFile("/tmp/shape1.yaml", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0750) | ||
rh.On("OpenFile", "/tmp/shape1.yaml", os.O_CREATE|os.O_RDWR|os.O_TRUNC, fs.FileMode(0750)).Once().Return(sh1cf, nil) | ||
rh.On("Sudo", ctx, "cp", "-f", "/tmp/shape1.yaml", "/tb/config/").Return(nil, nil) | ||
rh.On("Sudo", ctx, "cp", "-f", "/tmp/tau", "/tb/bin/").Return(nil, nil) | ||
if updatingTau { | ||
rh.On("Sudo", ctx, "cp", "-f", "/tmp/tau", "/tb/bin/").Return(nil, nil) | ||
} | ||
|
||
rh.On("Sudo", ctx, "systemctl", "list-units", "--type=service", "--quiet", "--no-pager", "--all", "tau@*.service").Once().Return([]byte(` [email protected] loaded inactive dead Description of compute | ||
[email protected] loaded inactive dead Description of storage | ||
|
@@ -158,9 +165,9 @@ func testDisplace(t *testing.T, sd Spore) { | |
} | ||
|
||
if updatingTau { | ||
assert.Equal(t, len(steps), 50) | ||
assert.Equal(t, len(steps), 56) | ||
} else { | ||
assert.Equal(t, len(steps), 44) | ||
assert.Equal(t, len(steps), 50) | ||
} | ||
|
||
for h, mfs := range fses { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters