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
add verification of series supported by units to juju upgrade-series #8849
Conversation
bf3a719
to
cf62e1a
Compare
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.
LGTM
return errors.Trace(err) | ||
} | ||
|
||
return machine.CreateUpgradeSeriesLock() |
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.
Would it be better to lock the machine first? A defer()
can be used to unlock the machine in case of error.
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.
Is the concern that something could have been added between the time we verified the units series until the series lock is taken?
Its a fair point, but given that creating the document is also going to start other events being queued, we certainly want to do a pre check. It may be that we want to then also do a post check.
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.
If the VerifyUnitsSeries() fails, we don't want units to run the pre hook, which is triggered by the machine lock existing. CreateUpgradeSeriesLock() should be the next step though, and defer unlock if err happens from there. Updated code, and added a todo list for after the lock is taken.
}, | ||
}) | ||
} | ||
|
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.
+1, good that these tests are added.
@@ -2030,7 +2030,7 @@ func (m *Machine) UpdateMachineSeries(series string, force bool) error { | |||
return errors.Annotatef(err, "cannot update series for %q to %s", m, series) | |||
} | |||
|
|||
func (m *Machine) verifyUnitsSeries(unitNames []string, series string, force bool) ([]*Unit, error) { | |||
func (m *Machine) VerifyUnitsSeries(unitNames []string, series string, force bool) ([]*Unit, error) { |
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.
Does this need to be exported? If it is only exported for test, then perhaps you can move the tests into the internal test package instead.
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.
it's exported for use by the machinemanager in the apiserver
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.
A couple small things, but I think it is mostly good.
return errors.Trace(err) | ||
} | ||
|
||
return machine.CreateUpgradeSeriesLock() |
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.
Is the concern that something could have been added between the time we verified the units series until the series lock is taken?
Its a fair point, but given that creating the document is also going to start other events being queued, we certainly want to do a pre check. It may be that we want to then also do a post check.
@@ -96,6 +98,11 @@ type Unit interface { | |||
UnitTag() names.UnitTag | |||
} | |||
|
|||
func (m machineShim) VerifyUnitsSeries(unitNames []string, series string, force bool) error { | |||
_, err := m.Machine.VerifyUnitsSeries(unitNames, series, force) |
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.
Given the underlying function has a return value, why is it that we don't need to do anything with that value? Would it be a list of things we should recurse on?
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.
Normally it'd return a slice of unit tags, both principals and subordinates. It depend on how the next pieces are implemented, where it's useful at this point. Posed question in google doc
@@ -41,7 +41,7 @@ func (s *UpgradeSeriesSuite) runUpgradeSeriesCommandWithConfirmation(c *gc.C, co | |||
// mock remote API | |||
mockController := gomock.NewController(c) | |||
mockUpgradeSeriesAPI := mocks.NewMockUpgradeMachineSeriesAPI(mockController) | |||
mockUpgradeSeriesAPI.EXPECT().UpgradeSeriesPrepare(gomock.Any()).AnyTimes() | |||
mockUpgradeSeriesAPI.EXPECT().UpgradeSeriesPrepare(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() |
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.
I'm surprised we don't care what parameters are being passed. I would think the machine Number and series and whether or not we are forcing is quite relevant to what we want to test.
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.
I concur, @ExternalReality had differing thoughts, conversation in pr 8822.
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.
@hmlanigan, @jameinel Due to the nature of these tests we don't need to spy on the UpgradeSeriesPrepareMethod
method so we use the mock
as a stub
.
At the risk of sounding didactic I would add that many times spying
& mocking
are not needed when all that is really needed is a stub. Where spying and mocking are concerned with invocations and arguments; stubs only "stub out" an external dependency. So here the tests are saying "I don't care what you're doing UpgradeSeriesPerpare, I already trust that you work since you are tested somewhere else. Now get out of my way!"
Here is what Bob Martin's Little Mocker has to say about spys
vs stubs
:
That [spys] sounds like coupling.
It is! You have to be careful. The more you spy, the tighter you couple your tests to the implementation of your system. And that leads to fragile tests.
So in general its not a good idea to spy if all you need is a stub. Concretely, these test only make assertions about the proper handling of command line arguments and options and command line behavior that is solely based on those CLI argument and options. And as such the external dependencies can be stubbed rather than spied or mocked.
Code: params.CodeIncompatibleSeries, | ||
Message: "series \"xenial\" not supported by charm, supported series are: yakkety,zesty", | ||
}, | ||
}) |
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.
Of the tests that I see here, the only path that doesn't seem to be covered is if VerifyUnitsSeries fails. Is that being done separately?
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.
VerifyUnitsSeries() failure is covered by TestUpgradeSeriesPrepareIncompatibleSeries()
a9f4f22
to
b400b38
Compare
testing/gomockmatchers/booltype.go
Outdated
} | ||
|
||
func (o *BoolType) Matches(x interface{}) bool { | ||
return o.b == x |
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.
Should this be the following.
This should make sure that value you're expecting should infact be a type of "bool"
func (o *BoolType) Matches(x interface{}) bool {
if b, ok := x.(bool) {
return o.b == b
}
return false
}
or
func (o *BoolType) Matches(x interface{}) {
return o.b == x.(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.
@SimonRichardson thx making the change - i'm going to put the test changes in a different pr, so i can get the other stuff landed.
|
1 similar comment
|
Description of change
Part of Managed Series Upgrades: add verification of series supported by units to juju upgrade-series prepare
QA steps
ERROR series "bionic" not supported by charm, supported series are: xenial,trusty
Documentation changes
N/A
Bug reference
N/A