add channels to juju charm list-resources and propagate it down to csclient.Client #4790

Closed
wants to merge 73 commits into
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+1,548 −427
Split
@@ -130,6 +130,7 @@ func retrieveLatestCharmInfo(st *state.State) ([]latestCharmInfo, error) {
var resultsIndexedServices []*state.Service
for _, service := range services {
curl, _ := service.CharmURL()
+
if curl.Schema == "local" {
// Version checking for charms from local repositories is not
// currently supported, since we don't yet support passing in
@@ -145,7 +146,13 @@ func retrieveLatestCharmInfo(st *state.State) ([]latestCharmInfo, error) {
return nil, err
}
- results, err := charmstore.LatestCharmInfo(client, curls)
+ // TODO(natefinch): get the real channel when we have one.
+ charms := make([]charmstore.CharmID, len(curls))
+ for i, c := range curls {
+ charms[i] = charmstore.CharmID{URL: c, Channel: "stable"}
+ }
+
+ results, err := charmstore.LatestCharmInfo(client, charms)
if err != nil {
return nil, err
}
@@ -309,7 +309,7 @@ type statusContext struct {
relations map[string][]*state.Relation
units map[string]map[string]*state.Unit
networks map[string]*state.Network
- latestCharms map[charm.URL]string
+ latestCharms map[charm.URL]*state.Charm
}
// fetchMachines returns a map from top level machine id to machines, where machines[0] is the host
@@ -349,11 +349,11 @@ func fetchMachines(st stateInterface, machineIds set.Strings) (map[string][]*sta
func fetchAllServicesAndUnits(
st stateInterface,
matchAny bool,
-) (map[string]*state.Service, map[string]map[string]*state.Unit, map[charm.URL]string, error) {
+) (map[string]*state.Service, map[string]map[string]*state.Unit, map[charm.URL]*state.Charm, error) {
svcMap := make(map[string]*state.Service)
unitMap := make(map[string]map[string]*state.Unit)
- latestCharms := make(map[charm.URL]string)
+ latestCharms := make(map[charm.URL]*state.Charm)
services, err := st.AllServices()
if err != nil {
return nil, nil, nil, err
@@ -374,7 +374,7 @@ func fetchAllServicesAndUnits(
// the latest store revision can be looked up.
charmURL, _ := s.CharmURL()
if charmURL.Schema == "cs" {
- latestCharms[*charmURL.WithRevision(-1)] = ""
+ latestCharms[*charmURL.WithRevision(-1)] = nil
}
}
}
@@ -386,8 +386,9 @@ func fetchAllServicesAndUnits(
if err != nil {
return nil, nil, nil, err
}
- latestCharms[baseURL] = ch.String()
+ latestCharms[baseURL] = ch
}
+
return svcMap, unitMap, latestCharms, nil
}
@@ -603,10 +604,12 @@ func (context *statusContext) processService(service *state.Service) (processedS
processedStatus.Exposed = service.IsExposed()
processedStatus.Life = processLife(service)
- latestCharm, ok := context.latestCharms[*serviceCharmURL.WithRevision(-1)]
- if ok && latestCharm != serviceCharmURL.String() {
- processedStatus.CanUpgradeTo = latestCharm
+ if latestCharm, ok := context.latestCharms[*serviceCharmURL.WithRevision(-1)]; ok && latestCharm != nil {
+ if latestCharm.Revision() > serviceCharmURL.Revision {
+ processedStatus.CanUpgradeTo = latestCharm.String()
+ }
}
+
var err error
processedStatus.Relations, processedStatus.SubordinateTo, err = context.processServiceRelations(service)
if err != nil {
@@ -4,14 +4,18 @@
package client_test
import (
- jc "github.com/juju/testing/checkers"
- gc "gopkg.in/check.v1"
-
+ "github.com/juju/juju/apiserver/charmrevisionupdater"
+ "github.com/juju/juju/apiserver/charmrevisionupdater/testing"
"github.com/juju/juju/apiserver/client"
+ "github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
+ apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/instance"
+ jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/state"
"github.com/juju/juju/testing/factory"
+ jc "github.com/juju/testing/checkers"
+ gc "gopkg.in/check.v1"
)
type statusSuite struct {
@@ -148,3 +152,64 @@ func (s *statusUnitTestSuite) TestMeterStatus(c *gc.C) {
}
}
}
+
+type statusUpgradeUnitSuite struct {
+ testing.CharmSuite
+ jujutesting.JujuConnSuite
+
+ charmrevisionupdater *charmrevisionupdater.CharmRevisionUpdaterAPI
+ resources *common.Resources
+ authoriser apiservertesting.FakeAuthorizer
+}
+
+var _ = gc.Suite(&statusUpgradeUnitSuite{})
+
+func (s *statusUpgradeUnitSuite) SetUpSuite(c *gc.C) {
+ s.JujuConnSuite.SetUpSuite(c)
+ s.CharmSuite.SetUpSuite(c, &s.JujuConnSuite)
+}
+
+func (s *statusUpgradeUnitSuite) TearDownSuite(c *gc.C) {
+ s.CharmSuite.TearDownSuite(c)
+ s.JujuConnSuite.TearDownSuite(c)
+}
+
+func (s *statusUpgradeUnitSuite) SetUpTest(c *gc.C) {
+ s.JujuConnSuite.SetUpTest(c)
+ s.CharmSuite.SetUpTest(c)
+ s.resources = common.NewResources()
+ s.AddCleanup(func(_ *gc.C) { s.resources.StopAll() })
+ s.authoriser = apiservertesting.FakeAuthorizer{
+ EnvironManager: true,
+ }
+ var err error
+ s.charmrevisionupdater, err = charmrevisionupdater.NewCharmRevisionUpdaterAPI(s.State, s.resources, s.authoriser)
+ c.Assert(err, jc.ErrorIsNil)
+}
+
+func (s *statusUpgradeUnitSuite) TearDownTest(c *gc.C) {
+ s.CharmSuite.TearDownTest(c)
+ s.JujuConnSuite.TearDownTest(c)
+}
+
+func (s *statusUpgradeUnitSuite) TestUpdateRevisions(c *gc.C) {
+ s.AddMachine(c, "0", state.JobManageModel)
+ s.SetupScenario(c)
+ client := s.APIState.Client()
+ status, _ := client.Status(nil)
+
+ serviceStatus, ok := status.Services["mysql"]
+ c.Assert(ok, gc.Equals, true)
+ c.Assert(serviceStatus.CanUpgradeTo, gc.Equals, "")
+
+ // Update to the latest available charm revision.
+ result, err := s.charmrevisionupdater.UpdateLatestRevisions()
+ c.Assert(err, jc.ErrorIsNil)
+ c.Assert(result.Error, gc.IsNil)
+
+ // Check if CanUpgradeTo suggest the latest revision.
+ status, _ = client.Status(nil)
+ serviceStatus, ok = status.Services["mysql"]
+ c.Assert(ok, gc.Equals, true)
+ c.Assert(serviceStatus.CanUpgradeTo, gc.Equals, "cs:quantal/mysql-23")
+}
@@ -125,6 +125,18 @@ func deployService(st *state.State, owner string, args params.ServiceDeploy) err
// Try to find the charm URL in state first.
ch, err := st.Charm(curl)
+ // TODO(wallyworld) - remove for 2.0 beta4
+ if errors.IsNotFound(err) {
+ // Clients written to expect 1.16 compatibility require this next block.
+ if curl.Schema != "cs" {
+ return errors.Errorf(`charm url has unsupported schema %q`, curl.Schema)
+ }
+ if err = AddCharmWithAuthorization(st, params.AddCharmWithAuthorization{
+ URL: args.CharmUrl,
+ }); err == nil {
+ ch, err = st.Charm(curl)
+ }
+ }
if err != nil {
return errors.Trace(err)
}
@@ -65,11 +65,10 @@ func (s *serviceSuite) TearDownSuite(c *gc.C) {
func (s *serviceSuite) SetUpTest(c *gc.C) {
s.JujuConnSuite.SetUpTest(c)
- s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
- s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
-
s.CharmStoreSuite.Session = s.JujuConnSuite.Session
s.CharmStoreSuite.SetUpTest(c)
+ s.BlockHelper = commontesting.NewBlockHelper(s.APIState)
+ s.AddCleanup(func(*gc.C) { s.BlockHelper.Close() })
s.service = s.Factory.MakeService(c, nil)
@@ -2367,6 +2367,14 @@ type uniterNetworkConfigSuite struct {
var _ = gc.Suite(&uniterNetworkConfigSuite{})
+func (s *uniterNetworkConfigSuite) SetUpSuite(c *gc.C) {
+ s.base.SetUpSuite(c)
+}
+
+func (s *uniterNetworkConfigSuite) TearDownSuite(c *gc.C) {
+ s.base.TearDownSuite(c)
+}
+
func (s *uniterNetworkConfigSuite) SetUpTest(c *gc.C) {
s.base.JujuConnSuite.SetUpTest(c)
Oops, something went wrong.