forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_commands_operations.txt
74 lines (63 loc) · 2.55 KB
/
block_commands_operations.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
PROBLEM
=========================
Customers and stakeholders want to be able to
prevent accidental damage to Juju deployments.
SOLUTION
=========================
To prevent running some commands, a concept of commands block was implemented.
Once the block is switched on, it has to be manually switched off
to run commands successfully.
There are currently three types of blocks developed.
1. DESTROY_BLOCK blocks destroy-model command.
2. REMOVE_BLOCK blocks destroy-model as well as all object removal -
machines, services, units, relations.
3. CHANGE_BLOCK blocks all commands from DESTROY and REMOVE blocks
as well as all model modifications.
For more information and the list of all commands that are blocked, run
`juju help block`
or
`juju help unblock`
IMPLEMENTATION
=========================
Command: package cmd/juju
---------------------------------------------
1. Help for block/unblock command is updated to contain your command.
2. Delegate error processing of the client from apiserver error.
Usually it would be done in the implementation of Command.Run.
E.g.
func (c *SetFluffCommand) Run(_ *cmd.Context) (err error) {
....
err := apiclient.SetFluff(args)
// there are corresponding
// block.BlockDestroy and block.BlockRemove
return block.ProcessBlockedError(err, block.BlockChange)
}
3. Add tests switching the block on before running the command.
Server: client instance in apiserver package
---------------------------------------------
1. Check if the block is enabled using common.BlockChecker,
before any other processing.
Some client already have this checker embedded.
To construct new checker, you'll need a state.State.
E.g.
func (c *Client) SetFluff(args params.SetFluff) error {
if err := c.check.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
......
}
or
func (c *Client) SetFluff(args params.SetFluff) error {
blockChecker := common.NewBlockChecker(st)
// there are corresponding
// blockChecker.DestroyAllowed() and block.RemoveAllowed()
if err := blockChecker.ChangeAllowed(); err != nil {
return errors.Trace(err)
}
......
}
2. Add tests switching the block on.
Interested Parties
---------------------------------------------
1. Notify QA team that a new command became block-able.
2. Juju documentation may need to be updated as well.