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

add verification of series supported by units to juju upgrade-series #8849

Merged
merged 1 commit into from Jun 27, 2018

Conversation

hmlanigan
Copy link
Member

Description of change

Part of Managed Series Upgrades: add verification of series supported by units to juju upgrade-series prepare

QA steps

  1. juju bootstrap
  2. export JUJU_DEV_FEATURE_FLAGS=upgrade-series
  3. juju deploy ghost (chosen because it doesn't support bionic)
  4. juju upgrade-series prepare 0 bionic
    ERROR series "bionic" not supported by charm, supported series are: xenial,trusty
  5. juju upgrade-series prepare 0 bionic --force

Documentation changes

N/A

Bug reference

N/A

@hmlanigan
Copy link
Member Author

@hmlanigan hmlanigan force-pushed the verify branch 2 times, most recently from bf3a719 to cf62e1a Compare June 22, 2018 20:14
Copy link
Contributor

@ExternalReality ExternalReality left a 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()
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member Author

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.

},
})
}

Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member

@jameinel jameinel left a 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()
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member Author

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()
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 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.

Copy link
Member Author

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.

Copy link
Contributor

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",
},
})
Copy link
Member

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?

Copy link
Member Author

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()

@hmlanigan hmlanigan force-pushed the verify branch 2 times, most recently from a9f4f22 to b400b38 Compare June 27, 2018 16:36
}

func (o *BoolType) Matches(x interface{}) bool {
return o.b == x
Copy link
Member

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)
}

Copy link
Member Author

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.

@hmlanigan
Copy link
Member Author

$$merge$$

1 similar comment
@hmlanigan
Copy link
Member Author

$$merge$$

@jujubot jujubot merged commit 4cc1696 into juju:develop Jun 27, 2018
@hmlanigan hmlanigan deleted the verify branch June 27, 2018 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants