Skip to content

Commit

Permalink
Merge pull request juju#18533 from Aflynn50/resource-state-methods
Browse files Browse the repository at this point in the history
juju#18533

This change adds several domain methods to the resources domain. It
adds:
- StoreResource
- StoreResourceAndIncrementCharmModifiedVersion
- OpenResource
- SetApplicationResource
- SetUnitResource (this one already existed but its behvaiour changes a lot)

These methods complete the foundation of the resource domain.

These methods differ from their state counterparts in several ways. In
state, most equivilents of these methods also returned the resource
record, even if they were only setting a resource. Here they do not.
They are designed to each do only one thing, the thing that their name
describes.

In state there was an OpenResource and OpenResourceForUniter. This
seperate method also set the unit resource doc. In the new domain
methods, this linking should be done via the SetUnitResource instead.

In state, the SetResource method did several things. It has now been
factored out into the StoreResource,
StoreResourceAndIncremenetCharmModifiedVersion and SetApplicationResource.
This is to make it clearer what each method does.

> [!NOTE]
> As a flyby, make the verbiage in resource domain errors consistent.
<!-- 
The PR title should match: <type>(optional <scope>): <description>.

Please also ensure all commits in this PR comply with our conventional commits specification:
https://github.com/juju/juju/blob/main/doc/conventional-commits.md
-->

<!-- Why this change is needed and what it does. -->

## 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
- [ ] [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
Run unit tests, none of this has been wired up yet.
<!-- 

Describe steps to verify that the change works. 

If you're changing any of the facades, you need to ensure that you've tested
a model migration from 3.6 to 4.0 and from 4.0 to 4.0.

The following steps are a good starting point:

 1. Bootstrap a 3.6 controller and deploy a charm.

```sh
$ juju bootstrap lxd src36
$ juju add-model moveme1
$ juju deploy juju-qa-test
```

 2. Bootstrap a 4.0 controller with the changes and migrate the model.

```sh
$ juju bootstrap lxd dst40
$ juju migrate src36:moveme1 dst40
$ juju add-unit juju-qa-test
```

 3. Verify no errors exist in the model logs for the agents. If there are
 errors, this is a bug and should be fixed before merging. The fix can
 either be applied to the 4.0 branch (preferable) or the 3.6 branch, though
 that needs to be discussed with the team.

```sh
$ juju debug-log -m dst40:controller
$ juju debug-log -m dst40:moveme1
```

 4. We also need to test a model migration from 4.0 to 4.0.

```sh
$ juju bootstrap lxd src40
$ juju add-model moveme2
$ juju deploy juju-qa-test
```

```sh
$ juju migrate src40:moveme2 dst40
$ juju add-unit juju-qa-test
```

 5. Verify that there are no errors in the controller or model logs.

```sh
$ juju debug-log -m dst40:controller
$ juju debug-log -m dst40:moveme2
```

-->
## Links

<!-- Link to all relevant specification, documentation, bug, issue or JIRA card. -->

**Jira card:** [JUJU-6397](https://warthogs.atlassian.net/browse/JUJU-6397)



[JUJU-6397]: https://warthogs.atlassian.net/browse/JUJU-6397?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
jujubot authored Dec 18, 2024
2 parents 8b2ff92 + f0bfacf commit 896a608
Show file tree
Hide file tree
Showing 12 changed files with 2,320 additions and 673 deletions.
8 changes: 8 additions & 0 deletions domain/application/state/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,14 @@ func (s *applicationStateSuite) TestGetCharmModifiedVersion(c *gc.C) {
c.Assert(charmModifiedVersion, gc.Equals, 7)
}

func (s *applicationStateSuite) TestGetCharmModifiedVersionNull(c *gc.C) {
appUUID := s.createApplication(c, "foo", life.Alive)

charmModifiedVersion, err := s.state.GetCharmModifiedVersion(context.Background(), appUUID)
c.Assert(err, jc.ErrorIsNil)
c.Assert(charmModifiedVersion, gc.Equals, 0)
}

func (s *applicationStateSuite) TestGetCharmModifiedVersionApplicationNotFound(c *gc.C) {
_, err := s.state.GetCharmModifiedVersion(context.Background(), applicationtesting.GenApplicationUUID(c))
c.Assert(err, jc.ErrorIs, applicationerrors.ApplicationNotFound)
Expand Down
17 changes: 13 additions & 4 deletions domain/resource/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const (
// not found.
ResourceNotFound = errors.ConstError("resource not found")

// UnknownRetrievedByType describes an error where the retrieved by type is
// RetrievedByTypeNotValid describes an error where the retrieved by type is
// neither user, unit nor application.
UnknownRetrievedByType = errors.ConstError("unknown retrieved by type")
RetrievedByTypeNotValid = errors.ConstError("retrieved by type not valid")

// ResourceNameNotValid describes an error where the resource name is not
// valid, usually because it's empty.
Expand All @@ -44,8 +44,17 @@ const (
// valid.
ResourceStateNotValid = errors.ConstError("resource state not valid")

// InvalidCleanUpState describes an error where the application state is
// CleanUpStateNotValid describes an error where the application state is
// during cleanup. It means that application dependencies are deleted in
// an incorrect order.
InvalidCleanUpState = errors.ConstError("invalid cleanup state")
CleanUpStateNotValid = errors.ConstError("cleanup state not valid")

// StoredResourceNotFound describes an error where the stored resource
// cannot be found in the relevant resource persistence layer for its
// resource type.
StoredResourceNotFound = errors.ConstError("stored resource not found")

// ResourceAlreadyStored describes an errors where the resource has already
// been stored.
ResourceAlreadyStored = errors.ConstError("resource already found in storage")
)
159 changes: 78 additions & 81 deletions domain/resource/service/package_mock_test.go

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

1 change: 1 addition & 0 deletions domain/resource/service/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

//go:generate go run go.uber.org/mock/mockgen -typed -package service -destination package_mock_test.go github.com/juju/juju/domain/resource/service State,ResourceStoreGetter
//go:generate go run go.uber.org/mock/mockgen -typed -package service -destination resource_store_mock_test.go github.com/juju/juju/core/resource/store ResourceStore

func TestPackage(t *testing.T) {
gc.TestingT(t)
Expand Down
Loading

0 comments on commit 896a608

Please sign in to comment.