36
37
"github.com/juju/juju/state"
37
38
"github.com/juju/juju/state/multiwatcher"
38
39
statetesting "github.com/juju/juju/state/testing"
40
"github.com/juju/juju/status"
39
41
"github.com/juju/juju/storage/poolmanager"
40
42
"github.com/juju/juju/storage/provider"
41
43
"github.com/juju/juju/storage/provider/registry"
42
44
"github.com/juju/juju/testcharms"
43
45
"github.com/juju/juju/testing"
44
46
"github.com/juju/juju/testing/factory"
45
"github.com/juju/juju/version"
47
jujuversion "github.com/juju/juju/version"
48
50
var goodPassword = "foo-12345678901234567890"
54
56
// asserting the behaviour of a given method in each state, and the unit quick-
55
57
// remove change caused many of these to fail.
56
58
func preventUnitDestroyRemove(c *gc.C, u *state.Unit) {
57
err := u.SetAgentStatus(state.StatusIdle, "", nil)
59
err := u.SetAgentStatus(status.StatusIdle, "", nil)
58
60
c.Assert(err, jc.ErrorIsNil)
1978
1980
bindings: map[string]string{"extra": "missing"},
1979
1981
expectedError: `unknown endpoint "extra" not valid`,
1981
about: "ensure network.DefaultSpace is not treated specially",
1982
bindings: map[string]string{"server": network.DefaultSpace},
1983
expectedError: `unknown space "default" not valid`,
1985
1983
about: "extra endpoint not bound to a space",
1986
1984
bindings: map[string]string{"extra": ""},
1987
1985
expectedError: `unknown endpoint "extra" not valid`,
2003
2001
expectedError: `unknown space "invalid" not valid`,
2005
2003
about: "known endpoint bound correctly and an extra endpoint",
2006
bindings: map[string]string{"server": "db", "foo": ""},
2004
bindings: map[string]string{"server": "db", "foo": "public"},
2007
2005
expectedError: `unknown endpoint "foo" not valid`,
2009
2007
c.Logf("test #%d: %s", i, test.about)
2055
2053
c.Assert(err, jc.ErrorIsNil)
2056
func (s *StateSuite) TestAddServiceCompatibleOSWithNoExplicitSupportedSeries(c *gc.C) {
2057
// If a charm doesn't declare any series, we can add it with any series we choose.
2058
charm := s.AddSeriesCharm(c, "dummy", "")
2059
_, err := s.State.AddService(state.AddServiceArgs{
2060
Name: "wordpress", Owner: s.Owner.String(), Charm: charm,
2063
c.Assert(err, jc.ErrorIsNil)
2058
2066
func (s *StateSuite) TestAddServiceOSIncompatibleWithSupportedSeries(c *gc.C) {
2059
2067
charm := state.AddTestingCharmMultiSeries(c, s.State, "multi-series")
2060
2068
// A charm with supported series can only be force-deployed to series
3222
func testSetAgentCompatPassword(c *gc.C, entity state.Authenticator) {
3223
// In Juju versions 1.16 and older we used UserPasswordHash(password,CompatSalt)
3224
// for Machine and Unit agents. This was determined to be overkill
3225
// (since we know that Unit agents will actually use
3226
// utils.RandomPassword() and get 18 bytes of entropy, and thus won't
3227
// be brute-forced.)
3228
c.Assert(entity.PasswordValid(goodPassword), jc.IsFalse)
3229
agentHash := utils.AgentPasswordHash(goodPassword)
3230
err := state.SetPasswordHash(entity, agentHash)
3231
c.Assert(err, jc.ErrorIsNil)
3232
c.Assert(entity.PasswordValid(goodPassword), jc.IsTrue)
3233
c.Assert(entity.PasswordValid(alternatePassword), jc.IsFalse)
3234
c.Assert(state.GetPasswordHash(entity), gc.Equals, agentHash)
3236
backwardsCompatibleHash := utils.UserPasswordHash(goodPassword, utils.CompatSalt)
3237
c.Assert(backwardsCompatibleHash, gc.Not(gc.Equals), agentHash)
3238
err = state.SetPasswordHash(entity, backwardsCompatibleHash)
3239
c.Assert(err, jc.ErrorIsNil)
3240
c.Assert(entity.PasswordValid(alternatePassword), jc.IsFalse)
3241
c.Assert(state.GetPasswordHash(entity), gc.Equals, backwardsCompatibleHash)
3242
// After succeeding to log in with the old compatible hash, the db
3243
// should be updated with the new hash
3244
c.Assert(entity.PasswordValid(goodPassword), jc.IsTrue)
3245
c.Assert(state.GetPasswordHash(entity), gc.Equals, agentHash)
3246
c.Assert(entity.PasswordValid(goodPassword), jc.IsTrue)
3248
// Agents are unable to set short passwords
3249
err = entity.SetPassword("short")
3250
c.Check(err, gc.ErrorMatches, "password is only 5 bytes long, and is not a valid Agent password")
3251
// Grandfather clause. Agents that have short passwords are allowed if
3252
// it was done in the compatHash form
3253
agentHash = utils.AgentPasswordHash("short")
3254
backwardsCompatibleHash = utils.UserPasswordHash("short", utils.CompatSalt)
3255
err = state.SetPasswordHash(entity, backwardsCompatibleHash)
3256
c.Assert(err, jc.ErrorIsNil)
3257
c.Assert(entity.PasswordValid("short"), jc.IsTrue)
3258
// We'll still update the hash, but now it points to the hash of the
3259
// shorter password. Agents still can't set the password to it
3260
c.Assert(state.GetPasswordHash(entity), gc.Equals, agentHash)
3261
// Still valid with the shorter password
3262
c.Assert(entity.PasswordValid("short"), jc.IsTrue)
3265
3230
type entity interface {
3823
3788
assertAgentVersion(c, otherSt, lower.Number.String())
3825
3790
// Set other environ version == server environ version
3826
err = otherSt.SetModelAgentVersion(version.Current)
3791
err = otherSt.SetModelAgentVersion(jujuversion.Current)
3827
3792
c.Assert(err, jc.ErrorIsNil)
3828
assertAgentVersion(c, otherSt, version.Current.String())
3793
assertAgentVersion(c, otherSt, jujuversion.Current.String())
3830
3795
// Set other environ version to > server environ version
3831
3796
err = otherSt.SetModelAgentVersion(higher.Number)
3832
3797
expected := fmt.Sprintf("a hosted model cannot have a higher version than the server model: %s > %s",
3799
jujuversion.Current,
3836
3801
c.Assert(err, gc.ErrorMatches, expected)
4637
4602
c.Assert(err, gc.ErrorMatches, `"invalid-id" is not a valid machine id`)
4605
func (s *StateSuite) TestSetOrGetMongoSpaceNameSets(c *gc.C) {
4606
info, err := s.State.ControllerInfo()
4607
c.Assert(err, jc.ErrorIsNil)
4608
c.Assert(info.MongoSpaceName, gc.Equals, "")
4609
c.Assert(info.MongoSpaceState, gc.Equals, state.MongoSpaceUnknown)
4611
spaceName := network.SpaceName("foo")
4613
name, err := s.State.SetOrGetMongoSpaceName(spaceName)
4614
c.Assert(err, jc.ErrorIsNil)
4615
c.Assert(name, gc.Equals, spaceName)
4617
info, err = s.State.ControllerInfo()
4618
c.Assert(err, jc.ErrorIsNil)
4619
c.Assert(info.MongoSpaceName, gc.Equals, string(spaceName))
4620
c.Assert(info.MongoSpaceState, gc.Equals, state.MongoSpaceValid)
4623
func (s *StateSuite) TestSetOrGetMongoSpaceNameDoesNotReplaceValidSpace(c *gc.C) {
4624
spaceName := network.SpaceName("foo")
4625
name, err := s.State.SetOrGetMongoSpaceName(spaceName)
4626
c.Assert(err, jc.ErrorIsNil)
4627
c.Assert(name, gc.Equals, spaceName)
4629
name, err = s.State.SetOrGetMongoSpaceName(network.SpaceName("bar"))
4630
c.Assert(err, jc.ErrorIsNil)
4631
c.Assert(name, gc.Equals, spaceName)
4633
info, err := s.State.ControllerInfo()
4634
c.Assert(err, jc.ErrorIsNil)
4635
c.Assert(info.MongoSpaceName, gc.Equals, string(spaceName))
4636
c.Assert(info.MongoSpaceState, gc.Equals, state.MongoSpaceValid)
4639
func (s *StateSuite) TestSetMongoSpaceStateSetsValidStates(c *gc.C) {
4640
mongoStates := []state.MongoSpaceStates{
4641
state.MongoSpaceUnknown,
4642
state.MongoSpaceValid,
4643
state.MongoSpaceInvalid,
4644
state.MongoSpaceUnsupported,
4646
for _, st := range mongoStates {
4647
err := s.State.SetMongoSpaceState(st)
4648
c.Assert(err, jc.ErrorIsNil)
4649
info, err := s.State.ControllerInfo()
4650
c.Assert(err, jc.ErrorIsNil)
4651
c.Assert(info.MongoSpaceState, gc.Equals, st)
4655
func (s *StateSuite) TestSetMongoSpaceStateErrorOnInvalidStates(c *gc.C) {
4656
err := s.State.SetMongoSpaceState(state.MongoSpaceStates("bad"))
4657
c.Assert(err, gc.ErrorMatches, "mongoSpaceState: bad not valid")
4658
info, err := s.State.ControllerInfo()
4659
c.Assert(err, jc.ErrorIsNil)
4660
c.Assert(info.MongoSpaceState, gc.Equals, state.MongoSpaceUnknown)
4640
4663
type SetAdminMongoPasswordSuite struct {
4641
4664
testing.BaseSuite