github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/worker/deployer/unit_manifolds_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package deployer_test
     5  
     6  import (
     7  	"sort"
     8  
     9  	"github.com/juju/collections/set"
    10  	"github.com/juju/loggo"
    11  	"github.com/juju/testing"
    12  	jc "github.com/juju/testing/checkers"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/agent"
    16  	"github.com/juju/juju/cmd/jujud/agent/agenttest"
    17  	"github.com/juju/juju/worker/deployer"
    18  )
    19  
    20  type ManifoldsSuite struct {
    21  	testing.IsolationSuite
    22  
    23  	config deployer.UnitManifoldsConfig
    24  }
    25  
    26  var _ = gc.Suite(&ManifoldsSuite{})
    27  
    28  func (s *ManifoldsSuite) SetUpTest(c *gc.C) {
    29  	s.IsolationSuite.SetUpTest(c)
    30  	s.config = deployer.UnitManifoldsConfig{
    31  		Agent:          struct{ agent.Agent }{},
    32  		LoggingContext: loggo.NewContext(loggo.DEBUG),
    33  	}
    34  }
    35  
    36  func (s *ManifoldsSuite) TestStartFuncs(c *gc.C) {
    37  	manifolds := deployer.UnitManifolds(s.config)
    38  	for name, manifold := range manifolds {
    39  		c.Logf("checking %q manifold", name)
    40  		c.Check(manifold.Start, gc.NotNil)
    41  	}
    42  }
    43  
    44  func (s *ManifoldsSuite) TestManifoldNames(c *gc.C) {
    45  	manifolds := deployer.UnitManifolds(s.config)
    46  	expectedKeys := []string{
    47  		"agent",
    48  		"api-address-updater",
    49  		"api-caller",
    50  		"s3-caller",
    51  		"api-config-watcher",
    52  		"charm-dir",
    53  		"hook-retry-strategy",
    54  		"leadership-tracker",
    55  		"log-sender",
    56  		"logging-config-updater",
    57  		"meter-status",
    58  		"metric-collect",
    59  		"metric-sender",
    60  		"metric-spool",
    61  		"migration-fortress",
    62  		"migration-inactive-flag",
    63  		"migration-minion",
    64  		"uniter",
    65  		"upgrader",
    66  		"secret-drain-worker",
    67  	}
    68  	keys := make([]string, 0, len(manifolds))
    69  	for k := range manifolds {
    70  		keys = append(keys, k)
    71  	}
    72  	sort.Strings(keys)
    73  	c.Assert(keys, jc.SameContents, expectedKeys)
    74  }
    75  
    76  func (s *ManifoldsSuite) TestMigrationGuards(c *gc.C) {
    77  	exempt := set.NewStrings(
    78  		"agent",
    79  		"machine-lock",
    80  		"api-config-watcher",
    81  		"api-caller",
    82  		"s3-caller",
    83  		"log-sender",
    84  		"upgrader",
    85  		"migration-fortress",
    86  		"migration-minion",
    87  		"migration-inactive-flag",
    88  	)
    89  	manifolds := deployer.UnitManifolds(s.config)
    90  	for name, manifold := range manifolds {
    91  		c.Logf("%v [%v]", name, manifold.Inputs)
    92  		if !exempt.Contains(name) {
    93  			checkContains(c, manifold.Inputs, "migration-inactive-flag")
    94  			checkContains(c, manifold.Inputs, "migration-fortress")
    95  		}
    96  	}
    97  }
    98  
    99  func (s *ManifoldsSuite) TestManifoldsDependencies(c *gc.C) {
   100  	agenttest.AssertManifoldsDependencies(c,
   101  		deployer.UnitManifolds(s.config),
   102  		expectedUnitManifoldsWithDependencies,
   103  	)
   104  }
   105  
   106  func checkContains(c *gc.C, names []string, seek string) {
   107  	for _, name := range names {
   108  		if name == seek {
   109  			return
   110  		}
   111  	}
   112  	c.Errorf("%q not present in %v", seek, names)
   113  }
   114  
   115  var expectedUnitManifoldsWithDependencies = map[string][]string{
   116  
   117  	"agent": {},
   118  
   119  	"api-address-updater": {
   120  		"agent",
   121  		"api-caller",
   122  		"api-config-watcher",
   123  		"migration-fortress",
   124  		"migration-inactive-flag",
   125  	},
   126  
   127  	"api-caller": {"agent", "api-config-watcher"},
   128  
   129  	"api-config-watcher": {"agent"},
   130  
   131  	"charm-dir": {
   132  		"agent",
   133  		"api-caller",
   134  		"api-config-watcher",
   135  		"migration-fortress",
   136  		"migration-inactive-flag",
   137  	},
   138  
   139  	"hook-retry-strategy": {
   140  		"agent",
   141  		"api-caller",
   142  		"api-config-watcher",
   143  		"migration-fortress",
   144  		"migration-inactive-flag",
   145  	},
   146  
   147  	"leadership-tracker": {
   148  		"agent",
   149  		"api-caller",
   150  		"api-config-watcher",
   151  		"migration-fortress",
   152  		"migration-inactive-flag",
   153  	},
   154  
   155  	"log-sender": {"agent", "api-caller", "api-config-watcher"},
   156  
   157  	"logging-config-updater": {
   158  		"agent",
   159  		"api-caller",
   160  		"api-config-watcher",
   161  		"migration-fortress",
   162  		"migration-inactive-flag",
   163  	},
   164  
   165  	"meter-status": {
   166  		"agent",
   167  		"api-caller",
   168  		"api-config-watcher",
   169  		"migration-fortress",
   170  		"migration-inactive-flag",
   171  	},
   172  
   173  	"metric-collect": {
   174  		"agent",
   175  		"api-caller",
   176  		"api-config-watcher",
   177  		"charm-dir",
   178  		"metric-spool",
   179  		"migration-fortress",
   180  		"migration-inactive-flag",
   181  	},
   182  
   183  	"metric-sender": {
   184  		"agent",
   185  		"api-caller",
   186  		"api-config-watcher",
   187  		"metric-spool",
   188  		"migration-fortress",
   189  		"migration-inactive-flag",
   190  	},
   191  
   192  	"metric-spool": {
   193  		"agent",
   194  		"api-caller",
   195  		"api-config-watcher",
   196  		"migration-fortress",
   197  		"migration-inactive-flag",
   198  	},
   199  
   200  	"migration-fortress": {},
   201  
   202  	"migration-inactive-flag": {
   203  		"agent",
   204  		"api-caller",
   205  		"api-config-watcher"},
   206  
   207  	"migration-minion": {
   208  		"agent",
   209  		"api-caller",
   210  		"api-config-watcher",
   211  		"migration-fortress"},
   212  
   213  	"s3-caller": {
   214  		"agent",
   215  		"api-caller",
   216  		"api-config-watcher",
   217  	},
   218  
   219  	"uniter": {
   220  		"agent",
   221  		"api-caller",
   222  		"s3-caller",
   223  		"api-config-watcher",
   224  		"charm-dir",
   225  		"hook-retry-strategy",
   226  		"leadership-tracker",
   227  		"migration-fortress",
   228  		"migration-inactive-flag",
   229  	},
   230  
   231  	"upgrader": {
   232  		"agent",
   233  		"api-caller",
   234  		"api-config-watcher",
   235  	},
   236  	"secret-drain-worker": {
   237  		"agent",
   238  		"api-caller",
   239  		"api-config-watcher",
   240  		"migration-fortress",
   241  		"migration-inactive-flag",
   242  	},
   243  }