-
Notifications
You must be signed in to change notification settings - Fork 2k
Upgrade the boot2docker.iso cache if possible when creating a VirtualBox machine #2298
Conversation
a4d1b80
to
711e1c4
Compare
cc @docker/machine-maintainers |
Could probably help #2248 |
Very nice. Will review this soon. |
711e1c4
to
9cd51c2
Compare
|
||
// offset and length of ISO volume ID | ||
// cf. http://serverfault.com/questions/361474/is-there-a-way-to-change-a-iso-files-volume-id-from-the-command-line | ||
volumeIDOffset int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just make these package-level const
instead? They are unlikely to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathanleclaire Actually I did at first, but I added these fields for testing.
0x8028 is too big and I want to set the offset as a smaller value in testing.
Any idea for cooler way? Maybe interface here too?
Instead of spinning up a whole server each time you need one, why not move the bits that you need to "mock" out into an embedded |
} | ||
|
||
// pathExists reports whether a file or directory specified by path exists. | ||
func pathExists(path string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, this could become a method on an interface and embedded into the B2DUtils
struct:
type PathChecker interface {
PathExists(string) bool
}
type StatPathChecker struct {}
func (spc *StatPathChecker) PathExists(path string) bool {
_, err := os.Stat(path)
return os.IsNotExist(err)
}
type B2DUtils struct {
StatPathChecker
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, GetLatestBoot2DockerReleaseURL
and other methods that contact the GitHub API could be turned into interfaces and embedded:
type LatestReleaseGetter interface {
GetLatestBoot2DockerReleaseURL(string) (string, error)
}
type GithubLatestReleaseGetter struct {}
func (g GithubLatestReleaseGetter) GetLatestBoot2DockerReleaseURL(url string) (string, error) {
....
}
type B2DUtils struct {
LatestReleaseGetter
...
}
Then it could be mocked out in a struct
for the tests:
type FakeLatestReleaseGetter struct {}
func (g FakeLatestReleaseGetter) GetLatestBoot2DockerReleaseURL(url string) (string, error) {
return "v1.9.0", nil // or however you wish to configure the behavior
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathanleclaire Useful sample code! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Current GetLatestBoot2DockerReleaseURL()
heavily relies on B2dUtils
.
If I delegate its implementation to GitHubLatestReleaseGetter
, I have to rethink an implementation of LatestReleaseGetter
interface...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sounds like you're on exactly the right track. You notice that GetLatestBoot2DockerReleaseURL
relies on getReleaseTag
. So, you will actually have to make that method as an interface
of LatestReleaseGetter
with getReleaseTag
method instead. This will enable you to embed it in the next interface up and mock that out completely in the bits which rely on it. It will require some jiggery-pokery due to all the passing of API URLs and so on that we're doing here, but doesn't have to be perfect on the first iteration.
Have posted some feedback, mostly that I would prefer to use interfaces to test instead of spinning up whole web servers in the tests (we're long past due for implementing this). Looking pretty decent so far though 👍 |
@nathanleclaire Thank you for your kind review! |
Good times. Make sure to ping us (@docker/machine-maintainers) when you've done some work in that direction. |
Any update on this @skatsuta ? |
e636400
to
a361636
Compare
@nathanleclaire Sorry for the late fix. Now I'm done. Please re-review it. Changelog
|
e53b0d9
to
9e3af3c
Compare
@@ -0,0 +1,27 @@ | |||
#!/usr/bin/env bats | |||
|
|||
load ${BASE_TEST_DIR}/helpers.bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not give this test file a more descriptive name? create.bats
doesn't tell me much about what it's intended to test.
c068697
to
bc15894
Compare
Reviewed this and everything looks solid. Even works without network access (defaults to the cached version). Great work @skatsuta. LGTM cc @docker/machine-maintainers |
We can follow-up after merge to rename the test file to something more specific. |
Very sorry I seemed to make a mistake to merge and rebase the upstream. |
6f3a746
to
fa69652
Compare
OK fixed and renamed |
fa69652
to
9c9a334
Compare
OK thanks @skatsuta. @dgageot @jeanlaurent please take a look at this when you get a chance. |
Hi @skatsuta Each time I upgrade a VBox VM that has docker 1.9.1 installed, b2d 1.9.1 is downloaded again even if it is already in my
|
Also, when the cache folder does not exist, the upgrade fails.
|
… latest one when it is out-of-date Signed-off-by: Soshi Katsuta <soshi.katsuta@gmail.com>
9c9a334
to
bbe7a00
Compare
@nathanleclaire @dgageot |
Thanks @skatsuta. This PR LGTM. @dgageot @jeanlaurent at your discretion whether you'd like to merge in for the 0.5.3 release. I'm in favor but don't feel like there's any hurry. |
@dgageot @jeanlaurent PTAL at this when you get a chance. |
LGTM |
Upgrade the boot2docker.iso cache if possible when creating a VirtualBox machine
close #1790
This PR will
B2dUtils
's methodsSigned-off-by: Soshi Katsuta soshi.katsuta@gmail.com