Skip to content

Commit

Permalink
Merge pull request #14350 from wallyworld/merge-2.9-20220722
Browse files Browse the repository at this point in the history
#14350

Merge 2.9

#14329 [JUJU-1466] Filter by model uuid when querying azure instances
#14318 [JUJU-1196] refactor nw-constraints-aws test
#14333 [JUJU-1468] Fixed test agents lxd
#14339 Fix cli/local_charms test due to deleted GitHub repo
#14342 Update deploy_revision tests to actually check revision
#14337 [JUJU-1475] Added lxd constraints tests
#14335 More unit charm url work
#14343 [JUJU-1480] Add support for retry-provisioning --all
#14345 [JUJU-1480] Fix display of upgrading-from for subordinate units

```
# Conflicts:
# api/client/client/client.go
# cmd/juju/model/retryprovisioning.go
# migration/precheck.go
# migration/precheck_test.go
# rpc/params/internal.go
# tests/suites/agents/key_workers_run.sh
```

## QA steps

See PRs

[JUJU-1466]: https://warthogs.atlassian.net/browse/JUJU-1466?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-1196]: https://warthogs.atlassian.net/browse/JUJU-1196?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-1468]: https://warthogs.atlassian.net/browse/JUJU-1468?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-1475]: https://warthogs.atlassian.net/browse/JUJU-1475?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-1480]: https://warthogs.atlassian.net/browse/JUJU-1480?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[JUJU-1480]: https://warthogs.atlassian.net/browse/JUJU-1480?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
jujubot committed Jul 20, 2022
2 parents 5e4b9ac + e936199 commit 7794554
Show file tree
Hide file tree
Showing 55 changed files with 664 additions and 239 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 6 additions & 4 deletions api/client/machinemanager/machinemanager.go
Expand Up @@ -142,11 +142,13 @@ func (c *Client) ProvisioningScript(args params.ProvisioningScriptParams) (scrip

// RetryProvisioning updates the provisioning status of a machine allowing the
// provisioner to retry.
func (c *Client) RetryProvisioning(machines ...names.MachineTag) ([]params.ErrorResult, error) {
p := params.Entities{}
p.Entities = make([]params.Entity, len(machines))
func (c *Client) RetryProvisioning(all bool, machines ...names.MachineTag) ([]params.ErrorResult, error) {
p := params.RetryProvisioningArgs{
All: all,
}
p.Machines = make([]string, len(machines))
for i, machine := range machines {
p.Entities[i] = params.Entity{Tag: machine.String()}
p.Machines[i] = machine.String()
}
var results params.ErrorResults
err := c.facade.FacadeCall("RetryProvisioning", p, &results)
Expand Down
36 changes: 31 additions & 5 deletions api/client/machinemanager/machinemanager_test.go
Expand Up @@ -126,10 +126,10 @@ func (s *MachinemanagerSuite) TestRetryProvisioning(c *gc.C) {
APICallerFunc: basetesting.APICallerFunc(func(objType string, version int, id, request string, a, response interface{}) error {
c.Assert(request, gc.Equals, "RetryProvisioning")
c.Assert(version, gc.Equals, 7)
c.Assert(a, jc.DeepEquals, params.Entities{
Entities: []params.Entity{
{Tag: "machine-0"},
{Tag: "machine-1"},
c.Assert(a, jc.DeepEquals, params.RetryProvisioningArgs{
Machines: []string{
"machine-0",
"machine-1",
},
})
c.Assert(response, gc.FitsTypeOf, &params.ErrorResults{})
Expand All @@ -140,7 +140,33 @@ func (s *MachinemanagerSuite) TestRetryProvisioning(c *gc.C) {
}
return nil
})})
result, err := client.RetryProvisioning(names.NewMachineTag("0"), names.NewMachineTag("1"))
result, err := client.RetryProvisioning(false, names.NewMachineTag("0"), names.NewMachineTag("1"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, []params.ErrorResult{
{&params.Error{Code: "boom"}},
{},
})
}

func (s *MachinemanagerSuite) TestRetryProvisioningAll(c *gc.C) {
client := machinemanager.NewClient(
basetesting.BestVersionCaller{
BestVersion: 7,
APICallerFunc: basetesting.APICallerFunc(func(objType string, version int, id, request string, a, response interface{}) error {
c.Assert(request, gc.Equals, "RetryProvisioning")
c.Assert(version, gc.Equals, 7)
c.Assert(a, jc.DeepEquals, params.RetryProvisioningArgs{
All: true,
})
c.Assert(response, gc.FitsTypeOf, &params.ErrorResults{})
out := response.(*params.ErrorResults)
*out = params.ErrorResults{Results: []params.ErrorResult{
{Error: &params.Error{Code: "boom"}},
{}},
}
return nil
})})
result, err := client.RetryProvisioning(true)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, []params.ErrorResult{
{&params.Error{Code: "boom"}},
Expand Down
2 changes: 1 addition & 1 deletion apiserver/admin_test.go
Expand Up @@ -1496,7 +1496,7 @@ func (s *loginV3Suite) TestClientLoginToController(c *gc.C) {
defer apiState.Close()

client := machineclient.NewClient(apiState)
_, err = client.RetryProvisioning(names.NewMachineTag("machine-0"))
_, err = client.RetryProvisioning(false, names.NewMachineTag("machine-0"))
c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
Message: `facade "MachineManager" not supported for controller API connection`,
Code: "not supported",
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/instancemutater/interface.go
Expand Up @@ -54,7 +54,7 @@ type Unit interface {
Application() (Application, error)
PrincipalName() (string, bool)
AssignedMachineId() (string, error)
CharmURL() (*charm.URL, error)
CharmURL() *string
}

// Charm represents point of use methods from the state Charm object.
Expand Down
24 changes: 10 additions & 14 deletions apiserver/facades/agent/instancemutater/lxdprofilewatcher.go
Expand Up @@ -449,12 +449,8 @@ func (w *machineLXDProfileWatcher) add(unit Unit) (bool, error) {

_, ok := w.applications[appName]
if !ok {
curl, err := unit.CharmURL()
if err != nil {
return false, errors.Trace(err)
}

if curl == nil {
curlStr := unit.CharmURL()
if curlStr == nil {
// this happens for new units to existing machines.
app, err := unit.Application()
if errors.IsNotFound(err) {
Expand All @@ -463,22 +459,22 @@ func (w *machineLXDProfileWatcher) add(unit Unit) (bool, error) {
} else if err != nil {
return false, errors.Annotatef(err, "failed to get application %s for machine-%s", appName, w.machine.Id())
}
cURL := app.CharmURL()
curl, err = charm.ParseURL(*cURL)
if err != nil {
return false, errors.Annotatef(err, "application charm url")
}
curlStr = app.CharmURL()
}

curl, err := charm.ParseURL(*curlStr)
if err != nil {
return false, errors.Annotatef(err, "application charm url")
}
ch, err := w.backend.Charm(curl)
if errors.IsNotFound(err) {
logger.Debugf("charm %s removed for %s on machine-%s", curl, unitName, w.machine.Id())
logger.Debugf("charm %s removed for %s on machine-%s", *curlStr, unitName, w.machine.Id())
return false, nil
} else if err != nil {
return false, errors.Annotatef(err, "failed to get charm %q for %s on machine-%s", curl, appName, w.machine.Id())
return false, errors.Annotatef(err, "failed to get charm %q for %s on machine-%s", *curlStr, appName, w.machine.Id())
}
info := appInfo{
charmURL: curl.String(),
charmURL: *curlStr,
units: set.NewStrings(unitName),
}

Expand Down
23 changes: 12 additions & 11 deletions apiserver/facades/agent/instancemutater/lxdprofilewatcher_test.go
Expand Up @@ -91,8 +91,8 @@ func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherProfile(c *gc.C) {
defer workertest.CleanKill(c, s.assertStartLxdProfileWatcher(c))

s.setupPrincipalUnit()
curl := charm.MustParseURL("ch:name-me")
s.unit.EXPECT().CharmURL().Return(curl, nil)
curlStr := "ch:name-me"
s.unit.EXPECT().CharmURL().Return(&curlStr)
s.unitChanges <- []string{"foo/0"}
s.wc0.AssertOneChange()
}
Expand Down Expand Up @@ -151,8 +151,8 @@ func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherAddUnit(c *gc.C) {
s.unit.EXPECT().Life().Return(state.Alive)
s.unit.EXPECT().PrincipalName().Return("", false)
s.unit.EXPECT().AssignedMachineId().Return("0", nil)
curl := charm.MustParseURL("ch:name-me")
s.unit.EXPECT().CharmURL().Return(curl, nil)
curlStr := "ch:name-me"
s.unit.EXPECT().CharmURL().Return(&curlStr)
s.unitChanges <- []string{"bar/0"}
s.wc0.AssertOneChange()
}
Expand Down Expand Up @@ -194,8 +194,8 @@ func (s *lxdProfileWatcherSuite) assertAddSubordinate() {
s.unit.EXPECT().PrincipalName().Return("principal/0", true)
s.unit.EXPECT().AssignedMachineId().Return("0", nil)

curl := charm.MustParseURL("ch:name-me")
s.unit.EXPECT().CharmURL().Return(curl, nil)
curlStr := "ch:name-me"
s.unit.EXPECT().CharmURL().Return(&curlStr)
s.unitChanges <- []string{"foo/0"}
}

Expand Down Expand Up @@ -290,8 +290,8 @@ func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherRemoveOnlyUnit(c *g
s.wc0.AssertNoChange()

s.setupPrincipalUnit()
curl := charm.MustParseURL("ch:name-me")
s.unit.EXPECT().CharmURL().Return(curl, nil)
curlStr := "ch:name-me"
s.unit.EXPECT().CharmURL().Return(&curlStr)
s.unitChanges <- []string{"foo/0"}
s.wc0.AssertOneChange()

Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherUnitChangeAppNotFou
s.machine0.EXPECT().Units().Return(nil, nil)

s.setupPrincipalUnit()
s.unit.EXPECT().CharmURL().Return(nil, nil)
s.unit.EXPECT().CharmURL().Return(nil)
s.unit.EXPECT().Application().Return(nil, errors.NotFoundf(""))

defer workertest.CleanKill(c, s.assertStartLxdProfileWatcher(c))
Expand All @@ -363,8 +363,9 @@ func (s *lxdProfileWatcherSuite) TestMachineLXDProfileWatcherUnitChangeCharmURLN
s.machine0.EXPECT().Units().Return(nil, nil)

s.setupPrincipalUnit()
curl := charm.MustParseURL("ch:name-me")
s.unit.EXPECT().CharmURL().Return(curl, nil)
curlStr := "ch:name-me"
s.unit.EXPECT().CharmURL().Return(&curlStr)
curl := charm.MustParseURL(curlStr)
s.state.EXPECT().Charm(curl).Return(nil, errors.NotFoundf(""))

defer workertest.CleanKill(c, s.assertStartLxdProfileWatcher(c))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions apiserver/facades/agent/metricsender/sender_test.go
Expand Up @@ -56,7 +56,8 @@ var _ metricsender.MetricSender = (*metricsender.HTTPSender)(nil)
// is in use metrics get sent
func (s *SenderSuite) TestHTTPSender(c *gc.C) {
metricCount := 3
expectedCharmURL, _ := s.unit.CharmURL()
expectedCharmURL := s.unit.CharmURL()
c.Assert(expectedCharmURL, gc.NotNil)

receiverChan := make(chan wireformat.MetricBatch, metricCount)
cleanup := s.startServer(c, testHandler(c, receiverChan, nil, 0))
Expand All @@ -74,7 +75,7 @@ func (s *SenderSuite) TestHTTPSender(c *gc.C) {
c.Assert(receiverChan, gc.HasLen, metricCount)
close(receiverChan)
for batch := range receiverChan {
c.Assert(batch.CharmUrl, gc.Equals, expectedCharmURL.String())
c.Assert(batch.CharmUrl, gc.Equals, *expectedCharmURL)
}

for _, metric := range metrics {
Expand Down
7 changes: 3 additions & 4 deletions apiserver/facades/agent/uniter/mocks/newlxdprofile.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiserver/facades/agent/uniter/newlxdprofile.go
Expand Up @@ -47,7 +47,7 @@ type LXDProfileMachineV2 interface {
type LXDProfileUnitV2 interface {
ApplicationName() string
AssignedMachineId() (string, error)
CharmURL() (*charm.URL, error)
CharmURL() *string
Name() string
Tag() names.Tag
}
Expand Down
13 changes: 4 additions & 9 deletions apiserver/facades/agent/uniter/uniter.go
Expand Up @@ -540,27 +540,22 @@ func (u *UniterAPI) CharmURL(args params.Entities) (params.StringBoolResults, er
var unitOrApplication state.Entity
unitOrApplication, err = u.st.FindEntity(tag)
if err == nil {
// TODO (hmlanigan) 2022-06-08
// cURL can be a string pointer once unit.CharmURL()
// returns a string pointer as well.
var cURL *charm.URL
var cURL *string
var force bool

switch entity := unitOrApplication.(type) {
case *state.Application:
var cURLStr *string
cURLStr, force = entity.CharmURL()
cURL, err = charm.ParseURL(*cURLStr)
cURL, force = entity.CharmURL()
case *state.Unit:
cURL, err = entity.CharmURL()
cURL = entity.CharmURL()
// The force value is not actually used on the uniter's unit api.
if cURL != nil {
force = true
}
}

if cURL != nil {
result.Results[i].Result = cURL.String()
result.Results[i].Result = *cURL
result.Results[i].Ok = force
}
}
Expand Down
15 changes: 7 additions & 8 deletions apiserver/facades/agent/uniter/uniter_test.go
Expand Up @@ -875,9 +875,9 @@ func (s *uniterSuite) TestCharmURL(c *gc.C) {
// Set wordpressUnit's charm URL first.
err := s.wordpressUnit.SetCharmURL(s.wpCharm.URL())
c.Assert(err, jc.ErrorIsNil)
curl, err := s.wordpressUnit.CharmURL()
c.Assert(err, jc.ErrorIsNil)
c.Assert(curl, gc.DeepEquals, s.wpCharm.URL())
curl := s.wordpressUnit.CharmURL()
c.Assert(curl, gc.NotNil)
c.Assert(*curl, gc.Equals, s.wpCharm.URL().String())

// Make sure wordpress application's charm is what we expect.
curlStr, force := s.wordpress.CharmURL()
Expand Down Expand Up @@ -913,8 +913,8 @@ func (s *uniterSuite) TestCharmURL(c *gc.C) {
}

func (s *uniterSuite) TestSetCharmURL(c *gc.C) {
_, ok := s.wordpressUnit.CharmURL()
c.Assert(ok, jc.IsFalse)
charmURL := s.wordpressUnit.CharmURL()
c.Assert(charmURL, gc.IsNil)

args := params.EntitiesCharmURL{Entities: []params.EntityCharmURL{
{Tag: "unit-mysql-0", CharmURL: "cs:quantal/application-42"},
Expand All @@ -935,10 +935,9 @@ func (s *uniterSuite) TestSetCharmURL(c *gc.C) {
err = s.wordpressUnit.Refresh()
c.Assert(err, jc.ErrorIsNil)

charmURL, err := s.wordpressUnit.CharmURL()
c.Assert(err, jc.ErrorIsNil)
charmURL = s.wordpressUnit.CharmURL()
c.Assert(charmURL, gc.NotNil)
c.Assert(charmURL.String(), gc.Equals, s.wpCharm.String())
c.Assert(*charmURL, gc.Equals, s.wpCharm.String())
}

func (s *uniterSuite) TestWorkloadVersion(c *gc.C) {
Expand Down
19 changes: 15 additions & 4 deletions apiserver/facades/client/client/status.go
Expand Up @@ -1531,9 +1531,9 @@ func (context *statusContext) processUnit(unit *state.Unit, applicationCharm str
if unit.IsPrincipal() {
result.Machine, _ = unit.AssignedMachineId()
}
curl, _ := unit.CharmURL()
if applicationCharm != "" && curl != nil && curl.String() != applicationCharm {
result.Charm = curl.String()
unitCharm := unit.CharmURL()
if applicationCharm != "" && unitCharm != nil && *unitCharm != applicationCharm {
result.Charm = *unitCharm
}
workloadVersion, err := context.status.UnitWorkloadVersion(unit.Name())
if err == nil {
Expand All @@ -1550,7 +1550,18 @@ func (context *statusContext) processUnit(unit *state.Unit, applicationCharm str
subUnit := context.unitByName(name)
// subUnit may be nil if subordinate was filtered out.
if subUnit != nil {
result.Subordinates[name] = context.processUnit(subUnit, applicationCharm, true)
subUnitAppCharm := ""
subUnitApp, err := subUnit.Application()
if err != nil {
logger.Debugf("error fetching subordinate application for %q", subUnit.ApplicationName())
}
subUnitAppCh, _, err := subUnitApp.Charm()
if err == nil {
subUnitAppCharm = subUnitAppCh.String()
} else {
logger.Debugf("error fetching subordinate application charm for %q", subUnit.ApplicationName())
}
result.Subordinates[name] = context.processUnit(subUnit, subUnitAppCharm, true)
}
}
}
Expand Down

0 comments on commit 7794554

Please sign in to comment.