Skip to content

Commit

Permalink
Merge pull request juju#18654 from gfouillet/v4/dqlite/resources/wire…
Browse files Browse the repository at this point in the history
…up/6402-resource-facade

juju#18654

> [!WARNING]
> Include commits from juju#18634 (which move domain.Resources to core and remove current core.Resources)
>
> prdesc [x] Wait for merge juju#18634 

* Wire up resources facade ListResources to domain
* Remove AddPendingResources from the facade code.

## Checklist

<!-- If an item is not applicable, use `~strikethrough~`. -->

- [X] Code style: imports ordered, good names, simple structure, etc
- [X] Comments saying why design decisions were made
- [X] Go unit tests, with comments saying what you're testing
- [X] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing
- [X] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages

## QA steps

### setup

```sh
juju bootstrap lxd lxd
juju add-model test
juju deploy juju-qa-test qa
juju add-unit qa
juju deploy juju-qa-test qa1 --resource foo-file=test.txt
juju add-unit qa1
juju deploy juju-qa-test qa2 --resource foo-file=1
juju add-unit qa2
``` 

### Test resources command

```sh
juju resources qa
# Resource Supplied by Revision
# foo-file store 2
juju resources qa --details
# Unit Resource Revision Expected
# qa/0 foo-file - 2
# qa/1 foo-file - 2


juju resources qa1
# Resource Supplied by Revision
# foo-file upload 2025-01-20T17:14 # Supplied by might be admin, depending of other PR.
juju resources qa1 --details
# Unit Resource Revision Expected
# qa1/0 foo-file - 2025-01-20T17:142
# qa1/1 foo-file - 2025-01-20T17:14


juju resources qa2
# Resource Supplied by Revision
# foo-file store 1
juju resources qa2 --details
# Unit Resource Revision Expected
# qa2/0 foo-file - 1
# qa2/1 foo-file - 1
```

> [!NOTE]
> It should be possible to test the loading of a resource into a unit, but it is not wired yet. Depends on 
> prdesc juju#18669
>
> However, the QA would be:
> ```sh
> juju deploy juju-qa-test qa3
> juju resources qa3 --details
> # Unit Resource Revision Expected
> # qa3/0 foo-file - 2
> juju add-unit qa3
> juju resources qa3 --details
> # Unit Resource Revision Expected
> # qa2/0 foo-file 2 2
> # qa3/0 foo-file - 2
> ```


> [!NOTE]
> It is not possible yet to test the `[Updates Available]` section of the resources report. We need to wire the revision worker first [JUJU\-6401](https://warthogs.atlassian.net/browse/JUJU\-6401)


## Documentation changes

None

## Links

**Jira card:** [JUJU\-6402](https://warthogs.atlassian.net/browse/JUJU-6402)
  • Loading branch information
jujubot authored Jan 29, 2025
2 parents bb7d0a7 + e4611c6 commit fed94ac
Show file tree
Hide file tree
Showing 25 changed files with 1,389 additions and 1,016 deletions.
24 changes: 0 additions & 24 deletions api/client/resources/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,6 @@ func apiResult2ApplicationResources(apiResult params.ResourcesResult) (resource.
return result, nil
}

func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params.ResourcesResult {
var result params.ResourcesResult
for _, res := range svcRes.Resources {
result.Resources = append(result.Resources, Resource2API(res))
}

for _, unitResources := range svcRes.UnitResources {
tag := names.NewUnitTag(unitResources.Name.String())
apiRes := params.UnitResources{
Entity: params.Entity{Tag: tag.String()},
}
for _, unitRes := range unitResources.Resources {
apiRes.Resources = append(apiRes.Resources, Resource2API(unitRes))
}
result.UnitResources = append(result.UnitResources, apiRes)
}

result.CharmStoreResources = make([]params.CharmResource, len(svcRes.RepositoryResources))
for i, chRes := range svcRes.RepositoryResources {
result.CharmStoreResources[i] = CharmResource2API(chRes)
}
return result
}

// API2Resource converts an API Resource struct into
// a resource.Resource.
func API2Resource(apiRes params.Resource) (resource.Resource, error) {
Expand Down
76 changes: 0 additions & 76 deletions api/client/resources/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/names/v6"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

"github.com/juju/juju/core/resource"
resourcetesting "github.com/juju/juju/core/resource/testing"
"github.com/juju/juju/core/unit"
charmresource "github.com/juju/juju/internal/charm/resource"
"github.com/juju/juju/rpc/params"
)
Expand Down Expand Up @@ -496,76 +493,3 @@ func (HelpersSuite) TestAPI2CharmResource(c *gc.C) {

c.Check(res, jc.DeepEquals, expected)
}

func (HelpersSuite) TestServiceResources2API(c *gc.C) {
res1 := resourcetesting.NewResource(c, nil, "res1", "a-application", "data").Resource
res2 := resourcetesting.NewResource(c, nil, "res2", "a-application", "data2").Resource

tag0 := names.NewUnitTag("a-application/0")
tag1 := names.NewUnitTag("a-application/1")

chres1 := res1.Resource
chres2 := res2.Resource
chres1.Revision++
chres2.Revision++

svcRes := resource.ApplicationResources{
Resources: []resource.Resource{
res1,
res2,
},
UnitResources: []resource.UnitResources{
{
Name: unit.Name(tag0.Id()),
Resources: []resource.Resource{
res1,
res2,
},
},
{
Name: unit.Name(tag1.Id()),
},
},
RepositoryResources: []charmresource.Resource{
chres1,
chres2,
},
}

result := ApplicationResources2APIResult(svcRes)

apiRes1 := Resource2API(res1)
apiRes2 := Resource2API(res2)

apiChRes1 := CharmResource2API(chres1)
apiChRes2 := CharmResource2API(chres2)

c.Check(result, jc.DeepEquals, params.ResourcesResult{
Resources: []params.Resource{
apiRes1,
apiRes2,
},
UnitResources: []params.UnitResources{
{
Entity: params.Entity{
Tag: "unit-a-application-0",
},
Resources: []params.Resource{
apiRes1,
apiRes2,
},
},
{
// we should have a listing for every unit, even if they
// have no resources.
Entity: params.Entity{
Tag: "unit-a-application-1",
},
},
},
CharmStoreResources: []params.CharmResource{
apiChRes1,
apiChRes2,
},
})
}
1 change: 0 additions & 1 deletion api/facadeversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ var facadeVersions = facades.FacadeVersions{
"UnitAssigner": {1},
"Uniter": {19, 20, 21},
"Upgrader": {1},
"UpgradeSteps": {3},
"UserManager": {3},
"VolumeAttachmentsWatcher": {2},
"VolumeAttachmentPlansWatcher": {1},
Expand Down
14 changes: 5 additions & 9 deletions apiserver/allfacades.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/juju/juju/apiserver/facades/agent/provisioner"
"github.com/juju/juju/apiserver/facades/agent/proxyupdater"
"github.com/juju/juju/apiserver/facades/agent/reboot"
"github.com/juju/juju/apiserver/facades/agent/resourceshookcontext"
"github.com/juju/juju/apiserver/facades/agent/retrystrategy"
"github.com/juju/juju/apiserver/facades/agent/secretsdrain"
"github.com/juju/juju/apiserver/facades/agent/secretsmanager"
Expand Down Expand Up @@ -55,6 +56,7 @@ import (
"github.com/juju/juju/apiserver/facades/client/modelmanager" // ModelUser Write
"github.com/juju/juju/apiserver/facades/client/modelupgrader"
"github.com/juju/juju/apiserver/facades/client/pinger"
"github.com/juju/juju/apiserver/facades/client/resources"
"github.com/juju/juju/apiserver/facades/client/secretbackends"
"github.com/juju/juju/apiserver/facades/client/secrets"
"github.com/juju/juju/apiserver/facades/client/spaces" // ModelUser Write
Expand Down Expand Up @@ -131,9 +133,7 @@ func requiredMigrationFacadeVersions() facades.FacadeVersions {
provisioner.Register(registry)
proxyupdater.Register(registry)
reboot.Register(registry)
// Temporarily disable the resourceshookcontext facade until
// it uses the new resource domain.
//resourceshookcontext.Register(registry)
resourceshookcontext.Register(registry)
retrystrategy.Register(registry)
secretsdrain.Register(registry)
secretsmanager.Register(registry)
Expand Down Expand Up @@ -223,12 +223,8 @@ func AllFacades() *facade.Registry {
proxyupdater.Register(registry)
reboot.Register(registry)
remoterelations.Register(registry)
// Temporarily disable the resourceshookcontext facade until
// it uses the new resource domain.
// TODO: when both have been enabled, remove Skip from
// TestFacadeVersionsMatchServerVersions
//resources.Register(registry)
//resourceshookcontext.Register(registry)
resources.Register(registry)
resourceshookcontext.Register(registry)
retrystrategy.Register(registry)
singular.Register(registry)
secrets.Register(registry)
Expand Down
Loading

0 comments on commit fed94ac

Please sign in to comment.