github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/cmd/containeragent/unit/manifolds_test.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package unit_test 5 6 import ( 7 "github.com/juju/collections/set" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/agent" 12 "github.com/juju/juju/cmd/containeragent/unit" 13 "github.com/juju/juju/cmd/jujud/agent/agenttest" 14 "github.com/juju/juju/testing" 15 ) 16 17 type ManifoldsSuite struct { 18 testing.BaseSuite 19 } 20 21 var _ = gc.Suite(&ManifoldsSuite{}) 22 23 func (s *ManifoldsSuite) TestStartFuncs(c *gc.C) { 24 manifolds := unit.Manifolds(unit.ManifoldsConfig{ 25 Agent: fakeAgent{}, 26 }) 27 28 for name, manifold := range manifolds { 29 c.Logf("checking %q manifold", name) 30 c.Check(manifold.Start, gc.NotNil) 31 } 32 } 33 34 func (s *ManifoldsSuite) TestManifoldNames(c *gc.C) { 35 config := unit.ManifoldsConfig{} 36 manifolds := unit.Manifolds(config) 37 expectedKeys := []string{ 38 "agent", 39 "api-config-watcher", 40 "api-caller", 41 "s3-caller", 42 "uniter", 43 "log-sender", 44 45 "charm-dir", 46 "leadership-tracker", 47 "hook-retry-strategy", 48 49 "migration-fortress", 50 "migration-inactive-flag", 51 "migration-minion", 52 53 "proxy-config-updater", 54 "logging-config-updater", 55 "api-address-updater", 56 57 "caas-prober", 58 "probe-http-server", 59 60 "upgrader", 61 "upgrade-steps-runner", 62 "upgrade-steps-gate", 63 "upgrade-steps-flag", 64 65 "caas-unit-termination-worker", 66 "caas-units-manager", 67 "secret-drain-worker", 68 69 "caas-zombie-prober", 70 71 "dead-flag", 72 "not-dead-flag", 73 74 "signal-handler", 75 } 76 keys := make([]string, 0, len(manifolds)) 77 for k := range manifolds { 78 keys = append(keys, k) 79 } 80 c.Assert(keys, jc.SameContents, expectedKeys) 81 } 82 83 func (s *ManifoldsSuite) TestManifoldNamesColocatedController(c *gc.C) { 84 config := unit.ManifoldsConfig{ 85 ColocatedWithController: true, 86 } 87 manifolds := unit.Manifolds(config) 88 expectedKeys := []string{ 89 "agent", 90 "api-config-watcher", 91 "api-caller", 92 "s3-caller", 93 "caas-prober", 94 "probe-http-server", 95 "uniter", 96 "log-sender", 97 98 "charm-dir", 99 "leadership-tracker", 100 "hook-retry-strategy", 101 102 "migration-fortress", 103 "migration-inactive-flag", 104 "migration-minion", 105 106 "proxy-config-updater", 107 "logging-config-updater", 108 109 "upgrader", 110 "upgrade-steps-runner", 111 "upgrade-steps-gate", 112 "upgrade-steps-flag", 113 114 "caas-unit-termination-worker", 115 "caas-units-manager", 116 "secret-drain-worker", 117 "caas-zombie-prober", 118 119 "dead-flag", 120 "not-dead-flag", 121 122 "signal-handler", 123 } 124 keys := make([]string, 0, len(manifolds)) 125 for k := range manifolds { 126 keys = append(keys, k) 127 } 128 c.Assert(keys, jc.SameContents, expectedKeys) 129 } 130 131 func (*ManifoldsSuite) TestMigrationGuards(c *gc.C) { 132 exempt := set.NewStrings( 133 "agent", 134 "api-config-watcher", 135 "api-caller", 136 "s3-caller", 137 "caas-prober", 138 "probe-http-server", 139 "log-sender", 140 141 "migration-fortress", 142 "migration-inactive-flag", 143 "migration-minion", 144 145 "upgrader", 146 "upgrade-steps-runner", 147 "upgrade-steps-gate", 148 149 "upgrade-steps-flag", 150 "caas-units-manager", 151 152 "dead-flag", 153 "not-dead-flag", 154 "signal-handler", 155 "caas-zombie-prober", 156 ) 157 config := unit.ManifoldsConfig{} 158 manifolds := unit.Manifolds(config) 159 for name, manifold := range manifolds { 160 c.Logf("%v [%v]", name, manifold.Inputs) 161 if !exempt.Contains(name) { 162 checkContains(c, manifold.Inputs, "migration-inactive-flag") 163 checkContains(c, manifold.Inputs, "migration-fortress") 164 } 165 } 166 } 167 168 func (s *ManifoldsSuite) TestManifoldsDependencies(c *gc.C) { 169 agenttest.AssertManifoldsDependencies(c, 170 unit.Manifolds(unit.ManifoldsConfig{ 171 Agent: fakeAgent{}, 172 }), 173 expectedUnitManifoldsWithDependencies, 174 ) 175 } 176 177 func checkContains(c *gc.C, names []string, seek string) { 178 for _, name := range names { 179 if name == seek { 180 return 181 } 182 } 183 c.Errorf("%q not present in %v", seek, names) 184 } 185 186 type fakeAgent struct { 187 agent.Agent 188 } 189 190 var expectedUnitManifoldsWithDependencies = map[string][]string{ 191 192 "agent": {}, 193 "api-config-watcher": { 194 "agent", 195 }, 196 "api-caller": { 197 "agent", 198 "api-config-watcher", 199 }, 200 "s3-caller": { 201 "agent", 202 "api-caller", 203 "api-config-watcher", 204 }, 205 "uniter": { 206 "agent", 207 "api-caller", 208 "s3-caller", 209 "api-config-watcher", 210 "charm-dir", 211 "hook-retry-strategy", 212 "leadership-tracker", 213 "migration-fortress", 214 "migration-inactive-flag", 215 "not-dead-flag", 216 }, 217 218 "log-sender": { 219 "agent", 220 "api-caller", 221 "api-config-watcher", 222 "not-dead-flag", 223 }, 224 225 "charm-dir": { 226 "agent", 227 "api-caller", 228 "api-config-watcher", 229 "migration-fortress", 230 "migration-inactive-flag", 231 }, 232 "leadership-tracker": { 233 "agent", 234 "api-caller", 235 "api-config-watcher", 236 "migration-fortress", 237 "migration-inactive-flag", 238 }, 239 "hook-retry-strategy": { 240 "agent", 241 "api-caller", 242 "api-config-watcher", 243 "migration-fortress", 244 "migration-inactive-flag", 245 }, 246 247 "migration-fortress": {}, 248 249 "migration-inactive-flag": { 250 "agent", 251 "api-caller", 252 "api-config-watcher", 253 }, 254 255 "migration-minion": { 256 "agent", 257 "api-caller", 258 "api-config-watcher", 259 "migration-fortress", 260 }, 261 262 "proxy-config-updater": { 263 "agent", 264 "api-caller", 265 "api-config-watcher", 266 "migration-fortress", 267 "migration-inactive-flag", 268 }, 269 "logging-config-updater": { 270 "agent", 271 "api-caller", 272 "api-config-watcher", 273 "migration-fortress", 274 "migration-inactive-flag", 275 }, 276 "api-address-updater": { 277 "agent", 278 "api-caller", 279 "api-config-watcher", 280 "migration-fortress", 281 "migration-inactive-flag", 282 }, 283 "probe-http-server": {}, 284 "caas-prober": { 285 "agent", 286 "api-caller", 287 "api-config-watcher", 288 "charm-dir", 289 "hook-retry-strategy", 290 "leadership-tracker", 291 "migration-fortress", 292 "migration-inactive-flag", 293 "probe-http-server", 294 "s3-caller", 295 "uniter", 296 "not-dead-flag", 297 }, 298 "upgrade-steps-flag": { 299 "upgrade-steps-gate", 300 }, 301 "upgrade-steps-gate": {}, 302 "upgrade-steps-runner": { 303 "agent", 304 "api-caller", 305 "api-config-watcher", 306 "upgrade-steps-gate", 307 "not-dead-flag", 308 }, 309 "upgrader": { 310 "agent", 311 "api-caller", 312 "api-config-watcher", 313 "upgrade-steps-gate", 314 "not-dead-flag", 315 }, 316 317 "caas-unit-termination-worker": { 318 "agent", 319 "api-caller", 320 "api-config-watcher", 321 "charm-dir", 322 "hook-retry-strategy", 323 "leadership-tracker", 324 "migration-fortress", 325 "migration-inactive-flag", 326 "s3-caller", 327 "uniter", 328 "not-dead-flag", 329 }, 330 "caas-units-manager": { 331 "agent", 332 "api-caller", 333 "api-config-watcher", 334 "not-dead-flag", 335 }, 336 "caas-zombie-prober": { 337 "agent", 338 "api-caller", 339 "api-config-watcher", 340 "dead-flag", 341 "probe-http-server", 342 }, 343 344 "dead-flag": { 345 "agent", 346 "api-caller", 347 "api-config-watcher", 348 }, 349 "not-dead-flag": { 350 "agent", 351 "api-caller", 352 "api-config-watcher", 353 }, 354 355 "signal-handler": { 356 "agent", 357 "api-caller", 358 "api-config-watcher", 359 "dead-flag", 360 }, 361 "secret-drain-worker": { 362 "agent", 363 "api-caller", 364 "api-config-watcher", 365 "migration-fortress", 366 "migration-inactive-flag", 367 }, 368 }